public class ProcessDefinitionAdapter implements org.uengine.processpublisher.Adapter{
static Hashtable adapters = new Hashtable();
public Object convert(Object src, java.util.Hashtable keyedContext) throws Exception{
ProcessDefinition srcProcDef = (ProcessDefinition)src;
tProcess proc = new tProcess();
String srcProcName = BPELSerializer.toSafeName(srcProcDef.getName().getText(), "Process");
proc.setname_Attribute(new XNCName(srcProcName));
proc.settargetNamespace_Attribute(new XAnyURI("urn:" + srcProcName));
Hashtable context = new Hashtable();
context.put("addVariables", new Vector());
activity actGrp = new activity();
tSequence seq = new tSequence();
seq.setname_Attribute(new XNCName("_main_sequence"));
Vector childActivities = srcProcDef.getChildActivities();
for(Enumeration enumeration = childActivities.elements(); enumeration.hasMoreElements();){
Object item = (Object)enumeration.nextElement();
Adapter adpt = getAdapter(item.getClass());
if(adpt==null){
continue;
}
activity actGrp_ = (activity)adpt.convert(item, context);
seq.addactivity_Group(actGrp_);
}
actGrp.setsequenceAsChoice(seq);
proc.setactivity_Group(actGrp);
//setting variables
tVariables variables = new tVariables();
ProcessVariable pvds[] = srcProcDef.getProcessVariables();
for(int i=0; i<pvds.length; i++){
ProcessVariable pvd = pvds[i];
tVariable variable = new tVariable();
variable.setname_Attribute(new XNCName(BPELSerializer.toSafeName(pvd.getName(), "variable"+i)));
//review: should be xsi type
variable.settype_Attribute(getXSDTypeName(pvd));
variables.addvariable(variable);
}
Vector addVariables = (Vector)context.get("addVariables");
for(Enumeration enumeration = addVariables.elements(); enumeration.hasMoreElements(); ){
Object [] varCtx = (Object[])enumeration.nextElement();
String variableName = (String)varCtx[0];
XQName variableType = (XQName)varCtx[1];
tVariable variable = new tVariable();
variable.setname_Attribute(new XNCName(variableName) );
//review: should be xsi type
variable.setmessageType_Attribute(variableType);
variables.addvariable(variable);
}
proc.setvariables(variables);
//
//setting partners
tPartnerLinks partnerLinks = new tPartnerLinks();
Role roles[] = srcProcDef.getRoles();
for(int i=0; i<roles.length; i++){
Role role = roles[i];
tPartnerLink partnerLink = new tPartnerLink();
String roleName = BPELSerializer.toSafeName(role.getName(), "role"+i);
partnerLink.setname_Attribute(new XNCName(roleName));
partnerLink.setpartnerLinkType_Attribute(new XQName("sdns", "", roleName + "PartnerLinkType"));
partnerLink.setpartnerRole_Attribute(new XNCName("partnerRole"));
partnerLinks.addpartnerLink(partnerLink);
}
//add my role
tPartnerLink partnerLink = new tPartnerLink();
partnerLink.setname_Attribute(new XNCName("myRole") );
partnerLink.setpartnerLinkType_Attribute(new XQName("sdns", "", srcProcName + "PartnerLinkType"));
partnerLink.setpartnerRole_Attribute(new XNCName("myRole"));
partnerLinks.addpartnerLink(partnerLink);
//
proc.setpartnerLinks(partnerLinks);
//
//setting correlations
tCorrelationSets correlationSets = new tCorrelationSets();
for(int i=0; i<roles.length; i++){
Role role = roles[i];
ProcessVariable identifier = role.getIdentifier();
if(identifier==null) identifier = srcProcDef.getProcessVariables()[0];//continue;
tCorrelationSet correlationSet = new tCorrelationSet();
correlationSet.setname_Attribute(new XNCName(BPELSerializer.toSafeName(role.getName(), "role"+i)+"Identification"));
//review:
correlationSet.setproperties_Attribute(new XQName("sdns","","property_" + identifier.getName()));