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.impl;
 
 import java.util.List;
 
 
 
 import static org.apache.tuscany.sca.interfacedef.Operation.IDL_INPUT;
 import static org.apache.tuscany.sca.interfacedef.Operation.IDL_OUTPUT;
 
Represents a Java interface.

Version:
$Rev: 1061775 $ $Date: 2011-01-21 14:04:42 +0200 (Fri, 21 Jan 2011) $
 
 public class JavaInterfaceImpl extends InterfaceImpl implements JavaInterface {
 
     private String className;
     private WeakReference<Class<?>> javaClass;
     private Class<?> callbackClass;
     private QName qname;
     private String jaxwsWSDLLocation;
     private String jaxwsJavaInterfaceName;
     
     protected JavaInterfaceImpl() {
     	super();
     	// Mark the interface as unresolved until all the basic processing is complete
     	// including Intent & Policy introspection
     	this.setUnresolved(true);
     }
 
     public String getName() {
         if (isUnresolved()) {
             return ;
         } else if ( != null) {
             return .get().getName();
         } else {
             return null;
         }
     }
 
     public void setName(String className) {
         if (!isUnresolved()) {
             throw new IllegalStateException();
         }
         this. = className;
     }
 
     public QName getQName() {
         return ;
     }
 
     public void setQName(QName interfacename) {
          = interfacename;
     }
 
     public Class<?> getJavaClass() {
         if ( != null){
             return .get();
         } else {
             return null;
         }
     }
    public void setJavaClass(Class<?> javaClass) {
        this. = new WeakReference<Class<?>>(javaClass);
        if (javaClass != null) {
            this. = javaClass.getName();
        }
    }
    
    public Class<?> getCallbackClass() {
        return ;
    }
    
    public void setCallbackClass(Class<?> callbackClass) {
        this. = callbackClass;
    }
    
    @Override
    public String toString() {
        return getName();
    }
    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (( == null) ? 0 : .hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        JavaInterfaceImpl other = (JavaInterfaceImpl)obj;
        if (isUnresolved() || other.isUnresolved()) {
            if ( == null) {
                if (other.className != null)
                    return false;
            } else if (!.equals(other.className))
                return false;
        } else {
            if ( == null) {
                if (other.javaClass != null)
                    return false;
            } else if (!.get().equals(other.javaClass.get()))
                return false;
            if ( == null) {
                if (other.callbackClass != null)
                    return false;
            } else if (!.equals(other.callbackClass))
                return false;
        }
        return true;
    }
    
    public List<OperationgetOperations() {
    	if( !isUnresolved() && isAsyncServer() ) {
    		return equivalentSyncOperations();
    	} else {
    		return super.getOperations();
    	}
    } // end method getOperations
    
    private List<OperationsyncOperations = null;
    	if != null ) return ;
    	List<OperationallOperations = super.getOperations();
    	 = new ArrayList<Operation>();
    	forOperation operationallOperations) {
    	// Store the actual async operations under the attribute "ASYNC-SERVER-OPERATIONS"
    	this.getAttributes().put("ASYNC-SERVER-OPERATIONS"allOperations);
    	} // end for
    	
    	return ;
    } // end method equivalentSyncOperations
    
    private static final String UNKNOWN_DATABINDING = null;
    
Prepares the synchronous form of an asynchronous operation - async form: void someOperationAsync( FooType inputParam, DispatchResponse<BarType> ) - sync form: BarType someOperation( FooType inputParam )

Parameters:
operation - the operation to convert
Returns:
- the synchronous form of the operation - for an input operation that is not async server in form, this method simply returns the original operation unchanged
    private Operation getSyncFormOfOperationJavaOperation operation ) {
    	ifisAsyncServerOperationoperation ) ) {
            JavaOperation syncOperation = new JavaOperationImpl();
            String opName = operation.getName().substring(0, operation.getName().length() - 5 );
        	
            // Prepare the list of equivalent input parameters, which simply excludes the (final) DispatchResponse object
            // and the equivalent return parameter, which is the (generic) type from the DispatchResponse object
            DataType<List<DataType>> requestParams = operation.getInputType();
        	DataType<List<DataType>> inputType = prepareSyncInputParamsrequestParams );
            DataType<List<DataType>> returnDataType = prepareSyncReturnParamrequestParams );
            List<DataTypefaultDataTypes = prepareSyncFaultsoperation );
        	
        	syncOperation.setName(opName);
        	syncOperation.setAsyncServer(true);
            syncOperation.setInputType(inputType);
            syncOperation.setOutputType(returnDataType);
            syncOperation.setFaultTypes(faultDataTypes);
            syncOperation.setNonBlocking(operation.isNonBlocking());
            syncOperation.setJavaMethod(operation.getJavaMethod());
            syncOperation.setInterface(this);
    		return syncOperation;
    	} else {
    		// If it's not Async form, then it's a synchronous operation
    		return operation;
    	} // end if
    } // end getSyncFormOfOperation
    
    
Produce the equivalent sync method input parameters from the input parameters of the async method

