View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.function;
17  
18  import java.util.Vector;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.juddi.datastore.DataStore;
23  import org.apache.juddi.datastore.DataStoreFactory;
24  import org.apache.juddi.datatype.RegistryObject;
25  import org.apache.juddi.datatype.publisher.Publisher;
26  import org.apache.juddi.datatype.request.AuthInfo;
27  import org.apache.juddi.datatype.request.GetPublisherAssertions;
28  import org.apache.juddi.datatype.response.PublisherAssertions;
29  import org.apache.juddi.error.RegistryException;
30  import org.apache.juddi.registry.RegistryEngine;
31  import org.apache.juddi.util.Config;
32  
33  /***
34   * @author Steve Viens (sviens@apache.org)
35   */
36  public class GetPublisherAssertionsFunction extends AbstractFunction
37  {
38    // private reference to jUDDI Logger
39    private static Log log = LogFactory.getLog(GetPublisherAssertionsFunction.class);
40  
41    /***
42     *
43     */
44    public GetPublisherAssertionsFunction(RegistryEngine registry)
45    {
46      super(registry);
47    }
48  
49    /***
50     *
51     */
52    public RegistryObject execute(RegistryObject regObject)
53      throws RegistryException
54    {
55      GetPublisherAssertions request = (GetPublisherAssertions)regObject;
56      String generic = request.getGeneric();
57      AuthInfo authInfo = request.getAuthInfo();
58  
59      // aquire a jUDDI datastore instance
60      DataStore dataStore = DataStoreFactory.getDataStore();
61  
62      try
63      {
64        dataStore.beginTrans();
65  
66        // validate authentication parameters
67        Publisher publisher = getPublisher(authInfo,dataStore);
68        String publisherID = publisher.getPublisherID();
69  
70        // validate request parameters & execute
71        // nothing that requires validation has been identified
72  
73        // get the PublisherAssertions
74        Vector assertionVector = dataStore.getAssertions(publisherID);
75  
76        dataStore.commit();
77  
78        PublisherAssertions assertions = new PublisherAssertions();
79        assertions.setGeneric(generic);
80        assertions.setOperator(Config.getOperator());
81        assertions.setPublisherAssertionVector(assertionVector);
82        return assertions;
83      }
84      catch(RegistryException regex)
85      {
86        try { dataStore.rollback(); } catch(Exception e) { }
87        log.error(regex);
88        throw (RegistryException)regex;
89      }
90      catch(Exception ex)
91      {
92        try { dataStore.rollback(); } catch(Exception e) { }
93        log.error(ex);
94        throw new RegistryException(ex);
95      }
96      finally
97      {
98        if (dataStore != null)
99          dataStore.release();
100     }
101   }
102 
103 
104   /****************************************************************************/
105   /****************************** TEST DRIVER *********************************/
106   /****************************************************************************/
107 
108 
109   public static void main(String[] args)
110   {
111     // initialize the registry
112     RegistryEngine reg = new RegistryEngine();
113     reg.init();
114 
115     try
116     {
117     }
118     catch (Exception ex)
119     {
120       // write execption to the console
121       ex.printStackTrace();
122     }
123     finally
124     {
125       // destroy the registry
126       reg.dispose();
127     }
128   }
129 }