/**
 *  Get rna id from Locus Link id
 *  Internet robot, LocusLink2RNA, that uses form, located in page
 *  http://www.ncbi.nlm.nih.gov/entrez/.
 *  It is your responsibility to find and cite appropriate references
 *  from this page.
 *  Generated 2002.8.9  by Sight 2.0, Ulm university.
 */
package impl.ext;

import Sight.Agents.*;
import Sight.Agents.Redirectors.*;
import Sight.Structures.*;
import Sight.dds.*;
import Sight.tools.xSignature.*;
import java.io.*;
import Sight.Agents.util.*;

public class LocusLink2RNA extends Sight.Agents.Prototypes.signatureBasedAgent implements Serializable {
 /* Data structure to pass query to this robot. */
  public class Request extends Sight.Request implements java.io.Serializable {
   /** default=4891 */
   public String Id="4891"; // Parameter
       /** Submit request, compute key by SHA digesting algorithm. */
       public Sight.Agents.Request submit() { return Sight.Agents.Request.submit(Public, this, getKey()); };
       /** Submit request with the known key. */
       public Sight.Agents.Request submit(String key)
        { return Sight.Agents.Request.submit(Public, this, key); };
       };

  public static String convert(String li)
   {
    try {
     Request a = getDefaultRequest();
     a.Id = li;
     Result r = (Result) Public.go(a, li);
     if (r==null) return null;
     if (r.a.length<1) return null;
     String rt = r.a[0].rna_Id.toString();
     Public.p(li+" to "+rt);
     return rt;
     } catch (Exception exc)
       {
         Sight.io.Output.e(exc);
         return null;
       }
   };

   /** Get the AMap data structure, required by post method. */
  protected AMap getFormParameters(Object req) {
    Request request = (Request) req;
    AMap map = new AMap();
    map.add("url:identifier", request.Id); // Parameter
    map.add("connect:master", "http://www.ncbi.nlm.nih.gov/entrez/"); // connect
    map.add("connect:action", "get"); // connect
    map.add("url:prefix", "http://www.ncbi.nlm.nih.gov/LocusLink/LocRpt.cgi?l="); // connect
    map.add("url:suffix", ""); // connect
    return map; };
  /** Get default request for this robot. */
  public static Request getDefaultRequest() {
     return Public.getRequest(); }
  private Request getRequest() { return new Request(); }; // must be non static

    /** Type definitions for Request. */
   public dStructure getRequestDds() {
    return new Sight.dds.Records(false,
     new dField[] {
        new dField("Id","CharSequence",null,"4891")                 }
    );
   }
 /* Record type, used in results for this robot. */
 /* The result of this robot is an array of records. */
  public static class Record extends Sight.Record implements Serializable {
        public CharSequence rna_Id;
      };
      /** The result of this robot. */
      public static class Result extends Sight.Result implements Serializable {
         public Record[] a; // array of results.
         /** Create report for one record. */
         public CharSequence getReportForRecord(Object ro, int level)
          { Record r = (Record) ro;
           switch (level) {
              case 0:  return ""+r.rna_Id+" ";
              case 1:  return ""+r.rna_Id+" ";
              default: return ""+" : "+r.rna_Id+" ";
            }
          };
      }

    /** Type definitions for Result. */
   public dStructure getResultDds() {
    return new Sight.dds.Records(true,
     new dField[] {
        new dField("rna_Id","CharSequence",null,"")                 }
    );
   }

  public Sight.Record createRecord(String[] row) throws Exception
    { return fillRecord(row); };
  public Class getRecordClass() { return Record.class; };
   Record fillRecord(String[] fields) throws Exception {
        Record r = new Record();
        r.rna_Id=fields[0];
        return r;
   };

   /** Get result from the given html content. */
  public Sight.Result resultFromString(String html) throws Exception {
     Result r = new Result();
     r.a = (Record[]) createResultArray(html);
     return r;
   };
  public LocusLink2RNA() { signatures = new multiSignatures();
   signatures.far_start="Annotated transcripts/proteins for this locus:";
   signatures.top=null;
   signatures.bottom=null;
   signatures.signatures =
   new Signature[] {
   new Signature("mRNA:</th>\n <td align=left valign=top ><a href=\"http://www.ncbi.nlm.nih.gov/entrez/viewer.cgi?val=","&db=Nucleotide&dopt=GenBank\"")
   };
   setDescription("Get rna id from Locus Link id");
   setFormURL("http://www.ncbi.nlm.nih.gov/entrez/");
   setMasterURL("http://www.ncbi.nlm.nih.gov/entrez/");
   // define pre scan section.
   preScan = new preScan();
   };
  /** Public instance of agent for user. */
  public static LocusLink2RNA Public = new LocusLink2RNA();
  public static Agent getAvailableAgent() { return Public; };
  /** main(..) method provided to check robot, launching it
   * as standalone program. */
  public static void main(String[] args) {
  Sight.Agents.util.Pind.showConsoles();
      try {
        Request request = getDefaultRequest();
        // Now modify and assign request fields in accordance with task:
        Sight.Agents.Request submission = request.submit();
        // processing now started in separate thread:
        Result response = (Result) submission.getResult();
        // print report, verbosity level 2:
        System.out.println(response.getReport(2));
      } catch (Exception exc)
         { if (exc!=null) System.out.println(exc.getMessage());
           exc.printStackTrace();
         };
   }
;
  }