KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > harmonise > ConfigSettingsClient


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.harmonise;
20
21 import java.net.*;
22 import java.net.URL JavaDoc;
23 import java.rmi.RemoteException JavaDoc;
24 import java.util.*;
25
26 import javax.xml.namespace.QName JavaDoc;
27 import javax.xml.rpc.ServiceException JavaDoc;
28
29 import org.apache.axis.client.*;
30 import org.apache.axis.encoding.ser.*;
31
32 /**
33  * This class provids a client interface to the system config property
34  * management webservice provided by the Harmonise server.
35  *
36  * @author Michael Bell
37  * @version $Revision: 1.3 $
38  *
39  */

40 public class ConfigSettingsClient {
41
42     /**
43      * Simulacra namespace
44      */

45     public static final String JavaDoc OPENHARMONISE_WEBSERVICE_NAMESPACE_URI = "http://www.openharmonise.org/";
46
47     /**
48      * Simple constructor
49      */

50     public ConfigSettingsClient() {
51         super();
52     }
53
54     /**
55      * Returns a <code>List</code> of <code>ConfigProperty</code> objects
56      * representing all the system config properties available
57      *
58      * @param endpoint the webservice endpoint
59      * @param sCurrUserName the user name
60      * @param sPwd the user password
61      * @return a <code>List</code> of <code>ConfigProperty</code> objects
62      * @throws RemoteException
63      * @throws ServiceException
64      */

65     public List getAllProperties(URL JavaDoc endpoint, String JavaDoc sCurrUserName, String JavaDoc sPwd)
66             throws RemoteException JavaDoc, ServiceException JavaDoc {
67         Service service = new Service();
68         Call call = (Call) service.createCall();
69
70         call.setTargetEndpointAddress(endpoint);
71         call.setOperationName(new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
72                 "getAllProperties"));
73
74         call.addParameter("username", org.apache.axis.Constants.XSD_STRING,
75                 javax.xml.rpc.ParameterMode.IN);
76         call.addParameter("password", org.apache.axis.Constants.XSD_STRING,
77                 javax.xml.rpc.ParameterMode.IN);
78
79         QName JavaDoc mtqn = new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
80                 "ConfigProperty");
81         call.registerTypeMapping(ConfigProperty.class, mtqn,
82                 BeanSerializerFactory.class, BeanDeserializerFactory.class);
83
84         call.setReturnType(org.apache.axis.Constants.SOAP_ARRAY);
85         call.setReturnClass(ArrayList.class);
86
87         List obj = (List) call.invoke(new Object JavaDoc[]{sCurrUserName,sPwd});
88
89         return obj;
90
91     }
92     
93     /**
94      * Returns a <code>ConfigProperty</code> representing the
95      * system config property associated with the specified
96      * property name
97      *
98      * @param endpoint the webservice endpoint
99      * @param sCurrUserName the user name
100      * @param sPwd the password
101      * @param sPropName the propert name
102      * @return a <code>ConfigProperty</code>
103      * @throws RemoteException
104      * @throws ServiceException
105      */

106     public ConfigProperty getProperty(URL JavaDoc endpoint, String JavaDoc sCurrUserName, String JavaDoc sPwd,
107             String JavaDoc sPropName) throws RemoteException JavaDoc, ServiceException JavaDoc {
108         ConfigProperty prop = null;
109         
110         List propList = new ArrayList();
111         
112         propList.add(sPropName);
113         
114         List props = getProperties(endpoint, sCurrUserName, sPwd, propList);
115         
116         if(props != null && props.size() > 0) {
117             prop = (ConfigProperty) props.get(0);
118         }
119         
120         return prop;
121     }
122
123     /**
124      * Returns a <code>List</code> of <code>ConfigProperty</code> objects
125      * for each of the property names in the given list.
126      *
127      * @param endpoint the webservice endpoint
128      * @param sCurrUserName the user name
129      * @param sPwd the user pasword
130      * @param propNames the list of property names
131      * @return a <code>List</code> of <code>ConfigProperty</code> objects
132      * @throws RemoteException
133      * @throws ServiceException
134      */

