1 package org.enhydra.shark.corba; 2 3 import org.omg.WfBase.*; 4 import org.omg.WorkflowModel.*; 5 import org.enhydra.shark.corba.WorkflowService.*; 6 import org.omg.CORBA.*; 7 8 import java.util.*; 9 import org.enhydra.shark.utilities.SequencedHashMap; 10 11 import java.io.Serializable ; 12 13 19 public class SharkCORBAUtilities { 20 21 static NameValueInfo makeCORBANameValueInfo(String attribute_name, 22 String type_name) { 23 NameValueInfo nvic = new NameValueInfo(); 24 nvic.attribute_name = attribute_name; 25 nvic.type_name = type_name; 26 return nvic; 27 } 28 29 static NameValueInfo[] makeCORBANameValueInfoArray(Map nvia) { 30 int size = 0; 31 if (nvia != null) size = nvia.size(); 32 NameValueInfo[] nvica = new NameValueInfo[size]; 33 int i = 0; 34 if (nvia != null) { 35 for (Iterator it = nvia.entrySet().iterator(); it.hasNext(); i++) { 36 Map.Entry me = (Map.Entry) it.next(); 37 nvica[i] = makeCORBANameValueInfo(me.getKey().toString(), 38 me.getValue().toString()); 39 } 40 } 41 return nvica; 42 } 43 44 static NameValue makeCORBANameValue(ORB orb, 45 String the_name, 46 java.lang.Object the_value) { 47 NameValue nvc = new NameValue(); 48 nvc.the_name = the_name; 49 nvc.the_value = createAnyFromValue(orb, the_value); 50 return nvc; 51 } 52 53 static NameValue[] makeCORBANameValueArray(ORB orb, Map nva) { 54 int size = 0; 55 if (nva != null) size = nva.size(); 56 NameValue[] nvca = new NameValue[size]; 57 int i = 0; 58 if (nva != null) { 59 for (Iterator it = nva.entrySet().iterator(); it.hasNext(); i++) { 60 Map.Entry me = (Map.Entry) it.next(); 61 nvca[i] = makeCORBANameValue(orb, 62 me.getKey().toString(), 63 me.getValue()); 64 } 65 } 66 return nvca; 67 } 68 69 static NameValue[] makeCORBANameValueArray(ORB orb, String [][] nva) { 70 int size = 0; 71 if (nva != null) size = nva.length; 72 NameValue[] nvca = new NameValue[size]; 73 if (nva != null) { 74 for (int i = 0; i < size; i++) { 75 nvca[i] = makeCORBANameValue(orb, nva[i][0], nva[i][1]); 76 } 77 } 78 return nvca; 79 } 80 81 static NameValue[] makeCORBANameValueArray(ORB orb, Properties props) { 82 int size = 0; 83 if (props != null) size = props.size(); 84 NameValue[] nvca = new NameValue[size]; 85 if (props != null) { 86 Iterator it = props.entrySet().iterator(); 87 int i = 0; 88 while (it.hasNext()) { 89 Map.Entry me = (Map.Entry) it.next(); 90 nvca[i] = makeCORBANameValue(orb, 91 (String ) me.getKey(), 92 (String ) me.getValue()); 93 i++; 94 } 95 } 96 return nvca; 97 } 98 99 static Map makeMap(NameValue[] nvca) { 100 Map m = new SequencedHashMap(); 101 if (nvca != null) { 102 for (int i = 0; i < nvca.length; i++) { 103 m.put(nvca[i].the_name, extractValueFromAny(nvca[i].the_value)); 104 } 105 } 106 return m; 107 } 108 109 static DeadlineInfo[] makeDeadlineInfoArray (org.enhydra.shark.api.common.DeadlineInfo[] di) { 110 DeadlineInfo[] cdi=new DeadlineInfo[di.length]; 111 for (int i=0; i<di.length; i++) { 112 cdi[i]=new DeadlineInfo(); 113 cdi[i].procId=di[i].procId; 114 cdi[i].actId=di[i].actId; 115 cdi[i].isExecuted=di[i].isExecuted; 116 cdi[i].timeLimit=di[i].timeLimit; 117 cdi[i].exceptionName=di[i].exceptionName; 118 cdi[i].isSynchronous=di[i].isSynchronous; 119 } 120 return cdi; 121 } 122 123 static java.lang.Object extractValueFromAny(Any any) { 124 java.lang.Object value = null; 125 try { 126 int kind = any.type().kind().value(); 127 if (kind == TCKind._tk_boolean) { 128 value = new Boolean (any.extract_boolean()); 129 } else if (kind == TCKind._tk_wstring) { 130 value = new String (any.extract_wstring()); 131 } else if (kind == TCKind._tk_long) { 132 value = new Integer (any.extract_long()); 133 } else if (kind == TCKind._tk_longlong) { 134 value = new Long (any.extract_longlong()); 135 } else if (kind == TCKind._tk_double) { 136 value = new Double (any.extract_double()); 137 } else if (kind == TCKind._tk_value) { 138 value = any.extract_Value(); 139 } 140 } catch (BAD_OPERATION bo) { 141 System.out.println("Extracting value failed - bo exception"); 142 return null; 144 } 145 return value; 146 } 147 148 static Any createAnyFromValue(ORB orb, java.lang.Object value) { 149 Any any = orb.create_any(); 150 151 try { 152 if (value instanceof Boolean ) { 153 any.insert_boolean(((Boolean ) value).booleanValue()); 154 } else if (value instanceof String ) { 155 any.insert_wstring((String ) value); 156 } else if (value instanceof Long ) { 157 any.insert_longlong(((Long ) value).longValue()); 158 } else if (value instanceof Double ) { 159 any.insert_double(((Double ) value).doubleValue()); 160 } else if (value instanceof Serializable ) { 161 any.insert_Value((Serializable ) value); 162 } 163 } catch (BAD_OPERATION bo) { 164 System.out.println("Creating any from val failed - bo exception"); 165 } 167 return any; 168 } 169 170 static WfProcessMgr[] makeCORBAProcessMgrs(Collective toJoin, 171 org.enhydra.shark.api.client.wfmodel.WfProcessMgr[] objs) { 172 int size = 0; 173 if (objs != null) size = objs.length; 174 WfProcessMgrCORBA[] cobjs = new WfProcessMgrCORBA[size]; 175 for (int i = 0; i < cobjs.length; i++) { 176 try { 177 cobjs[i] = new WfProcessMgrCORBA(toJoin, objs[i]); 178 } catch (Exception ex) {} 179 } 180 return cobjs; 181 } 182 183 static WfProcess[] makeCORBAProcesses(Collective toJoin, 184 org.enhydra.shark.api.client.wfmodel.WfProcess[] objs) { 185 int size = 0; 186 if (objs != null) size = objs.length; 187 WfProcessCORBA[] cobjs = new WfProcessCORBA[size]; 188 for (int i = 0; i < cobjs.length; i++) { 189 try { 190 cobjs[i] = new WfProcessCORBA(toJoin, objs[i]); 191 } catch (Exception ex) {} 192 } 193 return cobjs; 194 } 195 196 static WfActivity[] makeCORBAActivities(Collective toJoin, 197 org.enhydra.shark.api.client.wfmodel.WfActivity[] objs) { 198 int size = 0; 199 if (objs != null) size = objs.length; 200 WfActivityCORBA[] cobjs = new WfActivityCORBA[size]; 201 for (int i = 0; i < cobjs.length; i++) { 202 try { 203 cobjs[i] = new WfActivityCORBA(toJoin, objs[i]); 204 } catch (Exception ex) {} 205 } 206 return cobjs; 207 } 208 209 static WfAssignment[] makeCORBAAssignments(Collective toJoin, 210 org.enhydra.shark.api.client.wfmodel.WfAssignment[] objs) { 211 int size = 0; 212 if (objs != null) size = objs.length; 213 WfAssignmentCORBA[] cobjs = new WfAssignmentCORBA[size]; 214 for (int i = 0; i < cobjs.length; i++) { 215 try { 216 cobjs[i] = new WfAssignmentCORBA(toJoin, objs[i]); 217 } catch (Exception ex) {} 218 } 219 return cobjs; 220 } 221 222 static WfResource[] makeCORBAResources(Collective toJoin, 223 org.enhydra.shark.api.client.wfmodel.WfResource[] objs) { 224 int size = 0; 225 if (objs != null) size = objs.length; 226 WfResourceCORBA[] cobjs = new WfResourceCORBA[size]; 227 for (int i = 0; i < cobjs.length; i++) { 228 try { 229 cobjs[i] = new WfResourceCORBA(toJoin, objs[i]); 230 } catch (Exception ex) {} 231 } 232 return cobjs; 233 } 234 235 static WfEventAudit makeCORBAEventAudit(Collective toJoin, 236 org.enhydra.shark.api.client.wfmodel.WfEventAudit obj) { 237 try { 238 if (obj instanceof org.enhydra.shark.api.client.wfmodel.WfCreateProcessEventAudit) { 239 return new WfCreateProcessEventAuditCORBA(toJoin, 240 (org.enhydra.shark.api.client.wfmodel.WfCreateProcessEventAudit) obj); 241 } else if (obj instanceof org.enhydra.shark.api.client.wfmodel.WfAssignmentEventAudit) { 242 return new WfAssignmentEventAuditCORBA(toJoin, 243 (org.enhydra.shark.api.client.wfmodel.WfAssignmentEventAudit) obj); 244 } else if (obj instanceof org.enhydra.shark.api.client.wfmodel.WfDataEventAudit) { 245 return new WfDataEventAuditCORBA(toJoin, 246 (org.enhydra.shark.api.client.wfmodel.WfDataEventAudit) obj); 247 } else if (obj instanceof org.enhydra.shark.api.client.wfmodel.WfStateEventAudit) { 248 return new WfStateEventAuditCORBA(toJoin, 249 (org.enhydra.shark.api.client.wfmodel.WfStateEventAudit) obj); 250 } else { 251 return null; 252 } 253 } catch (Exception ex) { 254 return null; 255 } 256 } 257 258 static WfEventAudit[] makeCORBAEventAudits(Collective toJoin, 259 org.enhydra.shark.api.client.wfmodel.WfEventAudit[] objs) { 260 int size = 0; 261 if (objs != null) size = objs.length; 262 WfEventAudit[] cobjs = new WfEventAudit[size]; 263 for (int i = 0; i < cobjs.length; i++) { 264 cobjs[i] = makeCORBAEventAudit(toJoin, objs[i]); 265 } 266 return cobjs; 267 } 268 269 static WfStateEventAudit[] makeCORBAStateEventAudits(Collective toJoin, 270 org.enhydra.shark.api.client.wfmodel.WfEventAudit[] objs) throws Exception { 271 int size = 0; 272 if (objs != null) size = objs.length; 273 WfStateEventAudit[] cobjs = new WfStateEventAuditCORBA[size]; 274 for (int i = 0; i < cobjs.length; i++) { 275 cobjs[i] = (WfStateEventAudit) makeCORBAEventAudit(toJoin, objs[i]); 276 } 277 return cobjs; 278 } 279 280 static WfDataEventAudit[] makeCORBADataEventAudits(Collective toJoin, 281 org.enhydra.shark.api.client.wfmodel.WfEventAudit[] objs) throws Exception { 282 int size = 0; 283 if (objs != null) size = objs.length; 284 WfDataEventAudit[] cobjs = new WfDataEventAuditCORBA[size]; 285 for (int i = 0; i < cobjs.length; i++) { 286 cobjs[i] = (WfDataEventAudit) makeCORBAEventAudit(toJoin, objs[i]); 287 } 288 return cobjs; 289 } 290 291 static WfAssignmentEventAudit[] makeCORBAAssignmentEventAudits(Collective toJoin, 292 org.enhydra.shark.api.client.wfmodel.WfEventAudit[] objs) throws Exception { 293 int size = 0; 294 if (objs != null) size = objs.length; 295 WfAssignmentEventAudit[] cobjs = new WfAssignmentEventAuditCORBA[size]; 296 for (int i = 0; i < cobjs.length; i++) { 297 cobjs[i] = (WfAssignmentEventAudit) makeCORBAEventAudit(toJoin, 298 objs[i]); 299 } 300 return cobjs; 301 } 302 303 static ParticipantMap[] makeCORBAParticipantMaps(Collective toJoin, 304 org.enhydra.shark.api.client.wfservice.ParticipantMap[] objs) { 305 int size = 0; 306 if (objs != null) size = objs.length; 307 ParticipantMap[] cobjs = new ParticipantMap[size]; 308 for (int i = 0; i < cobjs.length; i++) { 309 cobjs[i] = new ParticipantMapCORBA(toJoin, objs[i]); 310 } 311 return cobjs; 312 } 313 314 static ApplicationMap[] makeCORBAApplicationMaps(Collective toJoin, 315 org.enhydra.shark.api.client.wfservice.ApplicationMap[] objs) { 316 int size = 0; 317 if (objs != null) size = objs.length; 318 ApplicationMap[] cobjs = new ApplicationMap[size]; 319 for (int i = 0; i < cobjs.length; i++) { 320 cobjs[i] = new ApplicationMapCORBA(toJoin, objs[i]); 321 } 322 return cobjs; 323 } 324 325 static org.enhydra.shark.api.client.wfservice.ApplicationMap fillApplicationMap(org.enhydra.shark.api.client.wfservice.ApplicationMap nm, 326 ApplicationMap am) { 327 nm.setToolAgentClassName(am.getToolAgentClassName()); 328 nm.setUsername(am.getUsername()); 329 nm.setPassword(am.getPassword()); 330 nm.setApplicationName(am.getApplicationName()); 331 if (am.getApplicationMode() != -Integer.MAX_VALUE) { 332 nm.setApplicationMode(new Integer (am.getApplicationMode())); 333 } 334 nm.setPackageId(am.getPackageId()); 335 nm.setProcessDefinitionId(am.getProcessDefinitionId()); 336 nm.setApplicationDefinitionId(am.getApplicationDefinitionId()); 337 return nm; 338 } 339 340 static org.enhydra.shark.api.client.wfservice.ParticipantMap fillParticipantMap(org.enhydra.shark.api.client.wfservice.ParticipantMap nm, 341 ParticipantMap pm) { 342 nm.setParticipantId(pm.getParticipantId()); 343 nm.setPackageId(pm.getPackageId()); 344 nm.setProcessDefinitionId(pm.getProcessDefinitionId()); 345 nm.setUsername(pm.getUsername()); 346 nm.setIsGroupUser(pm.getIsGroupUser()); 347 return nm; 348 } 349 350 } | Popular Tags |