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.interfacedef.wsdl.xml;
 
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 
 import java.net.URI;
 import java.util.List;
 
 
Handles a <interface.wsdl ... /> element in a SCDL file

Version:
$Rev: 987399 $ $Date: 2010-08-20 11:06:37 +0300 (Fri, 20 Aug 2010) $
 
 
     private WSDLFactory wsdlFactory;
     private PolicyFactory policyFactory;
 
     public WSDLInterfaceProcessor(ExtensionPointRegistry registry) {
         FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
         this. =
             registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(InterfaceContractMapper.class);
         
         this. = modelFactories.getFactory(WSDLFactory.class);
         
         this. = modelFactories.getFactory(PolicyFactory.class);
         this. = new PolicySubjectProcessor();      
     }
    
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(), "interface-wsdlxml-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(), "interface-wsdlxml-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(), "interface-wsdlxml-validation-messages".modelmessageex);
            monitor.problem(problem);
        }        
    }
    
    
Create a WSDL interface from a URI.

Parameters:
uri - the URI in the form nameSpace#wsdl.interface(porttypeName) or nameSpace#wsdl.porttype(porttypeName)
Returns:
a WSDLInterface object
Throws:
ContributionReadException
    private static String FRAGMENT_INTERFACE = "wsdl.interface";
    private static String FRAGMENT_PORTTYPE = "wsdl.porttype";
    private WSDLInterface createWSDLInterface(String uriMonitor monitorthrows ContributionReadException {
        
    	WSDLInterface wsdlInterface = null;        
        // Read a QName in the form:
        // namespace#wsdl.interface(name)
        int index = uri.indexOf('#');
        if (index == -1) {
        	error(monitor"InvalidWSDLInterfaceAttr"uri);
            //throw new ContributionReadException("Invalid WSDL interface attribute: " + uri);
        } else {
        	// Read the URI and extract namespace and fragment
        	String namespace = uri.substring(0, index);
        	String name = uri.substring(index + 1);
        	String porttype = null;
        	ifname.contains()) {
        		// Deal with the case where #wsdl.interface is used
        		porttype = name.substring("wsdl.interface(".length(), name.length() - 1);
        	} // end if
        	ifname.contains()) {
        		// Deal with the case where #wsdl.porttype is used
        		porttype = name.substring("wsdl.porttype(".length(), name.length() - 1);
        	} // end if
        	ifporttype == null ) {
        		error(monitor"InvalidWSDLInterfaceAttr"uri);
        		return null;
        	} // end if
        	wsdlInterface = .createWSDLInterface();
            wsdlInterface.setUnresolved(true);
            wsdlInterface.setName(new QName(namespaceporttype));
        } // end if       
        
        return wsdlInterface;
    } // end method createWSDLInterface

    
Creates a WSDLInterfaceContract from a <interface.wsdl/> element in a SCDL file The form of the <interface.wsdl/> element is as follows: <interface.wsdl interface="http://sampleNamespace#wsdl.interface(porttypeName)" callbackInterface="http://sampleNamespace#wsdl.porttype(callbackPorttypeName)"/> where interface = URI pointing to the WSDL document containing a WSDL interface or porttype for the forward call interface callbackInterface = URI pointing to the WSDL document containing a WSDL interface or porttype for the callback interface

