View Javadoc

1   /*
2    * $Id: ResourceMatcherClient.java 1447 2010-12-10 11:27:08Z hoheisel $
3    *
4    * Copyright (c) 2005-2006, The K-Wf Grid Consortium
5    * Fraunhofer Institute for Computer Architecture and Software Technology
6    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
7    */
8   
9   package de.fraunhofer.first.resmatch.client;
10  
11  import org.apache.log4j.Logger;
12  
13  import java.net.URL;
14  import java.util.ArrayList;
15  import java.rmi.RemoteException;
16  
17  import net.kwfgrid.gwes.Constants;
18  import net.kwfgrid.gwes.GenericWorkflowHandler;
19  import net.kwfgrid.gwes.exception.OperationMapperException;
20  import net.kwfgrid.gwes.operationmapper.OperationMapper;
21  import net.kwfgrid.gworkflowdl.structure.Transition;
22  
23  /**
24   * Singleton pattern
25   *
26   * @author Andreas Hoheisel
27   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
28   * @version $Id: ResourceMatcherClient.java 1447 2010-12-10 11:27:08Z hoheisel $
29   */
30  public class ResourceMatcherClient {
31  
32      /**
33       * log4j logger.
34       */
35      final static Logger logger = Logger.getLogger(ResourceMatcherClient.class);
36  
37      private static ResourceMatcherClient ourInstance;
38  
39      public ResourceMatcherServiceStub stub;
40  
41      public synchronized static ResourceMatcherClient getInstance() throws Exception {
42          if (ResourceMatcherClient.ourInstance == null) {
43              ResourceMatcherClient.ourInstance = new ResourceMatcherClient();
44          }
45          return ResourceMatcherClient.ourInstance;
46      }
47  
48      private ResourceMatcherClient() throws Exception {
49          String resmatchServiceStr = System.getProperty(Constants.PROP_RESOURCE_RESMATCH_SERVICE_URL);
50          if (resmatchServiceStr == null) {
51              throw new Exception("The resource matcher client has not been configured correctly. Please set the property\n"
52                      + Constants.PROP_RESOURCE_RESMATCH_SERVICE_URL + " in the file gwes.properties or as system property");
53          }
54  
55          stub = new ResourceMatcherServiceStub(resmatchServiceStr);
56          if (stub == null) throw new Exception("Could not connect to resource matcher at "+resmatchServiceStr);
57          ResourceMatcherClient.logger.info("connected to " + resmatchServiceStr);
58      }
59  
60      public String match(String gworkflowdl) throws RemoteException {
61          ResourceMatcherServiceStub.Match params = new ResourceMatcherServiceStub.Match();
62          org.apache.axis2.databinding.types.soapencoding.String str = new  org.apache.axis2.databinding.types.soapencoding.String();
63          str.setString(gworkflowdl);
64          params.setGworkflowdl(str);
65          return stub.match(params).getMatchReturn().getString();
66      }
67      
68  }