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