1 23 package com.sun.enterprise.webservice; 24 25 import java.lang.UnsupportedOperationException ; 26 27 import java.net.URL ; 28 import java.net.URI ; 29 30 import java.util.HashSet ; 31 import java.util.Set ; 32 import java.util.Map ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 import java.util.concurrent.Executor ; 37 38 import java.lang.reflect.Method ; 39 40 import javax.xml.namespace.QName ; 41 import javax.xml.bind.JAXBContext; 42 43 import javax.xml.ws.Service; 44 import javax.xml.ws.Dispatch; 45 import javax.xml.ws.handler.HandlerResolver; 46 47 import com.sun.enterprise.deployment.ServiceReferenceDescriptor; 48 import com.sun.enterprise.deployment.ServiceRefPortInfo; 49 50 54 public class JAXWSServiceDelegate extends Service { 55 56 private ServiceReferenceDescriptor serviceRef; 57 58 private Service serviceDelegate; 60 61 private ClassLoader classLoader; 62 63 private URL wsdlLocation; 65 66 private boolean fullWsdl = false; 67 private boolean noWsdl = false; 68 69 private static final int ADD_PORT = 1; 71 private static final int CREATE_DISPATCH_CLASS = 2; 72 private static final int CREATE_DISPATCH_CONTEXT = 3; 73 private static final int GET_EXECUTOR = 4; 74 private static final int SET_EXECUTOR = 5; 75 private static final int GET_HANDLER_RESOLVER = 6; 76 private static final int GET_PORT_CONTAINER_MANAGED = 7; 77 private static final int GET_PORT_CLIENT_MANAGED = 8; 78 private static final int GET_PORTS = 9; 79 private static final int GET_SERVICE_NAME = 10; 80 private static final int SET_HANDLER_RESOLVER = 11; 81 private static final int GET_WSDL_LOCATION = 12; 82 private static final int GENERATED_SERVICE_METHOD = 13; 83 84 private static Map serviceMethodTypes; 85 private static Set fullWsdlIllegalMethods; 86 private static Set noWsdlIllegalMethods; 87 88 static { 89 Init(); 90 } 91 92 public JAXWSServiceDelegate(ServiceReferenceDescriptor descriptor, 93 Service delegate, ClassLoader loader) throws Exception { 94 super((new WsUtil()).privilegedGetServiceRefWsdl(descriptor), 95 descriptor.getServiceName()); 96 serviceRef = descriptor; 97 serviceDelegate = delegate; 98 classLoader = loader; 99 if( serviceRef.hasWsdlFile() ) { 100 wsdlLocation = (new WsUtil()).privilegedGetServiceRefWsdl(serviceRef); 101 fullWsdl = true; 102 } else { 103 noWsdl = true; 104 } 105 } 106 107 public void addPort(QName q, String id, String addr) { 108 checkUnsupportedMethods(ADD_PORT); 109 serviceDelegate.addPort(q, id, addr); 110 return; 111 } 112 113 public <T> Dispatch<T> createDispatch(QName qName, Class <T> aClass, Service.Mode mode) { 115 checkUnsupportedMethods(CREATE_DISPATCH_CLASS); 116 return null; 117 } 118 119 public Dispatch<Object > createDispatch(QName qName, JAXBContext jaxbContext, Service.Mode mode) { 121 checkUnsupportedMethods(CREATE_DISPATCH_CONTEXT); 122 return null; 123 } 124 125 public Executor getExecutor() { 126 checkUnsupportedMethods(GET_EXECUTOR); 127 return serviceDelegate.getExecutor(); 128 } 129 130 public void setExecutor(Executor obj) { 131 checkUnsupportedMethods(SET_EXECUTOR); 132 serviceDelegate.setExecutor(obj); 133 return; 134 } 135 136 public HandlerResolver getHandlerResolver() { 137 checkUnsupportedMethods(GET_HANDLER_RESOLVER); 138 return serviceDelegate.getHandlerResolver(); 139 } 140 141 public Object getPort(QName q, Class sei) { 142 checkUnsupportedMethods(GET_PORT_CLIENT_MANAGED); 143 return serviceDelegate.getPort(q, sei); 144 } 145 146 public Object getPort(Class sei) { 147 checkUnsupportedMethods(GET_PORT_CONTAINER_MANAGED); 148 String serviceEndpointInterface = sei.getName(); 149 ServiceRefPortInfo portInfo = 150 serviceRef.getPortInfo(serviceEndpointInterface); 151 Object retVal; 152 if( (portInfo != null) && portInfo.hasWsdlPort() ) { 153 retVal = getPort(portInfo.getWsdlPort(), sei); 154 } else { 155 retVal = serviceDelegate.getPort(sei); 156 } 157 return retVal; 158 } 159 160 public Iterator getPorts() { 161 checkUnsupportedMethods(GET_PORTS); 162 return serviceDelegate.getPorts(); 163 } 164 165 public QName getServiceName() { 166 checkUnsupportedMethods(GET_SERVICE_NAME); 167 return serviceRef.getServiceName(); 168 } 169 170 public void setHandlerResolver(HandlerResolver resolver) { 171 checkUnsupportedMethods(SET_HANDLER_RESOLVER); 172 serviceDelegate.setHandlerResolver(resolver); 173 return; 174 } 175 176 public URL getWSDLDocumentLocation() { 177 checkUnsupportedMethods(SET_HANDLER_RESOLVER); 178 return wsdlLocation; 179 } 180 181 184 private static void Init() { 185 186 serviceMethodTypes = new HashMap (); 187 fullWsdlIllegalMethods = new HashSet (); 188 noWsdlIllegalMethods = new HashSet (); 189 190 try { 191 192 Class noParams[] = new Class [0]; 193 Class serviceClass = javax.xml.ws.Service.class; 194 195 199 Method addPort = serviceClass.getDeclaredMethod 200 ("addPort", new Class [] {QName .class, URI .class, String .class}); 201 serviceMethodTypes.put(addPort, 202 new Integer (ADD_PORT)); 203 204 Method createDispatchClass = serviceClass.getDeclaredMethod 205 ("createDispatch", new Class [] {QName .class, Class .class, Service.Mode.class}); 206 serviceMethodTypes.put(createDispatchClass, 207 new Integer (CREATE_DISPATCH_CLASS)); 208 209 Method createDispatchContext = serviceClass.getDeclaredMethod 210 ("createDispatch", new Class [] {QName .class, JAXBContext.class, Service.Mode.class}); 211 serviceMethodTypes.put(createDispatchContext, 212 new Integer (CREATE_DISPATCH_CONTEXT)); 213 214 Method getExecutor = serviceClass.getDeclaredMethod 215 ("getExecutor", noParams); 216 serviceMethodTypes.put(getExecutor, 217 new Integer (GET_EXECUTOR)); 218 219 Method setExecutor = serviceClass.getDeclaredMethod 220 ("setExecutor", new Class [] {Executor .class}); 221 serviceMethodTypes.put(setExecutor, 222 new Integer (SET_EXECUTOR)); 223 224 Method getHandlerResolver = serviceClass.getDeclaredMethod 225 ("getHandlerResolver", noParams); 226 serviceMethodTypes.put(getHandlerResolver, 227 new Integer (GET_HANDLER_RESOLVER)); 228 229 Method getPortContainerManaged = serviceClass.getDeclaredMethod 230 ("getPort", new Class [] { Class .class }); 231 serviceMethodTypes.put(getPortContainerManaged, 232 new Integer (GET_PORT_CONTAINER_MANAGED)); 233 234 Method getPortClientManaged = serviceClass.getDeclaredMethod 235 ("getPort", new Class [] { QName .class, Class .class }); 236 serviceMethodTypes.put(getPortClientManaged, 237 new Integer (GET_PORT_CLIENT_MANAGED)); 238 239 Method getPorts = serviceClass.getDeclaredMethod 240 ("getPorts", noParams); 241 serviceMethodTypes.put(getPorts, new Integer (GET_PORTS)); 242 243 Method getServiceName = serviceClass.getDeclaredMethod 244 ("getServiceName", noParams); 245 serviceMethodTypes.put(getServiceName, 246 new Integer (GET_SERVICE_NAME)); 247 248 Method setHandlerResolver = serviceClass.getDeclaredMethod 249 ("setHandlerResolver", new Class [] {HandlerResolver.class}); 250 serviceMethodTypes.put(setHandlerResolver, 251 new Integer (SET_HANDLER_RESOLVER)); 252 253 Method getWsdlLocation = serviceClass.getDeclaredMethod 254 ("getWSDLDocumentLocation", noParams); 255 serviceMethodTypes.put(getWsdlLocation, 256 new Integer (GET_WSDL_LOCATION)); 257 } catch(NoSuchMethodException nsme) {} 258 259 noWsdlIllegalMethods.add(new Integer (GET_PORT_CONTAINER_MANAGED)); 260 noWsdlIllegalMethods.add(new Integer (GET_PORT_CLIENT_MANAGED)); 261 noWsdlIllegalMethods.add(new Integer (GET_PORTS)); 262 noWsdlIllegalMethods.add(new Integer (GET_SERVICE_NAME)); 263 noWsdlIllegalMethods.add(new Integer (GET_WSDL_LOCATION)); 264 265 noWsdlIllegalMethods.add(new Integer (GENERATED_SERVICE_METHOD)); 269 } 270 271 private void checkUnsupportedMethods(int methodType) 272 throws UnsupportedOperationException { 273 274 Set illegalMethods = fullWsdl ? 275 fullWsdlIllegalMethods : noWsdlIllegalMethods; 276 277 if( illegalMethods.contains(new Integer (methodType)) ) { 278 throw new UnsupportedOperationException (); 279 } 280 281 return; 282 } 283 } 284 | Popular Tags |