Package jbprocessor

Source Code of jbprocessor.BpelScanner

package jbprocessor;

import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.Vector;

import javax.jws.WebService;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;

import jbprocess.JbprocessAttributeMapping;
import jbprocess.JbprocessBpelProcessMapping;
import jbprocess.JbprocessElementMapping;
import jbprocess.JbprocessMapping;
import jbprocess.JbprocessMappingBuilder;
import jbprocess.annotations.FlowActivity;
import jbprocess.annotations.FlowLinkSource;
import jbprocess.annotations.FlowLinkTarget;
import jbprocess.annotations.ReceiveActivity;
import jbprocess.annotations.ReplyActivity;
import jbprocess.bpel.BpelCatchScope;
import jbprocess.bpel.BpelProcessScopeImpl;
import jbprocess.bpel.BpelScope;
import jbprocess.bpel.BpelScopeImpl;
import jbprocess.bpel.xpath.XpathBinaryOpExpression;
import jbprocess.bpel.xpath.XpathBooleanExpression;
import jbprocess.bpel.xpath.XpathExprBinOpType;
import jbprocess.bpel.xpath.XpathExprType;
import jbprocess.bpel.xpath.XpathExpression;
import jbprocess.bpel.xpath.XpathFactory;
import jbprocess.bpel.xpath.XpathNotExpression;
import jbprocess.bpel.xpath.XpathNumberExpression;
import jbprocess.bpel.xpath.XpathOperatorMapping;
import jbprocess.bpel.xpath.XpathStringExpression;
import jbprocess.bpel.xpath.XpathTypeMapping;
import jbprocess.bpel.xpath.XpathVariableRefExpression;
import jbprocess.wsdl.WsdlImportInfo;
import jbprocess.wsdl.WsdlPartnerLinkSerializer;

import org.eclipse.bpel.model.Activity;
import org.eclipse.bpel.model.Assign;
import org.eclipse.bpel.model.BPELFactory;
import org.eclipse.bpel.model.Catch;
import org.eclipse.bpel.model.CatchAll;
import org.eclipse.bpel.model.Condition;
import org.eclipse.bpel.model.Copy;
import org.eclipse.bpel.model.Else;
import org.eclipse.bpel.model.Expression;
import org.eclipse.bpel.model.Flow;
import org.eclipse.bpel.model.From;
import org.eclipse.bpel.model.If;
import org.eclipse.bpel.model.Invoke;
import org.eclipse.bpel.model.Link;
import org.eclipse.bpel.model.Links;
import org.eclipse.bpel.model.PartnerLink;
import org.eclipse.bpel.model.PartnerLinks;
import org.eclipse.bpel.model.Query;
import org.eclipse.bpel.model.Receive;
import org.eclipse.bpel.model.RepeatUntil;
import org.eclipse.bpel.model.Reply;
import org.eclipse.bpel.model.Source;
import org.eclipse.bpel.model.Sources;
import org.eclipse.bpel.model.Target;
import org.eclipse.bpel.model.Targets;
import org.eclipse.bpel.model.Throw;
import org.eclipse.bpel.model.To;
import org.eclipse.bpel.model.Variable;
import org.eclipse.bpel.model.Variables;
import org.eclipse.bpel.model.While;
import org.eclipse.bpel.model.partnerlinktype.PartnerLinkType;
import org.eclipse.bpel.model.partnerlinktype.PartnerlinktypeFactory;
import org.eclipse.bpel.model.partnerlinktype.Role;
import org.eclipse.bpel.model.resource.BPELResource;
import org.eclipse.bpel.model.resource.BPELResourceFactoryImpl;
import org.eclipse.bpel.model.util.BPELConstants;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.Fault;
import org.eclipse.wst.wsdl.Import;
import org.eclipse.wst.wsdl.Input;
import org.eclipse.wst.wsdl.Message;
import org.eclipse.wst.wsdl.Operation;
import org.eclipse.wst.wsdl.Output;
import org.eclipse.wst.wsdl.Part;
import org.eclipse.wst.wsdl.PortType;
import org.eclipse.wst.wsdl.Types;
import org.eclipse.wst.wsdl.WSDLFactory;
import org.eclipse.wst.wsdl.XSDSchemaExtensibilityElement;
import org.eclipse.wst.wsdl.internal.util.WSDLResourceFactoryImpl;
import org.eclipse.wst.wsdl.util.WSDLConstants;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDCompositor;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDFactory;
import org.eclipse.xsd.XSDForm;
import org.eclipse.xsd.XSDImport;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
import org.eclipse.xsd.XSDTypeDefinition;
import org.eclipse.xsd.util.XSDConstants;
import org.jdom.input.DOMBuilder;
import org.jdom.output.XMLOutputter;

import spoon.processing.Environment;
import spoon.reflect.Factory;
import spoon.reflect.code.BinaryOperatorKind;
import spoon.reflect.code.CtAssignment;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtCatch;
import spoon.reflect.code.CtDo;
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtFieldAccess;
import spoon.reflect.code.CtIf;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.code.CtLiteral;
import spoon.reflect.code.CtLocalVariable;
import spoon.reflect.code.CtNewClass;
import spoon.reflect.code.CtReturn;
import spoon.reflect.code.CtStatement;
import spoon.reflect.code.CtStatementList;
import spoon.reflect.code.CtThrow;
import spoon.reflect.code.CtTry;
import spoon.reflect.code.CtUnaryOperator;
import spoon.reflect.code.CtVariableAccess;
import spoon.reflect.code.CtWhile;
import spoon.reflect.code.UnaryOperatorKind;
import spoon.reflect.declaration.CtAnnotationType;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtInterface;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtSimpleType;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtFieldReference;
import spoon.reflect.reference.CtLocalVariableReference;
import spoon.reflect.reference.CtPackageReference;
import spoon.reflect.reference.CtReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.CtScanner;

public class BpelScanner extends CtScanner {
 
  private static final String JAXB_DEFAULT_NAME = "##default";
  private static final String WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";
 
  private static final String WSDL_PREFIX = "wsdl";
 
  private static final String XML_SCHEMA_NAMESPACE_PREFIX = "xsd";
 
  private static final String XPATH_NAMESPACE = "http://www.w3.org/TR/1999/REC-xpath-19991116";
 
