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 java.net.URI;
 import java.util.List;
 
 
Implements a StAX artifact processor for BPEL implementations. The artifact processor is responsible for processing <implementation.bpel> elements in SCA assembly XML composite files and populating the BPEL implementation model, resolving its references to other artifacts in the SCA contribution, and optionally write the model back to SCA assembly XML.

Version:
$Rev: 889531 $ $Date: 2009-12-11 08:26:48 +0000 (Fri, 11 Dec 2009) $
 
     private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
     private static final String PROCESS = "process";
     private static final String IMPLEMENTATION_BPEL = "implementation.bpel";
     private static final QName IMPLEMENTATION_BPEL_QNAME = new QName();
     
     private AssemblyFactory assemblyFactory;
     private BPELFactory bpelFactory;
     private WSDLFactory wsdlFactory;
     
     
     public BPELImplementationProcessor(FactoryExtensionPoint modelFactories) {
         this. = modelFactories.getFactory(AssemblyFactory.class);
         this. = modelFactories.getFactory(WSDLFactory.class);
         this. = modelFactories.getFactory(BPELFactory.class);
     }
 
     public QName getArtifactType() {
         // Returns the QName of the XML element processed by this processor
         return ;
     }
 
     public Class<BPELImplementationgetModelType() {
         // Returns the type of model processed by this processor
         return BPELImplementation.class;
     }
 
         assert .equals(reader.getName());
         
         // Read an <implementation.bpel> element
        BPELImplementation implementation = null;
        
        // Read the process attribute. 
        QName process = getAttributeValueNS(readercontext.getMonitor());
        if (process == null) {
        	return implementation;
        }
        // Create and initialize the BPEL implementation model
        implementation = .createBPELImplementation();
        implementation.setProcess(process);
        implementation.setUnresolved(true);
        
        // Skip to end element
        while (reader.hasNext()) {
            if (reader.next() ==  && .equals(reader.getName())) {
                break;
            }
        }
        
        return implementation;
    }
    public void resolve(BPELImplementation implementationModelResolver resolverProcessorContext contextthrows ContributionResolveException {
        
    	ifimplementation != null && implementation.isUnresolved()) 
    	{
    	    implementation.setModelResolver(resolver);
    	    
            BPELProcessDefinition processDefinition = resolveBPELProcessDefinition(implementationresolvercontext);
            //resolveBPELImports(processDefinition, resolver);
            if(processDefinition.isUnresolved()) {
            	error(context.getMonitor(), "BPELProcessNotFound"implementationprocessDefinition.getName());
            } else {            
                implementation.setProcessDefinition(processDefinition);
            
                // Get the component type from the process definition
                generateComponentTypeimplementationcontext.getMonitor() );
                        
                //set current implementation resolved 
                implementation.setUnresolved(false);
            }
        }
        
    } // end resolve
    public void writeBPELImplementation bpelImplementation
    		           XMLStreamWriter writerProcessorContext context ) throws ContributionWriteExceptionXMLStreamException {
        //FIXME Deal with policy processing...
        // Write <implementation.bpel process="..."/>
        // policyProcessor.writePolicyPrefixes(bpelImplementation, writer);
        // policyProcessor.writePolicyAttributes(bpelImplementation, writer);
        
        if (bpelImplementation.getProcess() != null) {
            writer.writeAttribute(bpelImplementation.getProcess().toString() );
        }
        writer.writeEndElement();
    } // end write
        QName processName = impl.getProcess();
        BPELProcessDefinition processDefinition = this..createBPELProcessDefinition();
        processDefinition.setName(processName);
        processDefinition.setUnresolved(true);
        
        return resolver.resolveModel(BPELProcessDefinition.classprocessDefinitioncontext);
    } // end resolveBPELProcessDefinition
    
    private void resolveBPELImports(BPELProcessDefinition processDefinitionModelResolver resolverProcessorContext contextthrows ContributionResolveException {
    	for (BPELImportElement bpelImport : processDefinition.getImports()) {
    		String namespace = bpelImport.getNamespace();
    		String location = bpelImport.getLocation();
    		
    		WSDLDefinition wsdl = bpelImport.getWSDLDefinition();
    		if (wsdl == null) {
        			try {
        				wsdl = .createWSDLDefinition();
        				wsdl.setUnresolved(true);
        				wsdl.setNamespace(bpelImport.getNamespace());
						wsdl.setLocation(new URI(nullbpelImport.getLocation(), null));
						wsdl = resolver.resolveModel(WSDLDefinition.classwsdlcontext);
						if(! wsdl.isUnresolved()) {
							bpelImport.setWSDLDefinition(wsdl);
else {
							//error("BPELProcessNotFound", implementation, processDefinition.getName());
						}
catch (URISyntaxException e) {
						// TODO Auto-generated catch block
					}
    		}
    		
    	}
    }

    
    
Calculates the component type of the supplied implementation and attaches it to the implementation.

    private void generateComponentType(BPELImplementation implMonitor monitorthrows ContributionResolveException {
        // Create a ComponentType and mark it unresolved
        ComponentType componentType = .createComponentType();
        componentType.setUnresolved(true);
        impl.setComponentType(componentType);
        // Each partner link in the process represents either a service or a reference
        // - or both, in the sense of involving a callback
        BPELProcessDefinition theProcess = impl.getProcessDefinition();
        List<BPELPartnerLinkElementpartnerLinks = theProcess.getPartnerLinks();
        for (BPELPartnerLinkElement pLink : partnerLinks) {
            // check that the partner link has been designated as service or
            // reference in SCA terms
            if (pLink.isSCATyped()) {
                String scaName = pLink.getSCAName();
                if (pLink.querySCAType().equals("reference")) {
                    componentType.getReferences().add(generateReference(scaNamepLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces(), monitor));
                } else {
                    componentType.getServices().add(generateService(scaNamepLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces(), monitor));
                } // end if
            } // end if
        } // end for
        
        // Each SCA Property in the process becomes a Property in the ComponentType
        forProperty property : theProcess.getProperties() ) {
        	componentType.getProperties().add(property);
        } // end for
    } // end getComponentType
    
    
Create an SCA reference for a partnerLink

Parameters:
name - name of the reference
myRolePT - partner link type of myRole
partnerRolePT - partner link type of partnerRole
theInterfaces - list of WSDL interfaces associated with the BPEL process
Returns:
    private Reference generateReferenceString namePortType myRolePT
    		PortType partnerRolePTCollection<WSDLInterfacetheInterfacesMonitor monitorthrows ContributionResolveException {
        
        Reference reference = .createReference();
        WSDLInterfaceContract interfaceContract = .createWSDLInterfaceContract();
        reference.setInterfaceContract(interfaceContract);
        // Establish whether there is just a call interface or a call + callback interface
        PortType callPT = null;
        PortType callbackPT = null;
        if (partnerRolePT != null) {
            callPT = partnerRolePT;
            // If the 2 port types are not the same one, there is a callback...
            if (myRolePT != null) {
                if (!myRolePT.getQName().equals(partnerRolePT.getQName())) {
                    callbackPT = myRolePT;
                } // end if
            } // end if
        } else if (myRolePT != null) {
            callPT = myRolePT;
        } // end if
        // No interfaces mean an error
        if (callPT == null && callbackPT == null) {
            error(monitor"MyRolePartnerRoleNull"theInterfaces);
        } // end if
        // Set the name of the reference to the supplied name and the
        // multiplicity of the reference to 1..1
        // TODO: support other multiplicities
        reference.setName(name);
        reference.setMultiplicity(.);
        if (callPT != null) {
            // Set the call interface and, if present, the callback interface
            WSDLInterface callInterface = null;
            for (WSDLInterface anInterface : theInterfaces) {
                if (anInterface.getPortType().getQName().equals(callPT.getQName()))
                    callInterface = anInterface;
            } // end for
            if (callInterface == null) {
                error(monitor"NoInterfaceForPortType"theInterfacescallPT.getQName().toString());
            } else
                reference.getInterfaceContract().setInterface(callInterface);
        } // end if
        // There is a callback if the partner role is not null and if the
        // partner role port type is not the same as the port type for my role
        if (callbackPT != null) {
            WSDLInterface callbackInterface = null;
            for (WSDLInterface anInterface : theInterfaces) {
                if (anInterface.getPortType().getQName().equals(callbackPT.getQName()))
                    callbackInterface = anInterface;
            } // end for
            if (callbackInterface == null) {
                error(monitor"NoInterfaceForPortType"theInterfacescallbackPT.getQName().toString());
            } else
                reference.getInterfaceContract().setCallbackInterface(callbackInterface);
        } // end if
        return reference;
    } // end generateReference
    
    
Create an SCA service for a partnerLink

Parameters:
name - name of the service
myRolePT - partner link type of myRole
partnerRolePT - partner link type of partnerRole
theInterfaces - list of WSDL interfaces associated with the BPEL process
Returns:
    private Service generateServiceString namePortType myRolePT
    		PortType partnerRolePTCollection<WSDLInterfacetheInterfacesMonitor monitor ) 
        Service service = .createService();
        WSDLInterfaceContract interfaceContract = .createWSDLInterfaceContract();
        service.setInterfaceContract(interfaceContract);
        // Set the name of the service to the supplied name
        service.setName(name);
        // Establish whether there is just a call interface or a call + callback
        // interface
        PortType callPT = null;
        PortType callbackPT = null;
        if (myRolePT != null) {
            callPT = myRolePT;
            // If the 2 port types are not the same one, there is a callback...
            if (partnerRolePT != null) {
                if (!myRolePT.getQName().equals(partnerRolePT.getQName())) {
                    callbackPT = partnerRolePT;
                } // end if
            } // end if
        } else if (partnerRolePT != null) {
            callPT = partnerRolePT;
        } // end if
        // No interfaces mean an error
        if (callPT == null && callbackPT == null) {
            error(monitor"MyRolePartnerRoleNull"theInterfaces);
        } // end if
        if (callPT != null) {
            // Set the call interface and, if present, the callback interface
            WSDLInterface callInterface = null;
            for (WSDLInterface anInterface : theInterfaces) {
                if (anInterface.getPortType().getQName().equals(callPT.getQName()))
                    callInterface = anInterface;
            } // end for
            if (callInterface == null) {
                error(monitor"NoInterfaceForPortType"theInterfacescallPT.getQName().toString());
            } else
                service.getInterfaceContract().setInterface(callInterface);
        } // end if
        // There is a callback if the partner role is not null and if the
        // partner role port type is not the same as the port type for my role
        if (callbackPT != null) {
            WSDLInterface callbackInterface = null;
            for (WSDLInterface anInterface : theInterfaces) {
                if (anInterface.getPortType().getQName().equals(callbackPT.getQName()))
                    callbackInterface = anInterface;
            } // end for
            if (callbackInterface == null) {
                error(monitor"NoInterfaceForPortType"theInterfacescallbackPT.getQName().toString());
            } else
                service.getInterfaceContract().setCallbackInterface(callbackInterface);
        } // end if
        return service;
    } // end generateService
    
    
Returns a QName from its string representation in a named attribute of an XML element supplied in an XMLStreamReader QName attributes of an XML element (such as BPEL process) is presented in one of two alternative formats: 1) In the form of a local name with a prefix, with the prefix referencing a namespace URI declaration elsewhere in the composite (typically on the composite element) ie: nms:SomeName xmlns:nms="http://example.com/somenamespace" 2) In the XML Namespaces recommendation format (see http://jclark.com/xml/xmlns.htm ) where the namespace URI and the local name are encoded into a single string, with the namespace URI enclosed between a pair of braces {...} ie: {http://example.com/somenamespace}SomeName
    private QName getAttributeValueNS(XMLStreamReader readerString attributeMonitor monitor) {
        String fullValue = reader.getAttributeValue(nullattribute);
        if (fullValue == null) {
            error(monitor"AttributeProcessMissing"reader);
            return null;
        }
        // Deal with the attribute in the XML Namespaces recommendation format
        // - trim off any leading/trailing spaces and check that the first
        // character is '{'
        if (fullValue.trim().charAt(0) == '{') {
            try {
                // Attempt conversion to a QName object
                QName theProcess = QName.valueOf(fullValue);
                return theProcess;
            } catch (IllegalArgumentException e) {
                // This exception happens if the attribute begins with '{' but
                // doesn't conform
                // to the XML Namespaces recommendation format
                error(monitor"AttributeWithoutNamespace"readerattributefullValue);
                return null;
            }
        } // endif
        // Deal with the attribute in the local name + prefix format
        if (fullValue.indexOf(":") < 0) {
            error(monitor"AttributeWithoutPrefix"readerattributefullValue);
            return null;
        }
        String prefix = fullValue.substring(0, fullValue.indexOf(":"));
        String name = fullValue.substring(fullValue.indexOf(":") + 1);
        String nsUri = reader.getNamespaceContext().getNamespaceURI(prefix);
        if (nsUri == null) {
            error(monitor"AttributeUnrecognizedNamespace"readerattributefullValue);
            return null;
        }
        return new QName(nsUrinameprefix);
    }

    
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);
         }
    }
     
New to GrepCode? Check out our FAQ X