Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   * 
  *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.    
  */
 
 package org.apache.tuscany.sca.implementation.bpel.xml;
 
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
 
 import java.net.URI;
 import java.net.URL;
 import java.util.List;
 
 
BPEL document processor responsible for reading a BPEL file and producing necessary model info about it Handles both BPEL 1.1 documents and BPEL 2.0 documents

Version:
$Rev: 833331 $ $Date: 2009-11-06 09:41:12 +0000 (Fri, 06 Nov 2009) $
 
     
     private final static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
     
     private final BPELFactory factory;
     private WSDLFactory WSDLfactory;
     private AssemblyFactory assemblyFactory;
 
     public BPELDocumentProcessor(FactoryExtensionPoint modelFactories) {
         this. = modelFactories.getFactory(BPELFactory.class);
         this. = modelFactories.getFactory(WSDLFactory.class);
         this. = modelFactories.getFactory(AssemblyFactory.class);
     }
     
     public String getArtifactType() {
         return "*.bpel";
     }    
 
     public Class<BPELProcessDefinitiongetModelType() {
         return BPELProcessDefinition.class;
     }

    
Read the BPEL Process definition file from the location identified by an artifact URL

Parameters:
contributionURL - URL of the Contribution containing the Process definition
artifactURI - URI of the artifact containing the BPEL Process definition
artifactURL - URL of the artifact containing the BPEL Process definition
Returns:
BPELProcessDefinition - SCA model of the BPEL Process
 
     public BPELProcessDefinition read(URL contributionURLURI artifactURIURL artifactURLProcessorContext contextthrows ContributionReadException {
         BPELProcessDefinition processDefinition = null;
         try {
             processDefinition = readProcessDefinition(artifactURLcontext.getMonitor());
             processDefinition.setURI(artifactURI.toString());
             processDefinition.setUnresolved(true);
         } catch (Exception e) {
             ContributionReadException ce = new ContributionReadException(e);
             error(context.getMonitor(), "ContributionReadException"artifactURLce);
         }
 
         return processDefinition;
     }
 
    public void resolve(BPELProcessDefinition modelModelResolver resolverProcessorContext contextthrows ContributionResolveException {
    	// Delegate resolving to model resolver
    	if (model != null || model.isUnresolved()) {
    		resolver.resolveModel(BPELProcessDefinition.classmodelcontext);
    	}
    	
    } // end resolve

    
Read a process definition.

Parameters:
doc
Returns:
Throws:
java.lang.Exception
    private BPELProcessDefinition readProcessDefinition(URL docMonitor monitorthrows Exception {
        BPELProcessDefinition processDefinition = .createBPELProcessDefinition();
        processDefinition.setUnresolved(true);
        processDefinition.setLocation(doc.toString());
        InputStream is = doc.openStream();
        XMLStreamReader reader = null;
        try {
            reader = .createXMLStreamReader(is);
            /*
             * The principle here is to look for partnerLink elements, which
             * form either services or references. A partnerLink can be EITHER -
             * the algorithm for deciding is: 
             * 1) Explicit marking with sca:reference or sca:service attribute 
             * 2) "first use" of the partnerLink by specific BPEL activity elements: 
             *    <onEvent../>, <receive../> or <pick../> elements imply a service 
             *    <invoke../> implies a reference
             */
            // TODO - need to handle <scope../> elements as kind of "nested" processes
            // - and scopes introduce the possibility of partnerLinks with the
            // same name at different levels of scope.... (yuk!!)
            boolean completed = false;
            while (!completed) {
                switch (reader.next()) {
                    case :
                        QName qname = reader.getName();
                        if (..equals(qname) || ..equals(qname)) {
                            QName processName = new QName(getString(reader.), getString(reader.));
                            processDefinition.setName(processName);
                        } else if (..equals(qname) || ..equals(qname)) {
                            processDefinition.getPartnerLinks().add(processPartnerLinkElement(readermonitor));
                        } else if (..equals(qname) || ..equals(qname) || ..equals(qname) || 
                            processPartnerLinkAsService(reader.getAttributeValue(null"partnerLink"), processDefinition.getPartnerLinks(), monitor);
                        } else if (..equals(qname) || ..equals(qname)) {
                            processPartnerLinkAsReference(reader.getAttributeValue(null"partnerLink"), processDefinition.getPartnerLinks(), monitor);
                        } else if (..equals(qname) || ..equals(qname)) {
                            processDefinition.getImports().add(processImportElement(reader));
                        } else if (..equals(qname) || ..equals(qname)) {
                        	// deal with variables that are SCA properties through the presence of a sca-bpel:property="yes" attribute
                        	Property aProperty = processVariableElement(reader);
                        	ifaProperty != null ) {
                        		processDefinition.getProperties().addaProperty );
                        	} // end if
                        } // end if
                        break;
                    case :
                    	qname = reader.getName();
                    	if (..equals(qname) || ..equals(qname)) {
                            completed = true;
                            break;
                        } // end if
                } // end switch
            } // end while
        } finally {
            if (reader != null)
                reader.close();
            is.close();
        } // end try
        return processDefinition;
    } // end readProcessDefinition
    
    
Processes a BPEL <variable/> element and creates an SCA <property/> element if the variable is marked with sca-bpel:property="yes" A BPEL <variable/> element can declare its type in one of 3 ways: 1. using

Parameters:
reader - XMLStreamReader reading the BPEL process
Throws:
org.apache.tuscany.sca.contribution.processor.ContributionReadException
Type:
attribute, which must reference an XSD declared type 2. using @element attribute, which must reference an XSD global element 3. using @message attribute, which must reference a WSDL defined message type
    	String scaProperty = reader.getAttributeValue(."property");
    	if"yes".equals(scaProperty)) {
    		String varName = reader.getAttributeValue(null ,"name");
    		String varType = reader.getAttributeValue(null"type");
    		String varElement = reader.getAttributeValue(null"element");
    		String varMessage = reader.getAttributeValue(null"message");
    		// Pass over this variable if there is no name, or if there is no type information
    		ifvarName == null ) return null;
    		ifvarType == null && varElement == null && varMessage == null ) return null;
    		QName typeQName = getQNameValuereadervarType );
    		QName elementQName = getQNameValuereadervarElement );
    		// TODO deal with properties declared with @message for typing
    		Property theProperty = .createProperty();
    		theProperty.setName(varName);
    		theProperty.setXSDType(typeQName);
    		theProperty.setXSDElement(elementQName);
    		return theProperty;
    	} // end if
    	return null;
    	
    } // end processVariableElement
    
    