Parameters:
reader - XMLStreamReader holding the <interface.wsdl/> element
Returns:
- the WSDLInterfaceContract
        // Read an <interface.wsdl>
        WSDLInterfaceContract wsdlInterfaceContract = .createWSDLInterfaceContract();
        Monitor monitor = context.getMonitor();
        
        // Read wsdlLocation
        String location = reader.getAttributeValue();
        wsdlInterfaceContract.setLocation(location);
        
        String uri = getURIString(reader);
        if (uri != null) {
            WSDLInterface wsdlInterface = createWSDLInterface(urimonitor);
            if (wsdlInterface != null)
                wsdlInterfaceContract.setInterface(wsdlInterface);
        }
        
        uri = getURIString(reader);
        if (uri != null) {
            WSDLInterface wsdlCallbackInterface = createWSDLInterface(urimonitor);
            if (wsdlCallbackInterface != null)
                wsdlInterfaceContract.setCallbackInterface(wsdlCallbackInterface);
        }
        
        String remotable = reader.getAttributeValue(null);
        if (remotable != null &&
            !remotable.equals("true")){
            Monitor.error(monitor,
                          this,
                          "interface-wsdlxml-validation-messages",
                          "InvalidRemotableValue"
                          ((WSDLInterface)wsdlInterfaceContract.getInterface()).getName().toString(),
                          remotable);
        }
        
        // Read intents and policy sets
        .readPolicies(wsdlInterfaceContract.getInterface(), reader);
            
        // Skip to end element
        while (reader.hasNext()) {
            if (reader.next() ==  && .equals(reader.getName())) {
                break;
            }
        }
        return wsdlInterfaceContract;
    }
    
    public void write(WSDLInterfaceContract wsdlInterfaceContractXMLStreamWriter writerProcessorContext contextthrows ContributionWriteExceptionXMLStreamException {
        // Write an <interface.wsdl>
        // Write interface name
        WSDLInterface wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface();
        if (wsdlInterface != null) {
            QName qname = wsdlInterface.getName();
            String uri = qname.getNamespaceURI() + "#wsdl.interface(" + qname.getLocalPart() + ")";
            writer.writeAttribute(uri);
        }
        WSDLInterface wsdlCallbackInterface = (WSDLInterface)wsdlInterfaceContract.getCallbackInterface();
        if (wsdlCallbackInterface != null) {
            QName qname = wsdlCallbackInterface.getName();
            String uri = qname.getNamespaceURI() + "#wsdl.interface(" + qname.getLocalPart() + ")";
            writer.writeAttribute(uri);
        }
        
        // Write location
        if (wsdlInterfaceContract.getLocation() != null) {
            writer.writeAttribute(wsdlInterfaceContract.getLocation());
        }
        
        .writePolicyAttributes(wsdlInterfacewriter);
        
        writer.writeEndElement();
    }
    
    private WSDLInterface resolveWSDLInterface(WSDLInterface wsdlInterfaceModelResolver resolverProcessorContext contextthrows ContributionResolveException {
        
        if (wsdlInterface != null && wsdlInterface.isUnresolved()) {
            Monitor monitor = context.getMonitor();
            // Resolve the WSDL interface
            wsdlInterface = resolver.resolveModel(WSDLInterface.classwsdlInterfacecontext);
            if (wsdlInterface.isUnresolved()) {
                // If the WSDL interface has never been resolved yet, do it now
                // First, resolve the WSDL definition for the given namespace
                WSDLDefinition wsdlDefinition = .createWSDLDefinition();
                wsdlDefinition.setUnresolved(true);
                wsdlDefinition.setNamespace(wsdlInterface.getName().getNamespaceURI());
                wsdlDefinition.setNameOfPortTypeToResolve(wsdlInterface.getName());
                WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.classwsdlDefinitioncontext);
                if (!resolved.isUnresolved()) {
                    wsdlDefinition.setDefinition(resolved.getDefinition());
                    wsdlDefinition.setLocation(resolved.getLocation());
                    wsdlDefinition.setURI(resolved.getURI());
                    wsdlDefinition.getImportedDefinitions().addAll(resolved.getImportedDefinitions());
                    wsdlDefinition.getXmlSchemas().addAll(resolved.getXmlSchemas());
                    wsdlDefinition.setUnresolved(false);
                    WSDLObject<PortTypeportType = wsdlDefinition.getWSDLObject(PortType.classwsdlInterface.getName());
                    if (portType != null) {                        
                        // Introspect the WSDL portType and add the resulting
                        // WSDLInterface to the resolver
                        try {
                            wsdlDefinition.setDefinition(portType.getDefinition());
                            WSDLInterface newWSDLInterface = .createWSDLInterface(portType.getElement(), wsdlDefinitionresolvermonitor);
                            newWSDLInterface.setWsdlDefinition(wsdlDefinition);
                            newWSDLInterface.getRequiredIntents().addAll(wsdlInterface.getRequiredIntents());
                            newWSDLInterface.getPolicySets().addAll(wsdlInterface.getPolicySets());
                            resolver.addModel(newWSDLInterfacecontext);
                            wsdlInterface = newWSDLInterface;
                        } catch (InvalidInterfaceException e) {
                        	ContributionResolveException ce = new ContributionResolveException("Invalid interface when resolving " + 
                        			                                                            portType.toString(), e);
                        	error(monitor"ContributionResolveException"ce);
                            //throw ce;
                        } // end try                      
                    }
                    else {
                    	warning(monitor"WsdlInterfaceDoesNotMatch"wsdlDefinitionwsdlInterface.getName());
                    } // end if
                } else {
                	// If we get here, the WSDLDefinition is unresolved...
                	ContributionResolveException ce = new ContributionResolveException("WSDLDefinition unresolved " + 
                			wsdlInterface.getName() );
                    error(monitor"ContributionResolveException"ce);
                } // end if
            } // end if
        } // end if
        return wsdlInterface;
    }
    
    public static WSDLInterface resolveWSDLInterfaceWSDLInterface wsdlInterfaceModelResolver resolver
    		                                   Monitor monitorWSDLFactory wsdlFactory) {
        if (wsdlInterface != null && wsdlInterface.isUnresolved()) {
            ProcessorContext context = new ProcessorContext(monitor);
            // Resolve the WSDL interface
            wsdlInterface = resolver.resolveModel(WSDLInterface.classwsdlInterfacecontext);
            if (wsdlInterface.isUnresolved()) {
                // If the WSDL interface has never been resolved yet, do it now
                // First, resolve the WSDL definition for the given namespace
                WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition();
                wsdlDefinition.setUnresolved(true);
                wsdlDefinition.setNamespace(wsdlInterface.getName().getNamespaceURI());
                WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.classwsdlDefinitioncontext);
                if (!resolved.isUnresolved()) {
                    wsdlDefinition.setDefinition(resolved.getDefinition());
                    wsdlDefinition.setLocation(resolved.getLocation());
                    wsdlDefinition.setURI(resolved.getURI());
                    wsdlDefinition.getImportedDefinitions().addAll(resolved.getImportedDefinitions());
                    wsdlDefinition.getXmlSchemas().addAll(resolved.getXmlSchemas());
                    wsdlDefinition.setUnresolved(false);
                    WSDLObject<PortTypeportType = wsdlDefinition.getWSDLObject(PortType.classwsdlInterface.getName());
                    if (portType != null) {                        
                        // Introspect the WSDL portType and add the resulting
                        // WSDLInterface to the resolver
                        try {
                            wsdlDefinition.setDefinition(portType.getDefinition());
                            wsdlInterface = wsdlFactory.createWSDLInterface(portType.getElement(), wsdlDefinitionresolvermonitor);
                            wsdlInterface.setWsdlDefinition(wsdlDefinition);
                            resolver.addModel(wsdlInterfacecontext);
                        } catch (InvalidInterfaceException e) {
                        	ContributionResolveException ce = new ContributionResolveException("Invalid interface when resolving " + 
                        			                                                            portType.toString(), e);
                        	Monitor.error(monitorWSDLInterfaceProcessor.class.getName(), 
                        			"interface-wsdlxml-validation-messages""ContributionResolveException"
                        			wsdlFactory.getClass().getName(), ce.getMessage());
                            //throw ce;
                        } // end try                      
                    }
                    else {
                    	Monitor.warning(monitorWSDLInterfaceProcessor.class.getName(),
                    			"interface-wsdlxml-validation-messages""WsdlInterfaceDoesNotMatch"
                    			wsdlDefinition.getNamespace(), wsdlInterface.getName().toString() );
                    } // end if
                } else {
                	// If we get here, the WSDLDefinition is unresolved...
                	ContributionResolveException ce = new ContributionResolveException("WSDLDefinition unresolved " + 
                			wsdlInterface.getName() );
                    Monitor.error(monitorWSDLInterfaceProcessor.class.getName(), 
                			"interface-wsdlxml-validation-messages""ContributionResolveException"
                			wsdlFactory.getClass().getName(), ce.getMessage());
                } // end if
            } // end if
        } // end if
        return wsdlInterface;    	
    } // end method resolveWSDLInterface
    
    
