1 /********************************************************************
2 *
3 *  This library is free software; you can redistribute it and/or
4 *  modify it under the terms of the GNU Library General Public
5 *  License as published by the Free Software Foundation; either
6 *  version 2 of the License, or (at your option) any later version.
7 *
8 *  This library is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 *  Library General Public License for more details.
12 *
13 *  You should have received a copy of the GNU Library General Public
14 *  License along with this library; if not, write to the
15 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 *  Boston, MA  02111-1307, USA.
17 *
18 *  @author: Copyright (C) Alan Bleasby
19 *
20 ********************************************************************/
21 
22 package org.emboss.jemboss.server;
23 
24 
25 /**
26 *
27 * Used with JNI to access EMBOSS ajax library.
28 * This is used to determine sequence attributes and
29 * authenticate the server methods.
30 *
31 */
32 public class Ajax
33 {
34 
35   /** true if the sequence is protein */
36   public static boolean protein;
37   /** sequence length */
38   public static int     length;
39   /** sequence weight */
40   public static float   weight;
41 
42   /** determine sequence attributes     */
seqType(String usa)43   public native boolean seqType(String usa);
44   /** determine sequence set attributes */
seqsetType(String usa)45   public native boolean seqsetType(String usa);
46 
47   /** true if the sequence is protein */
48   public boolean protein_soap;
49   /** sequence length */
50   public int     length_soap;
51   /** sequence weight */
52   public float   weight_soap;
53 
54   /** determine sequence attributes as the user */
seqAttrib(String username, byte[] password, String environment, String usa)55   public native boolean seqAttrib(String username,
56                byte[] password, String environment,
57                String usa);
58   /** determine sequence set attributes as the user */
seqsetAttrib(String username, byte[] password, String environment, String usa)59   public native boolean seqsetAttrib(String username,
60                byte[] password, String environment,
61                String usa);
62 
63   /** user home dir */
64   public String home;
65 
66   /** authentication method */
userAuth(String username, byte[] password, String environment)67   public synchronized native boolean userAuth(String username,
68           byte[] password, String environment);
69   /** fork emboss proceess */
forkEmboss(String username, byte[] password, String environment, String commandline, String directory)70   public synchronized native boolean forkEmboss(String username,
71                byte[] password, String environment,
72                String commandline, String directory);
73   /** fork emboss batch proceess */
forkBatch(String username, byte[] password, String environment, String commandline, String directory)74   public synchronized native boolean forkBatch(String username,
75                byte[] password, String environment,
76                String commandline, String directory);
77   /** make a directory */
makeDir(String username, byte[] password, String environment, String directory)78   public synchronized native boolean makeDir(String username,
79                byte[] password, String environment,
80                String directory);
81   /** delete a file */
delFile(String username, byte[] password, String environment, String filename)82   public synchronized native boolean delFile(String username,
83                byte[] password, String environment,
84                String filename);
85   /** rename a file */
renameFile(String username, byte[] password, String environment, String filename, String filename2)86   public synchronized native boolean renameFile(String username,
87                byte[] password, String environment,
88                String filename, String filename2);
89   /** delete a directory */
delDir(String username, byte[] password, String environment, String directory)90   public synchronized native boolean delDir(String username,
91                byte[] password, String environment,
92                String directory);
93   /** list files in a directory */
listFiles(String username, byte[] password, String environment, String directory)94   public synchronized native boolean listFiles(String username,
95                byte[] password, String environment,
96                String directory);
97   /** list directorys */
listDirs(String username, byte[] password, String environment, String directory)98   public synchronized native boolean listDirs(String username,
99                byte[] password, String environment,
100                String directory);
101   /** get the contents of a file */
getFile(String username, byte[] password, String environment, String filename)102   public synchronized native byte[] getFile(String username,
103                byte[] password, String environment,
104                String filename);
105   /** create a file */
putFile(String username, byte[] password, String environment, String filename, byte[] bytearray)106   public synchronized native boolean putFile(String username,
107                byte[] password, String environment,
108                String filename, byte[] bytearray);
109 
110   /** stdout */
111   private String outStd;
112   /** stderr */
113   private String errStd;
114   private int size;
115   private int prnt;
116   private int fileok;
117 
118 //public native boolean fork(String cmdLine, String envp,
119 //                        String dir, int uid, int gid);
120 
121   static
122   {
123     try
124     {
125       System.loadLibrary("ajax");
126     }
127     catch(UnsatisfiedLinkError e)
128     {
129       e.printStackTrace();
130       if(e.getMessage().indexOf("already loaded in another classloader")
131                                != -1)
132       {
133         System.err.println(e);
134         System.err.println("Please check whether tomcat server started using" +
135         		"the tomstart script generated by the install script.");
136       }
137       else
138         throw e;
139     }
140   }
141 
142   /**
143   *
144   * Sets the sequence length
145   * @param length	 sequence length
146   *
147   */
setLength(int length)148   public void setLength(int length)
149   {
150     Ajax.length = length;
151   }
152 
153   /**
154   *
155   * Sets the sequence weight
156   * @param weight 	sequence weight
157   *
158   */
setWeight(float weight)159   public void setWeight(float weight)
160   {
161     Ajax.weight = weight;
162   }
163 
164   /**
165   *
166   * Sets whether sequence is protein (true)
167   * @param protein 	sequence type
168   *
169   */
setProtein(boolean protein)170   public void setProtein(boolean protein)
171   {
172     Ajax.protein = protein;
173   }
174 
175   /**
176   *
177   * Get the stdout
178   * @return 	stdout
179   *
180   */
getOutStd()181   public String getOutStd()
182   {
183     return outStd;
184   }
185 
186   /**
187   *
188   * Get the stderr
189   * @return     stderr
190   *
191   */
getErrStd()192   public String getErrStd()
193   {
194     return errStd;
195   }
196 
197   /**
198   *
199   * Clear the stderr
200   *
201   */
setErrStd()202   public void setErrStd()
203   {
204     errStd = new String();
205   }
206 
207   /**
208   *
209   *
210   *
211   */
getSize()212   public int getSize()
213   {
214     return size;
215   }
216 
getPrnt()217   public int getPrnt()
218   {
219     return prnt;
220   }
221 
getFileok()222   public int getFileok()
223   {
224     return fileok;
225   }
226 
227 }
228 
229