Processes a partnerLink element from the BPEL process and creates a BPELPartnerLink object

Parameters:
reader
        BPELPartnerLinkElement partnerLink = new BPELPartnerLinkElementreader.getAttributeValue(null"name"),
                                                                         getQNameValue(readerreader.getAttributeValue(null"partnerLinkType")),
                                                                         reader.getAttributeValue(null"myRole"),
                                                                         reader.getAttributeValue(null"partnerRole"));
        
        // See if there are any SCA extension attributes
        String scaService = reader.getAttributeValue(."service");
        String scaReference = reader.getAttributeValue(."reference");
        if ((scaService != null) && (scaReference != null)) {
            // It is incorrect to set both service & reference attributes
            error(monitor"PartnerLinkHasBothAttr"partnerLinkreader.getAttributeValue(null"name"));
            throw new ContributionReadException("BPEL PartnerLink " + reader.getAttributeValue(null"name") + 
            		   " has both sca:reference and sca:service attributes set");
        } // end if
        
        // Set the SCA type and the related name, if present
        if (scaService != null)
            partnerLink.setAsService(scaService);
        else if (scaReference != null)
            partnerLink.setAsReference(scaReference);
        return partnerLink;
        
    } // end processPartnerLinkElement

    
Processes an <import../> element from the BPEL process and creates a BPELImportElement object

Parameters:
reader
        return (new BPELImportElement(reader.getAttributeValue(null"location"),
                                      reader.getAttributeValue(null"importType"),
                                      reader.getAttributeValue(null"namespace")));
        
    } // end processImportElement

    
Mark a named partnerLink as a Service, unless it is already marked as a Reference

Parameters:
partnerLinkName
partnerLinks
    private void processPartnerLinkAsService(String partnerLinkNameList<BPELPartnerLinkElementpartnerLinksMonitor monitor) {
        BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinkspartnerLinkName);
        if (partnerLink == null) {
            warning(monitor"ReferencePartnerLinkNotInList"partnerLinkNamepartnerLinkName);
        } else {
            // Set the type of the partnerLink to "service" if not already
            // set...
            if (!partnerLink.isSCATyped())
                partnerLink.setAsService(partnerLinkName);
        } // endif
    } // end processPartnerLinkAsReference

    
Mark a named partnerLink as a Reference, unless it is already marked as a Service

Parameters:
partnerLinkName
partnerLinks
    private void processPartnerLinkAsReference(String partnerLinkNameList<BPELPartnerLinkElementpartnerLinksMonitor monitor) {
        BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinkspartnerLinkName);
        if (partnerLink == null) {
            warning(monitor"ReferencePartnerLinkNotInList"partnerLinkNamepartnerLinkName);
        } else {
            // Set the type of the partnerLink to "service" if not already
            // set...
            if (!partnerLink.isSCATyped())
                partnerLink.setAsReference(partnerLinkName);
        } // endif
    } // end processPartnerLinkAsReference

    
Finds a PartnerLink by name from a List of PartnerLinks returns null if there is no partnerLink with a matching name - returns the PartnerLink with a matching name

Parameters:
partnerLinks
partnerLinkName
    private BPELPartnerLinkElement findPartnerLinkByName(List<BPELPartnerLinkElementpartnerLinksString partnerLinkName) {
        // Scan the list looking for a partner link with the supplied name
        Iterator<BPELPartnerLinkElementit = partnerLinks.iterator();
        while (it.hasNext()) {
            BPELPartnerLinkElement thePartnerLink = it.next();
            if (thePartnerLink.getName().equals(partnerLinkName))
                return thePartnerLink;
        }
        return null;
    } // end method findPartnerLinkByName

    
Report a warning.

Parameters:
problems
message
model
    private void warning(Monitor monitorString messageObject modelObject... messageParameters) {
        if (monitor != null) {
            Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages".modelmessage, (Object[])messageParameters);
            monitor.problem(problem);
        }
    }

    
Report a error.

Parameters:
problems
message
model
    private void error(Monitor monitorString messageObject modelObject... messageParameters) {
        if (monitor != null) {
            Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages".modelmessage, (Object[])messageParameters);
            monitor.problem(problem);
        }
    }

    
Report a exception.

Parameters:
problems
message
model
    private void error(Monitor monitorString messageObject modelException ex) {
        if (monitor != null) {
            Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages".modelmessageex);
            monitor.problem(problem);
        }
    }
New to GrepCode? Check out our FAQ X