Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[bpel-dev] ExtensionActivity Deserializer problem

Hi Bob,

I am trying to implement an extensionActivity . This activity generates following XML code.

<bpel:extensionActivity>
<b4p:peopleActivity name="PeopleActivityRT">
<b4p:remoteTask></b4p:remoteTask>
</b4p:peopleActivity>
</bpel:extensionActivity>

But I have found an error when I open a saved bpel file using business process editor. When I open a bpel file using business process editor, it changes like this,

<bpel:extensionActivity>
<b4p:peopleActivity name="PeopleActivityRT">

</b4p:peopleActivity>
<b4p:remoteTask></b4p:remoteTask>
</bpel:extensionActivity>

This is not happened when I open a file using XML editor. So I thing it is a problem of Deserilizer of the extensionActivity. Any Idea about what went wrong ?.

I have attached Deserializer and Serializer classes.

--

Hasitha Aravinda,
Undergraduate,
Department of Computer Science and Engineering,
University of Moratuwa,
Sri Lanka.

My web portal : http://hasitha.comze.com

import javax.xml.namespace.QName;
import org.eclipse.bpel.model.Activity;
import org.eclipse.bpel.model.Process;
import org.eclipse.bpel.model.extensions.BPELActivitySerializer;
import org.eclipse.bpel.model.resource.BPELWriter;
import org.eclipse.wst.wsdl.Operation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.wso2.bpel.humantask.model.ModelPackage;
import org.wso2.bpel.humantask.model.PeopleActivityRT;
import org.wso2.bpel.humantask.model.RemoteTask;


public class HTSerializer implements BPELActivitySerializer {

	Document document = null;
	QName elementType =null;
	Process process = null;
	
	@Override
	public void marshall(QName elementType, Activity activity, Node parentNode,
			Process process, BPELWriter bpelWriter) {
		
		document = parentNode.getOwnerDocument();
		this.elementType = elementType;
		this.process = process;
		/*
		 *  RemoteTask
		 */
		if (activity instanceof PeopleActivityRT)
		{
			PeopleActivityRT pa = (PeopleActivityRT) activity;
			// create a new DOM element for our Activity
			Element paElement = document.createElementNS(elementType.getNamespaceURI(),
					HTConstants.ND_PEOPLE_ACTIVITY_RT);
			paElement.setPrefix(HTUtils.addNamespace(process));
			
			peopleActivityRTAttribute2XML(pa, paElement);
			peopleActivityRTNode2XML(pa, paElement);
			
			// insert the DOM element into the DOM tree
			parentNode.appendChild(paElement);
		}
		
	}
		
		
	protected void peopleActivityRTAttribute2XML(PeopleActivityRT pa, Element paElement){
			
		// handle Attributes
		//Input variable
		if (pa.getInputVariable() != null) {
			String attName = ModelPackage.eINSTANCE
					.getPeopleActivityRT_InputVariable().getName();
			paElement.setAttribute(attName, pa.getInputVariable().getName());	
		}
		if (pa.getOutputVariable() != null) {
			String attName = ModelPackage.eINSTANCE
					.getPeopleActivityRT_OutputVariable().getName();
			paElement.setAttribute(attName, pa.getOutputVariable().getName());
		}
		if (pa.isIsSkipable()) {
			String attName = ModelPackage.eINSTANCE
					.getPeopleActivityRT_IsSkipable().getName();
			paElement.setAttribute(attName, HTUtils.boolean2XML(pa.isIsSkipable()));
		}
		if (pa.isDontShareComments()) {
			String attName = ModelPackage.eINSTANCE
					.getPeopleActivityRT_DontShareComments().getName();
			paElement.setAttribute(attName, HTUtils.boolean2XML(pa.isIsSkipable()));
		}
	}

	protected void peopleActivityRTNode2XML(PeopleActivityRT activity, Element activityElement){
		
		// handle Nodes
		if(activity.getRemoteTask()!=null)
		{	
			activityElement.appendChild(RemoteTask2XML(activity.getRemoteTask()));
		}
			
	}
	
	protected Element RemoteTask2XML(RemoteTask remoteTask){
		
		Element rtElement = document.createElementNS(elementType.getNamespaceURI(),
				HTConstants.ND_REMOTE_TASK);
		rtElement.setPrefix(HTUtils.addNamespace(process));
		
		if (remoteTask.getPartnerLink() != null) {
			String attName = ModelPackage.eINSTANCE
					.getRemoteTask_PartnerLink().getName();
			rtElement.setAttribute(attName, remoteTask.getPartnerLink().getName());	
		}
		if (remoteTask.getOperation() != null) {
			String attName = ModelPackage.eINSTANCE
					.getRemoteTask_Operation().getName();
			rtElement.setAttribute(attName, getOperationSignature(remoteTask.getOperation()));	
		}
		if (remoteTask.getResponseOperation() != null) {
			String attName = ModelPackage.eINSTANCE
					.getRemoteTask_ResponseOperation().getName();
			rtElement.setAttribute(attName, getOperationSignature(remoteTask.getResponseOperation()));	
		}
		
		return rtElement;
	}
	
	
	protected String getOperationSignature(Operation op) {
		String signature = "";
		if (op != null) {
			signature = op.getName();
		}
		return signature;
	}
	
}
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.wsdl.extensions.ExtensionRegistry;
import javax.xml.namespace.QName;


