b9580b50c752cc5bf368ed1db8614ece1d1f5f2b
[jalview.git] / src / ext / jemboss / JembossParams.java
1 /***************************************************************
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program 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
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 *
17 *  @author: Copyright (C) Tim Carver
18 *
19 ***************************************************************/
20
21 package ext.jemboss;
22
23 import java.util.*;
24 import java.io.FileInputStream;
25 import java.io.FileOutputStream;
26 import java.net.InetAddress;
27
28
29 /**
30 *
31 * Contains all property information about the client
32 * and the server.
33 *
34 */
35 public class JembossParams
36 {
37
38 /** denotes a server is OK             */
39   static public final int SERVER_OK = 0;
40 /** denotes a server is giving errors  */
41   static public final int SERVER_ERR = 1;
42 /** denotes a server is not responding */
43   static public final int SERVER_DOWN = 2;
44
45   // these are the things that could be set
46   private boolean useHTTPSProxy = false;
47   private String useHTTPSProxyName = "useHTTPSProxy";
48
49   private boolean useProxy = false;
50   private String useProxyName = "proxy.use";
51
52   private String proxyHost = "wwwcache";
53   private String proxyHostName = "proxy.host";
54
55   private int proxyPortNum = 8080;
56   private String proxyPortNumName = "proxy.port";
57
58 //browser proxy
59
60   /** use a separate proxy for browsing the web                        */
61   private boolean useBrowserProxy = false;
62   /** property name for using separate proxy for browsing the web */
63   private String useBrowserProxyName = "browserProxy.use";
64   /** browser proxy host                   */
65   private String browserProxyHost = "wwwcache";
66   /** property name for browser proxy host  */
67   private String browserProxyHostName = "browserProxy.host";
68   /** browser proxy port                   */
69   private int browserProxyPort = 8080;
70   /** property name for browser proxy port */
71   private String browserProxyPortName = "browserProxy.port";
72
73   private boolean useTFM;
74   private String useTFMName = "tfm.use";
75
76   /** use proxy authentication                          */
77   private boolean useProxyAuth = false;
78   /** property name for using proxy authentication */
79   private String useProxyAuthName = "proxy.auth";
80
81   private String proxyAuthUser = "";
82   private String proxyAuthUserName = "proxy.user";
83
84   private String proxyAuthPasswd = "";
85   private String proxyAuthPasswdName = "proxy.passwd";
86
87   private boolean proxyOverride = false;
88   private String proxyOverrideName = "proxy.override";
89
90   /** use unix authentication to run applications on the server */
91   private boolean useAuth = false;
92   /** property name for using unix authentication               */
93   private String useAuthName = "user.auth";
94
95   /** public services URL                    */
96   private String publicSoapURL =
97              "http://anaplog.compbio.dundee.ac.uk:8080/axis/services";
98   /** property name for public services URL  */
99   private String publicSoapURLName = "server.public";
100
101   /** private services URL                   */
102   private String privateSoapURL =
103              "http://anaplog.compbio.dundee.ac.uk:8080/axis/services";
104   /** property name for private services URL */
105   private String privateSoapURLName = "server.private";
106
107   /** service name */
108   private String soapService = "JembossServer";
109   /** property name for service name */
110   private String soapServiceName = "VAMSAS Services";
111
112   /** private service name                   */
113   private String privateSoapService = "JembossServer";
114   /** property name for private service name */
115   private String privateSoapServiceName = "VAMSAS Services";
116
117   /** public service name                    */
118   private String publicSoapService = "JembossServer";
119   /** property name for public service name  */
120   private String publicSoapServiceName = "VAMSAS Services";
121
122   //soap options
123   private boolean debug = false;
124   private String debugName = "jemboss.debug";
125
126   /** batch mode support                   */
127   private boolean hasBatchMode = true;
128   /** property name for batch mode support */
129   private String hasBatchModeName = "jemboss.hasbatchmode";
130   /** interactive mode support                   */
131   private boolean hasInteractiveMode = true;
132   /** property name for interactive mode support */
133   private String hasInteractiveModeName = "jemboss.hasinteractivemode";
134   /** current mode for running an application    */
135   private String currentMode = "interactive";
136   /** property name for current mode             */
137   private String currentModeName = "jemboss.mode";
138
139   // server lists for redundancy
140   private String serverPublicList = "";
141   private String serverPublicListName = "server.publiclist";
142
143   private String serverPrivateList = "";
144   private String serverPrivateListName = "server.privatelist";
145
146   // we don't remember these perhaps we should for captive systems
147   private String serviceUserName = "jalview";
148   private String serviceUserNameName = "user.name";
149   private char[] servicePasswd = null;
150   /** services password */
151   private byte[] servicePasswdByte = null;
152
153   Properties jembossSettings;
154
155   // Internal flags to help in the dynamic evaluation of properties
156   private boolean useJavaProxy = false;
157   private String javaProxyPort = "";
158   private String javaProxyHost = "";
159   private boolean useJavaNoProxy = false;
160   private String javaNoProxy = "";
161   private Vector javaNoProxyEntries;
162   private int javaProxyPortNum = 8080;
163
164   // structures for server redundancy
165   private boolean publicServerFailOver = false;
166   private boolean privateServerFailOver = false;
167   private Hashtable serverStatusHash;
168   private Vector publicServers;
169   private Vector privateServers;
170
171   /** Jemboss java server                   */
172   private static boolean jembossServer = false;
173   /** property name for Jemboss java server */
174   private String jembossServerName = "jemboss.server";
175
176   /** cygwin */
177   private static String cygwin = null;
178   /** property name for Jemboss java server */
179   private String cygwinName = "cygwin";
180
181   //EMBOSS directories
182   /** plplot library location                            */
183   private String plplot = "/usr/local/share/EMBOSS/";
184   /** property name for plplot library location          */
185   private String plplotName = "plplot";
186   /** emboss data location                               */
187   private String embossData = "/usr/local/share/EMBOSS/data/";
188   /** property name for emboss data location             */
189   private String embossDataName = "embossData";
190   /** emboss binary location                             */
191   private String embossBin = "/usr/local/bin/";
192   /** property name for emboss binary location           */
193   private String embossBinName = "embossBin";
194   /** emboss path environment variable                   */
195   private String embossPath = "/usr/bin/:/bin";
196   /** property name for emboss path environment variable */
197   private String embossPathName = "embossPath";
198   /** emboss environment                                 */
199   private String embossEnvironment = "";
200   /** property name for emboss environment               */
201   private String embossEnvironmentName = "embossEnvironment";
202   /** acd file location                                  */
203   private String acdDirToParse = "/usr/local/share/EMBOSS/acd/";
204   /** property name for acd file location                */
205   private String acdDirToParseName = "acdDirToParse";
206
207   //EMBOSS Application pages
208   /** documentation URL                      */
209   private String embURL = "http://www.uk.embnet.org/Software/EMBOSS/Apps/";
210   /** property name for documentation URL    */
211   private String embossURL = "embossURL";
212
213   // user properties
214   /** user home directory                    */
215   private String userHome = System.getProperty("user.home");
216   /** property name for user home directory  */
217   private String userHomeName = "user.home";
218
219
220 /**
221 *
222 * Loads and holds the properties
223 *
224 */
225   public JembossParams()
226   {
227     Properties defaults = new Properties();
228     ClassLoader cl = this.getClass().getClassLoader();
229
230     // initialize data structures
231     serverStatusHash = new Hashtable();
232     publicServers = new Vector();
233     privateServers = new Vector();
234
235     // initialize settings from table above
236     defaults.put(userHomeName,userHome);
237     defaults.put(embossURL,embURL);
238     defaults.put(plplotName,plplot);
239     defaults.put(embossDataName,embossData);
240     defaults.put(embossBinName,embossBin);
241     defaults.put(embossPathName,embossPath);
242     defaults.put(embossEnvironmentName,embossEnvironment);
243     defaults.put(acdDirToParseName,acdDirToParse);
244
245     defaults.put(useBrowserProxyName, new Boolean(useBrowserProxy).toString());
246     defaults.put(browserProxyHostName,browserProxyHost);
247     defaults.put(browserProxyPortName,new Integer(browserProxyPort).toString());
248
249     defaults.put(useTFMName,new Boolean(useTFM).toString());
250
251     defaults.put(useProxyName, new Boolean(useProxy).toString());
252     defaults.put(useHTTPSProxyName, new Boolean(useHTTPSProxy).toString());
253     defaults.put(proxyHostName,proxyHost);
254     defaults.put(proxyPortNumName, new Integer(proxyPortNum).toString());
255     defaults.put(useProxyAuthName, new Boolean(useProxyAuth).toString());
256     defaults.put(proxyAuthUserName, proxyAuthUser);
257     defaults.put(proxyAuthPasswdName, proxyAuthPasswd);
258     defaults.put(proxyOverrideName, new Boolean(proxyOverride).toString());
259     defaults.put(useAuthName, new Boolean(useAuth).toString());
260     defaults.put(publicSoapURLName, publicSoapURL);
261     defaults.put(privateSoapURLName, privateSoapURL);
262     defaults.put(privateSoapServiceName, privateSoapService);
263     defaults.put(publicSoapServiceName, publicSoapService);
264     defaults.put(debugName, new Boolean(debug).toString());
265     defaults.put(hasBatchModeName, new Boolean(hasBatchMode).toString());
266     defaults.put(hasInteractiveModeName, new Boolean(hasInteractiveMode).toString());
267     defaults.put(currentModeName, currentMode);
268     defaults.put(serverPublicListName, serverPublicList);
269     defaults.put(serverPrivateListName, serverPrivateList);
270     defaults.put(serviceUserNameName, serviceUserName);
271
272     // load into real settings
273     jembossSettings = new Properties(defaults);
274
275     // try out of the classpath
276     try
277     {
278       jembossSettings.load(cl.getResourceAsStream("resources/jemboss.properties"));
279     }
280     catch (Exception e)
281     {
282       if(debug)
283         System.out.println("Didn't find properties file in classpath.");
284     }
285
286     // override with local system settings
287     loadIn(System.getProperty("user.dir"));
288
289     // override with local user settings
290     loadIn(System.getProperty("user.home"));
291
292     // update our settings
293     updateSettingsFromProperties();
294
295     if(System.getProperty("useHTTPSProxy") != null)
296       if(System.getProperty("useHTTPSProxy").equalsIgnoreCase("true"))
297         useHTTPSProxy=true;
298
299     // set up for overrides
300     javaNoProxyEntries = new Vector();
301     if(System.getProperty("proxyPort") != null)
302     {
303       if(System.getProperty("proxyHost") != null)
304       {
305         useJavaProxy = true;
306         useProxy = useJavaProxy;
307         useBrowserProxy = useJavaProxy;
308
309         javaProxyPort = System.getProperty("proxyPort");
310         javaProxyPortNum = Integer.parseInt(javaProxyPort);
311         javaProxyHost = System.getProperty("proxyHost");
312
313         browserProxyHost = javaProxyHost;
314         browserProxyPort = javaProxyPortNum;
315
316         if(System.getProperty("http.nonProxyHosts") != null)
317         {
318           useJavaNoProxy = true;
319           javaNoProxy = System.getProperty("http.nonProxyHosts");
320           StringTokenizer tok = new StringTokenizer(javaNoProxy,"|");
321           while (tok.hasMoreTokens())
322           {
323             String toks = tok.nextToken() + "/";
324             javaNoProxyEntries.add(toks);
325           }
326         }
327       }
328     }
329
330   }
331
332   /**
333   *
334   * Load a property from the jemboss.property file.
335   * @param folder       location of jemboss.property
336   *
337   */
338   private void loadIn(String folder)
339   {
340     FileInputStream in = null;
341     try
342     {
343       String fs = System.getProperty("file.separator");
344       in = new FileInputStream(folder + fs + "jemboss.properties");
345       jembossSettings.load(in);
346     }
347     catch (java.io.FileNotFoundException e)
348     {
349       in = null;
350       if(debug)
351         System.out.println("Can't find properties file in"+folder+"."+
352                            " Using defaults.");
353     }
354     catch (java.io.IOException e)
355     {
356       if(debug)
357         System.out.println("Can't read properties file. " +
358                            "Using defaults.");
359     }
360     finally
361     {
362       if (in != null)
363       {
364         try { in.close(); } catch (java.io.IOException e) { }
365         in = null;
366       }
367     }
368
369   }
370
371   /**
372   *
373   * Update the property settings for jembossSettings.
374   *
375   */
376   protected void updateSettingsFromProperties()
377   {
378
379     try
380     {
381       String tmp;
382
383       userHome = jembossSettings.getProperty(userHomeName);
384       embURL = jembossSettings.getProperty(embossURL);
385       plplot = jembossSettings.getProperty(plplotName);
386       embossData = jembossSettings.getProperty(embossDataName);
387       embossBin = jembossSettings.getProperty(embossBinName);
388       embossPath = jembossSettings.getProperty(embossPathName);
389       embossEnvironment = jembossSettings.getProperty(embossEnvironmentName);
390       acdDirToParse = jembossSettings.getProperty(acdDirToParseName);
391       tmp = jembossSettings.getProperty(jembossServerName);
392       jembossServer = new Boolean(tmp).booleanValue();
393
394       cygwin = jembossSettings.getProperty(cygwinName);
395
396       tmp = jembossSettings.getProperty(useHTTPSProxyName);
397       useHTTPSProxy = new Boolean(tmp).booleanValue();
398       tmp = jembossSettings.getProperty(useProxyName);
399       useProxy = new Boolean(tmp).booleanValue();
400       proxyHost = jembossSettings.getProperty(proxyHostName);
401       tmp = jembossSettings.getProperty(proxyPortNumName);
402       proxyPortNum = Integer.parseInt(tmp);
403
404       tmp = jembossSettings.getProperty(useBrowserProxyName);
405       useBrowserProxy = new Boolean(tmp).booleanValue();
406       browserProxyHost = jembossSettings.getProperty(browserProxyHostName);
407       tmp = jembossSettings.getProperty(browserProxyPortName);
408       browserProxyPort = Integer.parseInt(tmp);
409
410       tmp = jembossSettings.getProperty(useTFMName);
411       useTFM = new Boolean(tmp).booleanValue();
412
413       tmp = jembossSettings.getProperty(useProxyAuthName);
414       useProxyAuth = new Boolean(tmp).booleanValue();
415       proxyAuthUser = jembossSettings.getProperty(proxyAuthUserName);
416       proxyAuthPasswd = jembossSettings.getProperty(proxyAuthPasswdName);
417       tmp = jembossSettings.getProperty(proxyOverrideName);
418       proxyOverride = new Boolean(tmp).booleanValue();
419       tmp = jembossSettings.getProperty(useAuthName);
420       useAuth = new Boolean(tmp).booleanValue();
421       publicSoapURL = jembossSettings.getProperty(publicSoapURLName);
422       privateSoapURL = jembossSettings.getProperty(privateSoapURLName);
423       soapService = jembossSettings.getProperty(soapServiceName);
424       privateSoapService = jembossSettings.getProperty(privateSoapServiceName);
425       publicSoapService = jembossSettings.getProperty(publicSoapServiceName);
426       tmp = jembossSettings.getProperty(debugName);
427       debug = new Boolean(tmp).booleanValue();
428       tmp = jembossSettings.getProperty(hasBatchModeName);
429       hasBatchMode = new Boolean(tmp).booleanValue();
430       tmp = jembossSettings.getProperty(hasInteractiveModeName);
431       hasInteractiveMode = new Boolean(tmp).booleanValue();
432       currentMode = jembossSettings.getProperty(currentModeName);
433       serverPublicList = jembossSettings.getProperty(serverPublicListName);
434       serverPrivateList = jembossSettings.getProperty(serverPrivateListName);
435 //    serviceUserName = jembossSettings.getProperty(serviceUserNameName);
436     }
437     catch (Exception e) {  }
438   }
439
440 /**
441 *
442 * Initialize the server redundancy data. This is a separate
443 * method because the server info might not be initialized in
444 * the constructor, but may be imported later from the command line.
445 *
446 */
447   protected void setupServerRedundancy()
448   {
449     if (!serverPublicList.equals(""))
450     {
451       if(debug)
452         System.out.println("JembossParams: Redundant public servers\n  "
453                            +serverPublicList);
454
455       publicServerFailOver = true;
456       StringTokenizer tok = new StringTokenizer(serverPublicList,"|");
457       while (tok.hasMoreTokens())
458       {
459         String toks = tok.nextToken();
460         publicServers.add(toks);
461         if(debug)
462           System.out.println(" Entry " + toks);
463
464         serverStatusHash.put(toks, new Integer(SERVER_OK));
465       }
466     }
467
468     if(!serverPrivateList.equals(""))
469     {
470       if(debug)
471         System.out.println("JembossParams: Redundant private servers\n  "
472                            +serverPrivateList);
473
474       privateServerFailOver = true;
475       StringTokenizer tok = new StringTokenizer(serverPrivateList,"|");
476       while (tok.hasMoreTokens())
477       {
478         String toks = tok.nextToken();
479         privateServers.add(toks);
480         if(debug)
481           System.out.println(" Entry " + toks);
482
483         serverStatusHash.put(toks,new Integer(SERVER_OK));
484       }
485     }
486   }
487
488
489 /**
490 *
491 * If using a proxy server
492 *
493 */
494   public boolean getUseProxy()
495   {
496     return useProxy;
497   }
498
499
500 /**
501 *
502 * If using an https proxy server
503 *
504 */
505   public boolean getUseHTTPSProxy()
506   {
507     return useHTTPSProxy;
508   }
509
510
511 /**
512 *
513 * If using a proxy server for a given URL
514 * @param s      the URL we wish to connect to
515 *
516 */
517   public boolean getUseProxy(String s)
518   {
519     if(proxyOverride)
520       return useProxy;
521     else
522     {
523       if(!useJavaProxy)
524         return useProxy;
525       else
526       {
527         boolean jp = true;
528         if (useJavaNoProxy)
529         {
530           int ip = javaNoProxyEntries.size();
531           for(int j = 0 ; j<ip ; ++j)
532             if(s.indexOf((String)javaNoProxyEntries.get(j).toString()) != -1)
533               jp = false;
534         }
535         return jp;
536       }
537     }
538   }
539
540 /**
541 *
542 * The name of the proxy server
543 * @return       name of the proxy host
544 *
545 */
546   public String getProxyHost()
547   {
548     if (proxyOverride)
549       return proxyHost;
550     else
551     {
552       if(!useJavaProxy)
553         return proxyHost;
554       else
555         return javaProxyHost;
556     }
557   }
558
559 /**
560 *
561 * The port the proxy server listens on
562 * @return       proxy port number
563 *
564 */
565   public int getProxyPortNum()
566   {
567     if(proxyOverride)
568       return proxyPortNum;
569     else
570     {
571       if(!useJavaProxy)
572         return proxyPortNum;
573       else
574         return javaProxyPortNum;
575     }
576   }
577
578 /**
579 *
580 * Determine if the a proxy server is being used for web browsing
581 * @return       true if using a proxy server for the browser
582 *
583 */
584   public boolean isBrowserProxy()
585   {
586     return useBrowserProxy;
587   }
588
589 /**
590 *
591 * Get the name of the proxy server for the browser
592 * @return       the name of the proxy host
593 *
594 */
595   public String getBrowserProxyHost()
596   {
597     return browserProxyHost;
598   }
599
600
601 /**
602 *
603 * The port number of the proxy server for the browser
604 * @return       proxy port number
605 *
606 */
607   public int getBrowserProxyPort()
608   {
609     return browserProxyPort;
610   }
611
612
613   public boolean isUseTFM() { return useTFM; }
614
615
616 /**
617 *
618 * If using authenticate with the proxy
619 * @return       true if unix authentication used
620 *
621 */
622   public boolean getUseProxyAuth()
623   {
624     return useProxyAuth;
625   }
626
627 /**
628 *
629 * Username needed to use for the proxy server
630 *
631 */
632   public String getProxyAuthUser()
633   {
634     return proxyAuthUser;
635   }
636
637 /**
638 *
639 * Password needed to use for the proxy server
640 *
641 */
642   public String getProxyAuthPasswd()
643   {
644     return proxyAuthPasswd;
645   }
646
647 /**
648 *
649 * A description of the proxy settings
650 * @return       a description of the proxy settings
651 *
652 */
653   public String proxyDescription()
654   {
655     String pdesc = "";
656     if (proxyOverride)
657     {
658       if(useProxy)
659       {
660         String spnum = new Integer(proxyPortNum).toString();
661         pdesc = "Current Settings: " + "Proxy Host: " + proxyHost +
662                                            " Proxy Port: " + spnum;
663       }
664       else
665         pdesc = "No proxies, connecting direct.";
666     }
667     else
668     {
669       if (useJavaProxy)
670       {
671         pdesc = "Settings Imported from Java: " + "Proxy Host: " + javaProxyHost
672                                               + " Proxy Port: " + javaProxyPort;
673         if(useJavaNoProxy)
674           pdesc = pdesc + "\nNo Proxy On: " + javaNoProxy;
675       }
676       else
677       {
678         if(useProxy)
679         {
680           String spnum = new Integer(proxyPortNum).toString();
681           pdesc = "Current Settings: " + "Proxy Host: " + proxyHost +
682                                              " Proxy Port: " + spnum;
683         }
684         else
685           pdesc = "No proxies, connecting direct.";
686       }
687     }
688     return pdesc;
689   }
690
691 /**
692 *
693 * Whether the main service requires authentication
694 * @return       true if the server is using unix authentication
695 *
696 */
697   public boolean getUseAuth()
698   {
699     return useAuth;
700   }
701
702 /**
703 *
704 * Returns the URL of the public soap server
705 * @return       the public services URL
706 *
707 */
708   public String getPublicSoapURL()
709   {
710     return publicSoapURL;
711   }
712
713 /**
714 *
715 *  @return      true if using a Jemboss server
716 *
717 */
718   public static boolean isJembossServer()
719   {
720     return jembossServer;
721   }
722
723 /**
724 *
725 *  @return      true if using cygwin
726 *
727 */
728   public static boolean isCygwin()
729   {
730     if(cygwin == null || cygwin.equals(""))
731       return false;
732     else
733       return true;
734   }
735
736
737 /**
738 *
739 *  Get the cygwin root
740 *  @return      cygwin root
741 *
742 */
743   public String getCygwinRoot()
744   {
745     return cygwin;
746   }
747
748
749
750 /**
751 *
752 * Get the location of plplot
753 * @return       the location of plplot
754 *
755 */
756   public String getPlplot()
757   {
758     return plplot;
759   }
760
761 /**
762 *
763 * Get the user home directory
764 * @return       the user home directory
765 *
766 */
767   public String getUserHome()
768   {
769     return userHome;
770   }
771
772 /**
773 *
774 * Set the user home directory property
775 * @param s      the user home directory
776 *
777 */
778   public void setUserHome(String s)
779   {
780     userHome = s;
781   }
782
783 /**
784 *
785 * @return       the documentation URL
786 *
787 */
788   public String getembURL()
789   {
790     return embURL;
791   }
792
793 /**
794 *
795 * @return       the location of the emboss data
796 *
797 */
798   public String getEmbossData()
799   {
800     return embossData;
801   }
802
803 /**
804 *
805 * @return       the location of the emboss binaries
806 *
807 */
808   public String getEmbossBin()
809   {
810     return embossBin;
811   }
812
813 /**
814 *
815 * Get the path for emboss
816 * @return       the path for emboss
817 *
818 */
819   public String getEmbossPath()
820   {
821     return embossPath;
822   }
823
824 /**
825 *
826 * Get the environment for emboss
827 * @return       the environment for emboss
828 *
829 */
830   public String getEmbossEnvironment()
831   {
832     embossEnvironment = embossEnvironment.trim();
833     embossEnvironment = embossEnvironment.replace(':',' ');
834     embossEnvironment = embossEnvironment.replace(',',' ');
835     return embossEnvironment;
836   }
837
838 /**
839 *
840 * Get the emboss environment as a String array
841 * @return       the emboss environment as a String array
842 *
843 */
844   public String[] getEmbossEnvironmentArray(String[] envp)
845   {
846     embossEnvironment = embossEnvironment.trim();
847     embossEnvironment = embossEnvironment.replace(':',' ');
848     embossEnvironment = embossEnvironment.replace(',',' ');
849
850     if(embossEnvironment.equals(""))
851       return envp;
852
853     StringTokenizer st = new StringTokenizer(embossEnvironment," ");
854     int n=0;
855     while(st.hasMoreTokens())
856     {
857       st.nextToken();
858       n++;
859     }
860
861     int sizeEnvp = envp.length;
862     String environ[] = new String[n+sizeEnvp];
863     st = new StringTokenizer(embossEnvironment," ");
864     for(int i=0;i<sizeEnvp;i++)
865       environ[i] = envp[i];
866
867     n=sizeEnvp;
868     while(st.hasMoreTokens())
869     {
870       environ[n] = new String(st.nextToken());
871       n++;
872     }
873
874     return environ;
875   }
876
877 /**
878 *
879 * Acd file location
880 * @return       acd file location
881 *
882 */
883   public String getAcdDirToParse()
884   {
885     return acdDirToParse;
886   }
887
888 /**
889 *
890 * Set the URL of the public soap server
891 * @param s      URL of the public services
892 *
893 */
894   public void setPublicSoapURL(String s)
895   {
896     publicSoapURL = s;
897   }
898
899 /**
900 *
901 * Returns the URL of the private soap server
902 * @return       URL of the private services
903 *
904 */
905   public String getPrivateSoapURL()
906   {
907     return privateSoapURL;
908   }
909
910 /**
911 *
912 * Set the URL of the private soap server
913 * @param s      URL of the private services
914 *
915 */
916   public void setPrivateSoapURL(String s)
917   {
918     privateSoapURL = s;
919   }
920
921 /**
922 *
923 * Return whether we have failover on the public server
924 *
925 */
926   public boolean getPublicServerFailover()
927   {
928     return publicServerFailOver;
929   }
930
931 /**
932 *
933 * Return whether we have failover on the private server
934 *
935 */
936   public boolean getPrivateServerFailover()
937   {
938     return privateServerFailOver;
939   }
940
941 /**
942 *
943 * Return a vector containing the list of public servers
944 *
945 */
946   public Vector getPublicServers()
947   {
948     return publicServers;
949   }
950
951 /**
952 *
953 * Return a vector containing the list of private servers
954 *
955 */
956   public Vector getPrivateServers()
957   {
958     return privateServers;
959   }
960
961 /**
962 *
963 * Mark a server as bad
964 *
965 */
966   public void setServerStatus(String server, int i)
967   {
968     serverStatusHash.put(server, new Integer(i));
969   }
970
971 /**
972 *
973 * Return the username needed for the remote service
974 * @return       the username
975 *
976 */
977   public String getServiceUserName()
978   {
979     return serviceUserName;
980   }
981
982 /**
983 *
984 * Save the username needed for the remote service
985 * @param newUserName    the username
986 *
987 */
988   public void setServiceUserName(String newUserName)
989   {
990     serviceUserName = newUserName;
991   }
992
993 /**
994 *
995 * Return the password needed for the remote service
996 * @return       password
997 *
998 */
999   public char[] getServicePasswd()
1000   {
1001     return servicePasswd;
1002   }
1003
1004 /**
1005 *
1006 * Return the password needed for the remote service
1007 * @return       password
1008 *
1009 */
1010   public byte[] getServicePasswdByte()
1011   {
1012     return servicePasswdByte;
1013   }
1014
1015 /**
1016 *
1017 * Return the password as byte array
1018 *
1019 */
1020   private static byte[] toByteArr(char ch[])
1021   {
1022     int len = ch.length;
1023     byte msb[] = new byte[len];
1024
1025     for(int i=0;i<len;i++)
1026       msb[i] = (byte)(ch[i]);
1027     return msb;
1028   }
1029
1030
1031 /**
1032 *
1033 * Save the password needed for the remote service
1034 * @param newPasswd      the username
1035 *
1036 */
1037   public void setServicePasswd(char[] newPasswd)
1038   {
1039     int csize = newPasswd.length;
1040     servicePasswd = new char[csize];
1041
1042     for(int i=0;i<csize;i++)
1043       servicePasswd[i] = newPasswd[i];
1044
1045     servicePasswdByte = toByteArr(newPasswd);
1046   }
1047
1048 /**
1049 *
1050 * Get the name of the soap service
1051 * @return       soap service name
1052 *
1053 */
1054   public String getSoapService()
1055   {
1056     return soapService;
1057   }
1058
1059 /**
1060 *
1061 * Get the name of the private soap service
1062 * @return       private service name
1063 *
1064 */
1065   public String getPrivateSoapService()
1066   {
1067     return privateSoapService;
1068   }
1069
1070 /**
1071 *
1072 * Set the name of the private soap service
1073 * @param s      private service name
1074 *
1075 */
1076   public void setPrivateSoapService(String s)
1077   {
1078     privateSoapService = s;
1079   }
1080
1081 /**
1082 *
1083 * Get the name of the public soap service we're using
1084 * @return       public service name
1085 *
1086 */
1087   public String getPublicSoapService()
1088   {
1089     return publicSoapService;
1090   }
1091
1092 /**
1093 *
1094 * Set the name of the public soap service we're using
1095 * @param s      public service name
1096 *
1097 */
1098   public void setPublicSoapService(String s)
1099   {
1100     publicSoapService = s;
1101   }
1102
1103 /**
1104 *
1105 * A description of the server settings
1106 * @return       description of the services
1107 *
1108 */
1109   public String serverDescription()
1110   {
1111     String serverdesc = "Current Settings:"
1112       +"\nPublic Server: "+publicSoapURL
1113       +"\nPrivate Server: "+privateSoapURL
1114       +"\nPublic SOAP service: "+publicSoapService
1115       +"\nPrivate SOAP service: "+privateSoapService;
1116     return serverdesc;
1117   }
1118
1119 /**
1120 *
1121 * Whether to show debugging information
1122 *
1123 */
1124   public boolean getDebug()
1125   {
1126     return debug;
1127   }
1128
1129 /**
1130 *
1131 * Whether this service supports batch mode
1132 * @return       true if batch mode supported
1133 *
1134 */
1135   public boolean getHasBatchMode()
1136   {
1137     return hasBatchMode;
1138   }
1139
1140 /**
1141 *
1142 * Whether this service supports interactive mode
1143 * @return       true if interactive mode supported
1144 *
1145 */
1146   public boolean getHasInteractiveMode()
1147   {
1148     return hasInteractiveMode;
1149   }
1150
1151 /**
1152 *
1153 * The current mode (interactive or batch).
1154 * @return       a String containing the current mode
1155 *
1156 */
1157   public String getCurrentMode()
1158   {
1159     if(hasInteractiveMode)
1160     {
1161       if (hasBatchMode)
1162         return currentMode;
1163       else
1164         return "interactive";
1165     }
1166     else
1167     {
1168       if (hasBatchMode)
1169         return "batch";
1170       else
1171         return currentMode;
1172     }
1173   }
1174
1175 /**
1176 *
1177 * Set the current mode (interactive or batch).
1178 * @param newMode The new execution mode
1179 *
1180 */
1181   public void setCurrentMode(String newMode)
1182   {
1183     currentMode = newMode;
1184   }
1185
1186 /**
1187 *
1188 * Return the mode list as a vector, suitable for loading into
1189 * a combobox.
1190 * @return       mode list
1191 *
1192 */
1193   public Vector modeVector()
1194   {
1195     Vector mv = new Vector();
1196     if (hasInteractiveMode)
1197     {
1198       if (hasBatchMode)
1199       {
1200         if (currentMode.equals("interactive"))
1201         {
1202           mv.add("interactive");
1203           mv.add("batch");
1204         }
1205         else if (currentMode.equals("batch"))
1206         {
1207           mv.add("batch");
1208           mv.add("interactive");
1209         }
1210         else
1211         {
1212           mv.add(currentMode);
1213           mv.add("interactive");
1214           mv.add("batch");
1215         }
1216       }
1217       else
1218         mv.add("interactive");
1219     }
1220     else
1221     {
1222       if(hasBatchMode)
1223         mv.add("batch");
1224     }
1225     return mv;
1226   }
1227
1228 /**
1229 *
1230 * Update the properties structure.
1231 * This doesn't update the actual properties, just the Properties object
1232 * so you must call updateSettingsFromProperties yoursefl
1233 *
1234 * @param  name   A String naming the property to be updated
1235 * @param  newvalue  A String containing the new value of the property
1236 *
1237 */
1238   public void updateJembossProperty(String name, String newvalue)
1239   {
1240     if (jembossSettings.getProperty(name) != null)
1241       jembossSettings.setProperty(name,newvalue);
1242   }
1243
1244 /**
1245 *
1246 * Parse a key=value string to update the properties structure
1247 * @param entry String containing a key=value message
1248 *
1249 */
1250   public void updateJembossPropString(String entry)
1251   {
1252     int isep = entry.indexOf('=');
1253     if(isep != -1)
1254     {
1255       String pkey = entry.substring(0,isep);
1256       String pvalue = entry.substring(isep+1);
1257       updateJembossProperty(pkey, pvalue);
1258     }
1259   }
1260
1261 /**
1262 *
1263 * Parse an array of key=value strings to update the properties structure
1264 * @param entries Array of Strings containing key=value messages
1265 *
1266 */
1267   public void updateJembossPropStrings(String[] entries)
1268   {
1269     for (int i=0; i < entries.length; ++i)
1270       updateJembossPropString(entries[i]);
1271
1272     updateSettingsFromProperties();
1273     setupServerRedundancy();
1274   }
1275
1276 /**
1277 *
1278 * Update properties from a Hashtable
1279 * @param hash Hashtable containg properties
1280 *
1281 */
1282   public void updateJembossPropHash(Hashtable hash)
1283   {
1284     Enumeration enumer = hash.keys();
1285     while(enumer.hasMoreElements())
1286     {
1287       String thiskey = (String)enumer.nextElement().toString();
1288       String thisval = (String)hash.get(thiskey);
1289       updateJembossProperty(thiskey,thisval);
1290     }
1291     updateSettingsFromProperties();
1292   }
1293
1294 }
1295