KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > function > SetPublisherAssertionsFunction


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 JavaDoc;
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.SetPublisherAssertions;
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 SetPublisherAssertionsFunction extends AbstractFunction
37 {
38   // private reference to jUDDI Logger
39
private static Log log = LogFactory.getLog(SetPublisherAssertionsFunction.class);
40
41   /**
42    *
43    */

44   public SetPublisherAssertionsFunction(RegistryEngine registry)
45   {
46     super(registry);
47   }
48
49   /**
50    *
51    */

52   public RegistryObject execute(RegistryObject regObject)
53     throws RegistryException
54   {
55     SetPublisherAssertions request = (SetPublisherAssertions)regObject;
56     String JavaDoc generic = request.getGeneric();
57     AuthInfo authInfo = request.getAuthInfo();
58     Vector JavaDoc assertionVector = request.getPublisherAssertionVector();
59
60     // aquire a jUDDI datastore instance
61
DataStore dataStore = DataStoreFactory.getDataStore();
62
63     try
64     {
65       dataStore.beginTrans();
66
67       // validate authentication parameters
68
Publisher publisher = getPublisher(authInfo,dataStore);
69       String JavaDoc publisherID = publisher.getPublisherID();
70
71       // validate request parameters & execute
72
// nothing that requires validation has been identified
73

74       // set the PublisherAssertions
75
Vector JavaDoc savedAssertionsVector = dataStore.setAssertions(publisherID,assertionVector);
76
77       dataStore.commit();
78
79       PublisherAssertions assertions = new PublisherAssertions();
80       assertions.setGeneric(generic);
81       assertions.setOperator(Config.getOperator());
82       assertions.setPublisherAssertionVector(savedAssertionsVector);
83       return assertions;
84     }
85     catch(RegistryException regex)
86     {
87       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
88       log.error(regex);
89       throw (RegistryException)regex;
90     }
91     catch(Exception JavaDoc ex)
92     {
93       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
94       log.error(ex);
95       throw new RegistryException(ex);
96     }
97     finally
98     {
99       if (dataStore != null)
100         dataStore.release();
101     }
102   }
103
104
105   /***************************************************************************/
106   /***************************** TEST DRIVER *********************************/
107   /***************************************************************************/
108
109
110   public static void main(String JavaDoc[] args)
111   {
112     // initialize the registry
113
RegistryEngine reg = new RegistryEngine();
114     reg.init();
115
116     try
117     {
118     }
119     catch (Exception JavaDoc ex)
120     {
121       // write execption to the console
122
ex.printStackTrace();
123     }
124     finally
125     {
126       // destroy the registry
127
reg.dispose();
128     }
129   }
130 }
131
132
Popular Tags