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.java.xml;
 
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 
 import java.util.List;
 
 

Version:
$Rev: 986740 $ $Date: 2010-08-18 18:28:56 +0300 (Wed, 18 Aug 2010) $
 
     private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
     
     private JavaInterfaceFactory javaFactory;
     private PolicyFactory policyFactory;
     private WSDLFactory wsdlFactory;
     private transient InterfaceContractMapper interfaceContractMapper;
 
     public JavaInterfaceProcessor(ExtensionPointRegistry extensionPoints,  StAXArtifactProcessor<?> staxProcessor) {
         this. = extensionPoints;
         FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
         this. = modelFactories.getFactory(PolicyFactory.class);
         this. = new PolicySubjectProcessor();
         this. = modelFactories.getFactory(JavaInterfaceFactory.class);
         this. = modelFactories.getFactory(WSDLFactory.class);
         this. = (StAXArtifactProcessor<Object>)staxProcessor;
         UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
        this. = utilities.getUtility(InterfaceContractMapper.class);
    }
    
    
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-javaxml-validation-messages",
                                      .,
                                      model,
                                      message,
                                      ex);
            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-javaxml-validation-messages",
                                      .,
                                      model,
                                      message,
                                      (Object[])messageParameters);
            monitor.problem(problem);
        }
    }
    
    private JavaInterface createJavaInterface(String interfaceName) {
        JavaInterface javaInterface = .createJavaInterface();
        javaInterface.setUnresolved(true);
        javaInterface.setName(interfaceName);
        return javaInterface;
    }
        
        // Read an <interface.java>
        JavaInterfaceContract javaInterfaceContract = .createJavaInterfaceContract();
        String interfaceName = reader.getAttributeValue(null);
        if (interfaceName != null) {
            JavaInterface javaInterface = createJavaInterface(interfaceName);
            javaInterfaceContract.setInterface(javaInterface);
        }
        String callbackInterfaceName = reader.getAttributeValue(null);
        if (callbackInterfaceName != null) {
            JavaInterface javaCallbackInterface = createJavaInterface(callbackInterfaceName);
            javaInterfaceContract.setCallbackInterface(javaCallbackInterface);
        }
        String remotable = reader.getAttributeValue(null);
        if (remotable != null) {
            javaInterfaceContract.getInterface().setRemotable(Boolean.parseBoolean(remotable));
        }
        
        // Read intents and policy sets
        .readPolicies(javaInterfaceContract.getInterface(), reader);
        // Skip to end element
        while (reader.hasNext()) {
            if (reader.next() ==  && .equals(reader.getName())) {
                break;
            }
        }
        return javaInterfaceContract;
    }
    
    public void write(JavaInterfaceContract javaInterfaceContractXMLStreamWriter writerProcessorContext contextthrows ContributionWriteExceptionXMLStreamException {
        
        // Write an <interface.java>
        writer.writeStartElement();
        JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
        
        if (javaInterface != null && javaInterface.getName() != null) {
            writer.writeAttribute(javaInterface.getName());
        }
        
        if(javaInterface != null && javaInterface.isRemotableSet()) {
            writer.writeAttribute(, String.valueOf(javaInterface.isRemotable()));
        }
        
        JavaInterface javaCallbackInterface = (JavaInterface)javaInterfaceContract.getCallbackInterface();
        if (javaCallbackInterface != null && javaCallbackInterface.getName() != null) {
            writer.writeAttribute(javaCallbackInterface.getName());
        }
        
        .writePolicyAttributes(javaInterfacewriter);
        
        writer.writeEndElement();
    }
    
    private JavaInterface resolveJavaInterface(JavaInterface javaInterfaceModelResolver resolverProcessorContext contextthrows ContributionResolveException {
        
        if (javaInterface != null && javaInterface.isUnresolved()) {
            Monitor monitor = context.getMonitor();
            // Resolve the Java interface
            javaInterface = resolver.resolveModel(JavaInterface.classjavaInterfacecontext);
            if (javaInterface.isUnresolved()) {
                // If the Java interface has never been resolved yet, do it now
                ClassReference classReference = new ClassReference(javaInterface.getName());
                classReference = resolver.resolveModel(ClassReference.classclassReferencecontext);
                Class<?> javaClass = classReference.getJavaClass();
                if (javaClass == null) {
                    error(monitor"ClassNotFoundException"resolverjavaInterface.getName());
                    return javaInterface;
                    //throw new ContributionResolveException(new ClassNotFoundException(javaInterface.getName()));
                }
                
                try {                        
                    // Introspect the Java interface and populate the interface and
                    // operations
                    .createJavaInterface(javaInterfacejavaClass);
                    
                    // cache the contribution that was used to resolve the Java interface
                    // in case we need it to reolve a referenced WSDL file
                    javaInterface.setContributionContainingClass(classReference.getContributionContainingClass());
                
                } catch (InvalidInterfaceException e) {
                	ContributionResolveException ce = new ContributionResolveException("Resolving Java interface " + javaInterface.getName(), e);
                	//error("ContributionResolveException", javaFactory, ce);
                	error(monitor"InvalidInterfaceException"e);
                    return javaInterface;
                	//throw ce;
                } catch ( Exception e ) {
                	throw new ContributionResolveException"Resolving Java interface " + javaInterface.getName(), e );
                } // end try
                // Cache the resolved interface
                javaInterface.setUnresolved(false);
                resolver.addModel(javaInterfacecontext);
            }
        }
        return javaInterface;
    }
    public void resolve(JavaInterfaceContract javaInterfaceContractModelResolver resolverProcessorContext context)
        throws ContributionResolveException {
        try {
            Monitor monitor = context.getMonitor();
            // Resolve the interface and callback interface
            JavaInterface javaInterface =
                resolveJavaInterface((JavaInterface)javaInterfaceContract.getInterface(), resolvercontext);
            javaInterfaceContract.setInterface(javaInterface);
            JavaInterface javaCallbackInterface =
                resolveJavaInterface((JavaInterface)javaInterfaceContract.getCallbackInterface(), resolvercontext);
            javaInterfaceContract.setCallbackInterface(javaCallbackInterface);
            
            postJAXWSProcessorResolve(javaInterfaceContractresolvercontext);
	        
	        checkForbiddenAnnotations(monitorjavaInterfaceContract);
	        
        } catch (Exception e) {
            throw new ContributionResolveException("Resolving Java Interface " + javaInterfaceContract.getInterface()
                .toString(), e);
        } // end try
    }
    
    private static List<Class<?>> JCA30006_ANNOTATIONS =
        Arrays.asList(new Class<?>[] {AllowsPassByReference.classComponentName.classConstructor.classContext.class,
                                   Destroy.classEagerInit.classInit.classIntent.classProperty.classQualifier.class,
                                   Reference.classScope.classService.class});
    private static List<Class<?>> JCA30007_ANNOTATIONS =
        Arrays.asList(new Class<?>[] {AllowsPassByReference.classCallback.classComponentName.classConstructor.class,
                                   Context.classDestroy.classEagerInit.classInit.classIntent.class,
                                   Property.classQualifier.classReference.classScope.classService.class}); 
    private static List<Class<?>> JCA30008_ANNOTATIONS = Arrays.asList(new Class<?>[] {Intent.classQualifier.class}); 
    
    private void checkForbiddenAnnotations(Monitor monitorJavaInterfaceContract javaInterfaceContract) {
        if (javaInterfaceContract.getInterface() == null) {
            return;
        }
        Class<?> ifc = ((JavaInterfacejavaInterfaceContract.getInterface()).getJavaClass();
        if (ifc == null) {
            return;
        }
        for (Annotation a : ifc.getAnnotations()) {
            if (ifc.isInterface()) {
                if (.contains(a.annotationType())) {
                    error(monitor"ForbiddenAnnotationJCA30006"javaInterfaceContracta.annotationType(), ifc.getName());
                }
            } else {
                if (.contains(a.annotationType())) {
                    error(monitor"ForbiddenAnnotationJCA30008"javaInterfaceContracta.annotationType(), ifc.getName());
                }
            }
            
            if ( a.annotationType().equals(WebServiceClient.class) ) {
            	error(monitor"ForbiddenAnnotationJCA100018"javaInterfaceContracta.annotationType(), ifc.getName());
            }
            	
        }
        for (Method m : ifc.getMethods()) {
            for (Annotation a : m.getAnnotations()) {
                if (ifc.isInterface()) {
                    if (.contains(a.annotationType())) {
                        error(monitor"ForbiddenAnnotationJCA30006"javaInterfaceContracta.annotationType(), ifc.getName());
                    }
                } else {
                    if (.contains(a.annotationType())) {
                        error(monitor"ForbiddenAnnotationJCA30008"javaInterfaceContracta.annotationType(), ifc.getName());
                    }
                }
            }
        }
        for (Field f : ifc.getFields()) {
            for (Annotation a : f.getAnnotations()) {
                if (ifc.isInterface()) {
                    if (.contains(a.annotationType())) {
                        error(monitor"ForbiddenAnnotationJCA30006"javaInterfaceContracta.annotationType(), ifc.getName());
                    }
                } else {
                    if (.contains(a.annotationType())) {
                        error(monitor"ForbiddenAnnotationJCA30008"javaInterfaceContracta.annotationType(), ifc.getName());
                    }
                }
            }
        }
        
        if (javaInterfaceContract.getCallbackInterface() == null) {
            return;
        }
        ifc = ((JavaInterfacejavaInterfaceContract.getCallbackInterface()).getJavaClass();
        if (ifc == null) {
            return;
        }
        for (Annotation a : ifc.getAnnotations()) {
            if (ifc.isInterface()) {
                if (.contains(a.annotationType())) {
                    error(monitor"ForbiddenAnnotationJCA30007"javaInterfaceContracta.annotationType(), ifc.getName());
                }
            } else {
                if (.contains(a.annotationType())) {
                    error(monitor"ForbiddenAnnotationJCA30008"javaInterfaceContracta.annotationType(), ifc.getName());
                }
            }
        }
        for (Method m : ifc.getMethods()) {
            for (Annotation a : m.getAnnotations()) {
                if (ifc.isInterface()) {
                    if (.contains(a.annotationType())) {
                        error(monitor"ForbiddenAnnotationJCA30007"javaInterfaceContracta.annotationType(), ifc.getName());
                    }
                } else {
                    if (.contains(a.annotationType())) {
                        error(monitor"ForbiddenAnnotationJCA30008"javaInterfaceContracta.annotationType(), ifc.getName());
                    }
                }
            }
        }
        for (Field f : ifc.getFields()) {
            for (Annotation a : f.getAnnotations()) {
                if (ifc.isInterface()) {
                    if (.contains(a.annotationType())) {
                        error(monitor"ForbiddenAnnotationJCA30007"javaInterfaceContracta.annotationType(), ifc.getName());
                    }
                } else {
                    if (.contains(a.annotationType())) {
                        error(monitor"ForbiddenAnnotationJCA30008"javaInterfaceContracta.annotationType(), ifc.getName());
                    }
                }
            }
        }
    }
    public QName getArtifactType() {
        return ;
    }
    
        return JavaInterfaceContract.class;
    }
    
    private void postJAXWSProcessorResolve(JavaInterfaceContract javaInterfaceContractModelResolver resolverProcessorContext context)
        
        JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
        
        // the Java interface may now be marked as unresolved due to a new Java interface 
        // name retrieved from JAXWS annotations. Resolve it again if it is.
        if (javaInterface != null && javaInterface.isUnresolved()){
            javaInterface = resolveJavaInterface(javaInterfaceresolvercontext);
            javaInterfaceContract.setInterface(javaInterface);
        }
        
        JavaInterface javaCallbackInterface = (JavaInterface)javaInterfaceContract.getCallbackInterface();
        // the Java callback interface may now be marked as unresolved due to a new Java interface 
        // name retrieved from JAXWS annotations. Resolve it again if it is.
        if (javaCallbackInterface != null && javaCallbackInterface.isUnresolved()){
            javaCallbackInterface = resolveJavaInterface(javaCallbackInterfaceresolvercontext);
            javaInterfaceContract.setCallbackInterface(javaCallbackInterface);
        }
        
        // the Java interface may be replaced by a WSDL contract picked up from JAXWS annotation
        // if so we need to fluff up a WSDL contract and set it to be the normalized contract
        // for the Java interface so it's used during contract mapping
        if (javaInterface != null && javaInterface.getJAXWSWSDLLocation() != null){
            WSDLInterface wsdlInterface = .createWSDLInterface();
            wsdlInterface.setUnresolved(true);
            wsdlInterface.setRemotable(true);
            
            WSDLInterfaceContract wsdlInterfaceContract = .createWSDLInterfaceContract();
            wsdlInterfaceContract.setInterface(wsdlInterface);
            wsdlInterfaceContract.setLocation(javaInterface.getJAXWSWSDLLocation());
            javaInterfaceContract.setNormailizedWSDLContract(wsdlInterfaceContract);
            
            ProcessorContext wsdlContext = new ProcessorContext(javaInterface.getContributionContainingClass(), 
                                                                context.getMonitor());
            .resolve(wsdlInterfaceContractresolverwsdlContext);
            
            // check that the Java and WSDL contracts are compatible
            .checkCompatibility(wsdlInterfaceContract,
                                                       javaInterfaceContract
                                                       .
                                                       false
                                                       false);
            
            // copy policy from the WSDL interface to the Java interface
            javaInterface.getPolicySets().addAll(wsdlInterface.getPolicySets());
            javaInterface.getRequiredIntents().addAll(wsdlInterface.getRequiredIntents());
            
           // TODO - is there anything else to be copied from the user specified WSDL?
            
        }
        
        // TODO - how to handle callbacks as the location is stored at the contract level?        
    }      
New to GrepCode? Check out our FAQ X