[840] | 1 | package de.dass_it.vanhelsing.gui;
|
---|
| 2 |
|
---|
[865] | 3 | import java.util.Iterator;
|
---|
| 4 |
|
---|
[840] | 5 | import de.dass_it.www.vanhelsing.*;
|
---|
| 6 | import de.dass_it.www.vanhelsing.VanHelsingCallbackHandler.*;
|
---|
| 7 | import de.dass_it.www.vanhelsing.VanHelsingStub.*;
|
---|
[864] | 8 | /**
|
---|
[865] | 9 | * Client wraps access methods and data structure of the axis client
|
---|
[864] | 10 | * @author tgoecke
|
---|
| 11 | *
|
---|
| 12 | */
|
---|
[840] | 13 | public class Client {
|
---|
[865] | 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 | */
|
---|
[862] | 22 | public ResourceInfo[] getListResources(String director, String resource){
|
---|
| 23 | ListResourcesType lrt = new ListResourcesType();
|
---|
| 24 | lrt.setDirector(director);
|
---|
| 25 | lrt.setResourceType(resource);
|
---|
| 26 | return getListResources(lrt);
|
---|
| 27 | }
|
---|
[865] | 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 | */
|
---|
[840] | 36 | public ResourceInfo[] getListResources(ListResourcesType lrt){
|
---|
| 37 | VanHelsingStub stub;
|
---|
| 38 | try {
|
---|
[844] | 39 |
|
---|
| 40 | stub = getStub();
|
---|
[840] | 41 |
|
---|
| 42 | VanHelsingStub.ListResources req = new VanHelsingStub.ListResources();
|
---|
| 43 | req.setListResources(lrt);
|
---|
| 44 |
|
---|
| 45 | VanHelsingStub.ListResourcesResponse res = stub.listResources(req);
|
---|
| 46 | return (res.getListResourcesResponse()).getResource();
|
---|
| 47 |
|
---|
| 48 | } catch (Exception e){
|
---|
[844] | 49 | System.err.println("getListResources: " + e.toString());
|
---|
[840] | 50 | }
|
---|
| 51 | return new ResourceInfo[0];
|
---|
| 52 | }
|
---|
[865] | 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 | */
|
---|
[862] | 60 | public SimpleResource getSimpleResource(String director, int resId){
|
---|
| 61 | GetResourceType grt = new GetResourceType();
|
---|
| 62 | grt.setDirector(director);
|
---|
| 63 | grt.setResId(resId);
|
---|
| 64 | return getSimpleResource(grt);
|
---|
| 65 | }
|
---|
[865] | 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 | */
|
---|
[844] | 72 | public SimpleResource getSimpleResource(GetResourceType grt){
|
---|
[840] | 73 | VanHelsingStub stub;
|
---|
| 74 | try {
|
---|
[844] | 75 | stub = getStub();
|
---|
[840] | 76 |
|
---|
[844] | 77 | VanHelsingStub.GetSimpleResource req = new VanHelsingStub.GetSimpleResource();
|
---|
| 78 | req.setGetSimpleResource(grt);
|
---|
[840] | 79 |
|
---|
[844] | 80 | VanHelsingStub.GetSimpleResourceResponse res = stub.getSimpleResource(req);
|
---|
[840] | 81 |
|
---|
[844] | 82 | SimpleResource sr = new SimpleResource();
|
---|
| 83 | sr.setResourceInfo(res.getResInfo());
|
---|
| 84 | sr.setResourceAttributeType(res.getResAttribute());
|
---|
| 85 | return sr;
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | } catch(Exception e){
|
---|
[865] | 89 | System.err.println("getSR: " + grt.getResId() + " : " + e.toString());
|
---|
[840] | 90 | }
|
---|
[844] | 91 | return new SimpleResource(new ResourceInfo(), new ResourceAttributeType[0]);
|
---|
| 92 | }
|
---|
[865] | 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 |
|
---|
[862] | 120 | ResourceInitialization ri = new ResourceInitialization();
|
---|
[865] | 121 | ri.setResInfo(resInfo);
|
---|
| 122 | ri.setResAttribute(rat);
|
---|
| 123 | ri.setReplace(replace);
|
---|
[862] | 124 | return setSimpleResource(ri);
|
---|
| 125 | }
|
---|
[865] | 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 | */
|
---|
[860] | 132 | public SetSimpleResourceResponse setSimpleResource(ResourceInitialization ri){
|
---|
[854] | 133 | VanHelsingStub stub;
|
---|
| 134 | try {
|
---|
| 135 | stub = getStub();
|
---|
| 136 |
|
---|
| 137 | VanHelsingStub.SetSimpleResource req = new VanHelsingStub.SetSimpleResource();
|
---|
[860] | 138 | req.setSetSimpleResource(ri);
|
---|
[854] | 139 |
|
---|
[860] | 140 | VanHelsingStub.SetSimpleResourceResponse res = stub.setSimpleResource(req);
|
---|
[854] | 141 |
|
---|
| 142 | return res;
|
---|
[860] | 143 | } catch (SetSimpleResourceFault1Exception ef1){
|
---|
| 144 | System.err.println("Constraint Violation");
|
---|
| 145 | } catch (SetSimpleResourceFaultException ef){
|
---|
| 146 | System.err.println("Syntax Error");
|
---|
[854] | 147 | } catch (Exception e) {
|
---|
| 148 | System.err.println(e.toString());
|
---|
| 149 | }
|
---|
| 150 | return null;
|
---|
| 151 | }
|
---|
[865] | 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 | */
|
---|
[844] | 359 | private VanHelsingStub getStub() throws Exception {
|
---|
| 360 | String url = new String("http://localhost:8080/");
|
---|
| 361 | VanHelsingStub stub = new VanHelsingStub(url);
|
---|
| 362 | stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
|
---|
| 363 | return stub;
|
---|
| 364 | }
|
---|
[840] | 365 | }
|
---|