  static final QName xsdBooleanQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"boolean",XML_SCHEMA_NAMESPACE_PREFIX);
  static XSDSimpleTypeDefinition
    xsdBooleanType = null;
  static final QName xsdDoubleQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"double",XML_SCHEMA_NAMESPACE_PREFIX);
  static XSDSimpleTypeDefinition
    xsdDoubleType = null;
  static final QName xsdFloatQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"float",XML_SCHEMA_NAMESPACE_PREFIX);
  static XSDSimpleTypeDefinition
    xsdFloatType = null;
  static final QName xsdIntegerQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"integer",XML_SCHEMA_NAMESPACE_PREFIX);
  static XSDSimpleTypeDefinition
    xsdIntegerType = null;
  static final QName xsdLongQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"long",XML_SCHEMA_NAMESPACE_PREFIX);
  static XSDSimpleTypeDefinition
    xsdLongType = null;
  static final QName xsdShortQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"short",XML_SCHEMA_NAMESPACE_PREFIX);
  static XSDSimpleTypeDefinition
    xsdShortType = null;
  static final QName xsdStringQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"string",XML_SCHEMA_NAMESPACE_PREFIX);
  static XSDSimpleTypeDefinition
    xsdStringType = null;
 
  int bpelCounter = 1;
  HashMap<String,String> bpelNsPrefixMap = new HashMap<String,String>();

  //  A class's super interface can map to a partner link if the @PartnerLink annotation
  //    is present and the interface maps to a port type.
  HashMap<CtClass<?>,HashSet<PartnerLink>> classProcessLinksMap = new HashMap<CtClass<?>,HashSet<PartnerLink>>();
  //  A class maps to a Bpel Process
  HashMap<CtClass<?>,org.eclipse.bpel.model.Process> classProcessMap = new HashMap<CtClass<?>,org.eclipse.bpel.model.Process>();
  //  A Class/Process has an associated scope stack
  HashMap<CtClass<?>,Stack<BpelScope>> classScopeMap = new HashMap<CtClass<?>,Stack<BpelScope>>();
  HashMap<XSDComplexTypeDefinition,ArrayList<XSDElementDeclaration>> complexTypePropMap = new HashMap<XSDComplexTypeDefinition,ArrayList<XSDElementDeclaration>>();
 
  HashSet<CtClass<?>> exceptionTypes = new HashSet<CtClass<?>>();
 
  HashMap<CtField<?>,XSDElementDeclaration> fieldElementDeclMap = new HashMap<CtField<?>,XSDElementDeclaration>();
  //  A field may map to either a variable or a partner link (used by the process)
  HashMap<CtField<?>,PartnerLink> fieldPartnerLinkMap = new HashMap<CtField<?>,PartnerLink>();
  HashMap<CtField<?>,Variable> fieldVariableMap = new HashMap<CtField<?>,Variable>();
  HashMap<CtMethod<?>,XSDElementDeclaration> methodElementDeclMap = new HashMap<CtMethod<?>,XSDElementDeclaration>();
  //   A method may map to a flow's activity
  HashMap<CtMethod<?>,Activity> methodFlowActivityMap = new HashMap<CtMethod<?>,Activity>();
  // JAX-RPC v1.1 (JSR-101), section 5.5.5 - Java Interface Methods Map to PortType Operations
  HashMap<CtMethod<?>,Operation> methodOperationMap = new HashMap<CtMethod<?>,Operation>();
  //  A method may map to a receive activity
  HashMap<CtMethod<?>,Activity> methodReceiveActivityMap = new HashMap<CtMethod<?>,Activity>();
  HashMap<CtMethod<?>,Receive> methodReceiveMap = new HashMap<CtMethod<?>,Receive>();
  //  A method may map to a reply activity
  HashMap<CtMethod<?>,Activity> methodReplyActivityMap = new HashMap<CtMethod<?>,Activity>();
 
  int namespaceCounter = 1;
  ASTNodeDataStack nodeDataStack = new ASTNodeDataStack();
 
  HashMap<Operation,javax.jws.soap.SOAPBinding> operationSoapBindingMap = new HashMap<Operation,javax.jws.soap.SOAPBinding>();
  boolean outputToConsole = false;
  HashMap<CtPackage,String> packageBpelNamespaceMap = new HashMap<CtPackage,String>();
  //  A package maps to a namespace.  The namespace can contain many Bpel Processes
  HashMap<CtPackage,HashSet<org.eclipse.bpel.model.Process>> packageBpelProcessesMap = new HashMap<CtPackage,HashSet<org.eclipse.bpel.model.Process>>();
  HashMap<org.eclipse.bpel.model.Process,HashSet<XSDSchema>> processSchemaDeps = new HashMap<org.eclipse.bpel.model.Process,HashSet<XSDSchema>>();
 
  HashMap<org.eclipse.bpel.model.Process,HashSet<Definition>> processWsdlDeps = new HashMap<org.eclipse.bpel.model.Process,HashSet<Definition>>();
  //HashMap<Receive, Variable> recvReplyVarMap = new HashMap<Receive, Variable>();
  //HashMap<Receive, XpathExpression> recvReplyXpathMap = new HashMap<Receive, XpathExpression>();
  int schemaCounter = 1
  HashMap<XSDSchema,HashSet<XSDSchema>> schemaDependencies = new HashMap<XSDSchema,HashSet<XSDSchema>>();
  HashMap<String,String> schemaNsPrefixMap = new HashMap<String,String>();
  HashMap<XSDSchema,String> schemaFileMap = new HashMap<XSDSchema,String>();
 
  Environment spoonEnvironment;
  Factory spoonFactory;
 
  int tmpMsgCounter = 1
  int tmpVarCounter = 1;
  // JAX-RPC v1.1 (JSR-101), section 5.5.3 - Java Interface Maps to Service Endpoint Interfaces a.k.a PortTypes
  HashMap<CtSimpleType,PortType> typePortTypeMap  = new HashMap<CtSimpleType,PortType>();
  HashMap<CtSimpleType,javax.jws.soap.SOAPBinding> typeSoapBindingMap = new HashMap<CtSimpleType,javax.jws.soap.SOAPBinding>();
  // JAXB v2.0 (JSR-222), section 8.2.1, 8.7 - Java Class Maps to XML Schema Complex Type
  HashMap<CtSimpleType,XSDComplexTypeDefinition> typeXSDComplexTypeMap = new HashMap<CtSimpleType,XSDComplexTypeDefinition>();
 
  ///////////////////////////////////////
  // Bpel Structural Mappings
  ///////////////////////////////////////

  int wsdlCounter = 1;
  // JAX-RPC v1.1 (JSR-101), section 5.5.2 - Java Package Maps to WSDL Definition
  HashMap<CtPackage,Definition> wsdlDefMap = new HashMap<CtPackage,Definition>();
 
  HashMap<Definition,Vector<XSDSchema>> wsdlDependencies = new HashMap<Definition,Vector<XSDSchema>>();
  HashMap<Operation,LinkedList<XSDElementDeclaration>> wsdlDocLitParamElemMap = new HashMap<Operation,LinkedList<XSDElementDeclaration>>();
  HashMap<CtParameter,XSDElementDeclaration> wsdlDocLitWrapParamMap = new HashMap<CtParameter,XSDElementDeclaration>();
 
  HashMap<Operation,XSDElementDeclaration> wsdlDocLitWrapResultMap = new HashMap<Operation,XSDElementDeclaration>();
  HashMap<String,String> wsdlNsPrefixMap = new HashMap<String,String>();
 
  ///////////////////////////////////////
  // Bpel Behavioral Mappings
  ///////////////////////////////////////
 
  HashMap<String,OutputStream> wsdlOutputStreamMap = new HashMap<String,OutputStream>();
 
  HashMap<CtParameter,Part> wsdlRpcLitParamMap = new HashMap<CtParameter,Part>();
  HashMap<CtMethod,Part> wsdlRpcLitResultMap = new HashMap<CtMethod,Part>();
  HashMap<Definition,XSDSchema> wsdlTypesSchemaMap = new HashMap<Definition,XSDSchema>();
  XpathFactory xpathFactory;
 
  // JAXB v2.0 (JSR-222), section 8.2.1, 8.6 - Java Package Maps to XML Schema
  HashMap<CtPackage,XSDSchema> xsdSchemaMap = new HashMap<CtPackage,XSDSchema>()
 
  HashMap<String,Writer> xsdWriterMap = new HashMap<String,Writer>();
 
  List<JbprocessMappingBuilder> builders;
 
  String outputDirectory = ".\\output\\";
 
  public BpelScanner(Factory spoonFactory,
      XpathFactory xpathFactory,
      List<JbprocessMappingBuilder> builders){   
    this.spoonFactory = spoonFactory;
    this.spoonEnvironment = spoonFactory.getEnvironment();   
    this.xpathFactory = xpathFactory;
    this.builders = Collections.synchronizedList(builders);
   
    if (xsdBooleanType == null){
      xsdBooleanType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
      xsdBooleanType.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
      xsdBooleanType.setName("boolean");
     
      xsdDoubleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
      xsdDoubleType.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
      xsdDoubleType.setName("double");
     
      xsdFloatType =  XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
      xsdFloatType.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
      xsdFloatType.setName("float");
     
      xsdIntegerType =  XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
      xsdIntegerType.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
      xsdIntegerType.setName("integer");
     
      xsdLongType =  XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
      xsdLongType.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
      xsdLongType.setName("long");
     
      xsdShortType =  XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
      xsdShortType.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
      xsdShortType.setName("short");
     
      xsdStringType =  XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
      xsdStringType.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
      xsdStringType.setName("string");
    }
  }
 
  @SuppressWarnings("unchecked")
  public void createNewException(Assign assign, Variable variable, Vector<XSDElementDeclaration> constructorArgElementMap, List<CtExpression<?>> constructorArgs){
    int argIndex = 0;
    for (CtExpression<?> arg : constructorArgs){
      XSDElementDeclaration el = constructorArgElementMap.get(argIndex);
      if (el != null){
        scan(arg);
        ASTNodeData argData = nodeDataStack.peek();
       
        From from = BPELFactory.eINSTANCE.createFrom();
        if (argData.xpathLiteralExpr != null){
          Expression expr = BPELFactory.eINSTANCE.createExpression();
          expr.setBody(argData.xpathLiteralExpr.evaluate());
          from.setExpression(expr);       
        } else if (argData.variable != null && argData.xpathExpr != null){
          Query query = BPELFactory.eINSTANCE.createQuery();
          query.setQueryLanguage(XPATH_NAMESPACE);
          query.setValue(argData.xpathExpr.evaluate());
          from.setVariable(argData.variable);
        }
       
        Query toQuery = BPELFactory.eINSTANCE.createQuery();
        toQuery.setQueryLanguage(XPATH_NAMESPACE);
        toQuery.setValue("/" + schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getName());
       
        To to = BPELFactory.eINSTANCE.createTo();
        to.setVariable(variable);
        to.setQuery(toQuery);
       
        Copy copy = BPELFactory.eINSTANCE.createCopy();
        copy.setFrom(from);
        copy.setTo(to);
       
        assign.getCopy().add(copy);
      }
      argIndex++;
    }
  }
 
 
 
  @Override
  public <A extends Annotation> void visitCtAnnotationType(
      CtAnnotationType<A> annotationType) {
    return; // avoid processing any annotation information....
  }

  @SuppressWarnings("unchecked")
  @Override
  public <T, A extends T> void visitCtAssignment(
      CtAssignment<T, A> assignement) {
    enter(assignement);
   
    ASTNodeData assignmentData = nodeDataStack.peek();
   
    scan(assignement.getAnnotations());
   
    scan(assignement.getType());
    ASTNodeData typeData = nodeDataStack.peek();
    assignmentData.xsdType = typeData.xsdType;
    assignmentData.xsdTypeQName = typeData.xsdTypeQName;
    assignmentData.typeRefName = typeData.typeRefName;
   
    scanReferences(assignement.getTypeCasts());
   
    scan(assignement.getAssigned());
    ASTNodeData lhsData = nodeDataStack.peek();
   
    scan(assignement.getAssignment());
    ASTNodeData rhsData = nodeDataStack.peek();
   
    if (lhsData.variable != null){
      if (lhsData.xpathExpr != null){
        if (rhsData.xpathLiteralExpr != null){
          Assign assign = BPELFactory.eINSTANCE.createAssign();
          assignmentData.activity = assign;         
         
          To to = BPELFactory.eINSTANCE.createTo();   
          Query toQuery = BPELFactory.eINSTANCE.createQuery();
          toQuery.setQueryLanguage(XPATH_NAMESPACE);
          toQuery.setValue(lhsData.xpathExpr.evaluate());
          to.setQuery(toQuery);
          to.setVariable(lhsData.variable);
         
          From from = BPELFactory.eINSTANCE.createFrom();
          Expression expr = BPELFactory.eINSTANCE.createExpression();
          expr.setBody(rhsData.xpathLiteralExpr.evaluate());
          from.setExpression(expr);
          //from.setLiteral(rhsData.xpathLiteralExpr.evaluate());
          from.setVariable(rhsData.variable);
         
          Copy copy = BPELFactory.eINSTANCE.createCopy();
          copy.setTo(to);
          copy.setFrom(from);
          assign.getCopy().add(copy);
          assignmentData.activity = assign;
        } else if (rhsData.variable != null && rhsData.xpathExpr != null){
          Assign assign = BPELFactory.eINSTANCE.createAssign();
          assignmentData.activity = assign;         
         
          To to = BPELFactory.eINSTANCE.createTo();   
          Query toQuery = BPELFactory.eINSTANCE.createQuery();
          toQuery.setQueryLanguage(XPATH_NAMESPACE);
          toQuery.setValue(lhsData.xpathExpr.evaluate());
          to.setQuery(toQuery);
          to.setVariable(lhsData.variable);
         
          From from = BPELFactory.eINSTANCE.createFrom();
          if (rhsData.variable != null){
            from.setVariable(rhsData.variable);
            Query fromQuery = BPELFactory.eINSTANCE.createQuery();
            fromQuery.setQueryLanguage(XPATH_NAMESPACE);
            fromQuery.setValue(rhsData.xpathExpr.evaluate());
            from.setQuery(fromQuery);
          } else {
            Expression expr = BPELFactory.eINSTANCE.createExpression();         
            expr.setBody(rhsData.xpathExpr.evaluate());
            from.setExpression(expr);
          }
          //from.setLiteral(rhsData.xpathExpr.evaluate());         
         
          Copy copy = BPELFactory.eINSTANCE.createCopy();
          copy.setTo(to);
          copy.setFrom(from);
          assign.getCopy().add(copy);
          assignmentData.activity = assign;
        } else if (rhsData.receive != null){
          assignmentData.receive = rhsData.receive;
          assignmentData.activity = rhsData.activity;
        } else if (rhsData.invoke != null){
          setInvokeResult(rhsData.invoke,assignement.getAssigned(),rhsData.invokeScope);
          //assignmentData.invoke = rhsData.invoke;
          assignmentData.activity = rhsData.invokeScope.getActivity();
        }
      }
    }
   
    exit(assignement);
  }
  @Override
  public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) {
    enter(operator);
    ASTNodeData operatorNodeData = nodeDataStack.peek();
   
    scan(operator.getType());
    scanReferences(operator.getTypeCasts());
   
    scan(operator.getLeftHandOperand());
    ASTNodeData leftOperandNodeData = nodeDataStack.peek();
   
    scan(operator.getRightHandOperand());
    ASTNodeData rightOperandNodeData = nodeDataStack.peek();
   
    XpathBinaryOpExpression xpathBinOperation = xpathFactory.createBinaryOperation();
    XpathOperatorMapping xpathBinOpMap = xpathFactory.createBinOpMapping();
    XpathExprBinOpType xpathBinOp = xpathBinOpMap.getBinOp(operator.getKind());
   
    if (xpathBinOp != null){
      try {
        xpathBinOperation.setOperator(xpathBinOp);
        if (leftOperandNodeData.xpathExpr != null && rightOperandNodeData.xpathExpr != null){       
          xpathBinOperation.setLeftSide(leftOperandNodeData.xpathExpr);
          xpathBinOperation.setRightSide(rightOperandNodeData.xpathExpr);
          operatorNodeData.xpathExpr = xpathBinOperation;
        }
      } catch (Exception e){}
    }
   
    exit(operator);
  }
 
  @Override
  public <R> void visitCtBlock(CtBlock<R> block) {
    enter(block);
   
    ASTNodeData blockData = nodeDataStack.peek();
   
    scan(block.getAnnotations());
   
    if (block.getLabel() != null && block.getLabel().startsWith("flow_")){
      blockData.activity = createFlow(block);
    } else if (block.getStatements().size() > 0) { 
      if (blockData.scopeStack == null)
        blockData.scopeStack = new Stack<BpelScope>();
      BpelScopeImpl blockScope = new BpelScopeImpl();
      blockData.scopeStack.push(blockScope);       
     
      for (CtStatement stmt : block.getStatements()){
        scan(stmt);
        ASTNodeData stmtData = nodeDataStack.peek();
        if (stmtData != null){         
          if ( stmtData.receive != null ){           
            blockData.receive = stmtData.receive;
            blockScope.addActivity(stmtData.activity);
            break;
          } else if (stmtData.reply != null){           
            blockData.reply = stmtData.reply;
            blockScope.addActivity(stmtData.activity);           
            break;
          }   
          blockData.receive = null;
          blockData.reply = null;
          if (stmtData.activity != null)
            blockScope.addActivity(stmtData.activity);
          //Activity activity = stmtData.activity;
          //if (activity != null)
          //  blockData.scopeStack.peek().addActivity(activity);
        }
      }
     
      blockData.scopeStack.pop();
      blockData.activity = blockScope.getActivity();
    }
   
    exit(block);
  }
 
  @Override
  public void visitCtCatch(CtCatch catchBlock) {
    enter(catchBlock);
   
    ASTNodeData catchData = nodeDataStack.peek();
    BpelCatchScope catchScope = new BpelCatchScope(catchData.scopeStack.peek());
    catchData.scopeStack.push(catchScope);
   
    scan(catchBlock.getAnnotations());
   
    if (catchBlock.getBody() != null &&
        catchBlock.getBody().getStatements() != null &&
          catchBlock.getBody().getStatements().size() > 0){
     
      scan(catchBlock.getParameter());
      ASTNodeData paramNodeData = nodeDataStack.peek();
      if (paramNodeData.activity != null)
        catchScope.addActivity(paramNodeData.activity);
     
      scan(catchBlock.getBody());
      ASTNodeData bodyData = nodeDataStack.peek();
      if (bodyData.activity != null)
        catchScope.addActivity(bodyData.activity);
     
      if (paramNodeData.typeRefName.equals("java.lang.Exception"))
        catchData.isCatchAll = true;
      else {
        catchData.xsdType = paramNodeData.xsdType;
        catchData.xsdTypeQName = paramNodeData.xsdTypeQName;
        catchData.variable = paramNodeData.variable;
      }
    } else {
      catchData.isCatchAll = true;
    }
   
    catchData.scopeStack.pop();
    catchData.activity = catchScope.getActivity();
   
    exit(catchBlock);
  }

  @Override
  public <T> void visitCtClass(CtClass<T> ctClass) {
    enter(ctClass);
   
    createClassToBpelProcessMapping(ctClass);
    createClassToComplexTypeMapping(ctClass);
    createClassToPortTypeMapping(ctClass);
   
    scan(ctClass.getAnnotations());
    //scan(ctClass.getSuperclass());
    scanReferences(ctClass.getSuperInterfaces());
    scanReferences(ctClass.getFormalTypeParameters());
    //scan(ctClass.getAnonymousExecutables());
    //scan(ctClass.getNestedTypes());
   
    scan(ctClass.getFields());
    scan(ctClass.getConstructors());
    if (classProcessMap.get(ctClass) == null)
      scan(ctClass.getMethods());
    else
      scanProcessMethods(ctClass);
   
    exit(ctClass);
  }
 
  @Override
  public void visitCtDo(CtDo doLoop) {
    enter(doLoop);
    ASTNodeData doLoopNodeData = nodeDataStack.peek();
   
    scan(doLoop.getLoopingExpression());
    ASTNodeData exprNodeData = nodeDataStack.peek();
   
    scan(doLoop.getBody());
    ASTNodeData bodyNodeData = nodeDataStack.peek();
   
    if (exprNodeData.xpathExpr != null && bodyNodeData.activity != null){
      RepeatUntil repeatActivity = BPELFactory.eINSTANCE.createRepeatUntil();
      doLoopNodeData.activity = repeatActivity;
      repeatActivity.setActivity(bodyNodeData.activity);
      Condition condition = BPELFactory.eINSTANCE.createCondition();
      condition.setRequired(true);
      condition.setBody(exprNodeData.xpathExpr.evaluate());
      repeatActivity.setCondition(condition);     
    }
   
    exit(doLoop);
  }
 
  @SuppressWarnings("unchecked")
  @Override
  public <T> void visitCtExecutableReference(
      CtExecutableReference<T> reference) {
    enterReference(reference);
   
    ASTNodeData execRefData = nodeDataStack.peek();
   
    scan(reference.getDeclaringType());
    ASTNodeData declTypeData = nodeDataStack.peek();
   
    scan(reference.getType());   
    ASTNodeData execRefTypeData = nodeDataStack.peek();
   
    scanReferences(reference.getActualTypeArguments());
    scanReferences(reference.getParameterTypes());
   
    if (reference.getDeclaration() != null){
      XSDElementDeclaration el = methodElementDeclMap.get(reference.getDeclaration());
      if (el != null){
        execRefData.xsdPropElement = el;
        execRefData.xsdPropQName = new QName(el.getTargetNamespace(),el.getName(),schemaNsPrefixMap.get(el.getTargetNamespace()));
        execRefData.xsdType = execRefTypeData.xsdType;
        execRefData.xsdTypeQName = execRefTypeData.xsdTypeQName;
      }
      execRefData.flowActivity = methodFlowActivityMap.get(reference.getDeclaration())
      if (execRefData.flowActivity != null){
        execRefData.flowMethod = (CtMethod<?>)reference.getDeclaration();
      }
      execRefData.receiveActivity = methodReceiveActivityMap.get(reference.getDeclaration());
      execRefData.replyActivity = methodReplyActivityMap.get(reference.getDeclaration());
      if (reference.getDeclaration() instanceof CtMethod){
        if (declTypeData.bottomUpProcess != null){
          execRefData.operation = getProcessWsdlOperation((CtMethod)reference.getDeclaration());
          if (execRefData.operation != null){
            execRefData.wsdlDef = execRefData.operation.getEnclosingDefinition();
            execRefData.portType = getProcessWsdlPortType((CtMethod)reference.getDeclaration());
          }
        } else if (declTypeData.portType != null){
          execRefData.portType = declTypeData.portType;
          execRefData.wsdlDef = execRefData.portType.getEnclosingDefinition();
          execRefData.operation = methodOperationMap.get(reference.getDeclaration());
        }
      }
      if (reference.getDeclaration() instanceof CtConstructor){
        CtConstructor c = (CtConstructor)reference.getDeclaration();
        execRefData.constructor = c;
        if (c.getDeclaringType() instanceof CtClass){
          execRefData.constructorClass = (CtClass)c.getDeclaringType();
          XSDComplexTypeDefinition complexType = typeXSDComplexTypeMap.get(execRefData.constructorClass);
          if (complexType != null){
            execRefData.constructorArgElementMap = createConstructorFieldMap(c,complexType);
          }
        }
      }
    }
    if (reference.getSimpleName().equals("equals") && reference.getType().getQualifiedName().equals("boolean"))
      execRefData.isEqualsExecRef = true;
    execRefData.bottomUpProcess = declTypeData.bottomUpProcess;   
   
    exitReference(reference);
 
  @Override
  public <T> void visitCtField(CtField<T> f) {
    enter(f);
   
    ASTNodeData fieldNodeData = nodeDataStack.peek();
   
    scan(f.getAnnotations());
    scan(f.getType());
   
    ASTNodeData fieldTypeData =  new ASTNodeData();
    //fieldTypeData.xsdType = nodeDataStack.peek().xsdType;
    //fieldTypeData.xsdTypeQName = nodeDataStack.peek().xsdTypeQName;
    //fieldTypeData.xsdArrayDimensions = nodeDataStack.peek().xsdArrayDimensions;
    resolveTypeReference(f.getType(),fieldTypeData);
    resolvePortTypeReference(f.getType(),fieldTypeData);
   
    createFieldTypeMapping(f,fieldTypeData.xsdType);
    createFieldToPartnerLinkMapping(f,fieldTypeData.portType);
    createFieldToVariableMapping(f,fieldTypeData.xsdType);
   
    scan(f.getDefaultExpression());
    ASTNodeData defExprData = nodeDataStack.peek();
    setFieldDefaultValue(f,defExprData.xpathLiteralExpr);
    if (fieldNodeData.scopeStack != null && fieldNodeData.scopeStack.peek() != null)
      setFieldExceptionDefaultValue(fieldNodeData.scopeStack.peek(),f);
   
    exit(f);
  }
 
  @Override
  public <T> void visitCtFieldAccess(CtFieldAccess<T> fieldAccess) {
    enter(fieldAccess);
   
    ASTNodeData fieldAccessData = nodeDataStack.peek();
   
    scan(fieldAccess.getAnnotations());
   
    scan(fieldAccess.getType());
    fieldAccessData.xsdType = nodeDataStack.peek().xsdType;
    fieldAccessData.xsdTypeQName = nodeDataStack.peek().xsdTypeQName;
    fieldAccessData.typeRefName = nodeDataStack.peek().typeRefName;
   
    scanReferences(fieldAccess.getTypeCasts());
   
    scan(fieldAccess.getTarget());
    ASTNodeData targetNodeData = nodeDataStack.peek();
   
    scan(fieldAccess.getVariable());
    ASTNodeData variableNodeData = nodeDataStack.peek();
   
    fieldAccessData.xsdPropElement = variableNodeData.xsdPropElement;
    fieldAccessData.xsdPropQName = variableNodeData.xsdPropQName;
    if (fieldAccess.getTarget() == null){
      fieldAccessData.partnerLink = variableNodeData.partnerLink;
      fieldAccessData.variable = variableNodeData.variable;
      fieldAccessData.xpathExpr = variableNodeData.xpathExpr;     
    } else {
      if (targetNodeData.variable != null){
        fieldAccessData.variable = targetNodeData.variable;
        if (targetNodeData.xpathExpr != null && variableNodeData.xsdPropQName != null){
          targetNodeData.xpathExpr.addLocationStep(variableNodeData.xsdPropQName,  variableNodeData.xsdTypeQName);
          fieldAccessData.xpathExpr =  targetNodeData.xpathExpr;
        }
      }
    }
   
    exit(fieldAccess);
  }
  @Override
  public <T> void visitCtFieldReference(CtFieldReference<T> reference) {
    enterReference(reference);
    ASTNodeData fieldRefData = nodeDataStack.peek();
   
    scan(reference.getDeclaringType());
   
    scan(reference.getType());
    //resolveTypeReference(reference.getType(), fieldRefData);
    fieldRefData.xsdType =  nodeDataStack.peek().xsdType;
    fieldRefData.xsdTypeQName =  nodeDataStack.peek().xsdTypeQName;
    fieldRefData.typeRefName = nodeDataStack.peek().typeRefName;
   
    XSDElementDeclaration el = fieldElementDeclMap.get(reference.getDeclaration());
    if (el != null){
      fieldRefData.xsdPropElement = el;
      fieldRefData.xsdPropQName = new QName(el.getTargetNamespace(),el.getName(),schemaNsPrefixMap.get(el.getTargetNamespace()));
    }   
   
    fieldRefData.variable = resolveVariable(fieldRefData.scopeStack,reference.getSimpleName());
    if (fieldRefData.variable != null){
      XpathVariableRefExpression xpathVarRef = xpathFactory.createVariableReference();
      xpathVarRef.setVariableName(fieldRefData.variable.getName());
      xpathVarRef.setType(fieldRefData.xsdTypeQName);
      XpathTypeMapping xpathTypeMap = xpathFactory.createTypeMapping();
      XpathExprType varXpathType = xpathTypeMap.getXpathExprType(reference.getType().getQualifiedName());
      xpathVarRef.setXpathType(varXpathType);
      fieldRefData.xpathExpr = xpathVarRef;
    }
    fieldRefData.partnerLink = fieldPartnerLinkMap.get(reference.getDeclaration());
    if (fieldRefData.partnerLink != null){
      fieldRefData.portType = typePortTypeMap.get(reference.getType().getDeclaration());
      if (fieldRefData.portType != null)
        fieldRefData.wsdlDef = fieldRefData.portType.getEnclosingDefinition();
    }
   
    exitReference(reference);
 
  @Override
  public void visitCtIf(CtIf ifElement) {
    enter(ifElement);
    ASTNodeData ifNodeData = nodeDataStack.peek();
   
    scan(ifElement.getCondition());
    ASTNodeData condNodeData = nodeDataStack.peek();
   
    scan(ifElement.getThenStatement());
    ASTNodeData thenNodeData = nodeDataStack.peek();
   
    scan(ifElement.getElseStatement());
    ASTNodeData elseNodeData = nodeDataStack.peek();
   
    If ifActivity = BPELFactory.eINSTANCE.createIf();
    ifNodeData.activity = ifActivity;
    Condition condExpr = BPELFactory.eINSTANCE.createCondition();
    ifActivity.setCondition(condExpr);
    if (condNodeData.xpathExpr != null)
      condExpr.setBody(condNodeData.xpathExpr.evaluate());
   
    if (ifElement.getThenStatement() != null){
      //Then then = BPELFactory.eINSTANCE.createThen();
      //ifActivity.setThen(then);
      if (thenNodeData.activity != null)
        ifActivity.setActivity(thenNodeData.activity);//then.setActivity(thenNodeData.activity);
    }
    if (ifElement.getElseStatement() != null){
      Else elseActivity = BPELFactory.eINSTANCE.createElse();
      ifActivity.setElse(elseActivity);
      if (elseNodeData.activity != null)
        elseActivity.setActivity(elseNodeData.activity);
    }       
   
    exit(ifElement);
  }
 
  @Override
  public <T> void visitCtInterface(CtInterface<T> intrface) {
    enter(intrface);

    createInterfaceToPortTypeMapping(intrface);
    createTypeToComplexTypeMapping(intrface);
   
    scan(intrface.getAnnotations());
    scanReferences(intrface.getSuperInterfaces());
    scanReferences(intrface.getFormalTypeParameters());
    scan(intrface.getNestedTypes());
    scan(intrface.getFields());
    scan(intrface.getMethods());
    exit(intrface);
  }
 
  @SuppressWarnings("unchecked")
  @Override
  public <T> void visitCtInvocation(CtInvocation<T> invocation) {
    enter(invocation);
   
    ASTNodeData invocationData = nodeDataStack.peek();
   
    scan(invocation.getAnnotations());
    scan(invocation.getType());
    invocationData.xsdType = nodeDataStack.peek().xsdType;
    invocationData.xsdTypeQName = nodeDataStack.peek().xsdTypeQName;
   
    scanReferences(invocation.getTypeCasts());
    scan(invocation.getTarget());
    ASTNodeData targetNodeData = nodeDataStack.peek();
   
    scan(invocation.getExecutable());
    ASTNodeData execNodeData = nodeDataStack.peek();
   
    //scan(invocation.getArguments());
   
    if (execNodeData.isEqualsExecRef && invocation.getArguments().size() == 1){     
      XpathBinaryOpExpression xpathBinOperation = xpathFactory.createBinaryOperation();
      XpathOperatorMapping xpathBinOpMap = xpathFactory.createBinOpMapping();
      XpathExprBinOpType xpathBinOp = xpathBinOpMap.getBinOp(BinaryOperatorKind.EQ);
      scan(invocation.getArguments().get(0));
      ASTNodeData arg = nodeDataStack.peek();
      try {
        if (targetNodeData.xpathExpr != null && arg.xpathExpr != null){
          xpathBinOperation.setOperator(xpathBinOp);
          if (targetNodeData.xpathLiteralType == XpathExprType.STRING_EXPR_TYPE){
            XpathStringExpression newStr = xpathFactory.createString();
            newStr.setString("'" + targetNodeData.xpathLiteralExpr.evaluate() + "'");
            xpathBinOperation.setLeftSide(newStr);
          } else
            xpathBinOperation.setLeftSide(targetNodeData.xpathExpr);
          if (arg.xpathLiteralType == XpathExprType.STRING_EXPR_TYPE){
            XpathStringExpression newStr = xpathFactory.createString();
            newStr.setString("'" + arg.xpathLiteralExpr.evaluate() + "'");
            xpathBinOperation.setRightSide(newStr);
          } else
            xpathBinOperation.setRightSide(arg.xpathExpr);
          invocationData.xpathExpr = xpathBinOperation;
          invocationData.xpathLiteralType = XpathExprType.BOOLEAN_EXPR_TYPE;
          invocationData.xsdType = xsdBooleanType;
          invocationData.xsdTypeQName = xsdBooleanQName;
        }
      } catch (Exception e){
        invocationData.xpathExpr = null;
      }
    } else if (execNodeData.flowActivity != null){
      invocationData.flowActivity = execNodeData.flowActivity;
      invocationData.flowMethod = execNodeData.flowMethod;
    } else if (execNodeData.receiveActivity != null){
      invocationData.activity = execNodeData.receiveActivity;
    } else if (execNodeData.replyActivity != null){
      invocationData.activity = execNodeData.replyActivity;
    } else if (targetNodeData.partnerLink != null && execNodeData.operation != null){
      // this in an invocation of a partner's web service...
      Invoke invoke = BPELFactory.eINSTANCE.createInvoke();
      invoke.setPortType(execNodeData.portType);
      invoke.setOperation(execNodeData.operation);
      invoke.setPartnerLink(targetNodeData.partnerLink);
      invocationData.invokeScope = new BpelScopeImpl();
      setInvokeParameters(execNodeData.operation,invoke,invocation.getArguments(),invocationData.invokeScope);
      invocationData.invokeScope.addActivity(invoke);
      invocationData.activity = invocationData.invokeScope.getActivity();
      invocationData.invoke = invoke;
    } else if (execNodeData.bottomUpProcess != null && execNodeData.operation != null){
      // this is an invocation of a web service provided by a process...
      Receive recv = BPELFactory.eINSTANCE.createReceive();
      recv.setPortType(execNodeData.portType);
      recv.setOperation(execNodeData.operation);
      invocationData.receiveScope = new BpelScopeImpl();
      invocationData.receiveScope.addActivity(recv);
      setRecvParameters(execNodeData.operation, recv,invocation.getArguments(),invocationData.receiveScope);
      invocationData.activity = invocationData.receiveScope.getActivity();
      invocationData.receive = recv;
    } else {
      if (invocation.getExecutable() != null &&
          invocation.getExecutable().getDeclaration() != null &&
          invocation.getExecutable().getDeclaration() instanceof CtMethod ){
        CtMethod m = (CtMethod)invocation.getExecutable().getDeclaration();
        ReplyActivity replyAnn = m.getAnnotation(ReplyActivity.class);
        if (replyAnn != null && invocation.getArguments().size() == 1){
          scan(invocation.getArguments().get(0));
          ASTNodeData arg = nodeDataStack.peek();
          if (arg.xsdType != null && arg.xpathExpr != null && arg.variable != null){
            for (Receive recv : methodReceiveMap.values()){
              if (recv.getName().equals(replyAnn.receiveName())){
                Reply reply = BPELFactory.eINSTANCE.createReply();
                String replyName = m.getSimpleName();
                if (!replyAnn.name().equals(""))
                  replyName = replyAnn.name();
                reply.setName(replyName);
                if (exceptionTypes.contains(invocation.getArguments().get(0).getType().getDeclaration()))
                  reply.setFaultName(arg.xsdTypeQName);
                BpelScope tmpScope = new BpelScopeImpl();
                setReplyParameters(recv, reply, arg.variable, arg.xsdType, arg.xpathExpr, tmpScope);
                invocationData.activity = tmpScope.getActivity();
                invocationData.replyActivity = reply;
                invocationData.reply = reply;
                if (m.getAnnotation(FlowActivity.class) != null){
                  createMethodFlowMapping(m, invocationData.activity);
                  invocationData.flowActivity = invocationData.activity;
                  invocationData.flowMethod = m;
                }
                break;
              }
            }
          }         
        }         
      }
      if (execNodeData.xsdPropElement != null && targetNodeData.xpathExpr != null){
        targetNodeData.xpathExpr.addLocationStep(execNodeData.xsdPropQName, invocationData.xsdTypeQName);
        invocationData.variable = targetNodeData.variable;
        invocationData.xpathExpr = targetNodeData.xpathExpr;
        if (invocation.getArguments().size() == 1){
          scan(invocation.getArguments().get(0));
          ASTNodeData argData = nodeDataStack.peek();
          if (argData.xpathExpr != null){
            From from = BPELFactory.eINSTANCE.createFrom();
            if (argData.xpathLiteralExpr != null){
              Expression expr = BPELFactory.eINSTANCE.createExpression();         
              expr.setBody(argData.xpathLiteralExpr.evaluate());
              from.setExpression(expr);
              //from.setLiteral(argData.xpathExpr.evaluate());
            } else if (argData.variable != null){
              from.setVariable(argData.variable);
              Query fromQuery = BPELFactory.eINSTANCE.createQuery();
              fromQuery.setValue(argData.xpathExpr.evaluate());
              fromQuery.setQueryLanguage(XPATH_NAMESPACE);
              from.setQuery(fromQuery);
            } else {
              Expression expr = BPELFactory.eINSTANCE.createExpression();         
              expr.setBody(argData.xpathExpr.evaluate());
              from.setExpression(expr);
            }
            //from.setLiteral(argData.xpathExpr.evaluate());
           
            To to = BPELFactory.eINSTANCE.createTo();   
            Query toQuery = BPELFactory.eINSTANCE.createQuery();
            toQuery.setValue(invocationData.xpathExpr.evaluate());
            toQuery.setQueryLanguage(XPATH_NAMESPACE);
            to.setQuery(toQuery);
            to.setVariable(invocationData.variable);             
           
            Copy copy = BPELFactory.eINSTANCE.createCopy();
            copy.setTo(to);
            copy.setFrom(from);
           
            Assign assign = BPELFactory.eINSTANCE.createAssign();
            assign.getCopy().add(copy);
            invocationData.activity = assign;
          }
        }
      } else if (execNodeData.activity != null)
        invocationData.activity = execNodeData.activity;
    }

    exit(invocation);
  }
 
  @Override
  public <T> void visitCtLiteral(CtLiteral<T> literal) {
    enter(literal);
    ASTNodeData literalData = nodeDataStack.peek();
   
    scan(literal.getType());
    scanReferences(literal.getTypeCasts());
   
    if (literal.getValue() != null){
      if (literal.getValue().toString().equals("true") || literal.getValue().toString().equals("false")){
        XpathBooleanExpression boolExpr = xpathFactory.createBoolean();
        Boolean b = new Boolean(literal.getValue().toString());
        boolExpr.setBoolean(b);
        literalData.xpathLiteralExpr = boolExpr;
        literalData.xpathExpr = boolExpr;
        resolveTypeReference(literal.getType(),literalData);
        literalData.xpathLiteralType = XpathExprType.BOOLEAN_EXPR_TYPE;
      } else {
        XpathStringExpression strExpr = xpathFactory.createString();
        strExpr.setString(literal.getValue().toString());
        literalData.xpathLiteralExpr = strExpr;
        literalData.xpathExpr = strExpr;
        resolveTypeReference(literal.getType(),literalData);     
        literalData.xpathLiteralType = XpathExprType.STRING_EXPR_TYPE;
      }
    }
   
    exit(literal);
  }
 
  @SuppressWarnings("unchecked")
  @Override
  public <T> void visitCtLocalVariable(CtLocalVariable<T> localVariable) {
    enter(localVariable);
   
    ASTNodeData localVarData = nodeDataStack.peek();
   
    scan(localVariable.getAnnotations());
   
    scan(localVariable.getType());
    ASTNodeData typeNodeData = nodeDataStack.peek();
    localVarData.typeRefName = typeNodeData.typeRefName;
    localVarData.xsdType = typeNodeData.xsdType;
    localVarData.xsdTypeQName = typeNodeData.xsdTypeQName;
   
    scan(localVariable.getDefaultExpression());
    ASTNodeData defExprData = nodeDataStack.peek();
   
action:  if (localVarData.scopeStack != null){
      Variable variable = BPELFactory.eINSTANCE.createVariable();
      variable.setName(localVariable.getSimpleName());
      if (typeNodeData.xsdType != null)
        variable.setType(typeNodeData.xsdType);
      localVarData.scopeStack.peek().addVariable(variable);
      localVarData.variable = variable;
     
      if (localVariable.getDefaultExpression() != null){
        From from = BPELFactory.eINSTANCE.createFrom();
        To to = BPELFactory.eINSTANCE.createTo();
        Copy copy = BPELFactory.eINSTANCE.createCopy();
        Assign assign = BPELFactory.eINSTANCE.createAssign();
       
        if (defExprData.xpathLiteralExpr != null){
          Expression expr = BPELFactory.eINSTANCE.createExpression();
          expr.setBody(defExprData.xpathLiteralExpr.evaluate());
          from.setExpression(expr);       
        } else if (defExprData.variable != null && defExprData.xpathExpr != null){
          Query query = BPELFactory.eINSTANCE.createQuery();
          query.setQueryLanguage(XPATH_NAMESPACE);
          query.setValue(defExprData.xpathExpr.evaluate());
          from.setVariable(defExprData.variable);
        } else if (defExprData.isExceptionType && defExprData.constructor != null){
          createNewException(assign,variable,defExprData.constructorArgElementMap,defExprData.constructorArgs);
          localVarData.scopeStack.peek().addActivity(assign);
          localVarData.activity = assign;
          break action;
        }
       
        to.setVariable(variable);
        copy.setFrom(from);
        copy.setTo(to);
        assign.getCopy().add(copy);
        localVarData.activity = assign;
      }
    }   
    exit(localVariable);
  }
 
  @Override
  public <T> void visitCtLocalVariableReference(
      CtLocalVariableReference<T> reference) {
    enterReference(reference);
   
    ASTNodeData refNodeData = nodeDataStack.peek();
   
    scan(reference.getType());
    ASTNodeData typeNodeData = nodeDataStack.peek();
    refNodeData.typeRefName = reference.getType().getQualifiedName();
   
    refNodeData.xsdType = typeNodeData.xsdType;
    refNodeData.xsdTypeQName = typeNodeData.xsdTypeQName;
   
    XSDElementDeclaration el = this.fieldElementDeclMap.get(reference.getDeclaration());
    if (el != null){
      refNodeData.xsdPropElement = el;
      refNodeData.xsdPropQName = new QName(el.getTargetNamespace(),el.getName(),schemaNsPrefixMap.get(el.getTargetNamespace()));
    }   
   
    refNodeData.variable = resolveVariable(refNodeData.scopeStack,reference.getSimpleName());
    if (refNodeData.variable != null){
      XpathVariableRefExpression xpathVarRef = xpathFactory.createVariableReference();
      xpathVarRef.setVariableName(refNodeData.variable.getName());
      xpathVarRef.setType(refNodeData.xsdTypeQName);
      XpathTypeMapping xpathTypeMap = xpathFactory.createTypeMapping();
      XpathExprType varXpathType = xpathTypeMap.getXpathExprType(reference.getType().getQualifiedName());
      xpathVarRef.setXpathType(varXpathType);
      refNodeData.xpathExpr = xpathVarRef;
    }
   
    exitReference(reference);
  }
 
 
  @SuppressWarnings("unchecked")
  @Override
  public <T> void visitCtMethod(CtMethod<T> m) {
    enter(m);

    ASTNodeData methodNodeData = nodeDataStack.peek();   
   
    scan(m.getAnnotations());   
   
    scan(m.getType());
    ASTNodeData typeNodeData = new ASTNodeData();
    resolveTypeReference(m.getType(), typeNodeData);
    methodNodeData.xsdType = typeNodeData.xsdType;
    methodNodeData.xsdTypeQName = typeNodeData.xsdTypeQName;
   
    scanReferences(m.getThrownTypes());
   
    createMethodToOperationMapping(m);   
    createFieldToElementMapping(m,methodNodeData,typeNodeData);
   
    scan(m.getParameters());   
    scanReferences(m.getFormalTypeParameters());
   
   
   
    // This scanner is only interested in the behavior or classes
    //  that map to Bpel processes.  This simplifies the handling
    //  of the other nodes in the AST (blocks, statements, ect)
    //  because they are only scanned in the context of some type
    //  of Bpel behavior.
    org.eclipse.bpel.model.Process process = classProcessMap.get(m.getDeclaringType());
    if (process != null){     
      Stack<BpelScope> scopeStack = classScopeMap.get(m.getDeclaringType());
      methodNodeData.scopeStack = scopeStack;
      methodNodeData.bpelProcess = process;
      BpelScope methodScope = new BpelScopeImpl();
      scopeStack.push(methodScope);
      scan(m.getBody());
      ASTNodeData bodyData = nodeDataStack.peek();
      scopeStack.pop();
      FlowActivity flowActivity = m.getAnnotation(FlowActivity.class);
      ReceiveActivity receiveActivity = m.getAnnotation(ReceiveActivity.class);
      ReplyActivity replyActivity = m.getAnnotation(ReplyActivity.class);
      if (flowActivity != null && bodyData.activity != null)
        createMethodFlowMapping(m,bodyData.activity);
      if (receiveActivity != null && bodyData.receive != null){       
        List<PartnerLink> plinks = process.getPartnerLinks().getChildren();
        for (PartnerLink plink : plinks){
          if (plink.getName().equals(receiveActivity.partnerLink())){
            bodyData.receive.setPartnerLink(plink);
            String recvName = m.getSimpleName();
            if (!receiveActivity.name().equals(""))
              recvName = receiveActivity.name();
            bodyData.receive.setName(recvName);
            break;
          }
        }     
        methodReceiveMap.put(m,bodyData.receive);
        //methodReceiveActivityMap.put(m, methodScope.getActivity());
        methodReceiveActivityMap.put(m, bodyData.activity);
      } else if (flowActivity == null && receiveActivity == null && replyActivity == null && bodyData.activity != null){
        scopeStack.peek().addActivity(bodyData.activity);
      } //else if (methodScope.getActivity() != null)
        //scopeStack.peek().addActivity(methodScope.getActivity());
    }
   
    exit(m);
  }
 
  @Override
  public <T> void visitCtNewClass(CtNewClass<T> newClass) {
    enter(newClass);
    ASTNodeData newClassData = nodeDataStack.peek();
   
    scan(newClass.getAnnotations());
   
    scan(newClass.getType());
    ASTNodeData typeData = nodeDataStack.peek();
   
    scanReferences(newClass.getTypeCasts());
   
    scan(newClass.getExecutable());
    ASTNodeData execData = nodeDataStack.peek();
   
    scan(newClass.getTarget());
   
    scan(newClass.getArguments());
   
    scan(newClass.getAnonymousClass());
   
    newClassData.xsdType = typeData.xsdType;
    newClassData.xsdTypeQName = typeData.xsdTypeQName;
    newClassData.typeRefName = typeData.typeRefName;
    newClassData.isExceptionType = typeData.isExceptionType;
    newClassData.constructorArgs = newClass.getArguments();
    newClassData.constructor = execData.constructor;
    newClassData.constructorClass = execData.constructorClass;
    newClassData.constructorArgElementMap = execData.constructorArgElementMap;
   
    exit(newClass);
  }
 
  @Override
  public void visitCtPackage(CtPackage ctPackage) {
    enter(ctPackage);
   
    if (ctPackage.getQualifiedName() != null){
      if (ctPackage.getQualifiedName().startsWith("jbprocess") ||
          ctPackage.getQualifiedName().startsWith("spoon") ||
            ctPackage.getQualifiedName().startsWith("java"))
        return;
    }
   
//     JAX-RPC v1.1 (JSR-101), section 5.5.2 - Java Package Maps to WSDL Definition   
    createPackageToWsdlMapping(ctPackage);   
   
//     JAXB v2.0 (JSR-222), section 8.2.1, 8.6 - Java Package Maps to XML Schema
    createPackageToSchemaMapping(ctPackage)
   
    // Map Packages to a set of BPEL Processes
    createPackageToBpelProcessesMapping(ctPackage);
   
    scan(ctPackage.getAnnotations());
    scan(ctPackage.getPackages());
    scan(ctPackage.getTypes());
    exit(ctPackage);   
  }
 
  @Override
  public void visitCtPackageReference(CtPackageReference reference) {
    if (reference.getSimpleName().startsWith("java") || reference.getSimpleName().equals("edu.rh.dege9782.jbprocess"))
      return;
   
    enterReference(reference);   
   
    ASTNodeData packRefNodeData = nodeDataStack.peek();   
   
//     JAX-RPC v1.1 (JSR-101), section 5.5.2 - Java Package Maps to WSDL Definition   
    createPackageToWsdlMapping(reference.getDeclaration());
    packRefNodeData.wsdlDef = wsdlDefMap.get(reference.getDeclaration());

//     JAXB v2.0 (JSR-222), section 8.2.1, 8.6 - Java Package Maps to XML Schema
    createPackageToSchemaMapping(reference.getDeclaration());
    packRefNodeData.schema = xsdSchemaMap.get(reference.getDeclaration());
   
//     Map Packages to a set of BPEL Processes
    createPackageToBpelProcessesMapping(reference.getDeclaration());
    packRefNodeData.bpelProcesses = packageBpelProcessesMap.get(reference.getDeclaration());
    packRefNodeData.bpelNamespace = packageBpelNamespaceMap.get(reference.getDeclaration());
   
    exitReference(reference);
  }
 
  @SuppressWarnings("unchecked")
  @Override
  public <T> void visitCtParameter(CtParameter<T> parameter) {
    enter(parameter);
    ASTNodeData parameterNodeData = nodeDataStack.peek();
   
    scan(parameter.getAnnotations());
   
    scan(parameter.getType());
    ASTNodeData typeNodeData = new ASTNodeData();
    resolveTypeReference(parameter.getType(),typeNodeData);
    parameterNodeData.xsdType = typeNodeData.xsdType;
    parameterNodeData.xsdTypeQName = typeNodeData.xsdTypeQName;
   
    if (parameterNodeData.xsdType != null && parameterNodeData.xsdTypeQName != null){
      if (parameter.getParent() instanceof CtMethod){
        CtMethod method = (CtMethod)parameter.getParent();
        Operation operation = methodOperationMap.get(method);
        if (operation != null){
          createWsdlParameterMapping(method,operation,parameter,typeNodeData.xsdType);
        }       
      }
    }
   
    scan(parameter.getDefaultExpression());
    exit(parameter);
  }
  @Override
  public <R> void visitCtReturn(CtReturn<R> returnStatement) {
    enter(returnStatement);   
    ASTNodeData returnNodeData = nodeDataStack.peek();
   
    scan(returnStatement.getAnnotations());
   
    scan(returnStatement.getReturnedExpression());
    ASTNodeData exprNodeData = nodeDataStack.peek();
    returnNodeData.xsdType = exprNodeData.xsdType;
    returnNodeData.xsdTypeQName = exprNodeData.xsdTypeQName;   
    returnNodeData.xpathExpr = exprNodeData.xpathExpr;
    returnNodeData.xpathLiteralExpr = exprNodeData.xpathLiteralExpr;
    returnNodeData.xpathLiteralType = exprNodeData.xpathLiteralType;
   
    exit(returnStatement);
  }
  @Override
  public <R> void visitCtStatementList(CtStatementList<R> statements) {
    enter(statements);
    scan(statements.getAnnotations());
    scan(statements.getStatements());
    exit(statements);
  }
 
  @Override
  public void visitCtThrow(CtThrow throwStatement) {
    enter(throwStatement);
    ASTNodeData throwData = nodeDataStack.peek();
   
    scan(throwStatement.getAnnotations());
   
    scan(throwStatement.getThrownExpression());
    ASTNodeData exprData = nodeDataStack.peek();
   
    Throw throwStmt = BPELFactory.eINSTANCE.createThrow();
    throwData.activity = throwStmt;
   
    if (exprData.constructor != null && exprData.constructorArgElementMap != null && exprData.constructorArgs != null){
      if (throwData.scopeStack != null){
        Variable variable = createTempVariable(throwData.scopeStack, exprData.xsdType);
        Assign assign = BPELFactory.eINSTANCE.createAssign();
        createNewException(assign,variable,exprData.constructorArgElementMap,exprData.constructorArgs);
        throwData.scopeStack.peek().addActivity(assign);
        throwStmt.setFaultName(exprData.xsdTypeQName);
        throwStmt.setFaultVariable(variable);
      }
    } else if (exprData.variable != null && exprData.xsdTypeQName != null){
      throwStmt.setFaultName(exprData.xsdTypeQName);
      throwStmt.setFaultVariable(exprData.variable);
    } else if (exprData.typeRefName != null && exprData.typeRefName.equals("java.lang.Exception")){
      // how do we handle this?
    }
   
    exit(throwStatement);
  }
 
  @Override
  public void visitCtTry(CtTry tryBlock) {
    enter(tryBlock);
    ASTNodeData tryNodeData = nodeDataStack.peek();
   
    BpelScopeImpl tryScope = new BpelScopeImpl();
    tryNodeData.scopeStack.push(tryScope);
   
    scan(tryBlock.getAnnotations());
   
    scan(tryBlock.getBody());
    ASTNodeData bodyData = nodeDataStack.peek();
    if (bodyData.receive != null){
      tryNodeData.receive = bodyData.receive;
      tryScope.addActivity(bodyData.activity);
    } else if (bodyData.reply != null){  
      tryNodeData.reply = bodyData.reply;
      tryScope.addActivity(bodyData.activity);
    } else {
      if (bodyData.activity != null)
        tryScope.addActivity(bodyData.activity);
    }
    //else {
      //scan(tryBlock.getCatchers());
      for (CtCatch cat : tryBlock.getCatchers()){
        scan(cat);
        ASTNodeData catchData = nodeDataStack.peek();
        if (catchData.activity != null){
          if (!catchData.isCatchAll){
            Catch c = BPELFactory.eINSTANCE.createCatch();
            if (catchData.variable != null)
              c.setFaultVariable(catchData.variable);
            if (catchData.xsdTypeQName != null)
              c.setFaultName(catchData.xsdTypeQName);
            c.setActivity(catchData.activity);
            tryScope.addCatch(c);
          } else {
            CatchAll call = BPELFactory.eINSTANCE.createCatchAll();
            call.setActivity(catchData.activity);
            tryScope.setCatchAll(call);
          }
        }
      }
   
      if (tryBlock.getFinalizer() != null){
        scan(tryBlock.getFinalizer());
        ASTNodeData finalizerData = nodeDataStack.peek();   
        if (finalizerData.activity != null)
          tryScope.addActivity(finalizerData.activity);
      }     
    //}
   
    tryNodeData.scopeStack.pop();
   
    tryNodeData.activity = tryScope.getActivity();
   
    exit(tryBlock);
  }
 
  @Override
  public <T> void visitCtTypeReference(CtTypeReference<T> reference) {
   
    enterReference(reference);
   
    if (reference.getPackage() != null && reference.getPackage().getSimpleName().equals("edu.rh.dege9782.jbprocess")){     
      exitReference(reference);
      return;
    }
    if (reference.getPackage() == null && reference.getSimpleName().equals("<nulltype>")){     
      exitReference(reference);
      return;
    }
    //if (reference.getPackage() != null && reference.getPackage().getSimpleName().startsWith("java.")){     
    //  exitReference(reference);
    //  return;
    //}
       
    ASTNodeData typeRefNodeData = nodeDataStack.peek();
    typeRefNodeData.typeRefName = reference.getQualifiedName();
   
//    JAXB v2.0 (JSR-222), section 8.2.1, 8.5 - Java primitive data types and container classes map to XML Schema simple types
//    JAX-RPC v1.1 (JSR-101), section 5.3.1, 5.3.2 - Java primitive data types and container classes map to XML Schema simple types   

//    JAXB v2.0 (JSR-222), section 8.2.1, 8.7 - Java Class Maps to XML Schema Complex Type
//    JAX-RPC v1.1 (JSR-101), section 5.4.1 - Java Class Maps to XML Schema Complex Type
       
    scan(reference.getPackage());
    if (!reference.isPrimitive() &&
        !reference.getQualifiedName().startsWith("java") &&
        typePortTypeMap.get(reference.getDeclaration()) == null &&
        typeXSDComplexTypeMap.get(reference.getDeclaration()) == null &&
        classProcessMap.get(reference.getDeclaration()) == null){
      scan(reference.getDeclaration());         
    }
    resolveTypeReference(reference,typeRefNodeData);
    resolvePortTypeReference(reference,typeRefNodeData);
    if (reference.getPackage() != null && reference.getPackage().getDeclaration() != null){
      typeRefNodeData.wsdlDef = wsdlDefMap.get(reference.getPackage().getDeclaration());
      typeRefNodeData.schema = xsdSchemaMap.get(reference.getPackage().getDeclaration());   
      typeRefNodeData.bpelProcesses = packageBpelProcessesMap.get(reference.getPackage().getDeclaration());
      typeRefNodeData.bpelNamespace = packageBpelNamespaceMap.get(reference.getPackage().getDeclaration());
    }
    if (typeRefNodeData.bpelProcess != null){
      if (typeRefNodeData.schema != null && !typeRefNodeData.schema.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001))
        processSchemaDeps.get(typeRefNodeData.bpelProcess).add(typeRefNodeData.schema);     
      if (typeRefNodeData.wsdlDef != null)
        processWsdlDeps.get(typeRefNodeData.bpelProcess).add(typeRefNodeData.wsdlDef);
    }
    typeRefNodeData.bottomUpProcess = classProcessMap.get(reference.getDeclaration());
    if (exceptionTypes.contains(reference.getDeclaration()))
      typeRefNodeData.isExceptionType = true;
   
    scanReferences(reference.getActualTypeArguments());
    exitReference(reference);
  }
  @SuppressWarnings("unchecked")
  @Override
  public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) {
    enter(operator);
    ASTNodeData unaryOperatorContext = nodeDataStack.peek();
   
    scan(operator.getType());
    ASTNodeData typeNodeData = nodeDataStack.peek();   
    unaryOperatorContext.xsdType = typeNodeData.xsdType;
    unaryOperatorContext.xsdTypeQName = typeNodeData.xsdTypeQName;
   
    scanReferences(operator.getTypeCasts());
   
    scan(operator.getOperand());
    ASTNodeData operandNodeData = nodeDataStack.peek();
   
    BinaryOperatorKind binOp;
    XpathOperatorMapping xpathBinOpMap = xpathFactory.createBinOpMapping();
    XpathNumberExpression xpathNumberOne = xpathFactory.createNumber();
    xpathNumberOne.setNumber(1);
    XpathBinaryOpExpression xpathBinOperation = xpathFactory.createBinaryOperation();
    //XpathTypeMapping xpathTypeMap = xpathFactory.createTypeMapping();
    //XpathExprType varXpathType = xpathTypeMap.getXpathExprType(operator.getType().getQualifiedName());
   
    switch(operator.getKind()){
    case NEG: break;
    case NOT:
      if (operandNodeData.xpathExpr != null){
        XpathNotExpression xpathNotExpr = xpathFactory.createNotExpression();
        xpathNotExpr.setExpr(operandNodeData.xpathExpr);
        unaryOperatorContext.xpathExpr = xpathNotExpr;
        unaryOperatorContext.variable = operandNodeData.variable;
      }
      break;
     
    case POS: break;   
   
    case POSTDEC:
    case POSTINC:
      if (operator.getKind().equals(UnaryOperatorKind.PREDEC))
        binOp = BinaryOperatorKind.MINUS;
      else
        binOp = BinaryOperatorKind.PLUS;
      if (operandNodeData.variable != null && operandNodeData.xpathExpr != null){
      // create temp variable
        Variable tmpVar = createTempVariable(unaryOperatorContext.scopeStack,typeNodeData.xsdType);
       
      // assign real variable value to temp variable
        From from = BPELFactory.eINSTANCE.createFrom();
        from.setVariable(operandNodeData.variable);
        Query fromQuery = BPELFactory.eINSTANCE.createQuery();
        fromQuery.setQueryLanguage(XPATH_NAMESPACE);
        fromQuery.setValue(operandNodeData.xpathExpr.evaluate());
        from.setQuery(fromQuery);
       
        To to = BPELFactory.eINSTANCE.createTo();
        to.setVariable(tmpVar);
       
        Copy copy = BPELFactory.eINSTANCE.createCopy();
        copy.setTo(to);
        copy.setFrom(from);
        Assign assign = BPELFactory.eINSTANCE.createAssign();
        assign.getCopy().add(copy);
       
      // add assignment activty to curr scope
        operandNodeData.scopeStack.peek().addActivity(assign);
     
      // increment real variable
        try {
          xpathBinOperation.setLeftSide(operandNodeData.xpathExpr);
          xpathBinOperation.setOperator(xpathBinOpMap.getBinOp(binOp));
          xpathBinOperation.setRightSide(xpathNumberOne);
         
          from = BPELFactory.eINSTANCE.createFrom();
          from.setVariable(operandNodeData.variable);
          fromQuery = BPELFactory.eINSTANCE.createQuery();
          fromQuery.setQueryLanguage(XPATH_NAMESPACE);
          fromQuery.setValue(xpathBinOperation.evaluate());
          from.setQuery(fromQuery);
         
          to = BPELFactory.eINSTANCE.createTo();
          to.setVariable(operandNodeData.variable);
         
          copy = BPELFactory.eINSTANCE.createCopy();
          copy.setTo(to);
          copy.setFrom(from);
          assign = BPELFactory.eINSTANCE.createAssign();
          assign.getCopy().add(copy);
     
      // add increment activity to curr scope
          operandNodeData.scopeStack.peek().addActivity(assign);
     
      // set variable reference = temp variable
          operandNodeData.variable = tmpVar;
          XpathVariableRefExpression xpathVarRef = xpathFactory.createVariableReference();
          xpathVarRef.setVariableName(tmpVar.getName());
          xpathVarRef.setType(typeNodeData.xsdTypeQName);
          operandNodeData.xpathExpr = xpathVarRef;
         
        } catch (Exception e) {}
     
      }
      break;
     
    case PREDEC:
    case PREINC:
      if (operator.getKind().equals(UnaryOperatorKind.PREDEC))
        binOp = BinaryOperatorKind.MINUS;
      else
        binOp = BinaryOperatorKind.PLUS;
      if (operandNodeData.variable != null && operandNodeData.xpathExpr != null){
      // increment variable
        try {
          xpathBinOperation.setLeftSide(operandNodeData.xpathExpr);
          xpathBinOperation.setOperator(xpathBinOpMap.getBinOp(binOp));
          xpathBinOperation.setRightSide(xpathNumberOne);
         
          From from = BPELFactory.eINSTANCE.createFrom();
          from.setVariable(operandNodeData.variable);
          Query fromQuery = BPELFactory.eINSTANCE.createQuery();
          fromQuery.setQueryLanguage(XPATH_NAMESPACE);
          fromQuery.setValue(xpathBinOperation.evaluate());
          from.setQuery(fromQuery);
         
          To to = BPELFactory.eINSTANCE.createTo();
          to.setVariable(operandNodeData.variable);
         
          Copy copy = BPELFactory.eINSTANCE.createCopy();
          copy.setTo(to);
          copy.setFrom(from);
          Assign assign = BPELFactory.eINSTANCE.createAssign();
          assign.getCopy().add(copy);
     
      // add assignment/increment activity to curr scope
          operandNodeData.scopeStack.peek().addActivity(assign);
     
        } catch(Exception e){}
       
      }
      break;
     
    }
   
    exit(operator);
  }
  @Override
  public <T> void visitCtVariableAccess(CtVariableAccess<T> variableAccess) {
    enter(variableAccess);
    ASTNodeData varAccessData = nodeDataStack.peek();
   
    scan(variableAccess.getAnnotations());
   
    scan(variableAccess.getType());
    ASTNodeData typeData = nodeDataStack.peek();
   
    scanReferences(variableAccess.getTypeCasts());
   
    scan(variableAccess.getVariable());
    ASTNodeData varRefData = nodeDataStack.peek();
   
    varAccessData.variable = resolveVariable(varAccessData.scopeStack, variableAccess.getVariable().getSimpleName());
    varAccessData.xsdType = typeData.xsdType;
    varAccessData.xsdTypeQName = typeData.xsdTypeQName;
    varAccessData.constructorParamRef = varRefData.constructorParamRef;
    varAccessData.constructor = varRefData.constructor;   
    varAccessData.constructorClass = varRefData.constructorClass;
    varAccessData.constructorArgElementMap = varRefData.constructorArgElementMap;
    varAccessData.xpathExpr = varRefData.xpathExpr; 
   
    exit(variableAccess);
  }
 
  @Override
  public void visitCtWhile(CtWhile whileLoop) {
    enter(whileLoop);
    ASTNodeData whileNodeData = nodeDataStack.peek();
   
    scan(whileLoop.getLoopingExpression());
    ASTNodeData exprNodeData = nodeDataStack.peek();
   
    scan(whileLoop.getBody());
    ASTNodeData bodyNodeData = nodeDataStack.peek();
   
    if (exprNodeData.xpathExpr != null && bodyNodeData.activity != null){
      While whileActivity = BPELFactory.eINSTANCE.createWhile();
      whileNodeData.activity = whileActivity;
      whileActivity.setActivity(bodyNodeData.activity);
      Condition condition = BPELFactory.eINSTANCE.createCondition();
      condition.setRequired(true);
      condition.setBody(exprNodeData.xpathExpr.evaluate());
      whileActivity.setCondition(condition);     
    }
   
    exit(whileLoop);
 
 
  public void write(String outputDir){
    this.outputDirectory = outputDir;
    writeSchemas();
    writeWsdlDefinitions();
    writeBpelProcesses();
  }
 
  @Override
  protected void enter(CtElement e) {
    fireEnterElementEvent(e);
    nodeDataStack.createAndPush(e);   
  }
 
  @Override
  protected void enterReference(CtReference r) {
    nodeDataStack.createAndPush(r);
  }
 
  private void fireEnterElementEvent(CtElement element){
    for (JbprocessMappingBuilder builder : builders){
      builder.enterElement(element);
    }
  }
  private void fireExitElementEvent(CtElement element){
    for (JbprocessMappingBuilder builder : builders){
      builder.exitElement(element);
    }
  }
  private void fireAddMappingEvent(JbprocessMapping mapping){
    for (JbprocessMappingBuilder builder : builders){
      builder.addMapping(mapping);
    }
  }
  @Override
  protected void exit(CtElement e) {
    nodeDataStack.cleanUp(e);   
    if (nodeDataStack.contextStack.size() > 0){
      if (e != null){
        //JbprocessCompositeMapping container = new JbprocessCompositeMapping(e);

        if (packageBpelNamespaceMap.get(e) != null)
          fireAddMappingEvent(new JbprocessAttributeMapping("bpel namespace",e,"targetNamespace",packageBpelNamespaceMap.get(e)));
        if (xsdSchemaMap.get(e) != null){
          XSDSchema schema = xsdSchemaMap.get(e);
          schema.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,schema.getElement()));
        }
        if (wsdlDefMap.get(e) != null){
          Definition wsdl = wsdlDefMap.get(e);
          wsdl.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,wsdl.getElement()));
        }
        if (classProcessMap.get(e) != null){
          org.eclipse.bpel.model.Process process = classProcessMap.get(e);
          process.updateElement();
          fireAddMappingEvent(new JbprocessBpelProcessMapping(e,process));
        }
        if (typePortTypeMap.get(e) != null){
          PortType portType = typePortTypeMap.get(e);
          portType.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,portType.getDocumentationElement()));
        }
        if (methodElementDeclMap.get(e) != null){
          XSDElementDeclaration elem = methodElementDeclMap.get(e);
          elem.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,elem.getElement()));
        }
        if (fieldElementDeclMap.get(e) != null){
          XSDElementDeclaration elem = fieldElementDeclMap.get(e);
          elem.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,elem.getElement()));
        }
        if (fieldVariableMap.get(e) != null){
          Variable variable = fieldVariableMap.get(e);
          variable.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,variable.getElement()));
        }
        if (methodOperationMap.get(e) != null){
          Operation operation = methodOperationMap.get(e);
          operation.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,operation.getElement()));
        }
        if (typeXSDComplexTypeMap.get(e) != null){
          XSDComplexTypeDefinition complexType = typeXSDComplexTypeMap.get(e);
          complexType.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,complexType.getElement()));
        }
        if (wsdlRpcLitResultMap.get(e) != null){
          Part part = wsdlRpcLitResultMap.get(e);
          part.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,part.getElement()));
        }
        if (wsdlDocLitWrapResultMap.get(e) != null){
          XSDElementDeclaration elem = wsdlDocLitWrapResultMap.get(e);
          elem.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,elem.getElement()));
        }
        if (wsdlRpcLitParamMap.get(e) != null){
          Part part = wsdlRpcLitParamMap.get(e);
          part.updateElement();
          fireAddMappingEvent(new JbprocessElementMapping(e,part.getElement()));
        }
        if (wsdlDocLitParamElemMap.get(e) != null){
          List<XSDElementDeclaration> elems = wsdlDocLitParamElemMap.get(e);
          for (XSDElementDeclaration elem : elems){
            elem.updateElement();
            fireAddMappingEvent(new JbprocessElementMapping(e,elem.getElement()));
          }
        }
        if (nodeDataStack.peek().activity != null){
          fireAddMappingEvent(new JbprocessElementMapping(e,nodeDataStack.peek().activity.getElement()));
        }
        /*
        if (packageBpelNamespaceMap.get(e) != null)
          container.add(new JbprocessAttributeMapping("bpel namespace",e,"targetNamespace",packageBpelNamespaceMap.get(e)));
        if (xsdSchemaMap.get(e) != null){
          XSDSchema schema = xsdSchemaMap.get(e);
          schema.updateElement();
          container.add(new JbprocessElementMapping(e,schema.getElement()));
        }
        if (wsdlDefMap.get(e) != null){
          Definition wsdl = wsdlDefMap.get(e);
          wsdl.updateElement();
          container.add(new JbprocessElementMapping(e,wsdl.getElement()));
        }
        if (classProcessMap.get(e) != null){
          org.eclipse.bpel.model.Process process = classProcessMap.get(e);
          process.updateElement();
          container.add(new JbprocessBpelProcessMapping(e,process));
        }
        if (typePortTypeMap.get(e) != null){
          PortType portType = typePortTypeMap.get(e);
          portType.updateElement();
          container.add(new JbprocessElementMapping(e,portType.getDocumentationElement()));
        }
        if (methodElementDeclMap.get(e) != null){
          XSDElementDeclaration elem = methodElementDeclMap.get(e);
          elem.updateElement();
          container.add(new JbprocessElementMapping(e,elem.getElement()));
        }
        if (fieldElementDeclMap.get(e) != null){
          XSDElementDeclaration elem = fieldElementDeclMap.get(e);
          elem.updateElement();
          container.add(new JbprocessElementMapping(e,elem.getElement()));
        }
        if (fieldVariableMap.get(e) != null){
          Variable variable = fieldVariableMap.get(e);
          variable.updateElement();
          container.add(new JbprocessElementMapping(e,variable.getElement()));
        }
        if (methodOperationMap.get(e) != null){
          Operation operation = methodOperationMap.get(e);
          operation.updateElement();
          container.add(new JbprocessElementMapping(e,operation.getElement()));
        }
        if (typeXSDComplexTypeMap.get(e) != null){
          XSDComplexTypeDefinition complexType = typeXSDComplexTypeMap.get(e);
          complexType.updateElement();
          container.add(new JbprocessElementMapping(e,complexType.getElement()));
        }
        if (wsdlRpcLitResultMap.get(e) != null){
          Part part = wsdlRpcLitResultMap.get(e);
          part.updateElement();
          container.add(new JbprocessElementMapping(e,part.getElement()));
        }
        if (wsdlDocLitWrapResultMap.get(e) != null){
          XSDElementDeclaration elem = wsdlDocLitWrapResultMap.get(e);
          elem.updateElement();
          container.add(new JbprocessElementMapping(e,elem.getElement()));
        }
        if (wsdlRpcLitParamMap.get(e) != null){
          Part part = wsdlRpcLitParamMap.get(e);
          part.updateElement();
          container.add(new JbprocessElementMapping(e,part.getElement()));
        }
        if (wsdlDocLitParamElemMap.get(e) != null){
          List<XSDElementDeclaration> elems = wsdlDocLitParamElemMap.get(e);
          for (XSDElementDeclaration elem : elems){
            elem.updateElement();
            container.add(new JbprocessElementMapping(e,elem.getElement()));
          }
        }
        if (nodeDataStack.peek().activity != null){
          container.add(new JbprocessElementMapping(e,nodeDataStack.peek().activity.getElement()));
        }
        */
        //fireAddMappingEvent(container);
      }
    }
    fireExitElementEvent(e);
  }

  @Override
  protected void exitReference(CtReference r) {
    nodeDataStack.cleanUp(r);   
  }
 
  @SuppressWarnings("unchecked")
  void addBpelImports(org.eclipse.bpel.model.Process process){
    Iterator<PartnerLink> partnerLinks = process.getPartnerLinks().getChildren().iterator();
    HashSet<XSDSchema> schemaDeps = processSchemaDeps.get(process);
    HashSet<Definition> wsdlDeps = processWsdlDeps.get(process)
   
    while (partnerLinks.hasNext()){
      PartnerLink plink = partnerLinks.next();
      PartnerLinkType plinkType = plink.getPartnerLinkType();
      Iterator<Role> roles = plinkType.getRole().iterator();
      while (roles.hasNext()){
        Role role = roles.next();
        PortType portType = (PortType)role.getPortType();
        if (portType != null &&
            portType.getEnclosingDefinition() != null &&
             !wsdlDeps.contains(portType.getEnclosingDefinition())){
          wsdlDeps.add(portType.getEnclosingDefinition());
        }       
      }
    }
    Iterator<Definition> deflist = wsdlDeps.iterator();
    while (deflist.hasNext()){
      Definition def = deflist.next();
      org.eclipse.bpel.model.Import bpelImport = BPELFactory.eINSTANCE.createImport();
      bpelImport.setImportType(WSDLConstants.WSDL_NAMESPACE_URI);
      bpelImport.setLocation(def.getDocumentBaseURI());
      bpelImport.setNamespace(def.getTargetNamespace());
      process.getImports().add(bpelImport);
    }
    Iterator<XSDSchema> schemaList = schemaDeps.iterator();
    while (schemaList.hasNext()){
      XSDSchema schema = schemaList.next();
      if (!schema.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001) &&
          !schema.getTargetNamespace().equals(WSDLConstants.WSDL_NAMESPACE_URI)){
        org.eclipse.bpel.model.Import bpelImport = BPELFactory.eINSTANCE.createImport();
        bpelImport.setImportType(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
        //bpelImport.setLocation(schema.getSchemaLocation());
        bpelImport.setLocation(schemaFileMap.get(schema));
        bpelImport.setNamespace(schema.getTargetNamespace());
        process.getImports().add(bpelImport);
      }
    }
  }
 
  @SuppressWarnings("unchecked")
  void addSchemaImports(XSDSchema schema){       
    java.util.Map<String, String> qNamePrefixToNamespaceMap = schema.getQNamePrefixToNamespaceMap();
    HashSet<XSDSchema> dependencies = schemaDependencies.get(schema);
    for (XSDSchema s : dependencies){
      qNamePrefixToNamespaceMap.put(schemaNsPrefixMap.get(s.getTargetNamespace()), s.getTargetNamespace());
      XSDImport imp = XSDFactory.eINSTANCE.createXSDImport();     
      imp.setSchemaLocation(s.getSchemaLocation());
      imp.setNamespace(s.getTargetNamespace());
      schema.getReferencingDirectives().add(imp);   
      schema.getContents().add(0,imp);
    }   
  }

  @SuppressWarnings("unchecked")
  void addWsdlImports(Definition wsdl){
    Vector<XSDSchema> dependencies = wsdlDependencies.get(wsdl);
    if (dependencies != null){
      for (XSDSchema schema : dependencies){
        Import xsdImport = WSDLFactory.eINSTANCE.createImport();
        xsdImport.setSchema(schema);
        String fileName = schemaFileMap.get(schema);//schema.getSchemaLocation();
        xsdImport.setLocationURI(fileName);
        xsdImport.setNamespaceURI(schema.getTargetNamespace());
        wsdl.addImport(xsdImport);
        wsdl.addNamespace(schemaNsPrefixMap.get(schema.getTargetNamespace()), schema.getTargetNamespace());
        Types types = wsdl.getETypes();
        List<XSDSchema> schemas = types.getSchemas();
        if (schemas.size() == 1){
          java.util.Map qNamePrefixToNamespaceMap = schemas.get(0).getQNamePrefixToNamespaceMap();
          qNamePrefixToNamespaceMap.put(schemaNsPrefixMap.get(schema.getTargetNamespace()),schema.getTargetNamespace());         
          XSDImport imp = XSDFactory.eINSTANCE.createXSDImport();
          imp.setSchemaLocation(fileName);
          imp.setNamespace(schema.getTargetNamespace());         
          schemas.get(0).getReferencingDirectives().add(imp);
          schemas.get(0).getContents().add(0,imp);
        }       
      }
    }
  }
  <T> void createClassToBpelProcessMapping(CtClass<T> ctClass){
    jbprocess.annotations.Process processAnnotation = ctClass.getAnnotation(jbprocess.annotations.Process.class);
    if (processAnnotation != null){
      org.eclipse.bpel.model.Process process = classProcessMap.get(ctClass);
      if (process == null){
        /*
        BPELResourceSetImpl resourceSet = new BPELResourceSetImpl();
       
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
              "bpel", new BPELResourceFactoryImpl());
       
        URI uri = URI.createURI("C:\\test.bpel");
       
        BPELResource resource = (BPELResource)resourceSet.createResource(uri);
        */
        process = BPELFactory.eINSTANCE.createProcess();
       
        String processName = ctClass.getSimpleName();
        if (!processAnnotation.name().equals(""))
          processName = processAnnotation.name();
        process.setName(processName);
        process.setTargetNamespace(packageBpelNamespaceMap.get(ctClass.getPackage()));
       
        PartnerLinks partnerLinks = BPELFactory.eINSTANCE.createPartnerLinks();
        process.setPartnerLinks(partnerLinks);       
       
        Variables variables = BPELFactory.eINSTANCE.createVariables();
        process.setVariables(variables);

        classProcessMap.put(ctClass, process);
        classProcessLinksMap.put(ctClass, new HashSet<PartnerLink>());
        processWsdlDeps.put(process, new HashSet<Definition>());
        processSchemaDeps.put(process, new HashSet<XSDSchema>());
       
        BpelScope processScope = new BpelProcessScopeImpl(classProcessMap.get(ctClass));
        Stack<BpelScope> bpelScopeStack = new Stack<BpelScope>();
        bpelScopeStack.push(processScope);
        classScopeMap.put(ctClass, bpelScopeStack);
        nodeDataStack.peek().scopeStack = bpelScopeStack;
        nodeDataStack.peek().bpelProcess = process;
       
        createProcessRolesForPartnerLinks(ctClass, process);       
      }
    }   
  }
  <T> void createClassToComplexTypeMapping(CtClass<T> ctClass){
    if (ctClass.getSuperclass() != null){
      if (ctClass.getSuperclass().getQualifiedName().equals("java.lang.Exception"))
        if (!exceptionTypes.contains(ctClass))
          exceptionTypes.add(ctClass);       
    }
    if (!isThisClassABpelProcess(ctClass) && typeXSDComplexTypeMap.get(ctClass) == null){
      //javax.xml.bind.annotation.XmlType xmlTypeAnnotation = ctClass.getAnnotation(javax.xml.bind.annotation.XmlType.class);
      //if (xmlTypeAnnotation != null){
      //  createJAXBClassToComplexTypeMapping(ctClass,xmlTypeAnnotation);
      //} else {
        createTypeToComplexTypeMapping(ctClass);
      //}
    }
  }
 
  <T> void createClassToPortTypeMapping(CtClass<T> ctClass){
    javax.jws.WebService webService = ctClass.getAnnotation(javax.jws.WebService.class);
    if (webService != null){
      Definition wsdlDef = wsdlDefMap.get(ctClass.getPackage());
      if (wsdlDef != null){
        String prefix = wsdlNsPrefixMap.get(ctClass.getPackage().getQualifiedName());
        if (prefix != null){
          if (!webService.targetNamespace().equals("")){
            wsdlDef.getNamespaces().remove(wsdlDef.getTargetNamespace());
            //wsdlDef.removeNamespace(webService.targetNamespace());
            wsdlDef.setTargetNamespace(webService.targetNamespace());
            wsdlDef.addNamespace(prefix, webService.targetNamespace());
          }
          PortType portType = typePortTypeMap.get(ctClass);
          if (portType == null){
            String portTypeName = ctClass.getSimpleName();
            if (!webService.name().equals(""))
              portTypeName = webService.name();
            portType = WSDLFactory.eINSTANCE.createPortType();
            portType.setQName(new QName(wsdlDef.getQName().getNamespaceURI(),portTypeName));
            portType.setUndefined(false);
            wsdlDef.addPortType(portType);
            typePortTypeMap.put(ctClass, portType);
            javax.jws.soap.SOAPBinding soapBinding = ctClass.getAnnotation(javax.jws.soap.SOAPBinding.class);
            if (soapBinding != null)
              typeSoapBindingMap.put(ctClass, soapBinding);
          }       
        }
      }
    }
  }
 
  Vector<XSDElementDeclaration> createConstructorFieldMap(CtConstructor<?> c, XSDComplexTypeDefinition complexType){
    ArrayList<XSDElementDeclaration> elements = complexTypePropMap.get(complexType);
    if (elements != null){
      Vector<XSDElementDeclaration> setOfMappings = new Vector<XSDElementDeclaration>()
      setOfMappings.setSize(c.getParameters().size());
      int paramPos = 0;
      for (CtParameter<?> param : c.getParameters()){
        for (XSDElementDeclaration el : elements){
          if (param.getSimpleName().equals(el.getName())){
            setOfMappings.add(paramPos, el);
            break
          }           
        }
        paramPos++;
      }
      return setOfMappings;
    }
    return null;   
  }
 
  XSDElementDeclaration createFieldToElementMapping(CtField f, String targetNamespace, XSDComplexTypeDefinition parentType, XSDTypeDefinition fieldType){
    String elementName = f.getSimpleName()
    return createFieldToElementMapping(elementName,true,targetNamespace,parentType,fieldType);
  }
 
 
  <T> XSDElementDeclaration createFieldToElementMapping(CtMethod<T> m, ASTNodeData methodNodeData, ASTNodeData typeNodeData){
    String propertyName = getBeanPropertyName(m);
    XSDElementDeclaration el = null;
    if (!propertyName.equals("")){
      // default mapping
       if (m.getParameters().size() == 1 && m.getSimpleName().startsWith("set")){
        //scan(m.getParameters().get(0));
        resolveTypeReference(m.getParameters().get(0).getType(),typeNodeData);
        XSDComplexTypeDefinition parentType = typeXSDComplexTypeMap.get(m.getDeclaringType());
        el = createFieldToElementMapping(propertyName, false, "", parentType, typeNodeData.xsdType);
        methodElementDeclMap.put(m, el);
      }
      if (typeNodeData.xsdType != null && typeNodeData.xsdTypeQName != null){
        resolveTypeReference(m.getType(), typeNodeData);
        XSDComplexTypeDefinition parentType = typeXSDComplexTypeMap.get(m.getDeclaringType());
        el = createFieldToElementMapping(propertyName, false, "", parentType, typeNodeData.xsdType);
        methodElementDeclMap.put(m, el);
      }     
    }
    return el;
  }
  @SuppressWarnings("unchecked")
  XSDElementDeclaration createFieldToElementMapping(String elementName, boolean setTargetNamespace, String targetNamespace, XSDComplexTypeDefinition parentType, XSDTypeDefinition fieldType){
    ArrayList<XSDElementDeclaration> existingElements = complexTypePropMap.get(parentType);
    for (XSDElementDeclaration el : existingElements){
      if (el.getName().equals(elementName)){
        return el;     
      }
    }
    if (parentType.getContent() != null && parentType.getContent() instanceof XSDParticle){
      XSDParticle parentParticle = (XSDParticle)parentType.getContent();
      if (parentParticle.getContent() != null && parentParticle.getContent() instanceof XSDModelGroup){
        XSDModelGroup parentModelGroup = (XSDModelGroup)parentParticle.getContent();
        XSDParticle localElementParticle = XSDFactory.eINSTANCE.createXSDParticle();
        XSDElementDeclaration el = XSDFactory.eINSTANCE.createXSDElementDeclaration();
        localElementParticle.setContent(el);
        if (setTargetNamespace)
          el.setTargetNamespace(targetNamespace);
        if (!fieldType.getTargetNamespace().equals(parentType.getSchema().getTargetNamespace())){
          XSDSchema parentSchema = parentType.getSchema();
          XSDSchema fieldSchema = fieldType.getSchema();
         
          HashSet<XSDSchema> dependencies = schemaDependencies.get(parentSchema);
          if (fieldSchema != null){
            if (!dependencies.contains(fieldSchema) && !fieldSchema.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)){
              dependencies.add(fieldSchema);
            }
          }
        }
        el.setName(elementName);
        el.setTypeDefinition(fieldType);       
        parentModelGroup.getContents().add(localElementParticle);
        complexTypePropMap.get(parentType).add(el);
        return el;
      }
    }
    return null;
  }

  @SuppressWarnings("unchecked")
  <T> void createFieldToPartnerLinkMapping(CtField<T> f, PortType portType){
    jbprocess.annotations.PartnerLink plinkAnnotation = f.getAnnotation(jbprocess.annotations.PartnerLink.class);
    //if (plinkAnnotation != null){
      if (fieldPartnerLinkMap.get(f) == null && portType != null){
        org.eclipse.bpel.model.Process process = classProcessMap.get(f.getDeclaringType());
        if (process != null){
         
          PartnerLink plink = null;
          PartnerLinkType plinkType = null;
          Role partnerRole = null;
          String plinkName = f.getSimpleName();
          if (plinkAnnotation != null && !plinkAnnotation.name().equals(""))
            plinkName = plinkAnnotation.name();
          String roleName = plinkName;
          if (plinkAnnotation != null && !plinkAnnotation.role().equals(""))
            plinkName = plinkAnnotation.role();
          String partnerLinkTypeName = plinkName + process.getName() + "LT";
          Iterator<PartnerLink> plit = process.getPartnerLinks().getChildren().iterator();               
          while (plit.hasNext()){
            PartnerLink pl = plit.next();
            if (pl.getName().equals(plinkName)){ 
              partnerLinkTypeName = pl.getPartnerLinkType().getName();
              plink = pl;
              break;
            }
          }
          if (plink == null){
            plink = BPELFactory.eINSTANCE.createPartnerLink();
            plinkType = PartnerlinktypeFactory.eINSTANCE.createPartnerLinkType();
            plink.setName(plinkName);
            partnerRole = PartnerlinktypeFactory.eINSTANCE.createRole();
            partnerRole.setName(roleName);
            partnerRole.setPortType(portType);
            partnerRole.setRequired(true);
            plinkType.setName(partnerLinkTypeName);   
            plinkType.setName(partnerLinkTypeName);
            plinkType.setElementType(plinkType.getElementType());
            plinkType.setRequired(true);
            plinkType.getRole().add(partnerRole);
            plink.setPartnerRole(partnerRole);
            plink.setPartnerLinkType(plinkType);
            process.getPartnerLinks().getChildren().add(plink);
          } else {
            plinkType = plink.getPartnerLinkType();
            partnerRole = PartnerlinktypeFactory.eINSTANCE.createRole();
            partnerRole.setName(roleName);
            partnerRole.setPortType(portType);
            partnerRole.setRequired(true);
            plinkType.getRole().add(partnerRole);
            plink.setPartnerRole(partnerRole);
          }
         
          fieldPartnerLinkMap.put(f, plink);       
        }
      //}
    }
  }
 
  @SuppressWarnings("unchecked")
  <T> void createFieldToVariableMapping(CtField<T> f, XSDTypeDefinition fieldType){
   
    jbprocess.annotations.PartnerLink plinkAnnotation = f.getAnnotation(jbprocess.annotations.PartnerLink.class);
    if (plinkAnnotation == null){
      if (fieldPartnerLinkMap.get(f) == null && fieldType != null){     
        if (f.getDeclaringType() instanceof CtClass){ 
          CtClass ctClass = (CtClass)f.getDeclaringType();       
          if (isThisClassABpelProcess(ctClass) && fieldVariableMap.get(f) == null){         
            org.eclipse.bpel.model.Process process = classProcessMap.get(f.getDeclaringType());
            if (process != null){
              String variableName = f.getSimpleName();
              Variable var = BPELFactory.eINSTANCE.createVariable();
              var.setName(variableName);       
              var.setType(fieldType);
              fieldVariableMap.put(f, var);
              Stack<BpelScope> scopeStack = classScopeMap.get(ctClass);
              scopeStack.firstElement().addVariable(var);
            }
          }
        }
      }   
    }
  }
 
  <T> XSDElementDeclaration createFieldTypeMapping(CtField<T> f, XSDTypeDefinition fieldType){
    XSDElementDeclaration el = null;
    XSDComplexTypeDefinition parentType = typeXSDComplexTypeMap.get(f.getDeclaringType());
    if (parentType != null && fieldType != null){
      //if (f.getAnnotation(javax.xml.bind.annotation.XmlElement.class) != null && f.getParent() instanceof CtClass)
      //  el = createJAXBFieldToElementMapping(f,parentType,fieldType);
      //else
        el = createFieldToElementMapping(f,parentType.getTargetNamespace(),parentType,fieldType);
      if (el != null)
        fieldElementDeclMap.put(f, el);
    }
    return el;
  }
 
  @SuppressWarnings("unchecked")
  <R> Flow createFlow(CtBlock<R> block){
    if (block.getLabel() != null){
      if (block.getLabel().startsWith("flow_")){
        String flowName = block.getLabel().substring(5);
        Flow flow = BPELFactory.eINSTANCE.createFlow();
        flow.setName(flowName);
        Links links = BPELFactory.eINSTANCE.createLinks();
        flow.setLinks(links);
        for(CtStatement stmt : block.getStatements()){
          scan(stmt);
          ASTNodeData stmtData = nodeDataStack.peek();
          if (stmtData.flowActivity != null) {
            flow.getActivities().add(stmtData.flowActivity);
            setFlowActivityLinks(flow,stmtData.flowMethod,stmtData.flowActivity);
          }
        }
        return flow;
      }
    }
    return null;
  }
  void setFlowActivityLinks(Flow flow, CtMethod<?> flowMethod, Activity activity){
    HashMap<String,Link> linkMap = new HashMap<String,Link>();
    FlowActivity flowActivity = flowMethod.getAnnotation(FlowActivity.class);
    if (flowActivity != null){
      if (flowActivity.targets().length > 0){
        Targets targets = BPELFactory.eINSTANCE.createTargets();
        activity.setTargets(targets);
        for(int i=0; i < flowActivity.targets().length; i++){
          FlowLinkTarget linkTarget = flowActivity.targets()[i];
          if (!linkTarget.name().equals("")){
            Link link = linkMap.get(linkTarget.name());
            if (link == null){
              link = BPELFactory.eINSTANCE.createLink();
              link.setName(linkTarget.name());
              linkMap.put(linkTarget.name(), link);
              flow.getLinks().getChildren().add(link);
            }           
            Target target = BPELFactory.eINSTANCE.createTarget();
            target.setLink(link);
            target.setActivity(activity)
            targets.getChildren().add(target);
          }
        }       
      }     
      if (flowActivity.sources().length > 0){
        Sources sources = BPELFactory.eINSTANCE.createSources();
        activity.setSources(sources);     
        for(int i=0; i < flowActivity.sources().length; i++){
          FlowLinkSource linkSource = flowActivity.sources()[i];
          Link link = linkMap.get(linkSource.name());
          if (link == null){
            link = BPELFactory.eINSTANCE.createLink();
            link.setName(linkSource.name());
            linkMap.put(linkSource.name(), link);
            flow.getLinks().getChildren().add(link);
          }                           
          Source source = BPELFactory.eINSTANCE.createSource();
          source.setLink(link);
          source.setActivity(activity);
          Condition cond = BPELFactory.eINSTANCE.createCondition();
          cond.setBody(linkSource.transitionCondition());
          source.setTransitionCondition(cond);
          sources.getChildren().add(source);
        }
      }
    }
  }
  <T> void createInterfaceToPortTypeMapping(CtInterface<T> intrface){
    javax.jws.WebService webServiceAnnotation = intrface.getAnnotation(javax.jws.WebService.class);
    if (webServiceAnnotation != null && typePortTypeMap.get(intrface) == null){
      String packageName = intrface.getPackage().getQualifiedName();
      Definition wsdlDef = wsdlDefMap.get(intrface.getPackage());
      String prefix = wsdlNsPrefixMap.get(packageName);
      if (wsdlDef != null && prefix != null){     
        if (!webServiceAnnotation.targetNamespace().equals("")){
          // override default namespace
          wsdlDef.getNamespaces().remove(wsdlDef.getTargetNamespace());
          //wsdlDef.removeNamespace(wsdlDef.getTargetNamespace());
          wsdlDef.setTargetNamespace(webServiceAnnotation.targetNamespace());
          wsdlDef.addNamespace(prefix, webServiceAnnotation.targetNamespace());
        }       
        PortType portType = typePortTypeMap.get(intrface);
        if (portType == null){       
          String portTypeName = intrface.getSimpleName();
          if (!webServiceAnnotation.name().equals(""))
            portTypeName = webServiceAnnotation.name();
          portType = WSDLFactory.eINSTANCE.createPortType();
          portType.setQName(new QName(wsdlDef.getQName().getNamespaceURI(),portTypeName));
          portType.setUndefined(false);       
          wsdlDef.addPortType(portType);
          typePortTypeMap.put(intrface,portType);
          javax.jws.soap.SOAPBinding soapBindingAnnoation = intrface.getAnnotation(javax.jws.soap.SOAPBinding.class);
          if (soapBindingAnnoation != null)
            typeSoapBindingMap.put(intrface, soapBindingAnnoation);       
        }     
      } 
    }
  } 
  /*
  @SuppressWarnings("unchecked")
  <T> void createJAXBClassToComplexTypeMapping(CtClass<T> ctClass, javax.xml.bind.annotation.XmlType xmlTypeAnnotation){
//     JAXB v2.0 (JSR-222), section 8.2.1, 8.7 - Java Class Maps to XML Schema Complex Type
    XSDSchema schema = xsdSchemaMap.get(ctClass.getPackage());

    XSDComplexTypeDefinition complexType = typeXSDComplexTypeMap.get(ctClass);
    if (complexType == null)
      complexType = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    javax.xml.bind.annotation.XmlType xmlTypeBinding = ctClass.getAnnotation(javax.xml.bind.annotation.XmlType.class);
    String complexTypeName = "";
    String className = ctClass.getSimpleName();
   
    if (xmlTypeBinding.name().equals("")){
      // no name
    } else if (xmlTypeBinding.name().equals(JAXB_DEFAULT_NAME)){
      complexTypeName = java.beans.Introspector.decapitalize(className);
      complexType.setName(complexTypeName);
    } else {
      complexTypeName = xmlTypeBinding.name();
      complexType.setName(complexTypeName);
    }
   
    if (xmlTypeBinding.namespace().equals(JAXB_DEFAULT_NAME) &&
        xmlTypeBinding.name().equals("") &&
        ctClass.getAnnotation(javax.xml.bind.annotation.XmlRootElement.class) != null){
      javax.xml.bind.annotation.XmlRootElement xmlRootElementAnnotation = ctClass.getAnnotation(javax.xml.bind.annotation.XmlRootElement.class);
      if (xmlRootElementAnnotation.namespace().equals(JAXB_DEFAULT_NAME)){
        if (schema.getTargetNamespace() != null)
          complexType.setTargetNamespace(schema.getTargetNamespace());       
      } else
        complexType.setTargetNamespace(xmlRootElementAnnotation.namespace());
    }
   
    XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
    XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
    modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
    particle.setContent(modelGroup);   
    complexType.setContent(particle);
    schema.getContents().add(complexType);
    typeXSDComplexTypeMap.put(ctClass, complexType);
    complexTypePropMap.put(complexType, new ArrayList<XSDElementDeclaration>());
  }
  XSDElementDeclaration createJAXBFieldToElementMapping(CtField f, XSDComplexTypeDefinition parentType, XSDTypeDefinition fieldType){
    String elementName = f.getSimpleName(); 
    String targetNamespace = "";
    boolean setTargetNamespace = false;
    javax.xml.bind.annotation.XmlElement xmlElemAnnotation = f.getAnnotation(javax.xml.bind.annotation.XmlElement.class);
    if (xmlElemAnnotation != null){
      String xmlBeanPropertyName = getBeanPropertyName(f);
      if (xmlBeanPropertyName.equals(""))
        return null;  // JAXB requires that fields with XmlElement Annotation have valid Java Bean property names & accessors (section 8.12.1, 8.9.1.2)
      if (xmlElemAnnotation.name().equals(JAXB_DEFAULT_NAME)){
        elementName =xmlBeanPropertyName; 
      } else
        elementName = xmlElemAnnotation.name();
      if (xmlElemAnnotation.namespace().equals(JAXB_DEFAULT_NAME)){
        if (f.getDeclaringType().getPackage().getAnnotation(javax.xml.bind.annotation.XmlSchema.class) != null &&
            f.getDeclaringType().getPackage().getAnnotation(javax.xml.bind.annotation.XmlSchema.class).elementFormDefault() ==
              javax.xml.bind.annotation.XmlNsForm.QUALIFIED){
          setTargetNamespace = true;
          targetNamespace = parentType.getTargetNamespace();
         
        } else {
          setTargetNamespace = true;
          targetNamespace = "";
        }
      } else {
        setTargetNamespace = true;
        targetNamespace = xmlElemAnnotation.namespace();
      }       
    }   
    return createFieldToElementMapping(elementName,setTargetNamespace,targetNamespace,parentType,fieldType);
  }
  */
  @SuppressWarnings("unchecked")
  <T> void createMethodFlowMapping(CtMethod<T> m, Activity activity) {
    FlowActivity flowActivity = m.getAnnotation(FlowActivity.class);
    if (flowActivity != null && activity != null){
      String activityName = m.getSimpleName();
      if (!flowActivity.name().equals(""))
        activityName = flowActivity.name();
      activity.setName(activityName);
      methodFlowActivityMap.put(m,activity);   
      /*
      if (flowActivity.targets().length > 0){
        Targets targets = BPELFactory.eINSTANCE.createTargets();
        activity.setTargets(targets);
        for(int i=0; i < flowActivity.targets().length; i++){
          FlowLinkTarget linkTarget = flowActivity.targets()[i];
          if (!linkTarget.name().equals("")){
            //Link link = linkMap.get(linkTarget.name());
            //if (link == null){
              Link link = BPELFactory.eINSTANCE.createLink();
              link.setName(linkTarget.name());
            //  linkMap.put(linkTarget.name(), link);
            //}           
            Target target = BPELFactory.eINSTANCE.createTarget();
            target.setLink(link);
            target.setActivity(activity);
            targets.getChildren().add(target);
          }
        }       
      }     
      if (flowActivity.sources().length > 0){
        Sources sources = BPELFactory.eINSTANCE.createSources();
        activity.setSources(sources);     
        for(int i=0; i < flowActivity.sources().length; i++){
          FlowLinkSource linkSource = flowActivity.sources()[i];
          //Link link = linkMap.get(linkSource.name());
          //if (link == null){
            Link link = BPELFactory.eINSTANCE.createLink();
            link.setName(linkSource.name());
            //linkMap.put(linkSource.name(), link);
          //}                           
          Source source = BPELFactory.eINSTANCE.createSource();
          source.setLink(link);
          source.setActivity(activity); 
          sources.getChildren().add(source);
        }
      } 
      */   
    }   
  }
 
  @SuppressWarnings("unchecked")
  <T> void createMethodResultToOperationResultMapping(CtMethod<T> m, Operation operation, String resultName, XSDTypeDefinition xsdType, javax.jws.soap.SOAPBinding.Style style, javax.jws.soap.SOAPBinding.Use use, javax.jws.soap.SOAPBinding.ParameterStyle parameterStyle){
    if (style == javax.jws.soap.SOAPBinding.Style.DOCUMENT && use == javax.jws.soap.SOAPBinding.Use.LITERAL){
      if (parameterStyle == javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED){
        if (wsdlDocLitWrapResultMap.get(operation) == null){
          Part part = (Part)operation.getOutput().getMessage().getPart("parameters");
 
          XSDElementDeclaration parentElement = part.getElementDeclaration();
          XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition)parentElement.getType();       
          XSDParticle parentParticle = (XSDParticle)complexType.getContent();           
          XSDModelGroup parentModelGroup = (XSDModelGroup)parentParticle.getContent();       
         
          XSDElementDeclaration el = XSDFactory.eINSTANCE.createXSDElementDeclaration();
          el.setName(resultName);
          el.setTypeDefinition(xsdType);
         
          XSDParticle localElementParticle = XSDFactory.eINSTANCE.createXSDParticle();
          localElementParticle.setContent(el);                 
         
          parentModelGroup.getContents().add(localElementParticle);
          wsdlDocLitWrapResultMap.put(operation, el);
         
          XSDSchema schema = xsdType.getSchema();
          if (schema != null && !schema.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)){
            Vector<XSDSchema> dependencies = wsdlDependencies.get(operation.getEnclosingDefinition());
            if (!dependencies.contains(schema))
              dependencies.add(schema);
          }
        }
      } else {
       
      }
    } else if (style == javax.jws.soap.SOAPBinding.Style.RPC && use == javax.jws.soap.SOAPBinding.Use.LITERAL){
      if (wsdlRpcLitResultMap.get(m) == null){
        Part part = WSDLFactory.eINSTANCE.createPart();           
        part.setName(resultName);
        part.setTypeDefinition(xsdType);
        operation.getOutput().getMessage().addPart(part);
        wsdlRpcLitResultMap.put(m, part);
      }
    }
  }
 
  <T> void createMethodResultToOperationResultMapping(CtMethod<T> m, XSDTypeDefinition xsdType){   
    Operation operation = methodOperationMap.get(m);
    if (operation != null){
      javax.jws.soap.SOAPBinding soapBinding = typeSoapBindingMap.get(m.getDeclaringType());
      String operationName = m.getSimpleName();
      javax.jws.WebMethod webMethodAnnotation = m.getAnnotation(javax.jws.WebMethod.class);
      if (webMethodAnnotation != null && !webMethodAnnotation.operationName().equals(""))
        operationName = webMethodAnnotation.operationName();   
      String resultName = operationName + "Response";
      javax.jws.WebResult webResultAnnotation = m.getAnnotation(javax.jws.WebResult.class);
      if (webResultAnnotation != null && !webResultAnnotation.name().equals(""))
        resultName = webResultAnnotation.name();
      if (soapBinding != null){
        operationSoapBindingMap.put(operation, soapBinding);
        createMethodResultToOperationResultMapping(m, operation, resultName, xsdType, soapBinding.style(), soapBinding.use(), soapBinding.parameterStyle());
      } else {
        createMethodResultToOperationResultMapping(m, operation, resultName, xsdType, javax.jws.soap.SOAPBinding.Style.DOCUMENT, javax.jws.soap.SOAPBinding.Use.LITERAL, javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED);
      }
    }
  }
 
  <T> void createMethodToOperationMapping(CtMethod<T> m){
    String packageName = m.getDeclaringType().getPackage().getQualifiedName();
    String operationName = m.getSimpleName();

    Definition wsdlDef = wsdlDefMap.get(m.getDeclaringType().getPackage());
    String prefix = wsdlNsPrefixMap.get(packageName);
    if (wsdlDef != null && prefix != null){     
      if (wsdlDef.getTypes() == null)
        wsdlDef.setTypes(WSDLFactory.eINSTANCE.createTypes());
      PortType portType = typePortTypeMap.get(m.getDeclaringType());
      javax.jws.WebMethod webMethodAnnotation = m.getAnnotation(javax.jws.WebMethod.class);
      if (portType != null && webMethodAnnotation != null){ 
        Operation operation = methodOperationMap.get(m);
        if (operation == null) {
            operation = WSDLFactory.eINSTANCE.createOperation();       
          if (!webMethodAnnotation.operationName().equals(""))
            operationName = webMethodAnnotation.operationName();         
          operation.setName(operationName);
          operation.setUndefined(false);
          Input input = WSDLFactory.eINSTANCE.createInput();
          operation.setInput(input);
          Output output = WSDLFactory.eINSTANCE.createOutput();
          operation.setOutput(output);
          portType.addOperation(operation);
          Message inputMessage = WSDLFactory.eINSTANCE.createMessage();
          inputMessage.setQName(new QName(operation.getEnclosingDefinition().getTargetNamespace(), operationName));
          inputMessage.setUndefined(false);
          input.setMessage(inputMessage);
          wsdlDef.addMessage(inputMessage);
         
          Message outputMessage = WSDLFactory.eINSTANCE.createMessage();
          outputMessage.setQName(new QName(operation.getEnclosingDefinition().getTargetNamespace(), operationName + "Response"));
          outputMessage.setUndefined(false);
          output.setMessage(outputMessage);
          wsdlDef.addMessage(outputMessage);
          methodOperationMap.put(m,operation);
         
          createWsdlStyleMapping(m);
         
          ASTNodeData typeNodeData = new ASTNodeData();
          resolveTypeReference(m.getType(), typeNodeData);
          if (typeNodeData.xsdType != null)
            createMethodResultToOperationResultMapping(m,typeNodeData.xsdType);
         
          for (CtTypeReference<?> type : m.getThrownTypes()){
            if (type.getDeclaration() != null){
              if (exceptionTypes.contains(type.getDeclaration())){
                XSDComplexTypeDefinition complexType = typeXSDComplexTypeMap.get(type.getDeclaration());
                Part part = WSDLFactory.eINSTANCE.createPart();   
                part.setName(complexType.getName());
                part.setTypeDefinition(complexType);

                Message faultMessage = WSDLFactory.eINSTANCE.createMessage();
                //faultMessage.setQName(new QName(operation.getEnclosingDefinition().getTargetNamespace(), complexType.getName() + "Message"));
                faultMessage.setQName(new QName(operation.getEnclosingDefinition().getTargetNamespace(), complexType.getName()));
                //faultMessage.setQName(new QName(complexType.getName()));
                faultMessage.addPart(part);
                faultMessage.setUndefined(false);
                wsdlDef.addMessage(faultMessage);
               
                Fault fault = WSDLFactory.eINSTANCE.createFault();
                fault.setName(complexType.getName());
                fault.setMessage(faultMessage);
               
                operation.addFault(fault);
              }
            }
          }
        }
      }     
    }   
  }
 
  void createPackageToBpelProcessesMapping(CtPackage ctPackage){
//     Map Packages to a set of BPEL Processes
    if (ctPackage != null){
      if (!ctPackage.getQualifiedName().startsWith("java") &&
          !ctPackage.getQualifiedName().startsWith("spoon") &&
          !ctPackage.getQualifiedName().startsWith("jbprocess")){   
        if (packageBpelProcessesMap.get(ctPackage) == null){
          HashSet<org.eclipse.bpel.model.Process> processes = new HashSet<org.eclipse.bpel.model.Process>();
          packageBpelProcessesMap.put(ctPackage, processes);
        }
        if (packageBpelNamespaceMap.get(ctPackage) == null){
          String targetNamespace = ctPackage.getQualifiedName();
          targetNamespace = targetNamespace.replaceAll("\\s", "");
          String prefix = "ns" + namespaceCounter++;
          bpelNsPrefixMap.put(targetNamespace, prefix);
          packageBpelNamespaceMap.put(ctPackage, targetNamespace);
        }
      }
    }
  }
 
  @SuppressWarnings("unchecked")
  void createPackageToSchemaMapping(CtPackage ctPackage){ 
    if (ctPackage != null){
      if (!ctPackage.getQualifiedName().startsWith("java") &&
          !ctPackage.getQualifiedName().startsWith("spoon") &&
          !ctPackage.getQualifiedName().startsWith("jbprocess")){
        if (ctPackage != null && xsdSchemaMap.get(ctPackage) == null){
          String targetNamespace = ctPackage.getQualifiedName();
          targetNamespace = targetNamespace.replaceAll("\\s", "");     
         
          XSDSchema s = XSDFactory.eINSTANCE.createXSDSchema();
          s.setSchemaForSchemaQNamePrefix("xsd");
          java.util.Map qNamePrefixToNamespaceMap = s.getQNamePrefixToNamespaceMap();
          qNamePrefixToNamespaceMap.put(s.getSchemaForSchemaQNamePrefix(),
              XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
          s.setElementFormDefault(XSDForm.get(XSDForm.QUALIFIED));
          s.setAttributeFormDefault(XSDForm.get(XSDForm.QUALIFIED));     
          s.setTargetNamespace(targetNamespace);
         
          //XSDResourceImpl res = new XSDResourceImpl();     
          //res.getContents().add(s);
         
          String prefix = "ns" + namespaceCounter++;
          qNamePrefixToNamespaceMap.put(prefix,targetNamespace);
          schemaNsPrefixMap.put(targetNamespace, prefix);     
          schemaDependencies.put(s, new HashSet<XSDSchema>());
          xsdSchemaMap.put(ctPackage, s);
        }
      }
    }
  }
 
  @SuppressWarnings("unchecked")
  void createPackageToWsdlMapping(CtPackage ctPackage){
    if (ctPackage != null){
      if (!ctPackage.getQualifiedName().startsWith("java") &&
          !ctPackage.getQualifiedName().startsWith("spoon") &&
          !ctPackage.getQualifiedName().startsWith("jbprocess")){
        if (ctPackage != null && wsdlDefMap.get(ctPackage) == null){
          String targetNamespace = ctPackage.getQualifiedName();
          targetNamespace = targetNamespace.replaceAll("\\s", "");
          String prefix = "ns" + namespaceCounter++;
         
          Definition wsdlDef = WSDLFactory.eINSTANCE.createDefinition();
          wsdlDef.addNamespace(XML_SCHEMA_NAMESPACE_PREFIX,  WSDLConstants.SCHEMA_FOR_SCHEMA_URI_2001);// org.apache.ws.commons.schema.constants.Constants.URI_2001_SCHEMA_XSD);
          wsdlDef.addNamespace(WSDL_PREFIX,WSDL_NAMESPACE);
         
          wsdlDef.addNamespace(prefix, targetNamespace);
          wsdlDef.setTargetNamespace(targetNamespace);
          wsdlDef.setQName(new QName(targetNamespace,"",prefix))
          wsdlNsPrefixMap.put(targetNamespace, prefix);
          wsdlDependencies.put(wsdlDef, new Vector<XSDSchema>());   
         
          XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
          schema.setTargetNamespace(wsdlDef.getTargetNamespace());         
          schema.setSchemaForSchemaQNamePrefix(XML_SCHEMA_NAMESPACE_PREFIX);
          java.util.Map qNamePrefixToNamespaceMap = schema.getQNamePrefixToNamespaceMap();
          qNamePrefixToNamespaceMap.put(schema.getSchemaForSchemaQNamePrefix(),
              XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
          qNamePrefixToNamespaceMap.put(wsdlNsPrefixMap.get(wsdlDef.getTargetNamespace()), wsdlDef.getTargetNamespace());
          schema.setElementFormDefault(XSDForm.get(XSDForm.QUALIFIED));
          schema.setAttributeFormDefault(XSDForm.get(XSDForm.QUALIFIED));
          Types types = WSDLFactory.eINSTANCE.createTypes();
   
          XSDSchemaExtensibilityElement xsdExtElement = WSDLFactory.eINSTANCE.createXSDSchemaExtensibilityElement();
          xsdExtElement.setSchema(schema);       
          wsdlDef.setTypes(types);
          types.addExtensibilityElement(xsdExtElement);
          types.getSchemas().add(schema);
          wsdlTypesSchemaMap.put(wsdlDef, schema);
   
          wsdlDefMap.put(ctPackage, wsdlDef);     
        }
      }
    }
  }
 
  @SuppressWarnings("unchecked")
  <T> void createProcessRolesForPartnerLinks(CtClass<T> ctClass,
      org.eclipse.bpel.model.Process process){
    jbprocess.annotations.Process processAnnotation = ctClass.getAnnotation(jbprocess.annotations.Process.class);
    jbprocess.annotations.PartnerLinks plinks = ctClass.getAnnotation(jbprocess.annotations.PartnerLinks.class);

    if (processAnnotation != null && plinks != null){
      jbprocess.annotations.PartnerLink[] theLinks = plinks.links();
      for(int i=0; i < theLinks.length; i++){
        if (theLinks[i] != null){
          if (!theLinks[i].name().equals("")){
            Class c = theLinks[i].type();
            for (CtTypeReference ref : ctClass.getSuperInterfaces()){
              if (ref.getActualClass().equals(c)){
                scan(ref.getDeclaration());
                PortType portType = typePortTypeMap.get(ref.getDeclaration());
                if (portType != null){                             
                  PartnerLink plink = null;
                  PartnerLinkType plinkType = null;
                  Role myRole = null;
                  String plinkName = theLinks[i].name();
                  String partnerLinkTypeName = plinkName + process.getName() + "LT";
                  Iterator<PartnerLink> plit = process.getPartnerLinks().getChildren().iterator();               
                  while (plit.hasNext()){
                    PartnerLink pl = plit.next();
                    if (pl.getName().equals(plinkName)){ 
                      partnerLinkTypeName = pl.getPartnerLinkType().getName();
                      plink = pl;
                      break;
                    }
                  }
                  if (plink == null){
                    plink = BPELFactory.eINSTANCE.createPartnerLink();
                    plinkType = PartnerlinktypeFactory.eINSTANCE.createPartnerLinkType();
                    plink.setName(plinkName);
                    plinkType.setName(partnerLinkTypeName);   
                    plinkType.setName(partnerLinkTypeName);
                    plinkType.setElementType(plinkType.getElementType());
                    plinkType.setRequired(true);
                    plink.setPartnerLinkType(plinkType);
                  }     
                  myRole = PartnerlinktypeFactory.eINSTANCE.createRole();
                  if (!theLinks[i].role().equals(""))
                    myRole.setName(theLinks[i].role());
                  else
                    myRole.setName(theLinks[i].name());
                  myRole.setPortType(portType);
                  myRole.setRequired(true);
                  plinkType.getRole().add(myRole);
                  plink.setMyRole(myRole);               
                  HashSet<PartnerLink> processPlinks = classProcessLinksMap.get(ctClass);
                  processPlinks.add(plink);     
                  process.getPartnerLinks().getChildren().add(plink);
                }
              }
            }
          }
        }
      }
    }
  }
 
  Variable createTempMsgVar(Message msg, BpelScope scope){   
    Variable variable = BPELFactory.eINSTANCE.createVariable();
    variable.setName("tmpMsgVar" + tmpMsgCounter++);   
    variable.setMessageType(msg);
    scope.addVariable(variable);
    return variable;
  }
 
  Variable createTempMsgVar(Message msg, Stack<BpelScope> scopeStack){       
    return createTempMsgVar(msg,scopeStack.peek());
  }
 
  Variable createTempVariable(Stack<BpelScope> scopeStack, XSDTypeDefinition type){
    Variable variable = BPELFactory.eINSTANCE.createVariable();
    variable.setName("_tmpvar" + tmpVarCounter++);
    variable.setType(type);
    scopeStack.peek().addVariable(variable);
    return variable;
  }
 
  @SuppressWarnings("unchecked")
  void createTypeToComplexTypeMapping(CtSimpleType ctSimpleType){
   
    if (ctSimpleType instanceof CtClass || ctSimpleType instanceof CtInterface){
      XSDComplexTypeDefinition complexType = typeXSDComplexTypeMap.get(ctSimpleType);
      if (complexType == null){
        XSDSchema schema = xsdSchemaMap.get(ctSimpleType.getPackage());     
       
        complexType = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
        complexType.setTargetNamespace(schema.getTargetNamespace());
        complexType.setName(ctSimpleType.getSimpleName());
       
        XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
        XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
        modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
        particle.setContent(modelGroup);   
        complexType.setContent(particle);
        try {
          schema.getContents().add(complexType);
        }catch(Exception e){
          System.out.println(e.getMessage());
          e.printStackTrace();
        }
        typeXSDComplexTypeMap.put(ctSimpleType, complexType);
        complexTypePropMap.put(complexType, new ArrayList<XSDElementDeclaration>());
      }
    }
  }
  @SuppressWarnings("unchecked")
  <T> void createWsdlParameterMapping(CtMethod method, Operation operation, CtParameter<T> parameter, String paramName, XSDTypeDefinition xsdType, javax.jws.soap.SOAPBinding.Style style, javax.jws.soap.SOAPBinding.Use use, javax.jws.soap.SOAPBinding.ParameterStyle parameterStyle){
    if (style == javax.jws.soap.SOAPBinding.Style.DOCUMENT && use == javax.jws.soap.SOAPBinding.Use.LITERAL){
      if (parameterStyle == javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED){
        if (wsdlDocLitWrapParamMap.get(parameter) == null){
          Part part = (Part)operation.getInput().getMessage().getPart("parameters");
         
          XSDElementDeclaration parentElement = part.getElementDeclaration();
          XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition)parentElement.getType();
         
          XSDParticle parentParticle = (XSDParticle)complexType.getContent();           
          XSDModelGroup parentModelGroup = (XSDModelGroup)parentParticle.getContent();
          XSDParticle localElementParticle = XSDFactory.eINSTANCE.createXSDParticle();
          XSDElementDeclaration el = XSDFactory.eINSTANCE.createXSDElementDeclaration();
          localElementParticle.setContent(el);
          el.setName(paramName);
          el.setTypeDefinition(xsdType);         
          parentModelGroup.getContents().add(localElementParticle);
          if (wsdlDocLitParamElemMap.get(operation) == null)
            wsdlDocLitParamElemMap.put(operation, new LinkedList<XSDElementDeclaration>());
          wsdlDocLitParamElemMap.get(operation).add(el);
          wsdlDocLitWrapParamMap.put(parameter, el);
        }
      } else {
       
      }
    } else if (style == javax.jws.soap.SOAPBinding.Style.RPC && use == javax.jws.soap.SOAPBinding.Use.LITERAL){
      if (wsdlRpcLitParamMap.get(parameter) == null){
        Part part = WSDLFactory.eINSTANCE.createPart();           
        part.setName(paramName);
        part.setTypeDefinition(xsdType);
        operation.getInput().getMessage().addPart(part);
        wsdlRpcLitParamMap.put(parameter,part);
      }
    }
    XSDSchema schema = xsdType.getSchema();
    if (schema != null && !schema.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)){
      Vector<XSDSchema> dependencies = wsdlDependencies.get(operation.getEnclosingDefinition());
      if (!dependencies.contains(schema))
        dependencies.add(schema);
    }
  }
 
  <T> void createWsdlParameterMapping(CtMethod method, Operation operation, CtParameter<T> parameter, XSDTypeDefinition xsdType){
    javax.jws.WebParam webParamAnnotation = parameter.getAnnotation(javax.jws.WebParam.class);
    javax.jws.soap.SOAPBinding soapBinding = typeSoapBindingMap.get(method.getDeclaringType());
    String paramName = parameter.getSimpleName();
    if (webParamAnnotation != null && !webParamAnnotation.name().equals(""))
      paramName = webParamAnnotation.name();
    if (soapBinding != null
      createWsdlParameterMapping(method, operation, parameter, paramName, xsdType, soapBinding.style(), soapBinding.use(), soapBinding.parameterStyle());
    else
      createWsdlParameterMapping(method, operation, parameter, paramName, xsdType, javax.jws.soap.SOAPBinding.Style.DOCUMENT, javax.jws.soap.SOAPBinding.Use.LITERAL, javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED);   
  }
  @SuppressWarnings("unchecked")
  <T> void createWsdlStyleMapping(CtMethod<T> m){
    Operation operation = methodOperationMap.get(m);
    String operationName = operation.getName();
    javax.jws.WebMethod webMethod = m.getAnnotation(javax.jws.WebMethod.class);
    if (webMethod != null && !webMethod.operationName().equals(""))
      operationName = webMethod.operationName();     
    javax.jws.soap.SOAPBinding soapBinding = typeSoapBindingMap.get(m.getDeclaringType());
    if (soapBinding != null){
      createWsdlStyleMapping(m, operation, operationName, soapBinding.style(), soapBinding.use(), soapBinding.parameterStyle());
    } else {
      createWsdlStyleMapping(m, operation, operationName, javax.jws.soap.SOAPBinding.Style.DOCUMENT, javax.jws.soap.SOAPBinding.Use.LITERAL, javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED);
    }
  } 
 
  @SuppressWarnings("unchecked")
  <T> void createWsdlStyleMapping(CtMethod<T> m, Operation operation, String operationName, javax.jws.soap.SOAPBinding.Style style, javax.jws.soap.SOAPBinding.Use use, javax.jws.soap.SOAPBinding.ParameterStyle parameterStyle){
    if (style == javax.jws.soap.SOAPBinding.Style.DOCUMENT && use == javax.jws.soap.SOAPBinding.Use.LITERAL){
      // document style message contains one part.  this part refers to an element which contains a sub-element for each parameter
      //  this function adds the part and the top-level element, the sub-elements are added when the parameter is scanned
      if (parameterStyle == javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED){
        XSDSchema schema = wsdlTypesSchemaMap.get(operation.getEnclosingDefinition());
       
        XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
        XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
        modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
        particle.setContent(modelGroup);
       
        XSDComplexTypeDefinition complexType = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
        complexType.setContent(particle);
       
        XSDElementDeclaration elIn = XSDFactory.eINSTANCE.createXSDElementDeclaration();
        elIn.setName(operationName);
        elIn.setAnonymousTypeDefinition(complexType);
        schema.getContents().add(elIn);
       
        Part partIn = WSDLFactory.eINSTANCE.createPart();
        partIn.setName("parameters");
        partIn.setElementDeclaration(elIn);
        operation.getInput().getMessage().addPart(partIn);
       
        particle = XSDFactory.eINSTANCE.createXSDParticle();
        modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
        modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
        particle.setContent(modelGroup);
       
        complexType = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
        complexType.setContent(particle);
       
        XSDElementDeclaration elOut = XSDFactory.eINSTANCE.createXSDElementDeclaration();
        elOut.setName(operationName + "Response");
        elOut.setAnonymousTypeDefinition(complexType);
        schema.getContents().add(elOut);
       
        Part partOut = WSDLFactory.eINSTANCE.createPart();
        partOut.setName("parameters");
        partOut.setElementDeclaration(elOut);
        operation.getOutput().getMessage().addPart(partOut);
      } else {
       
      }
    } else if (style == javax.jws.soap.SOAPBinding.Style.RPC && use == javax.jws.soap.SOAPBinding.Use.LITERAL){
      // rpc style message contains a part for each parameter.  the parts are added when the parameter is scanned
    }
  }
 
  @SuppressWarnings("unchecked")
  void fixPartnerLinkPrefixes(BPELResource currResource, org.eclipse.bpel.model.Process currProcess, String artifactsPrefix){
    Iterator<PartnerLink> plinkIt = currProcess.getPartnerLinks().getChildren().iterator();
    String artifactsNamespace = currProcess.getTargetNamespace() + "Artifacts";
    currResource.getPrefixToNamespaceMap().put(artifactsPrefix, artifactsNamespace);
    while (plinkIt.hasNext()){
      PartnerLink plink = plinkIt.next();
      plink.getPartnerLinkType().setName(artifactsPrefix + ":" + plink.getPartnerLinkType().getName());
    }
  }
 
  String getBeanPropertyName(CtField f){
    String propName = "";
    try {
      BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(f.getDeclaringType().getActualClass());
      PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
      for(int i=0; i < props.length; i++){
        if (f.getSimpleName().equals(props[i].getName()))
          return props[i].getName();
      }
    } catch (Exception e){
      System.err.println("Exception " + e.getMessage());
    }   
    return propName;
  }
 
  String getBeanPropertyName(CtMethod m){
    String propName = ""
    String possiblePropName = "";
    if (m.getSimpleName().startsWith("get") || m.getSimpleName().startsWith("set")){
      possiblePropName = m.getSimpleName().substring(3);
    } else if (m.getSimpleName().startsWith("is") &&
        (m.getType().getActualClass().getName().equals("boolean") ||
        m.getType().getActualClass().getName().equals("java.lang.Boolean"))){
      possiblePropName = m.getSimpleName().substring(2);
    }   
    if (!possiblePropName.equals("")){
      possiblePropName = java.beans.Introspector.decapitalize(possiblePropName);   
      try {
        BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(m.getDeclaringType().getActualClass());
        PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
        for(int i=0; i < props.length; i++){
          if (possiblePropName.equals(props[i].getName()))
            return possiblePropName;
        }
      } catch (Exception e){
        System.err.println("Exception " + e.getMessage());
      }   
    }
    return propName;
  }
  @SuppressWarnings("unchecked")
  Operation getProcessWsdlOperation(CtMethod<?> m){
    if (m.getParent() instanceof CtClass){     
      CtClass<?> ctClass = (CtClass)m.getParent();
      if (classProcessMap.get(ctClass) != null){
        for(CtTypeReference<?> typeRef : ctClass.getSuperInterfaces()){
          CtInterface<?> intf = (CtInterface)typeRef.getDeclaration();
          PortType portType = typePortTypeMap.get(intf);
          if (portType != null){
            for(CtMethod<?> intfMeth : intf.getAllMethods()){             
              if (intfMeth.getSimpleName().equals(m.getSimpleName()) &&
                  intfMeth.getSignature().equals(m.getSignature())){             
                Operation operation = methodOperationMap.get(intfMeth);
                if (operation != null)
                  return operation;
              }
            }
          }
        }
      }
    }
    return null;
  }
 
  @SuppressWarnings("unchecked")
  PortType getProcessWsdlPortType(CtMethod<?> m){
    if (m.getParent() instanceof CtClass){     
      CtClass<?> ctClass = (CtClass)m.getParent();
      if (classProcessMap.get(ctClass) != null){
        for(CtTypeReference<?> typeRef : ctClass.getSuperInterfaces()){
          CtInterface<?> intf = (CtInterface)typeRef.getDeclaration();
          PortType portType = typePortTypeMap.get(intf);
          if (portType != null)
            return portType;
        }
      }
    }
    return null;
  }
  <T> boolean isThisClassABpelProcess(CtClass<T> ctClass){
    jbprocess.annotations.Process processAnnotation = ctClass.getAnnotation(jbprocess.annotations.Process.class);
    if (processAnnotation == null || classProcessMap.get(ctClass) == null)
      return false;
    else
      return true;
  }
 
  @SuppressWarnings("unchecked")
  boolean methodImplementsWebService(CtClass<?> ctClass, CtMethod m){   
    for(CtTypeReference<?> typeRef : ctClass.getSuperInterfaces()){
      CtInterface<?> intf = (CtInterface)typeRef.getDeclaration();
      for(CtMethod<?> intfMeth : intf.getAllMethods()){
        if (intfMeth.getSimpleName().equals(m.getSimpleName()) &&
            intfMeth.getSignature().equals(m.getSignature()))
          return true;
      }
    }
    return false;
  }
  @SuppressWarnings("unchecked")
  <T> void resolvePortTypeReference(CtTypeReference<T> reference,ASTNodeData typeRefNodeData){   
    typeRefNodeData.portType = typePortTypeMap.get(reference.getDeclaration());
    if (typeRefNodeData.portType != null)
      typeRefNodeData.wsdlDef = typeRefNodeData.portType.getEnclosingDefinition();
  }
  @SuppressWarnings("unchecked")
  <T> void resolveTypeReference(CtTypeReference<T> reference,ASTNodeData typeRefNodeData){
    if (reference != null){
      if (reference.isPrimitive()){     
        if (reference.getQualifiedName().equals("int")){
          typeRefNodeData.xsdTypeQName = xsdIntegerQName;
          typeRefNodeData.xsdType = xsdIntegerType;
        } else if (reference.getQualifiedName().equals("short")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"short",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdShortType;
        } else if (reference.getQualifiedName().equals("long")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"long",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdLongType;
        } else if (reference.getQualifiedName().equals("float")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"float",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdFloatType;
        } else if (reference.getQualifiedName().equals("double")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"double",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdDoubleType;
        } else if (reference.getQualifiedName().equals("boolean")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"boolean",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdBooleanType;
        }
      } else if (reference.getQualifiedName().startsWith("java")){   
        if (reference.getQualifiedName().equals("java.lang.String")){     
          typeRefNodeData.xsdTypeQName = xsdStringQName;
          typeRefNodeData.xsdType = xsdStringType;
        } else if (reference.getQualifiedName().equals("java.lang.Integer")){     
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"integer",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdIntegerType;
        } else if (reference.getQualifiedName().equals("java.lang.Short")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"short",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdShortType;
        } else if (reference.getQualifiedName().equals("java.lang.Long")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"long",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdLongType;
        } else if (reference.getQualifiedName().equals("java.lang.Float")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"float",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdFloatType;
        } else if (reference.getQualifiedName().equals("java.lang.Double")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"double",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdDoubleType;
        } else if (reference.getQualifiedName().equals("java.lang.Boolean")){
          typeRefNodeData.xsdTypeQName = new QName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"boolean",XML_SCHEMA_NAMESPACE_PREFIX);
          typeRefNodeData.xsdType = xsdBooleanType;
        }
      } else if (!reference.getQualifiedName().startsWith("jbprocess")){
        if (reference.getDeclaration().getAnnotation(javax.jws.WebService.class) == null){
          XSDComplexTypeDefinition xsdType = typeXSDComplexTypeMap.get(reference.getDeclaration());
          if (xsdType != null){
            typeRefNodeData.xsdTypeQName = new QName(xsdType.getSchema().getTargetNamespace(),xsdType.getName(),schemaNsPrefixMap.get(xsdType.getSchema().getTargetNamespace()));
            typeRefNodeData.xsdType = xsdType;
          } else {
            //javax.xml.bind.annotation.XmlType xmlTypeAnnotation = reference.getDeclaration().getAnnotation(javax.xml.bind.annotation.XmlType.class);
            jbprocess.annotations.Process processAnnotation = reference.getDeclaration().getAnnotation(jbprocess.annotations.Process.class);
            WebService webServiceAnnotation = reference.getDeclaration().getAnnotation(WebService.class);
            if (processAnnotation == null && webServiceAnnotation == null){
              //if (xmlTypeAnnotation != null && reference.getDeclaration() instanceof CtClass){
              //  createJAXBClassToComplexTypeMapping((CtClass)reference.getDeclaration(),xmlTypeAnnotation);
              //} else {
                createTypeToComplexTypeMapping(reference.getDeclaration());
              //}
              typeRefNodeData.xsdType = typeXSDComplexTypeMap.get(reference.getDeclaration());
              if (typeRefNodeData.xsdType != null){
                XSDSchema schema = xsdSchemaMap.get(reference.getDeclaration().getPackage());
                if (schema != null){
                  typeRefNodeData.xsdTypeQName = new QName(typeRefNodeData.xsdType.getSchema().getTargetNamespace(),typeRefNodeData.xsdType.getName(),schemaNsPrefixMap.get(typeRefNodeData.xsdType.getSchema().getTargetNamespace()));
                }
              }
            }
          }
        }
      }
    }
  }
  Variable resolveVariable(Stack<BpelScope> scopeStack, String name){
    if (scopeStack != null && scopeStack.size() > 0 && name != null){
      for(int i=scopeStack.size() -1; i >= 0; i--){
        BpelScope scope = scopeStack.get(i);
        Variable variable = scope.getVariable(name);
        if (variable != null)
          return variable;
      }
    }
    return null;
  }
 
  <T> void scanProcessMethods(CtClass<T> ctClass){
    HashSet<CtMethod<?>> flowActivities = new HashSet<CtMethod<?>>();
    HashSet<CtMethod<?>> recvActivities = new HashSet<CtMethod<?>>();
    HashSet<CtMethod<?>> replyActivities = new HashSet<CtMethod<?>>();
    CtMethod<?> processMethod = null;
    for(CtMethod<?> m : ctClass.getMethods()){
      FlowActivity flowActivity = m.getAnnotation(FlowActivity.class);
      if (flowActivity != null)
        flowActivities.add(m);
      else if (m.getAnnotation(ReceiveActivity.class) != null)
        recvActivities.add(m);
      else if (m.getAnnotation(ReplyActivity.class) != null)
        replyActivities.add(m);
      else if (!methodImplementsWebService(ctClass,m)){
        if (processMethod == null// allows only one process method
          processMethod = m;
      }
    }
    // scan flow activites first
    scan(flowActivities);
    // scan receive activities next
    scan(recvActivities);
    // scan reply activities next
    scan(replyActivities);
    // scan the single process method next
    scan(processMethod);
  }
  <T> void setFieldDefaultValue(CtField<T> f, XpathExpression expr){
    Variable variable = fieldVariableMap.get(f);
    if (variable != null && expr != null){
      From from = BPELFactory.eINSTANCE.createFrom();
      String val = expr.evaluate();
      from.setLiteral(val);
      //if (!val.contains("<") && !val.contains(">"))
        from.setUnsafeLiteral(true); // is this really necessary?
      variable.setFrom(from);
    }
  }
  void setFieldExceptionDefaultValue(BpelScope scope, CtField<?> f){   
    if (scope != null && f != null){     
      Variable variable = fieldVariableMap.get(f);
      if (variable != null){
        if (f.getDefaultExpression() != null){         
          scan(f.getDefaultExpression());
          ASTNodeData exprData = nodeDataStack.peek();         
          if (exprData.constructorArgElementMap != null && exprData.constructorArgs != null){
            Assign assign = BPELFactory.eINSTANCE.createAssign();         
            createNewException(assign, variable, exprData.constructorArgElementMap, exprData.constructorArgs);
            scope.addActivity(assign);
          }         
        }
      }
    }
  }
 
  @SuppressWarnings("unchecked")
  void setInvokeParameters(Operation operation, Invoke invoke, List<CtExpression<?>> args, BpelScope scope){
    javax.jws.soap.SOAPBinding soapBinding = operationSoapBindingMap.get(operation);
    List<Part> msgParts = operation.getInput().getMessage().getOrderedParts(null);
    Variable tmp = createTempMsgVar((Message)operation.getInput().getMessage(),scope);
    invoke.setInputVariable(tmp);
   
    Assign assign = BPELFactory.eINSTANCE.createAssign();
   
    for (int argIndex=0; argIndex < args.size(); argIndex++){
      CtExpression<?> arg = args.get(argIndex);       
      scan(arg);
      ASTNodeData argNodeData = nodeDataStack.peek();
     
      // doc/literal has one part, which is an element, which contains sub-elements for each param
      if (argNodeData.xpathExpr != null){
        From from = BPELFactory.eINSTANCE.createFrom();
       
        if (argNodeData.variable != null){
          from.setVariable(argNodeData.variable)
          Query fromQuery = BPELFactory.eINSTANCE.createQuery();
          fromQuery.setQueryLanguage(XPATH_NAMESPACE);
          fromQuery.setValue(argNodeData.xpathExpr.evaluate());
          from.setQuery(fromQuery);
        } else if (argNodeData.xpathLiteralExpr != null){
          Expression expr = BPELFactory.eINSTANCE.createExpression();         
          expr.setBody(argNodeData.xpathLiteralExpr.evaluate());
          from.setExpression(expr);
        }
       
        To to = BPELFactory.eINSTANCE.createTo();
        to.setVariable(tmp);
        Query toQuery = BPELFactory.eINSTANCE.createQuery();
        toQuery.setQueryLanguage(XPATH_NAMESPACE);
       
        if (soapBinding == null ||
            (soapBinding != null &&
            soapBinding.style() == javax.jws.soap.SOAPBinding.Style.DOCUMENT &&
            soapBinding.use() == javax.jws.soap.SOAPBinding.Use.LITERAL &&
            soapBinding.parameterStyle() == javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED)){
          XSDElementDeclaration el = wsdlDocLitParamElemMap.get(operation).get(argIndex);
          //toQuery.setValue("$" + tmp.getName() + "." + msgParts.get(0).getName() + "/" + this.schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getQName());
          to.setPart(msgParts.get(0));
          toQuery.setValue("/" + this.schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getQName());
          to.setQuery(toQuery);
        } else if (soapBinding != null &&
            soapBinding.style() == javax.jws.soap.SOAPBinding.Style.RPC &&
            soapBinding.use() == javax.jws.soap.SOAPBinding.Use.LITERAL){
          //toQuery.setValue("$" + tmp.getName() + "." + msgParts.get(argIndex).getName());
          to.setPart(msgParts.get(argIndex));
        }                     
       
        Copy copy = BPELFactory.eINSTANCE.createCopy();
        copy.setFrom(from);
        copy.setTo(to);
       
        assign.getCopy().add(copy);
      }             
    }
   
    scope.addActivity(assign);
  }
 
  @SuppressWarnings("unchecked")
  void setInvokeResult(Invoke invoke, CtExpression<?> result, BpelScope scope){
   
    scan(result);
    ASTNodeData resultData = nodeDataStack.peek();
   
    Operation operation = invoke.getOperation();
    javax.jws.soap.SOAPBinding soapBinding = operationSoapBindingMap.get(operation);
    List<Part> msgParts = operation.getOutput().getMessage().getOrderedParts(null);
    Variable tmp = createTempMsgVar((Message)operation.getOutput().getMessage(),scope);
    invoke.setOutputVariable(tmp);
   
    From from = BPELFactory.eINSTANCE.createFrom();
    from.setVariable(tmp);
    Query fromQuery = BPELFactory.eINSTANCE.createQuery();
   
    if (soapBinding == null ||
        (soapBinding != null &&
        soapBinding.style() == javax.jws.soap.SOAPBinding.Style.DOCUMENT &&
        soapBinding.use() == javax.jws.soap.SOAPBinding.Use.LITERAL &&
        soapBinding.parameterStyle() == javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED)){
      XSDElementDeclaration el = wsdlDocLitWrapResultMap.get(operation);
      //fromQuery.setValue("$" + tmp.getName() + "." + msgParts.get(0).getName() + "/" + this.schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getQName());
      from.setPart(msgParts.get(0));
      fromQuery.setValue("/" + this.schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getQName());
      from.setQuery(fromQuery);
    } else if (soapBinding != null &&
        soapBinding.style() == javax.jws.soap.SOAPBinding.Style.RPC &&
        soapBinding.use() == javax.jws.soap.SOAPBinding.Use.LITERAL){
      //fromQuery.setValue("$" + tmp.getName() + "." + msgParts.get(argIndex).getName());
      from.setPart(msgParts.get(0));
    }
   
    To to = BPELFactory.eINSTANCE.createTo();
    to.setVariable(resultData.variable);
    Query toQuery = BPELFactory.eINSTANCE.createQuery();
    toQuery.setQueryLanguage(XPATH_NAMESPACE);
    toQuery.setValue(resultData.xpathExpr.evaluate());
   
    Copy copy = BPELFactory.eINSTANCE.createCopy();
    copy.setFrom(from);
    copy.setTo(to);
   
    Assign assign = BPELFactory.eINSTANCE.createAssign();
    assign.getCopy().add(copy);
   
    scope.addActivity(assign);
  }
 
  @SuppressWarnings("unchecked")
  void setRecvParameters(Operation operation, Receive recv, List<CtExpression<?>> args, BpelScope scope){
    javax.jws.soap.SOAPBinding soapBinding = operationSoapBindingMap.get(operation);
    List<Part> msgParts = operation.getInput().getMessage().getOrderedParts(null);
    //Variable tmp = createTempMsgVar((Message)operation.getInput().getMessage(),scopeStack);
    Variable tmp = createTempMsgVar((Message)operation.getInput().getMessage(),scope);
    recv.setVariable(tmp);
   
    Assign assign = BPELFactory.eINSTANCE.createAssign();
   
    for (int argIndex=0; argIndex < args.size(); argIndex++){
      CtExpression<?> arg = args.get(argIndex);       
      scan(arg);
      ASTNodeData argNodeData = nodeDataStack.peek();
     
      // doc/literal has one part, which is an element, which contains sub-elements for each param
      if (argNodeData.variable != null && argNodeData.xpathExpr != null){
        From from = BPELFactory.eINSTANCE.createFrom();
        from.setVariable(tmp);
        Query fromQuery = BPELFactory.eINSTANCE.createQuery();
        fromQuery.setQueryLanguage(XPATH_NAMESPACE);
       
        if (soapBinding == null ||
            (soapBinding != null &&
            soapBinding.style() == javax.jws.soap.SOAPBinding.Style.DOCUMENT &&
            soapBinding.use() == javax.jws.soap.SOAPBinding.Use.LITERAL &&
            soapBinding.parameterStyle() == javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED)){
          XSDElementDeclaration el = wsdlDocLitParamElemMap.get(operation).get(argIndex);
          //fromQuery.setValue("$" + tmp.getName() + "." + msgParts.get(0).getName() + "/" + this.schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getQName());
          from.setPart(msgParts.get(0));
          fromQuery.setValue("/" + this.schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getQName());
          from.setQuery(fromQuery);
        } else if (soapBinding != null &&
            soapBinding.style() == javax.jws.soap.SOAPBinding.Style.RPC &&
            soapBinding.use() == javax.jws.soap.SOAPBinding.Use.LITERAL){
          //fromQuery.setValue("$" + tmp.getName() + "." + msgParts.get(argIndex).getName());
          from.setPart(msgParts.get(argIndex));
        }                     
       
        To to = BPELFactory.eINSTANCE.createTo();
        to.setVariable(argNodeData.variable);
        Query toQuery = BPELFactory.eINSTANCE.createQuery();
        toQuery.setQueryLanguage(XPATH_NAMESPACE);
        toQuery.setValue(argNodeData.xpathExpr.evaluate());
        to.setQuery(toQuery);
       
        Copy copy = BPELFactory.eINSTANCE.createCopy();
        copy.setFrom(from);
        copy.setTo(to);
       
        assign.getCopy().add(copy);
      }             
    }
    scope.addActivity(assign);
  }
 
 
  @SuppressWarnings("unchecked")
  void setReplyParameters(Receive recv, Reply reply, Variable variable, XSDTypeDefinition type, XpathExpression xpath, BpelScope scope){
    Operation operation = recv.getOperation();
    reply.setPartnerLink(recv.getPartnerLink());
    reply.setOperation(operation);
    reply.setPortType(recv.getPortType());   
    reply.setVariable(variable);
   
    From from = BPELFactory.eINSTANCE.createFrom();
    from.setVariable(variable);
    Query fromQuery = BPELFactory.eINSTANCE.createQuery();
    fromQuery.setValue(xpath.evaluate());
    fromQuery.setQueryLanguage(XPATH_NAMESPACE);
    from.setQuery(fromQuery);
   
    To to = BPELFactory.eINSTANCE.createTo();
    to.setVariable(variable);
    Query toQuery = BPELFactory.eINSTANCE.createQuery();
    toQuery.setQueryLanguage(XPATH_NAMESPACE);
   
    javax.jws.soap.SOAPBinding soapBinding = operationSoapBindingMap.get(operation);
    Message message = null;
    javax.wsdl.Fault f = operation.getFault(type.getName());
    if (f != null){
      message = (org.eclipse.wst.wsdl.Message)f.getMessage();
    } else {
      javax.wsdl.Output output = operation.getOutput();
      if (output != null)
        message = (org.eclipse.wst.wsdl.Message)output.getMessage();
    }
    if (message != null){
      List<Part> msgParts = message.getOrderedParts(null);
      if (soapBinding == null ||
          (soapBinding != null &&
          soapBinding.style() == javax.jws.soap.SOAPBinding.Style.DOCUMENT &&
          soapBinding.use() == javax.jws.soap.SOAPBinding.Use.LITERAL &&
          soapBinding.parameterStyle() == javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED)){
        //XSDElementDeclaration el = wsdlDocLitWrapResultMap.get(operation);
        //toQuery.setValue("$" + tmp.getName() + "." + msgParts.get(0).getName() + "/" + this.schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getQName());
        to.setPart(msgParts.get(0));
        //toQuery.setValue("/" + this.schemaNsPrefixMap.get(el.getTargetNamespace()) + ":" + el.getQName());
        //to.setQuery(toQuery);
      } else if (soapBinding != null &&
          soapBinding.style() == javax.jws.soap.SOAPBinding.Style.RPC &&
          soapBinding.use() == javax.jws.soap.SOAPBinding.Use.LITERAL){
        //toQuery.setValue("$" + tmp.getName() + "." + msgParts.get(0).getName());
        to.setPart(msgParts.get(0));
      }   
     
      Copy copy = BPELFactory.eINSTANCE.createCopy();
      copy.setFrom(from);
      copy.setTo(to);
     
      Assign assign = BPELFactory.eINSTANCE.createAssign();
      assign.getCopy().add(copy);
     
      scope.addActivity(assign);
      scope.addActivity(reply);   
    }
  }
 
  private Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
    File file = new File(outputDirectory + suggestedFileName);
    File dir = file.getParentFile();
    if (dir != null)
      dir.mkdir();
    StreamResult result = new StreamResult(new FileWriter(file));
    return result;
  }
 
  private Result createBpelOutput(String namespaceUri, String suggestedFileName) throws IOException {
    return createWsdlOutput(namespaceUri,suggestedFileName);
  }

  private Result createWsdlOutput(String namespaceUri, String suggestedFileName) throws IOException {
    File file = new File(outputDirectory + suggestedFileName);
    File dir = file.getParentFile();
    if (dir != null)
      dir.mkdir();
    StreamResult result = new StreamResult(new FileOutputStream(file));
    return result;
  }


   
  @SuppressWarnings("unchecked")
  void writeBpelProcesses(){
    BPELResourceFactoryImpl brsf = new BPELResourceFactoryImpl();   
    Iterator<org.eclipse.bpel.model.Process> processes = classProcessMap.values().iterator();
    int bpelCounter = 1;
    while (processes.hasNext()){
      org.eclipse.bpel.model.Process process = processes.next();     
      addBpelImports(process);
      HashSet<WsdlImportInfo> wsdlImports = new HashSet<WsdlImportInfo>();
      Iterator<Definition> bpelWsdlImports = processWsdlDeps.get(process).iterator();
      while (bpelWsdlImports.hasNext()){
        Definition def = bpelWsdlImports.next();
        WsdlImportInfo imp = new WsdlImportInfo();
        imp.setLocation(def.getDocumentBaseURI());
        imp.setNamespace(def.getTargetNamespace());
        wsdlImports.add(imp);
      }
      WsdlPartnerLinkSerializer plinkSerializer = new WsdlPartnerLinkSerializer();
      plinkSerializer.serializePartnerLinkTypes(process.getPartnerLinks(),
          process.getTargetNamespace() + "Artifacts",
          process.getName() + "Artifacts",
          outputDirectory + process.getName() + "Artifacts.wsdl",
          wsdlImports,wsdlNsPrefixMap,outputToConsole);
      org.eclipse.bpel.model.Import bpelImport = BPELFactory.eINSTANCE.createImport();
      bpelImport.setImportType(WSDLConstants.WSDL_NAMESPACE_URI);
      bpelImport.setLocation(process.getName() + "Artifacts.wsdl");
      bpelImport.setNamespace(process.getTargetNamespace() + "Artifacts");
      process.getImports().add(bpelImport);
      try {
        String fileName = "bpel" + bpelCounter + ".bpel";
        String namespacePrefix = "bpel" + bpelCounter++;
        //javax.xml.transform.Result result = bpelOutputResolver.createBpelOutput(process.getTargetNamespace(), fileName);
        javax.xml.transform.Result result = createBpelOutput(process.getTargetNamespace(), fileName);
        if(result instanceof StreamResult) {           
          final OutputStream outstream = ((StreamResult)result).getOutputStream();         
          URI uri = URI.createPlatformResourceURI(fileName);
          BPELResource resource =  (org.eclipse.bpel.model.resource.BPELResource)brsf.createResource(uri);
          fixPartnerLinkPrefixes(resource,process,namespacePrefix);
          resource.getContents().add(process);
          HashSet<XSDSchema> schemaDeps = processSchemaDeps.get(process);
          for (XSDSchema schema : schemaDeps){
            resource.getPrefixToNamespaceMap().put(schemaNsPrefixMap.get(schema.getTargetNamespace()), schema.getTargetNamespace());
          }
          resource.getPrefixToNamespaceMap().put("bpel", BPELConstants.NAMESPACE);
          resource.getPrefixToNamespaceMap().put(XML_SCHEMA_NAMESPACE_PREFIX,XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
          resource.getPrefixToNamespaceMap().put(WSDL_PREFIX,WSDL_NAMESPACE);
         
          process.updateElement();
          //write(process.getElement(),outstream);
         
          resource.save(outstream,Collections.EMPTY_MAP);         
          //if (outputToConsole)
          //  resource.save(System.out, Collections.EMPTY_MAP);
         
        }
      } catch (Exception e){       
      }
    }
  }
 
  private void write(org.w3c.dom.Element element, OutputStream outstream){   
    boolean status = false;
    try {
      DOMBuilder domBuilder = new DOMBuilder("org.apache.xerces.parsers.DOMParser");
      org.jdom.Element jroot = domBuilder.build(element);
      XMLOutputter outputter = new XMLOutputter();
      outputter.output(jroot, outstream);
          status = true;
    } catch (Exception e){
      status = false;
      System.out.println(e.getMessage());
      e.printStackTrace();
    }
  }
 
  private void write(org.w3c.dom.Element element, String fileName){   
    boolean status = false;
    try {
      Result result = createOutput("",fileName);
      if(result instanceof StreamResult) {           
        final Writer writer = ((StreamResult)result).getWriter();
       
        DOMBuilder domBuilder = new DOMBuilder("org.apache.xerces.parsers.DOMParser");
        org.jdom.Element jroot = domBuilder.build(element);
        XMLOutputter outputter = new XMLOutputter();
        outputter.output(jroot, writer);
            if(writer != null) writer.close();
            status = true;
      }
    } catch (Exception e){
      status = false;
      System.out.println(e.getMessage());
      e.printStackTrace();
    }
  }

  @SuppressWarnings("unchecked")
  void writeSchemas(){   
    Iterator<XSDSchema> schemas = xsdSchemaMap.values().iterator();
    while(schemas.hasNext()){
      XSDSchema schema = schemas.next();
      addSchemaImports(schema);
      try {       
        String fileName = "schema" + schemaCounter++ + ".xsd";
        schemaFileMap.put(schema, fileName);
        schema.setSchemaLocation(fileName);
        schema.updateElement();
        schema.updateDocument();
        write(schema.getElement(),fileName);                     
      } catch (Exception e){
        System.err.println("Error writing XML Schema: " + e.getMessage());
      }
    }
  }
 
  @SuppressWarnings("unchecked")
  void writeWsdlDefinitions(){
    ResourceSet resourceSet = new ResourceSetImpl();
    Resource.Factory.Registry registry = resourceSet
        .getResourceFactoryRegistry();
    Map extensionToFactoryMap = registry.getExtensionToFactoryMap();
    extensionToFactoryMap.put("wsdl", new WSDLResourceFactoryImpl());
   
    Iterator<Definition> wsdlDefs = this.wsdlDefMap.values().iterator();
    while(wsdlDefs.hasNext()){
      Definition wsdl = wsdlDefs.next();
      addWsdlImports(wsdl);
      String fileName = "wsdl" + wsdlCounter++ + ".wsdl";
      wsdl.setDocumentBaseURI(fileName);
      wsdl.updateElement();
      write(wsdl.getElement(),fileName);     
    }
  }
}
TOP

Related Classes of jbprocessor.BpelScanner

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.