001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.harmonise;
020:
021: import java.net.*;
022: import java.net.URL;
023: import java.rmi.RemoteException;
024: import java.util.*;
025:
026: import javax.xml.namespace.QName;
027: import javax.xml.rpc.ServiceException;
028:
029: import org.apache.axis.client.*;
030: import org.apache.axis.encoding.ser.*;
031:
032: /**
033: * This class provids a client interface to the system config property
034: * management webservice provided by the Harmonise server.
035: *
036: * @author Michael Bell
037: * @version $Revision: 1.3 $
038: *
039: */
040: public class ConfigSettingsClient {
041:
042: /**
043: * Simulacra namespace
044: */
045: public static final String OPENHARMONISE_WEBSERVICE_NAMESPACE_URI = "http://www.openharmonise.org/";
046:
047: /**
048: * Simple constructor
049: */
050: public ConfigSettingsClient() {
051: super ();
052: }
053:
054: /**
055: * Returns a <code>List</code> of <code>ConfigProperty</code> objects
056: * representing all the system config properties available
057: *
058: * @param endpoint the webservice endpoint
059: * @param sCurrUserName the user name
060: * @param sPwd the user password
061: * @return a <code>List</code> of <code>ConfigProperty</code> objects
062: * @throws RemoteException
063: * @throws ServiceException
064: */
065: public List getAllProperties(URL endpoint, String sCurrUserName,
066: String sPwd) throws RemoteException, ServiceException {
067: Service service = new Service();
068: Call call = (Call) service.createCall();
069:
070: call.setTargetEndpointAddress(endpoint);
071: call.setOperationName(new QName(
072: OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
073: "getAllProperties"));
074:
075: call.addParameter("username",
076: org.apache.axis.Constants.XSD_STRING,
077: javax.xml.rpc.ParameterMode.IN);
078: call.addParameter("password",
079: org.apache.axis.Constants.XSD_STRING,
080: javax.xml.rpc.ParameterMode.IN);
081:
082: QName mtqn = new QName(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
083: "ConfigProperty");
084: call.registerTypeMapping(ConfigProperty.class, mtqn,
085: BeanSerializerFactory.class,
086: BeanDeserializerFactory.class);
087:
088: call.setReturnType(org.apache.axis.Constants.SOAP_ARRAY);
089: call.setReturnClass(ArrayList.class);
090:
091: List obj = (List) call.invoke(new Object[] { sCurrUserName,
092: sPwd });
093:
094: return obj;
095:
096: }
097:
098: /**
099: * Returns a <code>ConfigProperty</code> representing the
100: * system config property associated with the specified
101: * property name
102: *
103: * @param endpoint the webservice endpoint
104: * @param sCurrUserName the user name
105: * @param sPwd the password
106: * @param sPropName the propert name
107: * @return a <code>ConfigProperty</code>
108: * @throws RemoteException
109: * @throws ServiceException
110: */
111: public ConfigProperty getProperty(URL endpoint,
112: String sCurrUserName, String sPwd, String sPropName)
113: throws RemoteException, ServiceException {
114: ConfigProperty prop = null;
115:
116: List propList = new ArrayList();
117:
118: propList.add(sPropName);
119:
120: List props = getProperties(endpoint, sCurrUserName, sPwd,
121: propList);
122:
123: if (props != null && props.size() > 0) {
124: prop = (ConfigProperty) props.get(0);
125: }
126:
127: return prop;
128: }
129:
130: /**
131: * Returns a <code>List</code> of <code>ConfigProperty</code> objects
132: * for each of the property names in the given list.
133: *
134: * @param endpoint the webservice endpoint
135: * @param sCurrUserName the user name
136: * @param sPwd the user pasword
137: * @param propNames the list of property names
138: * @return a <code>List</code> of <code>ConfigProperty</code> objects
139: * @throws RemoteException
140: * @throws ServiceException
141: */
142: public List getProperties(URL endpoint, String sCurrUserName,
143: String sPwd, List propNames) throws RemoteException,
144: ServiceException {
145: Service service = new Service();
146: Call call = (Call) service.createCall();
147:
148: call.setTargetEndpointAddress(endpoint);
149: call
150: .setOperationName(new QName(
151: OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
152: "getProperties"));
153:
154: call.addParameter("username",
155: org.apache.axis.Constants.XSD_STRING,
156: javax.xml.rpc.ParameterMode.IN);
157: call.addParameter("password",
158: org.apache.axis.Constants.XSD_STRING,
159: javax.xml.rpc.ParameterMode.IN);
160: call.addParameter("propNames",
161: org.apache.axis.Constants.SOAP_ARRAY,
162: javax.xml.rpc.ParameterMode.IN);
163:
164: QName mtqn = new QName(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
165: "ConfigProperty");
166: call.registerTypeMapping(ConfigProperty.class, mtqn,
167: BeanSerializerFactory.class,
168: BeanDeserializerFactory.class);
169:
170: call.setReturnType(org.apache.axis.Constants.SOAP_ARRAY);
171: call.setReturnClass(ArrayList.class);
172:
173: List obj = (List) call.invoke(new Object[] { sCurrUserName,
174: sPwd, propNames });
175:
176: return obj;
177:
178: }
179:
180: /**
181: * Sets the value of the given system config property
182: *
183: * @param endpoint the webservice endpoint
184: * @param sCurrUserName the user name
185: * @param sPwd the user password
186: * @param prop the <code>ConfigProperty</code> to set
187: * @throws RemoteException
188: * @throws ServiceException
189: */
190: public void setProperty(URL endpoint, String sCurrUserName,
191: String sPwd, ConfigProperty prop) throws RemoteException,
192: ServiceException {
193:
194: ArrayList props = new ArrayList();
195: props.add(prop);
196:
197: setProperties(endpoint, sCurrUserName, sPwd, props);
198:
199: }
200:
201: /**
202: * Sets the given list of <code>ConfigProperty</code> objects
203: * on the server
204: *
205: * @param endpoint the webservice endpoint
206: * @param sCurrUserName the user name
207: * @param sPwd the password
208: * @param props the list of <code>ConfigProperty</code> objects
209: * @throws RemoteException
210: * @throws ServiceException
211: */
212: public void setProperties(URL endpoint, String sCurrUserName,
213: String sPwd, List props) throws RemoteException,
214: ServiceException {
215: Service service = new Service();
216: Call call = (Call) service.createCall();
217:
218: call.setTargetEndpointAddress(endpoint);
219: call
220: .setOperationName(new QName(
221: OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
222: "setProperties"));
223:
224: call.addParameter("username",
225: org.apache.axis.Constants.XSD_STRING,
226: javax.xml.rpc.ParameterMode.IN);
227: call.addParameter("password",
228: org.apache.axis.Constants.XSD_STRING,
229: javax.xml.rpc.ParameterMode.IN);
230: call.addParameter("props",
231: org.apache.axis.Constants.SOAP_ARRAY,
232: javax.xml.rpc.ParameterMode.IN);
233:
234: QName mtqn = new QName(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
235: "ConfigProperty");
236: call.registerTypeMapping(ConfigProperty.class, mtqn,
237: BeanSerializerFactory.class,
238: BeanDeserializerFactory.class);
239:
240: call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
241:
242: call.invoke(new Object[] { sCurrUserName, sPwd, props });
243:
244: }
245:
246: /**
247: * Adds a new system config property
248: *
249: * @param endpoint the webservice endpoint
250: * @param sCurrUserName the user name
251: * @param sPwd the user password
252: * @param prop the <code>ConfigProperty</code> to add
253: * @throws RemoteException
254: * @throws ServiceException
255: */
256: public void addProperty(URL endpoint, String sCurrUserName,
257: String sPwd, ConfigProperty prop) throws RemoteException,
258: ServiceException {
259:
260: ArrayList props = new ArrayList();
261: props.add(prop);
262:
263: addProperties(endpoint, sCurrUserName, sPwd, props);
264:
265: }
266:
267: /**
268: * Adds the list of system config properties to the server
269: *
270: * @param endpoint the webservice endpoint
271: * @param sCurrUserName the user name
272: * @param sPwd the user password
273: * @param props the list of <code>ConfigProperties</code> to add
274: * @throws RemoteException
275: * @throws ServiceException
276: */
277: public void addProperties(URL endpoint, String sCurrUserName,
278: String sPwd, List props) throws RemoteException,
279: ServiceException {
280: Service service = new Service();
281: Call call = (Call) service.createCall();
282:
283: call.setTargetEndpointAddress(endpoint);
284: call
285: .setOperationName(new QName(
286: OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
287: "addProperties"));
288:
289: call.addParameter("username",
290: org.apache.axis.Constants.XSD_STRING,
291: javax.xml.rpc.ParameterMode.IN);
292: call.addParameter("password",
293: org.apache.axis.Constants.XSD_STRING,
294: javax.xml.rpc.ParameterMode.IN);
295: call.addParameter("props",
296: org.apache.axis.Constants.SOAP_ARRAY,
297: javax.xml.rpc.ParameterMode.IN);
298:
299: QName mtqn = new QName(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
300: "ConfigProperty");
301: call.registerTypeMapping(ConfigProperty.class, mtqn,
302: BeanSerializerFactory.class,
303: BeanDeserializerFactory.class);
304:
305: call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
306:
307: call.invoke(new Object[] { sCurrUserName, sPwd, props });
308:
309: }
310:
311: /**
312: * Remove the specified server config property from the server
313: *
314: * @param endpoint the webservice endpoint
315: * @param sCurrUserName the user name
316: * @param sPwd the user password
317: * @param propName the property to delete
318: * @throws RemoteException
319: * @throws ServiceException
320: */
321: public void removeProperty(URL endpoint, String sCurrUserName,
322: String sPwd, String propName) throws RemoteException,
323: ServiceException {
324: ArrayList props = new ArrayList();
325: props.add(propName);
326:
327: removeProperties(endpoint, sCurrUserName, sPwd, props);
328: }
329:
330: /**
331: * Removes the list of config system properties from the
332: * server
333: *
334: * @param endpoint the webservice endpoint
335: * @param sCurrUserName the user password
336: * @param sPwd the user password
337: * @param propNames the list of names of config property to remove
338: * @throws RemoteException
339: * @throws ServiceException
340: */
341: public void removeProperties(URL endpoint, String sCurrUserName,
342: String sPwd, List propNames) throws RemoteException,
343: ServiceException {
344: Service service = new Service();
345: Call call = (Call) service.createCall();
346:
347: call.setTargetEndpointAddress(endpoint);
348: call.setOperationName(new QName(
349: OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
350: "removeProperties"));
351:
352: call.addParameter("username",
353: org.apache.axis.Constants.XSD_STRING,
354: javax.xml.rpc.ParameterMode.IN);
355: call.addParameter("password",
356: org.apache.axis.Constants.XSD_STRING,
357: javax.xml.rpc.ParameterMode.IN);
358: call.addParameter("props",
359: org.apache.axis.Constants.SOAP_ARRAY,
360: javax.xml.rpc.ParameterMode.IN);
361:
362: QName mtqn = new QName(OPENHARMONISE_WEBSERVICE_NAMESPACE_URI,
363: "ConfigProperty");
364: call.registerTypeMapping(ConfigProperty.class, mtqn,
365: BeanSerializerFactory.class,
366: BeanDeserializerFactory.class);
367:
368: call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);
369:
370: call.invoke(new Object[] { sCurrUserName, sPwd, propNames });
371:
372: }
373:
374: /**
375: * Main method to test class methods
376: *
377: * @param args
378: */
379: public static void main(String[] args) {
380: try {
381: URL url = new URL(
382: "http://localhost:7000/webdav/services/ConfigService");
383:
384: ConfigSettingsClient client = new ConfigSettingsClient();
385:
386: List props = client.getAllProperties(url, "super",
387: "Tanger1ne");
388:
389: Iterator iter = props.iterator();
390: List nameList = new ArrayList();
391: int i = 0;
392: while (iter.hasNext()) {
393: ConfigProperty prop = (ConfigProperty) iter.next();
394: System.out.println("prop " + prop.getName()
395: + ", val = " + prop.getValue());
396: nameList.add(prop.getName());
397: }
398:
399: props = client.getProperties(url, "super", "Tanger1ne",
400: nameList);
401:
402: while (iter.hasNext()) {
403: ConfigProperty prop = (ConfigProperty) iter.next();
404: System.out.println("--- prop " + prop.getName()
405: + ", val = " + prop.getValue());
406: }
407:
408: ArrayList list = new ArrayList();
409:
410: list.add(new ConfigProperty("ERROR_EMAIL_ADDRESS",
411: "bob@simulacramedia.com"));
412:
413: client.setProperties(url, "super", "Tanger1ne", list);
414:
415: } catch (MalformedURLException e) {
416: e.printStackTrace();
417: } catch (RemoteException e) {
418: e.printStackTrace();
419: } catch (ServiceException e) {
420: e.printStackTrace();
421: }
422: }
423:
424: }
|