Resolve a WSDLInterfaceContract
    public void resolve(WSDLInterfaceContract wsdlInterfaceContractModelResolver resolverProcessorContext contextthrows ContributionResolveException {
        Monitor monitor = context.getMonitor();
        
        WSDLInterface wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface();
        
        // if the contract has a location but no WSDL definition yet we need to read the WSDL
        // from the specified location and create an interface based on the first port type
        // this is required if the user uses the @WebService(wsdlLocation="") or 
        // @WebServiceProvider(wsdlLocation="") annotation in a Java component implementation. 
        if (wsdlInterfaceContract.getLocation() != null &&
            wsdlInterface.getWsdlDefinition() == null){
            
            WSDLDefinition wsdlDefinition = null;
 
            URI wsdlFileURI = null;
            
            try {
                wsdlFileURI = new URI(wsdlInterfaceContract.getLocation());
            } catch (Exception ex) {
                Monitor.error(context.getMonitor(), 
                        WSDLInterfaceProcessor.class.getName(), 
                        "interface-wsdlxml-validation-messages"
                        "wsdliLocationException"
                        ex.getMessage() );
                return;
            }
            
            // We need to find a portType from the user specified WSDL (the first one?) from which to defined
            // the service interface. We can't just use the Tuscany resolution mechanism to find the WSDL file
            // as that lumps together all WSDL in the same namespace. That's fine if you already know what portType
            // your after. In this case we don't so we have to get the WSDL specified, find out what it's first portType
            // is and then go from there with the usual Tuscany resolution mechanism
            try {
                if (wsdlFileURI.isAbsolute()){
                    // use the wsdli:wsdlLocation mechanism in the WSDLModelResolver to 
                    // load the WSDL from an absolute location                
                    wsdlDefinition = .createWSDLDefinition();
                    wsdlDefinition.setUnresolved(true);
                    wsdlDefinition.setNamespace("nonamespace"); 
                    wsdlDefinition.getWsdliLocations().put("nonamespace"wsdlInterfaceContract.getLocation());
                    wsdlDefinition.setLocation(new URI(wsdlInterfaceContract.getLocation()));
                } else {
                    // Find the wsdl in the contribution ready for further resolution
                    for (Artifact artifact : context.getContribution().getArtifacts()) {
                        if (artifact.getLocation().endsWith(wsdlInterfaceContract.getLocation())){
                            WSDLDefinition artifactWSDLDefinition = artifact.getModel();
                            wsdlDefinition = .createWSDLDefinition();
                            wsdlDefinition.setUnresolved(true);
                            wsdlDefinition.setNamespace(artifactWSDLDefinition.getNamespace()); 
                            wsdlDefinition.getWsdliLocations().put(artifactWSDLDefinition.getNamespace(), 
                                                                   artifact.getLocation());
                            wsdlDefinition.setLocation(new URI(artifact.getLocation()));
                            break;
                        }
                    }
                    
                    if (wsdlDefinition == null){
                        Monitor.error(context.getMonitor(), 
                                WSDLInterfaceProcessor.class.getName(), 
                                "interface-wsdlxml-validation-messages"
                                "wsdliLocationException"
                                "WSDL not found inside contribution at relative URI " + wsdlFileURI );
                        return;
                    }
                }
            } catch (Exception ex) {
                Monitor.error(context.getMonitor(), 
                              WSDLInterfaceProcessor.class.getName(), 
                              "interface-wsdlxml-validation-messages"
                              "wsdliLocationException"
                              ex.getMessage() );
                return;
            }
            
            wsdlDefinition.setUnresolved(true);
            wsdlDefinition = resolver.resolveModel(WSDLDefinition.classwsdlDefinitioncontext);
            // create the interface based on the first port type
            PortType portType = (PortType)wsdlDefinition.getDefinition().getAllPortTypes().values().iterator().next();
            try {
                WSDLInterface newWSDLInterface = .createWSDLInterface(portTypewsdlDefinitionresolvermonitor);
                newWSDLInterface.getRequiredIntents().addAll(wsdlInterface.getRequiredIntents());
                newWSDLInterface.getPolicySets().addAll(wsdlInterface.getPolicySets());
                wsdlInterface = newWSDLInterface;
            } catch (InvalidInterfaceException e) {
                ContributionResolveException ce = new ContributionResolveException("Invalid interface when resolving " + 
                                                                                    portType.toString(), e);
                error(monitor"ContributionResolveException"ce);
            }    
            
            wsdlInterface.setWsdlDefinition(wsdlDefinition);
            wsdlInterfaceContract.setInterface(wsdlInterface);
        }
        
        // Resolve the interface and callback interface
        wsdlInterface = resolveWSDLInterface(wsdlInterfaceresolvercontext);
        wsdlInterfaceContract.setInterface(wsdlInterface);
        
        // The forward interface (portType) may have a callback interface declared on it using an sca:callback attribute
        WSDLInterface intrinsicWSDLCallbackInterface = wsdlInterface.getCallbackInterface();
        
        // There may be a callback interface explicitly declared on the <interface.wsdl .../> element
        WSDLInterface wsdlCallbackInterface = resolveWSDLInterface((WSDLInterface)wsdlInterfaceContract.getCallbackInterface(), resolvercontext);
        ifintrinsicWSDLCallbackInterface != null ) {
        	ifwsdlCallbackInterface != null ) {
        		// If there is both a callback interface declared on the forward interface and also one declared on the
        		// interface.wsdl element, then the two interfaces must match [ASM80011]
        		if( !.isMutuallyCompatible(intrinsicWSDLCallbackInterfacewsdlCallbackInterface) ) {
                    Monitor.error(context.getMonitor(), WSDLInterfaceProcessor.class.getName(), 
                			"interface-wsdlxml-validation-messages""IncompatibleCallbacks"
                			intrinsicWSDLCallbackInterface.getName().toString(), 
                			wsdlCallbackInterface.getName().toString() );
        		} // end if
        	} // end if
        	wsdlInterfaceContract.setCallbackInterface(intrinsicWSDLCallbackInterface);
        } else {
        	wsdlInterfaceContract.setCallbackInterface(wsdlCallbackInterface);
        } // end if
    } // end method resolve( WSDLInterfaceContract, ModelResolver)
    
    public QName getArtifactType() {
        return .;
    }
    
        return WSDLInterfaceContract.class;
    }
New to GrepCode? Check out our FAQ X