1 25 package org.objectweb.jonas.ws.axis; 26 27 import java.lang.reflect.InvocationHandler ; 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 import java.util.Iterator ; 31 32 import javax.xml.namespace.QName ; 33 import javax.xml.rpc.Service ; 34 import javax.xml.rpc.ServiceException ; 35 36 37 42 public class JServiceProxy implements InvocationHandler { 43 44 48 private JService service = null; 49 50 53 private static Method getTypeMappingRegistryMethod = null; 54 55 58 private static Method getHandlerRegistryMethod = null; 59 60 63 private static Method getPortQNameClass = null; 64 65 70 public JServiceProxy(JService service) throws ServiceException { 71 this.service = service; 72 try { 73 getTypeMappingRegistryMethod = Service .class.getDeclaredMethod("getTypeMappingRegistry", new Class []{}); 74 getHandlerRegistryMethod = Service .class.getDeclaredMethod("getHandlerRegistry", new Class []{}); 75 getPortQNameClass = Service .class.getDeclaredMethod("getPort", new Class []{QName .class, Class .class}); 76 } catch (Exception e) { 77 throw new ServiceException (e); 78 } 79 } 80 81 84 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 85 if (getHandlerRegistryMethod.equals(method)) { 87 throw new UnsupportedOperationException ("J2EE components shouldn't use getHandlerRegistry method"); 88 } 89 if (getTypeMappingRegistryMethod.equals(method)) { 91 throw new UnsupportedOperationException ("J2EE components shouldn't use getTypeMappingRegistry method"); 92 } 93 if (getPortQNameClass.equals(method)) { 95 return getPort(args); 96 } 97 try { 99 return method.invoke(service, args); 100 } catch (InvocationTargetException ite) { 101 throw ite.getTargetException(); 102 } 103 } 104 105 110 private Object getPort(Object [] args) throws ServiceException { 111 QName name = (QName ) args[0]; 112 Class clazz = (Class ) args[1]; 113 boolean portFound = false; 114 for (Iterator ports = service.getPorts(); ports.hasNext() && !portFound;) { 115 QName portName = (QName ) ports.next(); 116 if (portName.equals(name)) { 117 return service.getPort(name, clazz); 118 } 119 } 120 121 throw new ServiceException ("Unknown Port : " + name); 124 } 125 126 } 127 | Popular Tags |