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

Last change on this file since 867 was 867, checked in by tobias, on Apr 26, 2010 at 6:20:44 PM

create Client function added

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