1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.SavePublisher;
28 import org.apache.juddi.datatype.response.PublisherDetail;
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 SavePublisherFunction extends AbstractFunction
37 {
38
39 private static Log log = LogFactory.getLog(SavePublisherFunction.class);
40
41 /***
42 *
43 */
44 public SavePublisherFunction(RegistryEngine registry)
45 {
46 super(registry);
47 }
48
49 /***
50 *
51 */
52 public RegistryObject execute(RegistryObject regObject)
53 throws RegistryException
54 {
55 SavePublisher request = (SavePublisher)regObject;
56 String generic = request.getGeneric();
57 AuthInfo authInfo = request.getAuthInfo();
58 Vector publisherVector = request.getPublisherVector();
59
60
61 DataStore dataStore = DataStoreFactory.getDataStore();
62
63 try
64 {
65 dataStore.beginTrans();
66
67
68 Publisher publisher = getPublisher(authInfo,dataStore);
69 String publisherID = publisher.getPublisherID();
70
71
72 if (!dataStore.isAdministrator(publisherID))
73 throw new RegistryException("Invalid Operation, You must have " +
74 "administrative priveledges to create a new publisher account.");
75
76
77 for (int i=0; i<publisherVector.size(); i++)
78 {
79
80 Publisher pub = (Publisher)publisherVector.elementAt(i);
81 String pubID = pub.getPublisherID();
82
83
84 if ((pubID == null) || (pubID.length() == 0))
85 throw new RegistryException("A valid Publisher ID was " +
86 "not specified: "+pubID);
87 }
88
89 for (int i=0; i<publisherVector.size(); i++)
90 {
91
92 Publisher pub = (Publisher)publisherVector.elementAt(i);
93 String pubID = pub.getPublisherID();
94
95
96 dataStore.deletePublisher(pubID);
97
98
99 dataStore.savePublisher(pub);
100 }
101
102 dataStore.commit();
103
104 PublisherDetail detail = new PublisherDetail();
105 detail.setGeneric(generic);
106 detail.setOperator(Config.getOperator());
107 detail.setTruncated(false);
108 detail.setPublisherVector(publisherVector);
109 return detail;
110 }
111 catch(RegistryException regex)
112 {
113 try { dataStore.rollback(); } catch(Exception e) { }
114 log.error(regex);
115 throw (RegistryException)regex;
116 }
117 catch(Exception ex)
118 {
119 try { dataStore.rollback(); } catch(Exception e) { }
120 log.error(ex);
121 throw new RegistryException(ex);
122 }
123 finally
124 {
125 if (dataStore != null)
126 dataStore.release();
127 }
128 }
129
130 /****************************************************************************/
131 /****************************** TEST DRIVER *********************************/
132 /****************************************************************************/
133
134
135 public static void main(String[] args)
136 {
137
138 RegistryEngine reg = new RegistryEngine();
139 reg.init();
140
141 try
142 {
143 }
144 catch (Exception ex)
145 {
146
147 ex.printStackTrace();
148 }
149 finally
150 {
151
152 reg.dispose();
153 }
154 }
155 }