import org.eclipse.bpel.model.Activity;
import org.eclipse.bpel.model.BPELPackage;
import org.eclipse.bpel.model.PartnerLink;
import org.eclipse.bpel.model.Process;
import org.eclipse.bpel.model.Variable;
import org.eclipse.bpel.model.extensions.BPELActivityDeserializer;
import org.eclipse.bpel.model.partnerlinktype.Role;
import org.eclipse.bpel.model.proxy.PartnerLinkProxy;
import org.eclipse.bpel.model.resource.BPELReader;
import org.eclipse.bpel.model.util.BPELUtils;
import org.eclipse.bpel.ui.util.ModelHelper;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.wst.wsdl.Operation;
import org.eclipse.wst.wsdl.PortType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.wso2.bpel.humantask.model.ModelFactory;
import org.wso2.bpel.humantask.model.ModelPackage;
import org.wso2.bpel.humantask.model.PeopleActivityRT;
import org.wso2.bpel.humantask.model.RemoteTask;

public class HTDeserializer implements BPELActivityDeserializer {


	private QName elementType =null;
	private Process process = null;
	private Node node = null;
	private BPELReader bpelReader = null;
	private PartnerLink ptlink= null;
	private List<Runnable> fPass2Runnables = new ArrayList<Runnable>();
	
	@Override
	public Activity unmarshall(QName elementType, Node node, Activity activity,
			Process process, Map nsMap, ExtensionRegistry extReg, URI uri,
			BPELReader bpelReader) {
		
		String childLocalName = "";
		this.elementType = elementType;
		this.process = process;
		this.node = node;
		this.bpelReader = bpelReader;
		

		
		if(HTConstants.ND_PEOPLE_ACTIVITY_RT.equalsIgnoreCase(elementType.getLocalPart())){
			
			if(node.hasChildNodes()){
				NodeList ndlist = node.getChildNodes();
				
				for(int j=0 ; j<ndlist.getLength();j++)	{
				
					childLocalName = ndlist.item(j).getLocalName();
					if (HTConstants.ND_REMOTE_TASK.equalsIgnoreCase(childLocalName)) {
					
						PeopleActivityRT peopelActivityRT;
						Element paElement = (Element)node;
						if (activity instanceof PeopleActivityRT) {
							peopelActivityRT = (PeopleActivityRT)activity;
						}
						else {
							peopelActivityRT = ModelFactory.eINSTANCE.createPeopleActivityRT();
							// attach the DOM node to our new activity
							peopelActivityRT.setElement(paElement);
						}
						
						//Handling Attributes
						xml2PeopleActivityAttributrs(peopelActivityRT,paElement);
						
						//Nodes
						Element rtElement  = null;   
						
						NodeList children = paElement.getElementsByTagName("*");
						if (children != null && children.getLength() > 0) {
							for (int i = 0; i < children.getLength(); i++) {
								
								if ((children.item(i).getNodeType() == Node.ELEMENT_NODE)) {
									Node nd = children.item(i);
									if (HTConstants.ND_REMOTE_TASK.equals(nd.getLocalName()) ) {
										rtElement = (Element) nd;
										if(rtElement!=null){
											peopelActivityRT.setRemoteTask(xml2RemoteTask(rtElement));
										}
										break; 
						            }
								}
								
							}
						}
						
						return peopelActivityRT;

				}else if ("copy".equalsIgnoreCase(childLocalName)) {
					// For RemoteNotification
						
				break;
				}
				
				

			
				} // End of For loop
			}// end of Node has children
		}
		return null;
	}// end of unmarshall method
	
