source: vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/Client.java@ 871

Last change on this file since 871 was 871, checked in by tobias, on May 10, 2010 at 7:42:51 PM

additional clients can be added to the configuration

File size: 13.9 KB
Line 
1package de.dass_it.vanhelsing.gui;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5
6import de.dass_it.www.vanhelsing.*;
7//import de.dass_it.www.vanhelsing.VanHelsingCallbackHandler.*;
8import de.dass_it.www.vanhelsing.VanHelsingStub.*;
9
10/**
11 * Client wraps access methods and data structure of the axis client
12 * @author tgoecke
13 */
14public class Client {
15 /**
16 * Access method to get a list of resources of a given director and resource type.
17 * @param director the director on which the configuration is based on.
18 * @param resource the name of the resource, e.g. client or job
19 * @return an array of ResourceInfo objects. ResourceInfo has four attributes: <br/>
20 * director, resource id, resource name and resource type.
21 * If an Exception is thrown an empty array is returned.
22 */
23 public ResourceInfo[] getListResources(String director, String resource){
24 ListResourcesType lrt = new ListResourcesType();
25 lrt.setDirector(director);
26 lrt.setResourceType(resource);
27 return getListResources(lrt);
28 }
29 /**
30 * Access method to get a list of resources of a given director and resource type.
31 * The argument is wrapped within the ListReosurceType object.
32 * @param lrt ListResourceType contains the director and the resource type as strings
33 * @return an array of ResourceInfo objects. ResourceInfo has four attributes:
34 * director, resource id, resource name and resource type.
35 * If an Exception is thrown an empty array is returned.
36 */
37 public ResourceInfo[] getListResources(ListResourcesType lrt){
38 VanHelsingStub stub;
39 try {
40
41 stub = getStub();
42
43 VanHelsingStub.ListResources req = new VanHelsingStub.ListResources();
44 req.setListResources(lrt);
45
46 VanHelsingStub.ListResourcesResponse res = stub.listResources(req);
47 return (res.getListResourcesResponse()).getResource();
48
49 } catch (Exception e){
50 System.err.println("getListResources: " + e.toString());
51 }
52 return new ResourceInfo[0];
53 }
54 /**
55 * retrieve an array of key value pairs describing a given simple resource
56 * @param director the director on which the configuration is based on.
57 * @param resId the id of the resource.
58 * @return a SimpleResource object containing a ResourceInfo object and a <br/>
59 * ResourceAttributeType object array.
60 */
61 public SimpleResource getSimpleResource(String director, int resId){
62 GetResourceType grt = new GetResourceType();
63 grt.setDirector(director);
64 grt.setResId(resId);
65 return getSimpleResource(grt);
66 }
67 /**
68 * retrieve an array of key value pairs describing a given simple resource
69 * @param grt GetResourceType contains a director and a resId.
70 * @return a SimpleResource object containing a ResourceInfo object and a <br/>
71 * ResourceAttributeType object array.
72 */
73 public SimpleResource getSimpleResource(GetResourceType grt){
74 VanHelsingStub stub;
75 try {
76 stub = getStub();
77
78 VanHelsingStub.GetSimpleResource req = new VanHelsingStub.GetSimpleResource();
79 req.setGetSimpleResource(grt);
80
81 VanHelsingStub.GetSimpleResourceResponse res = stub.getSimpleResource(req);
82
83 SimpleResource sr = new SimpleResource();
84 sr.setResourceInfo(res.getResInfo());
85 sr.setResourceAttributeType(res.getResAttribute());
86 return sr;
87
88
89 } catch(Exception e){
90 System.err.println("getSR: " + grt.getResId() + " : " + e.toString());
91 }
92 return null;
93 }
94 /**
95 * Update or replace method for a simple resource.
96 * @param director the director on which the configuration is based on
97 * @param resourceType the name of the resource e.g. client or job
98 * @param resId the id number of the resource in the tree of the service
99 * @param replace true if the given object is to be replaced,<br/>
100 * false if only the changed values are to be updated.
101 * @param name name of a given resource
102 * @param keyValues containing the key-value-pairs of the resource
103 * @return a status value of type string
104 */
105 public SetSimpleResourceResponse setSimpleResource(String director, String resourceType,
106 int resId, boolean replace, String name, String[][] keyValues){
107 ResourceInfo resInfo = new ResourceInfo();
108 resInfo.setDirector(director);
109 resInfo.setResId(resId);
110 resInfo.setResName(name);
111 resInfo.setResType(resourceType);
112
113 ResourceAttributeType[] rat = new ResourceAttributeType[keyValues.length];
114 int i = 0;
115 for (String [] pair : keyValues){
116 rat[i].setKey(pair[0]);
117 rat[i].setValue(pair[1]);
118 i++;
119 }
120
121 ResourceInitialization ri = new ResourceInitialization();
122 ri.setResInfo(resInfo);
123 ri.setResAttribute(rat);
124 ri.setReplace(replace);
125 return setSimpleResource(ri);
126 }
127 /**
128 * Update or replace method for a simple resource.
129 * @param ri ResourceInitialization contains a ResAttributeType array,<br/>
130 * a boolean value Replace and a ResourceInfo object
131 * @return a string containing a status value
132 */
133 public SetSimpleResourceResponse setSimpleResource(ResourceInitialization ri){
134 VanHelsingStub stub;
135 try {
136 stub = getStub();
137
138 VanHelsingStub.SetSimpleResource req = new VanHelsingStub.SetSimpleResource();
139 req.setSetSimpleResource(ri);
140
141 VanHelsingStub.SetSimpleResourceResponse res = stub.setSimpleResource(req);
142
143 return res;
144 } catch (SetSimpleResourceFault1Exception ef1){
145 System.err.println("Constraint Violation");
146 } catch (SetSimpleResourceFaultException ef){
147 System.err.println("Syntax Error");
148 } catch (Exception e) {
149 System.err.println(e.toString());
150 }
151 return null;
152 }
153 /**
154 * Helper method to create a FileSetInclude object to be used by the<br/>
155 * setFileSetResource and createFileSetResource method
156 * @param fileList file parameter list of the include component
157 * @param fsOptions options parameter list of the include component
158 * @return a FileSetInclude object
159 */
160 public FileSetInclude makeFileSetInclude(ResourceAttributeType[] fileList,
161 ResourceAttributeType[] fsOptions){
162 FileSetInclude fsi = new FileSetInclude();
163 fsi.setFileList(fileList);
164 fsi.setOptions(fsOptions);
165 return fsi;
166 }
167 /**
168 * Helper method to create a ResourceAttributeType[] out auf an ArrayList of type ViewItem
169 * @param array ArrayList<ViewItem> containing all key value pairs
170 * @return the created ResourceAttributeType array
171 */
172 public ResourceAttributeType[] makeResAttrTypeArray(ArrayList<ViewItem> array){
173 array.trimToSize();
174 int i = 0;
175 ResourceAttributeType[] rat = new ResourceAttributeType[array.size()];
176 for (ViewItem vi : array){
177 rat[i] = new ResourceAttributeType();
178 rat[i].setKey(vi.getKey());
179 rat[i].setValue(vi.getKeyValue());
180 i++;
181 }
182 return rat;
183 }
184 /**
185 * Helper method to create a ResourceAttributeType[] object out of an array of arrays of strings
186 * @param array contains the key-value-pairs which will be stored in the ResourceAttributeType[]
187 * @return the created ResourceAttributeType array
188 */
189 public ResourceAttributeType[] makeResAttrTypeArray(String[][] array){
190 ResourceAttributeType[] rat = new ResourceAttributeType[array.length];
191 int i = 0;
192 for (String[] pair : array){
193 rat[i].setKey(pair[0]);
194 rat[i].setValue(pair[1]);
195 i++;
196 }
197 return rat;
198 }
199 /**
200 * helper method to create a FileSetResource as an argument to the setFileSetResource method and calls said method
201 * @param replace the object will be replaced if this parameter is set to true, otherwise the changed values will be updated
202 * @param fsi a FileSetInclude object containing the include block of the FileSetResource
203 * @param options a ResourceAttributeType[] object containing the options block of the FileSetResource
204 * @param exclude a ResourceAttributeType[] object containing the exclude options
205 * @param param a ResourceAttributeType[] object containing the file set options
206 * @return a status value of type string
207 */
208 public SetFileSetResourceResponse setFileSetResource(boolean replace, FileSetInclude fsi,
209 ResourceAttributeType[] options, ResourceAttributeType[] exclude,
210 ResourceAttributeType[] param){
211 FileSetResource fsr = new FileSetResource();
212 fsr.setReplace(replace);
213 fsr.setInclude(fsi);
214 fsr.setOptions(options);
215 fsr.setExclude(exclude);
216 fsr.setParameters(param);
217 return setFileSetResource(fsr);
218 }
219 /**
220 * Update or replace method for a file set resource.
221 * @param fsr
222 * @return a status value of type string
223 */
224 public SetFileSetResourceResponse setFileSetResource(FileSetResource fsr){
225 VanHelsingStub stub;
226 try {
227 stub = getStub();
228 VanHelsingStub.SetFileSetResource req = new VanHelsingStub.SetFileSetResource();
229 req.setSetFileSetResource(fsr);
230
231 VanHelsingStub.SetFileSetResourceResponse res = stub.setFileSetResource(req);
232 return res;
233
234 } catch (SetFileSetResourceFault1Exception ef1){
235 System.err.println("Constraint Violation");
236 } catch (SetFileSetResourceFaultException ef) {
237 System.err.println("Syntax Error");
238 } catch (Exception e){
239 System.err.println(e.toString());
240 }
241 return null;
242 }
243 /**
244 * helper method for accessing the deleteResource method.
245 * @param director the director on which the configuration is based on
246 * @param resId the id of the resource.
247 * @param resName the name of the resource
248 * @param resType the type of the resource
249 */
250 public void deleteResource(String director, int resId, String resName, String resType){
251 ResourceInfo ri = new ResourceInfo();
252 ri.setDirector(director);
253 ri.setResId(resId);
254 ri.setResName(resName);
255 ri.setResType(resType);
256 deleteResource(ri);
257 }
258 /**
259 * deletes a resource object of any type identified by the resource id
260 * @param ri ResourceInfo object containing the identification of the resource
261 */
262 public void deleteResource(ResourceInfo ri){
263 VanHelsingStub stub;
264 try{
265 stub = getStub();
266 VanHelsingStub.DeleteResource req = new VanHelsingStub.DeleteResource();
267 req.setDeleteResource(ri);
268 stub.deleteResource(req);
269 } catch (DeleteResourceFault1Exception ef1){
270 System.err.println("invalid Id");
271 } catch (DeleteResourceFaultException ef){
272 System.err.println("Constraint Violation");
273 } catch (Exception e){
274 System.err.println(e.toString());
275 }
276 }
277 /**
278 * helper method to create a ResourceInfo object
279 * @param director the director on which the configuration is based on
280 * @param id the id of the resource.
281 * @param name the name of the resource
282 * @param type the type of the resource
283 * @return new ResourceInfo object
284 */
285 public ResourceInfo makeResourceInfo(String director, int id, String name, String type){
286 ResourceInfo ri = new ResourceInfo();
287 ri.setDirector(director);
288 ri.setResId(id);
289 ri.setResName(name);
290 ri.setResType(type);
291 return ri;
292 }
293 /**
294 * creates a simple resource object at Van Helsing
295 * @param replace this parameter is part of the ResourceInitialization object but will not be used by the create method
296 * @param rat list of key value pairs of type ResourceAttributeType[]
297 * @param rinfo ResourceInfo object containing identification information of the object
298 * @return Id of the created simple resource
299 */
300 public int createSimpleResource(ResourceAttributeType[] rat, ResourceInfo rinfo){
301
302 ResourceInitialization ri = new ResourceInitialization();
303 ri.setReplace(false);
304 ri.setResInfo(rinfo);
305 ri.setResAttribute(rat);
306 return createSimpleResource(ri);
307 }
308 /**
309 * creates a simple resource object at Van Helsing
310 * @param ri ResourceInitialization object containing the needed information to create a simple resource object
311 * @return the id of the created SimpleResource
312 */
313 public int createSimpleResource(ResourceInitialization ri){
314 VanHelsingStub stub;
315 try {
316 stub = getStub();
317 VanHelsingStub.CreateSimpleResource req = new VanHelsingStub.CreateSimpleResource();
318 req.setCreateSimpleResource(ri);
319
320 VanHelsingStub.CreateSimpleResourceResponse res = stub.createSimpleResource(req);
321 return res.getResId();
322 } catch (CreateSimpleResourceFaultException ef) {
323 System.err.println("Syntax Error");
324 } catch (Exception e){
325 System.err.println(e.toString());
326 }
327 return -1;
328 }
329 /**
330 * creates a file set resource at Van Helsing
331 * @param replace the object will be replaced if this parameter is set to true, otherwise the changed values will be updated
332 * @param fsi FileSetInclude object containing the options and
333 * @param options list of key value pairs containing the options of a file set
334 * @param exclude list of key value pairs containing the excluded file(types)
335 * @param param list of key value pairs containing parameters of a file set
336 * @return the id of the created resource
337 */
338 public int createFileSetResource(boolean replace, FileSetInclude fsi,
339 ResourceAttributeType[] options, ResourceAttributeType[] exclude,
340 ResourceAttributeType[] param){
341 FileSetResource fsr = new FileSetResource();
342 fsr.setReplace(replace);
343 fsr.setInclude(fsi);
344 fsr.setOptions(options);
345 fsr.setExclude(exclude);
346 fsr.setParameters(param);
347 return createFileSetResource(fsr);
348 }
349 /**
350 * creates a file set object at Van Helsing
351 * @param fsr FileSetResource object contains the needed information to create a FileSetResource
352 * @return the id of the created FileSetResource
353 */
354 public int createFileSetResource(FileSetResource fsr){
355 VanHelsingStub stub;
356 try{
357 stub = getStub();
358 VanHelsingStub.CreateFileSetResource req = new VanHelsingStub.CreateFileSetResource();
359 req.setCreateFileSetResource(fsr);
360
361 VanHelsingStub.CreateFileSetResourceResponse res = stub.createFileSetResource(req);
362 return res.getResId();
363
364 } catch (CreateFileSetResourceFaultException ef){
365 System.err.println();
366 } catch (Exception e) {
367 System.err.println(e.toString());
368 }
369 return -1;
370 }
371 /**
372 * Helper method to create a VanHelsingStub.<br/>
373 * Chunked encoding is deactivated because of ZSI.
374 * @return a stub object used by the other access methods
375 * @throws Exception
376 */
377 private VanHelsingStub getStub() throws Exception {
378 String url = new String("http://localhost:8080/");
379 VanHelsingStub stub = new VanHelsingStub(url);
380 stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
381 return stub;
382 }
383}
Note: See TracBrowser for help on using the repository browser.