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.client.Stub;
13  import org.apache.log4j.Logger;
14  
15  import java.net.URL;
16  
17  /**
18   * @author carcassi
19   */
20  public abstract class RemoteCommand extends AbstractCommand {
21      private Logger log = Logger.getLogger(RemoteCommand.class);
22  	
23      private GUMSAPI clientStub;
24  
25      protected GUMSAPI getGums(String gumsUrlStr) {
26          log.debug("Retrieving GUMS stub");
27          if (clientStub != null) return clientStub;        
28          try {
29              GUMSAPIService service = new GUMSAPIServiceLocator();
30              if (Configuration.getInstance().isDirect()) {
31                  log.info("Accessing direct implementation.");
32                  return new GUMSAPIImpl();
33              } else {
34              	URL gumsUrl = gumsUrlStr!=null ? new URL(gumsUrlStr) : Configuration.getInstance().getGUMSLocation();;
35  
36                  log.info("Accessing GUMS implementation at " + gumsUrl + ".");
37                  clientStub = service.getadmin(gumsUrl);
38                  Stub axisStub = (Stub) clientStub;
39                  axisStub.setMaintainSession(true);
40                  Iterator iter = axisStub._getPropertyNames();
41                  while (iter.hasNext()) {
42                      String name = (String) iter.next();
43                      log.debug("Client stub property '" + name + "' value '" + axisStub._getProperty(name));
44                  }
45                  return clientStub;
46              }
47          } catch (Exception e) {
48              System.out.println("Couldn't initialize GUMS client:" + e.getMessage());
49              log.fatal("Couldn't initialize GUMS client", e);
50              System.exit(-1);
51  
52              return null;
53          }
54      }
55      
56      protected GUMSAPI getGums() {
57      	return getGums(null);
58      }
59  }