View Javadoc

1   /*
2    * AbstractWebCommand.java
3    *
4    * Created on November 4, 2004, 10:07 AM
5    */
6   package gov.bnl.gums.admin;
7   
8   
9   import gov.bnl.gums.command.AbstractCommand;
10  import gov.bnl.gums.command.Configuration;
11  import java.util.Iterator;
12  import org.apache.axis.AxisFault;
13  import org.apache.axis.client.Stub;
14  
15  import org.apache.commons.cli.*;
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  
19  import java.net.ConnectException;
20  import java.net.URL;
21  
22  import java.util.logging.Logger;
23  import gov.bnl.gums.admin.*;
24  
25  
26  /***
27   * @author carcassi
28   */
29  public abstract class RemoteCommand extends AbstractCommand {
30      private Log log = LogFactory.getLog(RemoteCommand.class);
31  
32      private GUMSAPI clientStub;
33  
34      protected GUMSAPI getGums() {
35          log.trace("Retrieving GUMS stub");
36          if (clientStub != null) return clientStub;
37          try {
38              GUMSAPIService service = new GUMSAPIServiceLocator();
39              if (Configuration.getInstance().isDirect()) {
40                  log.info("Accessing direct implementation.");
41                  return new GUMSAPIImpl();
42              } else {
43                  URL gumsLocation = Configuration.getInstance()
44                                                    .getGUMSLocation();
45  
46                  log.info("Accessing GUMS implementation at " + gumsLocation + ".");
47                  clientStub = service.getadmin(gumsLocation);
48                  Stub axisStub = (Stub) clientStub;
49                  axisStub.setMaintainSession(true);
50                  Iterator iter = axisStub._getPropertyNames();
51                  while (iter.hasNext()) {
52                      String name = (String) iter.next();
53                      log.trace("Client stub property '" + name + "' value '" + axisStub._getProperty(name));
54                  }
55                  return clientStub;
56              }
57          } catch (Exception e) {
58              System.out.println("Couldn't initialize GUMS client:" +
59                  e.getMessage());
60              log.fatal("Couldn't initialize GUMS client", e);
61              System.exit(-1);
62  
63              return null;
64          }
65      }
66  
67  
68  }