axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jayachan...@apache.org
Subject svn commit: r216126 - in /webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client: CallImpl.java ServiceFactoryImpl.java ServiceImpl.java
Date Wed, 13 Jul 2005 08:29:17 GMT
Author: jayachandra
Date: Wed Jul 13 01:29:16 2005
New Revision: 216126

URL: http://svn.apache.org/viewcvs?rev=216126&view=rev
Log:
More implementation into Call. Plz ignore the weird comments, if any. I've added them to help
me in my coding later

Modified:
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/CallImpl.java
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceFactoryImpl.java
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceImpl.java

Modified: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/CallImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/CallImpl.java?rev=216126&r1=216125&r2=216126&view=diff
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/CallImpl.java
(original)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/CallImpl.java
Wed Jul 13 01:29:16 2005
@@ -20,6 +20,10 @@
 import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.BufferedOutputStream;
+import java.net.URI;
 
 import javax.wsdl.Operation;
 import javax.xml.namespace.QName;
@@ -29,9 +33,21 @@
 import javax.xml.rpc.ParameterMode;
 import javax.xml.rpc.soap.SOAPFaultException;
 
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMOutput;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.AddressingConstants;
+
 /**
  * @author sunja07
- *
+ * Class CallImpl
+ * <documentation> to be completed </documentation>
+ * 
+ * Forget not that Call instance is MUTABLE. i.e. the configuration of call
+ * instance can be changed and it can be re-used for some other need.
  */
 public class CallImpl extends BindingProviderImpl implements javax.xml.rpc.Call {
 
@@ -57,7 +73,13 @@
 	 * Field returnType
 	 * The xml return type to expect from the method invocation
 	 */
-	private static QName returnType;
+	private QName returnType;
+	
+	/**
+	 * Field returnTypeClass
+	 * The java class into which return value will be stuffed.
+	 */
+	private Class returnTypeClass;
 	
 	/**
 	 * Field paramAndReturnSpecRequired
@@ -65,7 +87,7 @@
 	 * the operation corresponding to this Call object has to have the
 	 * parameters added explicitly and return type specified explicitly
 	 */
-	protected static boolean paramAndReturnSpecRequired;
+	protected static boolean paramAndReturnSpecRequired=false;
 	
 	/**
 	 * Field propertyBag
@@ -83,6 +105,10 @@
 	private static HashMap outputParams = new HashMap();
 	
 	/**
+	 * Field service object from which this call instance is created.
+	 */
+	private transient ServiceImpl service;
+	/**
 	 * 
 	 */
 	public CallImpl() {
@@ -163,6 +189,10 @@
 			UnsupportedOperationException, JAXRPCException {
 		// TODO Auto-generated method stub
 
+		//don't know about rest of the impl. But at least, adding parameter
+		//would override the default false value of paramAndSpecRequired to true
+		paramAndReturnSpecRequired = true;
+
 	}
 
 	/**
@@ -188,9 +218,39 @@
 	 */
 	public void setReturnType(QName xmlType) throws JAXRPCException,
 			IllegalArgumentException, UnsupportedOperationException {
-		// TODO Auto-generated method stub
+		if(operationName==null) {
+			throw new JAXRPCException("Can't set returnType. Try setting the " +
+					"operationName prior to calling setReturnType");
+		}
+		if(isParameterAndReturnSpecRequired(operationName)==false) {
+			throw new JAXRPCException("Call instance is configured not to " +
+					"specify Parameter and ReturnType");
+		}
+		
+		//TODO identify if the QName is valid, if not, throw IllegalArgumentException
+		this.returnType = xmlType;
+		if(service.isJAXB_USAGE()){
+			Class jaxbBindedObjectClass = getJAXBObjectClassForQName(xmlType);
+			returnTypeClass = jaxbBindedObjectClass;
+		}
+		else { //no JAXB_USAGE, so try getting things from registered TypeMapping
+		//TODO get the java type mapped to this xmlType QName and set it as the 
+		//returnTypeClass
+		
+		//come to think of this, we don't need to identify the mapped javaType
+		//and set the returnTypeClass with it. Actually in the invoke method itself
+		//we will get hold of the corresponding deserializer and ask it to
+		//prepare the object out of the response OMElement. How does that sound!?!
+		
+		}
 
 	}
+	
+	//This can be a utils class method
+	public Class getJAXBObjectClassForQName(QName xmlType) {
+		//This is a black box for now
+		return Object.class;
+	}
 
 	/**
 	 * Method setReturnType
@@ -210,8 +270,39 @@
 	public void setReturnType(QName xmlType, Class javaType)
 			throws UnsupportedOperationException, IllegalArgumentException,
 			JAXRPCException {
-		// TODO Auto-generated method stub
-
+		if(operationName==null) {
+			throw new JAXRPCException("Can't set returnType. Try setting the " +
+					"operationName prior to calling setReturnType");
+		}
+		if(isParameterAndReturnSpecRequired(operationName)==false) {
+			throw new JAXRPCException("Call instance is configured not to " +
+					"specify Parameter and ReturnType");
+		}
+		
+		//TODO identify if the QName is valid, if not, throw IllegalArgumentException
+		
+		this.returnType = xmlType;
+		
+		if(service.isJAXB_USAGE()) { //JAXB is used
+			//check if the JAXB bound class is compatible with the javaType
+			//class mentioned here. If not throw JAXRPCException
+			Class jaxbBindedJavaClass = getJAXBObjectClassForQName(xmlType);
+			if(javaType.isAssignableFrom(jaxbBindedJavaClass)) {
+				this.returnTypeClass = javaType;
+			}
+			else
+				throw new JAXRPCException("Set return type java class can't be cast " +
+						"from underlying JAXB databinding object");
+		}
+		else {//no JAXB.
+			//check if the typeMapping has a registration for this xmlType
+			//and javaType pair. If not, throw JAXRPCException
+			if(!service.getTypeMappingRegistry().
+					getTypeMapping(ENCODINGSTYLE_URI_PROPERTY).
+					isRegistered(javaType,xmlType))
+				throw new JAXRPCException("Invalid javaType for xmlType. " +
+						"Underlying type mapping has no corresponding pair registered");
+		}
 	}
 
 	/**
@@ -375,6 +466,39 @@
 	public Object invoke(Object[] inputParams) throws RemoteException,
 			SOAPFaultException, JAXRPCException {
 
+		//check if the call instance is properly configured. If not throw
+		//a JAXRPCException.
+		
+		//I'll try to create an OMElement that would wrap the input params
+		//and use that to invoke the invokeBlocking() method of Axis2's call
+		//implementation.
+		//I'm not sure if the way I wrap the contents into an OMElement should
+		//keep track of any properties set on the call object viz. style and
+		//use. For now am just wrapping each element as a child in the method
+		//element
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		String operationNS = operationName.getNamespaceURI();
+		OMNamespace omNS = (operationNS == null || operationNS == "")? fac.createOMNamespace("http://jaxwsforaxis2.org","ns1"):
fac.createOMNamespace(operationNS, "ns1");
+		OMElement methodElement = fac.createOMElement(operationName.getLocalPart(),omNS);
+		for(int i=0; i<inputParams.length;i++) {
+			OMElement paramElement = fac.createOMElement("param"+String.valueOf(i),omNS);
+			paramElement.addChild(fac.createText(inputParams[i].toString()));
+			methodElement.addChild(paramElement);
+		}
+		
+		org.apache.axis2.clientapi.Call axis2Call = new org.apache.axis2.clientapi.Call();
+		axis2Call.setTo(new EndpointReference(AddressingConstants.WSA_TO,"http://localhost:9090/axis/services/Echo"));
+		OMElement response = axis2Call.invokeBlocking(operationName.getLocalPart(),methodElement);
+		
+		//Now the job of extracting the return value out of the OMElement and
+		//populating it into the ReturnType.
+		//As 'response' we already get the contents of soap body.
+		OMElement returnValue = response.getFirstElement();
+		//corresponding to the returnType set, we should get a java object
+		//instantiated and fill in the contents into the datamembers and return 
+		//that object
+		Object returnObject = getReturnObject(returnType);
+		
 		// ---
 		// some solid code will have to go here
 		// ---
@@ -388,10 +512,20 @@
 		outputParams.clear();
 		//populateOutputParams(operationName); // a private method to be coded
 		
-		// TODO Auto-generated method stub
-		return null;
+		//Returning the request OMElement only for testing purposes
+		return response;
+		
+	}
+	
+	public Object getReturnObject(QName returnType) {
 		
+		//if there has been a class registered associated with this QName
+		//return that class
+		if (returnTypeClass != null) {
+			//Object returnObject = 
+		}
 		
+		return null;
 	}
 
 	/**
@@ -414,6 +548,9 @@
 	public Object invoke(QName operationName, Object[] inputParams)
 			throws RemoteException {
 		
+		//check if the call instance is properly configured. If not throw
+		//a JAXRPCException.
+		
 		//---
 		// some solid code will have to go here
 		// ---
@@ -471,6 +608,20 @@
 	 */
 	public List getOutputValues() throws JAXRPCException {
 		return (List)outputParams.values();
+	}
+
+	/**
+	 * @return Returns the service.
+	 */
+	public ServiceImpl getService() {
+		return service;
+	}
+
+	/**
+	 * @param service The service to set.
+	 */
+	public void setService(ServiceImpl service) {
+		this.service = service;
 	}
 
 }

Modified: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceFactoryImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceFactoryImpl.java?rev=216126&r1=216125&r2=216126&view=diff
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceFactoryImpl.java
(original)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceFactoryImpl.java
Wed Jul 13 01:29:16 2005
@@ -32,7 +32,11 @@
 	@Override
 	public Service createService(URL wsdlDocumentLocation, QName serviceName)
 			throws ServiceException {
-		
+		return createService(wsdlDocumentLocation, serviceName, true);
+	}
+	
+	public Service createService(URL wsdlDocumentLocation, QName serviceName, boolean jaxbUsage)
+		throws ServiceException {
 		if(parserWrapper==null) {
 			//Here am hard coding the parser choice. Should think of better
 			//flexible implementation
@@ -40,7 +44,7 @@
 			
 		}
 		javax.wsdl.Service wsdlService = parserWrapper.getService(wsdlDocumentLocation, serviceName);
-		service = (Service) new ServiceImpl(parserWrapper, wsdlService);
+		service = (Service) new ServiceImpl(parserWrapper, wsdlService, jaxbUsage);
 		
 		return service;
 	}

Modified: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceImpl.java?rev=216126&r1=216125&r2=216126&view=diff
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceImpl.java
(original)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/client/ServiceImpl.java
Wed Jul 13 01:29:16 2005
@@ -56,7 +56,7 @@
 	
 	private TypeMappingRegistry typeMappingRegistry;
 
-	public static boolean JAXB_USAGE = true;
+	public boolean JAXB_USAGE = true;
 	
 	public String wsdlLoc = null;
 	
@@ -74,6 +74,7 @@
 	 */
 	public Call createCall() throws ServiceException {
 		Call call = new CallImpl();
+		((CallImpl)call).setService(this);
 		return call;
 	}
 	
@@ -558,8 +559,7 @@
 	 */
 	public SecurityConfiguration getSecurityConfiguration() throws 
 	UnsupportedOperationException {
-		// TODO Auto-generated method stub
-		return null;
+		throw new UnsupportedOperationException();
 	}
 
 	/**
@@ -623,19 +623,26 @@
 		this.parserWrapper = parserWrap;
 		this.wsdlService = wsdlSvc;
 	}
+	
+	public ServiceImpl(JAXRPCWSDLInterface parserWrap, Service wsdlSvc, boolean jaxbUsage) {
+		super();
+		this.parserWrapper = parserWrap;
+		this.wsdlService = wsdlSvc;
+		this.JAXB_USAGE = jaxbUsage;
+	}
 
 	/**
 	 * @return Returns the JAXB_USAGE.
 	 */
-	public static boolean isJAXB_USAGE() {
-		return JAXB_USAGE;
+	public boolean isJAXB_USAGE() {
+		return this.JAXB_USAGE;
 	}
 
 	/**
 	 * @param jaxb_usage The JAXB_USAGE to set.
 	 */
-	public static void setJAXB_USAGE(boolean jaxb_usage) {
-		JAXB_USAGE = jaxb_usage;
+	public void setJAXB_USAGE(boolean jaxb_usage) {
+		this.JAXB_USAGE = jaxb_usage;
 	}
 
 }



Mime
View raw message