You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ja...@apache.org on 2005/06/28 17:07:11 UTC

svn commit: r202218 - in /webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws: src/org/ src/org/apache/ src/org/apache/axis/ src/org/apache/axis/jaxrpc/ test/ test/org/ test/org/apache/ test/org/apache/axis/ test/org/apache/axis/jaxrpc/

Author: jayachandra
Date: Tue Jun 28 08:07:09 2005
New Revision: 202218

URL: http://svn.apache.org/viewcvs?rev=202218&view=rev
Log:
committing ServiceFactory implementation so far, and parallel junit test code.

Added:
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/ServiceFactoryImpl.java
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/apache/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/apache/axis/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/apache/axis/jaxrpc/
    webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/apache/axis/jaxrpc/ServiceFactoryTest.java

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/ServiceFactoryImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/ServiceFactoryImpl.java?rev=202218&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/ServiceFactoryImpl.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/src/org/apache/axis/jaxrpc/ServiceFactoryImpl.java Tue Jun 28 08:07:09 2005
@@ -0,0 +1,162 @@
+package org.apache.axis.jaxrpc;
+
+import java.net.URL;
+import java.util.Properties;
+
+import javax.xml.namespace.QName;
+import javax.xml.rpc.Service;
+import javax.xml.rpc.ServiceException;
+import javax.xml.rpc.ServiceFactory;
+
+public class ServiceFactoryImpl extends ServiceFactory {
+
+	private Service serviceClass = null;
+	
+	public ServiceFactoryImpl() {
+		super();
+	}
+
+	/**
+	 * Method createService
+	 * Create a Service instance.
+	 * @param wsdlDocumentLocation URL for the WSDL document location for the service
+	 * @param serviceName QName for the service.
+	 * @return a <code>Service</code> instance
+	 * @throws ServiceException
+	 */
+	@Override
+	public Service createService(URL wsdlDocumentLocation, QName serviceName)
+			throws ServiceException {
+		
+		if(serviceClass == null) {
+			//As of now properties isn't finalized. So send null
+			//TODO Revisit this after finalizing how property resources
+			//		would be fed to our implementation.
+			serviceClass = loadService(wsdlDocumentLocation, serviceName, null);
+		}
+		return serviceClass;
+	}
+
+	/**
+	 * Method loadService
+	 * Create an instance of the generated service implementation class for a given service interface, if available.
+	 * @param serviceInterface Service interface 
+	 * @return ??? read the spec once again
+	 * @throws ServiceException If there is any error while creating the specified service, including the case where a generated service implementation class cannot be located
+	 */
+	@Override
+	public Service loadService(Class serviceInterface) throws ServiceException {
+		return loadService(null, serviceInterface, null);
+	}
+
+	/**
+	 * Method loadService
+	 * Create an instance of the generated service implementation class for a 
+	 * given service interface, if available. An implementation may use the 
+	 * provided wsdlDocumentLocation and properties to help locate the 
+	 * generated implementation class. If no such class is present, a 
+	 * ServiceException will be thrown.
+	 * @param wsdlDocumentLocation URL for the WSDL document location for the service or null
+	 * @param serviceInterface Service interface
+	 * @param properties A set of implementation-specific properties to help locate the generated service implementation class 
+	 * @return ??? read the spec once again
+	 * @throws ServiceException If there is any error while creating the specified service, including the case where a generated service implementation class cannot be located
+	 */
+	@Override
+	public Service loadService(URL wsdlDocumentLocation,
+			Class serviceInterface, Properties properties)
+			throws ServiceException {
+		Service returnClass;
+		//Check if serviceInterface is already available to load and return
+		try {
+			returnClass = (Service)serviceInterface.newInstance();
+		} catch (InstantiationException e) {
+			//attempt to load the interface failed, so lets check other
+			//alternative - interpret the generated service class using wsdl
+			//location and or properties and see if you have any luck
+			String serviceClassName;
+			serviceClassName = interpretServiceClassName(wsdlDocumentLocation, properties);
+			Class loadedClass;
+			try {
+				loadedClass = Thread.currentThread().getContextClassLoader().loadClass(serviceClassName);
+				returnClass = (Service)loadedClass.newInstance();
+			} catch (Exception e1) {
+				throw new ServiceException(e1);
+			}
+		} catch (IllegalAccessException e) {
+			throw new ServiceException(e);
+		}
+		return returnClass;
+	}
+
+	/**
+	 * Method loadService
+	 * Create an instance of the generated service implementation class for a 
+	 * given service, if available. The service is uniquely identified by the 
+	 * wsdlDocumentLocation and serviceName arguments. An implementation may 
+	 * use the provided properties to help locate the generated implementation 
+	 * class. If no such class is present, a ServiceException will be thrown.
+	 * @param wsdlDocumentLocation URL for the WSDL document location for the service or null
+	 * @param serviceName Qualified name for the service
+	 * @param properties A set of implementation-specific properties to help locate the generated service implementation class 
+	 * @return ??? read the spec once again
+	 * @throws ServiceException If there is any error while creating the specified service, including the case where a generated service implementation class cannot be located
+	 */
+	@Override
+	public Service loadService(URL wsdlDocumentLocation, QName serviceName,
+			Properties properties) throws ServiceException {
+		Service returnClass = null;
+		// TODO Need to consult someone, I'm not fully clear abt this implmntn
+		// as to how should wsdlDocumentLocation be used etc.
+		if (properties != null) {
+			//TODO Do something and get the name of the generated service 
+			//implementation class name
+			//load the class with that name, instantiate it and return
+			return null;
+		}
+		else {
+			//Interpreting the name of generated class for this service
+			//WITHOUT taking into consideration name-collisions.
+			//TODO Revisit to embedd name collision logic
+			String localPart = serviceName.getLocalPart();
+			String packageName = getGeneratedClassPackageName(serviceName);
+			try {
+				returnClass = (Service)Thread.currentThread().getContextClassLoader().loadClass(packageName + "." + localPart).newInstance();
+			} catch (Exception e) {
+				throw new ServiceException(e);
+			}
+		}
+		return returnClass;
+	}
+
+	/**
+	 * Method getServiceClassName
+	 * This will interpret and return the name of the generated Service 
+	 * implementation class using wsdl location and or properties
+	 * @param wsdlDocumentLocation
+	 * @param properties
+	 */
+	private String interpretServiceClassName(URL wsdlDocumentLocation, Properties properties) {
+		//This code could be a tiny beast, code little by little
+		String serviceClassName = null;
+		if (wsdlDocumentLocation==null && properties == null) {
+			//Not wise to spend time trying to interpret serviceName out of nulls :)
+			return null;
+		}
+		//TODO method implementation is not complete
+		
+		return serviceClassName;
+	}
+	
+	/**
+	 * Method getGeneratedClassPackageName
+	 * Returns the package in which requested class was generated
+	 * @param className
+	 * @return
+	 */
+	public String getGeneratedClassPackageName (QName className) {
+		//TODO Providing just a hard coded makeshift implementation for now
+		//Need to properly code the method.
+		return new String("defaultPackage");
+	}
+}//class ServiceFactoryImpl.

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/apache/axis/jaxrpc/ServiceFactoryTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/apache/axis/jaxrpc/ServiceFactoryTest.java?rev=202218&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/apache/axis/jaxrpc/ServiceFactoryTest.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/jaxws/test/org/apache/axis/jaxrpc/ServiceFactoryTest.java Tue Jun 28 08:07:09 2005
@@ -0,0 +1,34 @@
+package org.apache.axis.jaxrpc;
+
+import junit.framework.TestCase;
+
+import javax.xml.rpc.ServiceFactory;
+import javax.xml.rpc.Service;
+import javax.xml.namespace.QName;
+
+public class ServiceFactoryTest extends TestCase {
+
+	public ServiceFactoryTest(String name) {
+		super(name);
+	}
+	
+	public void testServiceFactoryInstantiation() {
+		try {
+			ServiceFactory sf = ServiceFactory.newInstance();
+			assertTrue(sf!=null);
+		} catch (Exception e) {
+			fail(e.getMessage());
+		}
+	}
+	
+	public void testServiceCreation() {
+		try {
+			ServiceFactory sf = ServiceFactory.newInstance();
+			Service s = sf.createService(null,new QName("http://defaultPackage","Echo"));
+			assertTrue(s!=null);
+		} catch (Exception e) {
+			fail(e.getMessage());
+		}
+	}
+
+}