final static String VAR_DEFS = "variables";
final static String MY_SVC_DEF = "my service definition";
final static String MY_ROLE = "my role";
public Object convert(Object src, java.util.Hashtable keyedContext) throws Exception{
ProcessDefinition srcProc = (ProcessDefinition)src;
ProcessDefinition dstProc = new ProcessDefinition();
Role role = (Role)keyedContext.get("role");
ServiceDefinition mySvcDef = new ServiceDefinition();
//review: ProcessDefinition need WSDL location field if once exposed as a Web service
String srcProcName = srcProc.getName().getText().replace(' ', '_');
mySvcDef.setName(srcProcName);
mySvcDef.setWsdlLocation("http://localhost:8082/axis/services/" + srcProcName );
mySvcDef.setStubPackage("org.uengine");
dstProc.setServiceDefinitions(new ServiceDefinition[]{mySvcDef});
Role myRole = new Role();
//review: seems occur namespace collision
myRole.setName(srcProcName);
myRole.setServiceType(mySvcDef);
dstProc.setRoles(new Role[]{myRole});
dstProc.setName(role.getName());
MessageDefinition message = new MessageDefinition();
ServiceDefinition svcDef = role.getServiceType();
// Definition wsdlDef = svcDef.getDefinition();
// keyedContext.put(WSDL_DEF, wsdlDef);
keyedContext.put(DEST_PROC, dstProc);
keyedContext.put(MSG_DEFS, new ExclusiveList());
keyedContext.put(VAR_DEFS, new ExclusiveList());
keyedContext.put(MY_SVC_DEF, mySvcDef);
keyedContext.put(MY_ROLE, myRole);
Vector childActivities = srcProc.getChildActivities();
for(Enumeration enumeration = childActivities.elements(); enumeration.hasMoreElements();){
Object item = (Object)enumeration.nextElement();
Adapter adpt = getAdapter(item.getClass());
if(adpt==null){
continue;
}
Activity convertedAct = (Activity)adpt.convert(item, keyedContext);
if(convertedAct!=null){
if(convertedAct instanceof SequenceActivity){
SequenceActivity seq = (SequenceActivity)convertedAct;
Vector childActs = seq.getChildActivities();
for(Iterator iter = childActs.iterator(); iter.hasNext();){
Activity act = (Activity)iter.next();
dstProc.addChildActivity(act);
}
}else
dstProc.addChildActivity(convertedAct);
}
}
Vector messageDefinitions = (Vector)keyedContext.get(ProcessDefinitionAdapter.MSG_DEFS);
MessageDefinition[] mds = new MessageDefinition[messageDefinitions.size()];
messageDefinitions.toArray(mds);
dstProc.setMessageDefinitions(mds);
Vector variableDefinitions = (Vector)keyedContext.get(ProcessDefinitionAdapter.VAR_DEFS);
ProcessVariable[] pvs = new ProcessVariable[variableDefinitions.size()];
variableDefinitions.toArray(pvs);
dstProc.setProcessVariables(pvs);
return dstProc;
}