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.SetPublisherAssertions;
28  import org.apache.juddi.datatype.response.PublisherAssertions;
29  import org.apache.juddi.datatype.assertion.PublisherAssertion;
30  import org.apache.juddi.datatype.KeyedReference;
31  import org.apache.juddi.error.RegistryException;
32  import org.apache.juddi.registry.RegistryEngine;
33  import org.apache.juddi.error.InvalidKeyPassedException;
34  import org.apache.juddi.util.Config;
35  
36  /***
37   * @author Steve Viens (sviens@apache.org)
38   */
39  public class SetPublisherAssertionsFunction extends AbstractFunction
40  {
41    // private reference to jUDDI Logger
42    private static Log log = LogFactory.getLog(SetPublisherAssertionsFunction.class);
43  
44    /***
45     *
46     */
47    public SetPublisherAssertionsFunction(RegistryEngine registry)
48    {
49      super(registry);
50    }
51  
52    /***
53     *
54     */
55    public RegistryObject execute(RegistryObject regObject)
56      throws RegistryException
57    {
58      SetPublisherAssertions request = (SetPublisherAssertions)regObject;
59      String generic = request.getGeneric();
60      AuthInfo authInfo = request.getAuthInfo();
61      Vector assertionVector = request.getPublisherAssertionVector();
62  
63      // aquire a jUDDI datastore instance
64      DataStore dataStore = DataStoreFactory.getDataStore();
65  
66      try
67      {
68        dataStore.beginTrans();
69  
70        // validate authentication parameters
71        Publisher publisher = getPublisher(authInfo,dataStore);
72        String publisherID = publisher.getPublisherID();
73  
74        // validate request parameters & execute
75        // Per UDDI v2.0 specification, the tModelKey in a passed publisherAssertion CANNOT be null or blank.  An invalidKeyPassed error must be thrown.
76        if (assertionVector != null) {
77      	  for (int i = 0; i < assertionVector.size(); i++) {
78      		  PublisherAssertion publisherAssertion = (PublisherAssertion)assertionVector.elementAt(i);
79      		  if (publisherAssertion != null) {
80      			  KeyedReference kr = publisherAssertion.getKeyedReference();
81      			  if (kr != null) {
82      				  if (kr.getTModelKey() == null || kr.getTModelKey().length() == 0) {
83      					  //throw new InvalidKeyPassedException("tModelKey must be provided in KeyedReference for publisherAssertion: fromKey=" + 
84      					//		                               publisherAssertion.getFromKey() + "; toKey=" + publisherAssertion.getToKey());
85    					  throw new InvalidKeyPassedException("tModelKey must be provided in KeyedReference for publisherAssertion: fromKey=");
86  
87      				  }
88      			  }
89      		  }
90      		  
91      	  }
92        }
93        // nothing that requires validation has been identified
94  
95        // set the PublisherAssertions
96        Vector savedAssertionsVector = dataStore.setAssertions(publisherID,assertionVector);
97  
98        dataStore.commit();
99  
100       PublisherAssertions assertions = new PublisherAssertions();
101       assertions.setGeneric(generic);
102       assertions.setOperator(Config.getOperator());
103       assertions.setPublisherAssertionVector(savedAssertionsVector);
104       return assertions;
105     }
106     catch(InvalidKeyPassedException ivkex)
107     {
108       try { dataStore.rollback(); } catch(Exception e) { }
109       log.error(ivkex);
110       throw (RegistryException)ivkex;
111     }
112     catch(RegistryException regex)
113     {
114       try { dataStore.rollback(); } catch(Exception e) { }
115       log.error(regex);
116       throw (RegistryException)regex;
117     }
118     catch(Exception ex)
119     {
120       try { dataStore.rollback(); } catch(Exception e) { }
121       log.error(ex);
122       throw new RegistryException(ex);
123     }
124     finally
125     {
126       if (dataStore != null)
127         dataStore.release();
128     }
129   }
130 
131 
132   /****************************************************************************/
133   /****************************** TEST DRIVER *********************************/
134   /****************************************************************************/
135 
136 
137   public static void main(String[] args)
138   {
139     // initialize the registry
140     RegistryEngine reg = new RegistryEngine();
141     reg.init();
142 
143     try
144     {
145     }
146     catch (Exception ex)
147     {
148       // write execption to the console
149       ex.printStackTrace();
150     }
151     finally
152     {
153       // destroy the registry
154       reg.dispose();
155     }
156   }
157 }
158