135     public List getProperties(URL JavaDoc endpoint, String JavaDoc sCurrUserName, String JavaDoc sPwd,
136             List propNames) throws RemoteException JavaDoc, ServiceException JavaDoc {
137         Service service = new Service();
138         Call call = (Call) service.createCall();
139
140         call.setTargetEndpointAddress(endpoint);
141         call.setOperationName(new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
142                 "getProperties"));
143
144         call.addParameter("username", org.apache.axis.Constants.XSD_STRING,
145                 javax.xml.rpc.ParameterMode.IN);
146         call.addParameter("password", org.apache.axis.Constants.XSD_STRING,
147                 javax.xml.rpc.ParameterMode.IN);
148         call.addParameter("propNames", org.apache.axis.Constants.SOAP_ARRAY,
149                 javax.xml.rpc.ParameterMode.IN);
150
151         QName JavaDoc mtqn = new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
152                 "ConfigProperty");
153         call.registerTypeMapping(ConfigProperty.class, mtqn,
154                 BeanSerializerFactory.class, BeanDeserializerFactory.class);
155
156         call.setReturnType(org.apache.axis.Constants.SOAP_ARRAY);
157         call.setReturnClass(ArrayList.class);
158
159         List obj = (List) call.invoke(new Object JavaDoc[] { sCurrUserName,sPwd,propNames });
160
161         return obj;
162
163     }
164
165     /**
166      * Sets the value of the given system config property
167      *
168      * @param endpoint the webservice endpoint
169      * @param sCurrUserName the user name
170      * @param sPwd the user password
171      * @param prop the <code>ConfigProperty</code> to set
172      * @throws RemoteException
173      * @throws ServiceException
174      */

175     public void setProperty(URL JavaDoc endpoint, String JavaDoc sCurrUserName, String JavaDoc sPwd,
176             ConfigProperty prop) throws RemoteException JavaDoc, ServiceException JavaDoc {
177         
178         ArrayList props = new ArrayList();
179         props.add(prop);
180         
181         setProperties(endpoint, sCurrUserName, sPwd, props);
182         
183     }
184     
185     /**
186      * Sets the given list of <code>ConfigProperty</code> objects
187      * on the server
188      *
189      * @param endpoint the webservice endpoint
190      * @param sCurrUserName the user name
191      * @param sPwd the password
192      * @param props the list of <code>ConfigProperty</code> objects
193      * @throws RemoteException
194      * @throws ServiceException
195      */

196     public void setProperties(URL JavaDoc endpoint, String JavaDoc sCurrUserName, String JavaDoc sPwd,
197             List props) throws RemoteException JavaDoc, ServiceException JavaDoc {
198         Service service = new Service();
199         Call call = (Call) service.createCall();
200
201         call.setTargetEndpointAddress(endpoint);
202         call.setOperationName(new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
203                 "setProperties"));
204
205         call.addParameter("username", org.apache.axis.Constants.XSD_STRING,
206                 javax.xml.rpc.ParameterMode.IN);
207         call.addParameter("password", org.apache.axis.Constants.XSD_STRING,
208                 javax.xml.rpc.ParameterMode.IN);
209         call.addParameter("props", org.apache.axis.Constants.SOAP_ARRAY,
210                 javax.xml.rpc.ParameterMode.IN);
211
212         QName JavaDoc mtqn = new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
213                 "ConfigProperty");
214         call.registerTypeMapping(ConfigProperty.class, mtqn,
215                 BeanSerializerFactory.class, BeanDeserializerFactory.class);
216
217         call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
218
219         call.invoke(new Object JavaDoc[] { sCurrUserName,sPwd,props });
220
221     }
222     
223     /**
224      * Adds a new system config property
225      *
226      * @param endpoint the webservice endpoint
227      * @param sCurrUserName the user name
228      * @param sPwd the user password
229      * @param prop the <code>ConfigProperty</code> to add
230      * @throws RemoteException
231      * @throws ServiceException
232      */

233     public void addProperty(URL JavaDoc endpoint, String JavaDoc sCurrUserName, String JavaDoc sPwd,
234             ConfigProperty prop) throws RemoteException JavaDoc, ServiceException JavaDoc {
235         
236         ArrayList props = new ArrayList();
237         props.add(prop);
238         
239         addProperties(endpoint, sCurrUserName, sPwd, props);
240         
241     }
242
243     /**
244      * Adds the list of system config properties to the server
245      *
246      * @param endpoint the webservice endpoint
247      * @param sCurrUserName the user name
248      * @param sPwd the user password
249      * @param props the list of <code>ConfigProperties</code> to add
250      * @throws RemoteException
251      * @throws ServiceException
252      */

