Any public officer or employee, in a criminal or civil action against the person arising from state employment, shall be entitled to petition the court for a court-appointed attorney to represent the person's interests in the matter. If the judge, after consideration of the petition, examination of the petitioner and receipt of such further evidence as the judge may require, determines that the petition has merit, the judge shall appoint an attorney to represent the interests of such public officer or employee. The court-appointed attorney shall represent such person at all stages, trial and appellate, until the final determination of the matter, unless the attorney is earlier released by such person or by the court. The court may first appoint an attorney from the Department of Justice. If the court determines that the Department is unable to represent such public officer or employee, the court may appoint an attorney from the Office of Defense Services in criminal actions only, and in civil actions may appoint an attorney licensed in this State. This section shall also apply to all federal courts within this State.