public void resolve()

in modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java [387:507]


    public void resolve(WSDLInterfaceContract wsdlInterfaceContract, ModelResolver resolver, ProcessorContext context) throws 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 = wsdlFactory.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 = wsdlFactory.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.class, wsdlDefinition, context);
            // create the interface based on the first port type
            PortType portType = (PortType)wsdlDefinition.getDefinition().getAllPortTypes().values().iterator().next();
            try {
                WSDLInterface newWSDLInterface = wsdlFactory.createWSDLInterface(portType, wsdlDefinition, resolver, monitor);
                newWSDLInterface.getRequiredIntents().addAll(wsdlInterface.getRequiredIntents());
                newWSDLInterface.getPolicySets().addAll(wsdlInterface.getPolicySets());
                wsdlInterface = newWSDLInterface;
            } catch (InvalidInterfaceException e) {
                String message = context.getMonitor().getMessageString(WSDLInterfaceProcessor.class.getName(),
                                        "interface-wsdlxml-validation-messages", 
                                        "InvalidInterface");
                message = message.replace("{0}",  portType.toString());
                ContributionResolveException ce = new ContributionResolveException(message, e);
                error(monitor, "ContributionResolveException", wsdlFactory, ce);
            }    
            
            wsdlInterface.setWsdlDefinition(wsdlDefinition);
            wsdlInterfaceContract.setInterface(wsdlInterface);
        }
        
        // Resolve the interface and callback interface
        wsdlInterface = resolveWSDLInterface(wsdlInterface, resolver, context);
        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(), resolver, context);
        if( intrinsicWSDLCallbackInterface != null ) {
        	if( wsdlCallbackInterface != 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( !interfaceContractMapper.isMutuallyCompatible(intrinsicWSDLCallbackInterface, wsdlCallbackInterface) ) {
                    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)