253     public void addProperties(URL JavaDoc endpoint, String JavaDoc sCurrUserName, String JavaDoc sPwd,
254             List props) throws RemoteException JavaDoc, ServiceException JavaDoc {
255         Service service = new Service();
256         Call call = (Call) service.createCall();
257
258         call.setTargetEndpointAddress(endpoint);
259         call.setOperationName(new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
260                 "addProperties"));
261
262         call.addParameter("username", org.apache.axis.Constants.XSD_STRING,
263                 javax.xml.rpc.ParameterMode.IN);
264         call.addParameter("password", org.apache.axis.Constants.XSD_STRING,
265                 javax.xml.rpc.ParameterMode.IN);
266         call.addParameter("props", org.apache.axis.Constants.SOAP_ARRAY,
267                 javax.xml.rpc.ParameterMode.IN);
268
269         QName JavaDoc mtqn = new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
270                 "ConfigProperty");
271         call.registerTypeMapping(ConfigProperty.class, mtqn,
272                 BeanSerializerFactory.class, BeanDeserializerFactory.class);
273
274         call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
275
276         call.invoke(new Object JavaDoc[] { sCurrUserName,sPwd,props });
277
278     }
279     
280     /**
281      * Remove the specified server config property from the server
282      *
283      * @param endpoint the webservice endpoint
284      * @param sCurrUserName the user name
285      * @param sPwd the user password
286      * @param propName the property to delete
287      * @throws RemoteException
288      * @throws ServiceException
289      */

290     public void removeProperty(URL JavaDoc endpoint, String JavaDoc sCurrUserName,
291             String JavaDoc sPwd, String JavaDoc propName) throws RemoteException JavaDoc, ServiceException JavaDoc {
292         ArrayList props = new ArrayList();
293         props.add(propName);
294         
295         removeProperties(endpoint, sCurrUserName, sPwd, props);
296     }
297
298     /**
299      * Removes the list of config system properties from the
300      * server
301      *
302      * @param endpoint the webservice endpoint
303      * @param sCurrUserName the user password
304      * @param sPwd the user password
305      * @param propNames the list of names of config property to remove
306      * @throws RemoteException
307      * @throws ServiceException
308      */

309     public void removeProperties(URL JavaDoc endpoint, String JavaDoc sCurrUserName,
310             String JavaDoc sPwd, List propNames) throws RemoteException JavaDoc, ServiceException JavaDoc {
311         Service service = new Service();
312         Call call = (Call) service.createCall();
313
314         call.setTargetEndpointAddress(endpoint);
315         call.setOperationName(new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
316                 "removeProperties"));
317
318         call.addParameter("username", org.apache.axis.Constants.XSD_STRING,
319                 javax.xml.rpc.ParameterMode.IN);
320         call.addParameter("password", org.apache.axis.Constants.XSD_STRING,
321                 javax.xml.rpc.ParameterMode.IN);
322         call.addParameter("props", org.apache.axis.Constants.SOAP_ARRAY,
323                 javax.xml.rpc.ParameterMode.IN);
324
325         QName JavaDoc mtqn = new QName JavaDoc(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
326                 "ConfigProperty");
327         call.registerTypeMapping(ConfigProperty.class, mtqn,
328                 BeanSerializerFactory.class, BeanDeserializerFactory.class);
329
330         call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
331
332         call.invoke(new Object JavaDoc[] { sCurrUserName,sPwd,propNames });
333
334     }
335
336     /**
337      * Main method to test class methods
338      *
339      * @param args
340      */

341     public static void main(String JavaDoc[] args) {
342         try {
343             URL JavaDoc url = new URL JavaDoc(
344                     "http://localhost:7000/webdav/services/ConfigService");
345
346             ConfigSettingsClient client = new ConfigSettingsClient();
347
348                         List props = client.getAllProperties(url,"super","Tanger1ne");
349                         
350                         Iterator iter = props.iterator();
351                         List nameList = new ArrayList();
352                         int i =0;
353                         while (iter.hasNext()) {
354                             ConfigProperty prop = (ConfigProperty) iter.next();
355                             System.out.println("prop " + prop.getName() + ", val = " +
356              prop.getValue());
357                             nameList.add(prop.getName());
358                         }
359                         
360                         props = client.getProperties(url, "super","Tanger1ne",nameList);
361                         
362                         while (iter.hasNext()) {
363                             ConfigProperty prop = (ConfigProperty) iter.next();
364                             System.out.println("--- prop " + prop.getName() + ", val = "
365              + prop.getValue());
366                         }
367
368             ArrayList list = new ArrayList();
369
370             list.add(new ConfigProperty("ERROR_EMAIL_ADDRESS",
371                     "bob@simulacramedia.com"));
372
373             client.setProperties(url,"super","Tanger1ne", list);
374
375         } catch (MalformedURLException e) {
376             e.printStackTrace();
377         } catch (RemoteException JavaDoc e) {
378             e.printStackTrace();
379         } catch (ServiceException JavaDoc e) {
380             e.printStackTrace();
381         }
382     }
383
384 }
Popular Tags