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 bu...@apache.org on 2002/02/11 19:55:29 UTC
cvs commit: xml-axis/java/src/org/apache/axis/client ServiceFactory.java Service.java
butek 02/02/11 10:55:29
Modified: java/src/org/apache/axis/client ServiceFactory.java
Service.java
Log:
Round 2 to make the Service object Referenceable. I think I got it this time. Test
case to follow (hopefully soon).
Revision Changes Path
1.6 +79 -1 xml-axis/java/src/org/apache/axis/client/ServiceFactory.java
Index: ServiceFactory.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/ServiceFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServiceFactory.java 7 Feb 2002 13:46:36 -0000 1.5
+++ ServiceFactory.java 11 Feb 2002 18:55:29 -0000 1.6
@@ -59,8 +59,23 @@
import org.apache.axis.AxisFault;
import org.apache.axis.configuration.DefaultEngineConfigurationFactory;
+import javax.naming.Context;
import javax.naming.InitialContext;
+import javax.naming.Name;
import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+import javax.naming.spi.ObjectFactory;
+
+import javax.xml.rpc.namespace.QName;
+
+import java.lang.reflect.Constructor;
+
+import java.net.URL;
+
+import java.util.Hashtable;
import java.util.Map;
/**
@@ -71,7 +86,14 @@
* @author Glen Daniels (gdaniels@macromedia.com)
*/
-public class ServiceFactory {
+public class ServiceFactory implements ObjectFactory {
+ // Constants for RefAddrs in the Reference.
+ public static final String SERVICE_CLASSNAME = "service classname";
+ public static final String WSDL_LOCATION = "WSDL location";
+ public static final String MAINTAIN_SESSION = "maintain session";
+ public static final String SERVICE_NAMESPACE = "service namespace";
+ public static final String SERVICE_LOCAL_PART = "service local part";
+
private static EngineConfiguration defaultEngineConfig =
(new DefaultEngineConfigurationFactory()).getClientEngineConfig();
private static ThreadLocal threadDefaultConfig = new ThreadLocal();
@@ -136,4 +158,60 @@
return service;
}
+
+ public Object getObjectInstance(Object refObject, Name name,
+ Context nameCtx, Hashtable environment) throws Exception
+ {
+ Object instance = null;
+ if (refObject instanceof Reference) {
+ Reference ref = (Reference) refObject;
+
+ RefAddr addr = ref.get(SERVICE_CLASSNAME);
+ Object obj = null;
+ // If an explicit service classname is provided, then this is a
+ // generated Service class. Just use its default constructor.
+ if (addr != null && (obj = addr.getContent()) instanceof String) {
+ instance = Class.forName((String) obj).newInstance();
+ }
+ // else this is an instance of the Service class, so grab the
+ // reference data...
+ else {
+ // Get the WSDL location...
+ addr = ref.get(WSDL_LOCATION);
+ if (addr != null && (obj = addr.getContent()) instanceof String) {
+ URL wsdlLocation = new URL((String) obj);
+
+ // Build the service qname...
+ addr = ref.get(SERVICE_NAMESPACE);
+ if (addr != null
+ && (obj = addr.getContent()) instanceof String) {
+ String namespace = (String) obj;
+ addr = ref.get(SERVICE_LOCAL_PART);
+ if (addr != null
+ && (obj = addr.getContent()) instanceof String) {
+ String localPart = (String) obj;
+ QName serviceName = new QName(namespace, localPart);
+
+ // Construct an instance of the service
+ Class[] formalArgs = new Class[]
+ {URL.class, QName.class};
+ Object[] actualArgs = new Object[]
+ {wsdlLocation, serviceName};
+ Constructor ctor =
+ Service.class.getDeclaredConstructor(
+ formalArgs);
+ instance = ctor.newInstance(actualArgs);
+ }
+ }
+ }
+ }
+ // If maintainSession should be set to true, there will be an
+ // addr for it.
+ addr = ref.get(MAINTAIN_SESSION);
+ if (addr != null && instance instanceof Service) {
+ ((Service) instance).setMaintainSession(true);
+ }
+ }
+ return instance;
+ } // getObjectInstance
}
1.42 +40 -2 xml-axis/java/src/org/apache/axis/client/Service.java
Index: Service.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Service.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- Service.java 8 Feb 2002 03:18:48 -0000 1.41
+++ Service.java 11 Feb 2002 18:55:29 -0000 1.42
@@ -65,6 +65,7 @@
import javax.naming.Reference;
import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
import javax.wsdl.Binding;
import javax.wsdl.Definition;
@@ -79,6 +80,7 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;
@@ -152,6 +154,7 @@
*/
public Service(URL wsdlDoc, QName serviceName) throws ServiceException {
engine = getAxisClient();
+ this.wsdlLocation = wsdlDoc;
Document doc = XMLUtils.newDocument(wsdlDoc.toString());
initService(doc, serviceName);
}
@@ -171,6 +174,11 @@
throws ServiceException {
engine = getAxisClient();
try {
+ this.wsdlLocation = new URL(wsdlLocation);
+ }
+ catch (MalformedURLException mue) {
+ }
+ try {
// Start by reading in the WSDL using WSDL4J
FileInputStream fis = new FileInputStream(wsdlLocation);
Document doc = XMLUtils.newDocument(fis);
@@ -215,7 +223,6 @@
reader.setFeature("javax.wsdl.verbose", false);
Definition def = reader.readWSDL( null, doc );
- this.wsdlLocation = null ;
this.wsdlDefinition = def ;
// grrr! Too many flavors of QName
@@ -466,7 +473,38 @@
* @return Reference ...
*/
public Reference getReference() {
- return new Reference(this.getClass().getName());
+ String classname = this.getClass().getName();
+ Reference reference = new Reference(classname,
+ "org.apache.axis.client.ServiceFactory", null);
+ StringRefAddr addr = null;
+ if (!classname.equals("org.apache.axis.client.Service")) {
+ // This is a generated derived class. Don't bother with
+ // all the Service instance variables.
+ addr = new StringRefAddr(
+ ServiceFactory.SERVICE_CLASSNAME, classname);
+ reference.add(addr);
+ }
+ else {
+ if (wsdlLocation != null) {
+ addr = new StringRefAddr(
+ ServiceFactory.WSDL_LOCATION, wsdlLocation.toString());
+ reference.add(addr);
+ }
+ QName serviceName = getServiceName();
+ if (serviceName != null) {
+ addr = new StringRefAddr(ServiceFactory.SERVICE_NAMESPACE,
+ serviceName.getNamespaceURI());
+ reference.add(addr);
+ addr = new StringRefAddr(ServiceFactory.SERVICE_LOCAL_PART,
+ serviceName.getLocalPart());
+ reference.add(addr);
+ }
+ }
+ if (maintainSession) {
+ addr = new StringRefAddr(ServiceFactory.MAINTAIN_SESSION, "true");
+ reference.add(addr);
+ }
+ return reference;
}
/**