Parameters:
requestParams - async method input parameters
Returns:
- the equivalent sync method input parameters
    private DataType<List<DataType>> prepareSyncInputParamsDataType<List<DataType>> requestParams ) {
        List<DataTyperequestLogical = requestParams.getLogical();
    	int paramCount = requestLogical.size();
    	
    	// Copy the list of async parameters, removing the final DispatchResponse
    	List<DataTypeasyncParams = new ArrayList<DataType>( paramCount - 1);
    	forint i = 0 ; i < (paramCount - 1) ; i++ ) {
    		asyncParams.addrequestLogical.get(i) );
    	} // end for
    	
    	DataType<List<DataType>> inputType =
            new DataTypeImpl<List<DataType>>(requestParams.getDataBinding(),
            		                         requestParams.getPhysical(), asyncParams);
    	return inputType;
    } // end method prepareSyncInputParams
    
    
Prepare the return data type of the equivalent sync operation, based on the parameterization of the ResponseDispatch object of the async operation - the return data type is the Generic type of the final DispatchResponse<?>

Parameters:
requestParams - - async method input parameters
Returns:
- the sync method return parameter
    @SuppressWarnings("rawtypes")
	private DataType<List<DataType>> prepareSyncReturnParamDataType<List<DataType>> requestParams ) {
    	List<DataTyperequestLogical = requestParams.getLogical();
    	int paramCount = requestLogical.size();
    	
    	DataType<?> finalParam = requestLogical.getparamCount - 1 );
    	XMLType returnXMLType = (XMLType)finalParam.getLogical();
    	
    	String namespace = null;
    	ifreturnXMLType.isElement() ) {
    		namespace = returnXMLType.getElementName().getNamespaceURI();
    	} else {
    		namespace = returnXMLType.getTypeName().getNamespaceURI();
    	}
    	
    	Type[] typeArgs = t.getActualTypeArguments();
    	iftypeArgs.length != 1 ) throw new IllegalArgumentException"ResponseDispatch parameter is not parameterized correctly");
    	
    	Class<?> returnType = (Class<?>)typeArgs[0];
        
    	// Set outputType to null for void
        XMLType xmlReturnType = new XMLType(new QName(namespace"return"), null);
        DataType<XMLTypereturnDataType =
            returnType == void.class ? null : new DataTypeImpl<XMLType>(returnTypexmlReturnType);
        
        ArrayList<DataTypereturnTypes = new ArrayList<DataType>();
        returnTypes.add(returnDataType);
        
        DataType<List<DataType>> outputType =
            new DataTypeImpl<List<DataType>>(requestParams.getPhysical(), returnTypes);
    
        return outputType;
    } // end method prepareSyncReturnParam
    
    
Prepare the set of equivalent sync faults for a given async operation

Returns:
- the list of faults
    private List<DataTypeprepareSyncFaultsJavaOperation operation ) {
    	//TODO - deal with Faults - for now just copy through whatever is associated with the async operation
    	return operation.getFaultTypes();
    }
    
    
Determines if an interface operation has the form of an async server operation - async form: void someOperationAsync( FooType inputParam, ...., DispatchResponse<BarType> )

Parameters:
operation - the operation to examine
Returns:
- true if the operation has the form of an async operation, false otherwise
    private boolean isAsyncServerOperationOperation operation ) {
    	// Async form operations have:
    	// 1) void return type (equivalent to an output logical List of size '0')
    	// 2) name ending in "Async"
    	// 3) final parameter which is of ResponseDispatch<?> type
    	int size = operation.getOutputType().getLogical().size();
    	if (size != 0) {
    	    return false;
    	}
    	
    	if ( !operation.getName().endsWith("Async") ) return false;
    	
    	DataType<List<DataType>> requestParams = operation.getInputType();
    	int paramCount = requestParams.getLogical().size();
    	ifparamCount < 1 ) return false;
    	DataType<?> finalParam = requestParams.getLogical().getparamCount - 1 );
    	if ( finalParam.getPhysical() != ResponseDispatch.class ) return false;
    	
    	return true;
    } // end method isAsyncServerOperation
    
    static QName ASYNC_INVOCATION = new QName(."asyncInvocation");
    
Indicates if this interface is an Async Server interface

Returns:
true if the interface is Async Server, false otherwise
    private boolean isAsyncServer() {
    	
    	List<Intentintents = getRequiredIntents();
    	forIntent intentintents ) {
    		if ( intent.getName().equals() ) {
    			return true;
    		}
    	} // end for
    	return false;
    } // end method isAsyncServer
    
    public String getJAXWSWSDLLocation() {
        return ;
    }
    
    public void setJAXWSWSDLLocation(String wsdlLocation) {
        this. = wsdlLocation;
    }
    
    public String getJAXWSJavaInterfaceName() {
        return ;
    }
    
    public void setJAXWSJavaInterfaceName(String javaInterfaceName) {
        this. = javaInterfaceName;
    }
    
    
A Java class may reference a WSDL file via a JAXWS annotation. We need to resolve the WSDL file location in the context of the same contribution that holds the Java file. In order to do this we need to remember the actual contribution that was used to resolve a Java class.

Returns:
        return ;
    }
    
    public void setContributionContainingClass(Contribution contributionContainingClass) {
        this. = contributionContainingClass;
    }
New to GrepCode? Check out our FAQ X