	protected void xml2PeopleActivityAttributrs(EObject peopelActivity, Element paElement)
	{
		//inputVariable
		String attName = ModelPackage.eINSTANCE
				.getPeopleActivityRT_InputVariable().getName();
		String value = paElement.getAttribute(attName);
		if (paElement.hasAttribute(attName)) {
			Variable[] vars = ModelHelper.getVisibleVariables(peopelActivity); // peopelActivityRT == activity
			for (int i=vars.length-1; i>=0; --i) {
				if (value.equals(vars[i].getName())) {
					peopelActivity.eSet(ModelPackage.eINSTANCE.getPeopleActivityRT_InputVariable(), vars[i]);
					break;
				}
			}
		}
		//outputVariable
		attName = ModelPackage.eINSTANCE
				.getPeopleActivityRT_OutputVariable().getName();
		value = paElement.getAttribute(attName);
		if (paElement.hasAttribute(attName)) {
			Variable[] vars = ModelHelper.getVisibleVariables(peopelActivity); // peopelActivityRT == activity
			for (int i=vars.length-1; i>=0; --i) {
				if (value.equals(vars[i].getName())) {
					peopelActivity.eSet(ModelPackage.eINSTANCE.getPeopleActivityRT_OutputVariable(), vars[i]);
					break;
				}
			}
		}
		
		//isSkipable
		attName = ModelPackage.eINSTANCE
				.getPeopleActivityRT_IsSkipable().getName();
		if(paElement.hasAttribute(attName)){
			boolean val =(Boolean.valueOf(paElement.getAttribute(attName).trim().equalsIgnoreCase("yes")));
			peopelActivity.eSet(ModelPackage.eINSTANCE.getPeopleActivityRT_IsSkipable(), val);
		}
		//dontSharecomments
		attName =ModelPackage.eINSTANCE
				.getPeopleActivityRT_DontShareComments().getName();
		if(paElement.hasAttribute(attName)){
			//peopelActivity.setDontShareComments(
			boolean val= Boolean.valueOf(paElement.getAttribute(attName).trim().equalsIgnoreCase("yes"));
			peopelActivity.eSet(ModelPackage.eINSTANCE.getPeopleActivityRT_DontShareComments(),val);
			
		}// End of attributes
		
	}
	
	
	
	protected RemoteTask xml2RemoteTask(Element rtElement){
		
		RemoteTask remoteTask = ModelFactory.eINSTANCE.createRemoteTask();
		remoteTask.setElement(rtElement);
		

		//Partner Link
		String attName = ModelPackage.eINSTANCE.getRemoteTask_PartnerLink().getName();
		if(rtElement.hasAttribute(attName)){
			setPartnerLink(rtElement, remoteTask, BPELPackage.eINSTANCE.getPartnerActivity_PartnerLink());

		}
		
		//Operation
		attName = ModelPackage.eINSTANCE.getRemoteTask_Operation().getName();
		if(rtElement.hasAttribute(attName)){
			remoteTask.setOperation(getOperation(rtElement, attName));

		}
		
		//Response Operation
		attName = ModelPackage.eINSTANCE.getRemoteTask_ResponseOperation().getName();
		if(rtElement.hasAttribute(attName)){
		remoteTask.setResponseOperation(getResponseOperation(rtElement, attName));

		}
		
		return remoteTask;
	}
	
	
	protected void setPartnerLink(Element activityElement, final EObject eObject, final EReference reference) {
		
		if (!activityElement.hasAttribute("partnerLink")) {
			return ;
		}

		final String partnerLinkName = activityElement.getAttribute("partnerLink");
		// We must do this as a post load runnable because the partner link might not
		// exist yet.
		fPass2Runnables.add(new Runnable() {
			public void run() {	
				PartnerLink targetPartnerLink = BPELUtils.getPartnerLink(eObject, partnerLinkName);
				if (targetPartnerLink == null) {
					targetPartnerLink = new PartnerLinkProxy( bpelReader.getResource().getURI(), partnerLinkName);
				}
				eObject.eSet(reference, targetPartnerLink);	
				ptlink = targetPartnerLink;
			}
		});
	}
	
	
	protected Operation getResponseOperation(Element activityElement,String value)
	{
	 Operation operation = BPELUtils.getOperation(bpelReader.getResource().getURI(), 
			 getMyRolePortType(), activityElement, value);
	 return operation;
	}
	
	protected Operation getOperation(Element activityElement,String value)
	{
	 Operation operation = BPELUtils.getOperation(bpelReader.getResource().getURI(), 
			 getPartnerRolePortType(), activityElement, value);
	 return operation;
	}
	
	
	public PortType getMyRolePortType() {
		PortType portType=null; 
			// portType is now optional. If the user hasn't set it, then
			// infer it from the partnerLink attribute and the 
			// direction of this activity.
		
			if (ptlink != null) {
				Role role = ptlink.getMyRole();
				if (role != null) {
					portType = (PortType) role.getPortType();
				}
			}
	 return portType;
		
	}
	
	public PortType getPartnerRolePortType() {
		PortType portType=null; 
			// portType is now optional. If the user hasn't set it, then
			// infer it from the partnerLink attribute and the 
			// direction of this activity.
		
			if (ptlink != null) {
				Role role = ptlink.getPartnerRole();
				if (role != null) {
					portType = (PortType) role.getPortType();
				}
			}
	 return portType;
		
	}
}

Back to the top