1 57 58 package org.apache.wsif.naming; 59 60 import java.util.Hashtable ; 61 62 import javax.naming.Context ; 63 import javax.naming.Name ; 64 import javax.naming.RefAddr ; 65 import javax.naming.Reference ; 66 import javax.naming.spi.ObjectFactory ; 67 import org.apache.wsif.WSIFService; 68 import org.apache.wsif.WSIFServiceFactory; 69 import org.apache.wsif.logging.Trc; 70 71 82 public class WSIFServiceObjectFactory implements ObjectFactory { 83 84 public WSIFServiceObjectFactory() { 86 Trc.entry(this); 87 Trc.exit(); 88 } 89 90 103 public Object getObjectInstance( 104 Object obj, 105 Name name, 106 Context context, 107 Hashtable env) 108 throws Exception { 109 Trc.entry(this, obj, name, context, env); 110 111 if (obj instanceof Reference && obj != null) { 113 Reference ref = (Reference ) obj; 114 if (ref.getClassName().equals(WSIFServiceRef.class.getName())) { 115 String wsdlLoc = resolveString(ref.get("wsdlLoc")); 116 String serviceNS = resolveString(ref.get("serviceNS")); 117 String serviceName = resolveString(ref.get("serviceName")); 118 String portTypeNS = resolveString(ref.get("portTypeNS")); 119 String portTypeName = resolveString(ref.get("portTypeName")); 120 121 if (wsdlLoc != null) { 122 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 123 WSIFService service = 124 factory.getService(wsdlLoc, serviceNS, serviceName, portTypeNS, portTypeName); 125 Trc.exit(service); 126 return service; 127 } 128 } else if (ref.getClassName().equals(WSIFServiceStubRef.class.getName())) { 129 String wsdlLoc = resolveString(ref.get("wsdlLoc")); 130 String serviceNS = resolveString(ref.get("serviceNS")); 131 String serviceName = resolveString(ref.get("serviceName")); 132 String portTypeNS = resolveString(ref.get("portTypeNS")); 133 String portTypeName = resolveString(ref.get("portTypeName")); 134 String preferredPort = resolveString(ref.get("preferredPort")); 135 String className = resolveString(ref.get("className")); 136 137 if (wsdlLoc != null) { 138 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 139 WSIFService service = 140 factory.getService(wsdlLoc, serviceNS, serviceName, portTypeNS, portTypeName); 141 Class iface = 142 Class.forName(className, true, Thread.currentThread().getContextClassLoader()); 143 Object stub = service.getStub(preferredPort, iface); 144 Trc.exit(stub); 145 return stub; 146 } 147 } 148 } 149 Trc.exit(); 152 return null; 153 } 154 155 private String resolveString(RefAddr a) { 156 String e = ""; 157 String s = (String ) a.getContent(); 158 return (e.equals(s)) ? null : s; 159 } 160 } | Popular Tags |