00001
00025 package org.objectweb.jonas.ws.axis;
00026
00027 import java.lang.reflect.InvocationHandler;
00028 import java.lang.reflect.InvocationTargetException;
00029 import java.lang.reflect.Method;
00030 import java.util.Iterator;
00031
00032 import javax.xml.namespace.QName;
00033 import javax.xml.rpc.Service;
00034 import javax.xml.rpc.ServiceException;
00035
00036
00042 public class JServiceProxy implements InvocationHandler {
00043
00048 private JService service = null;
00049
00053 private static Method getTypeMappingRegistryMethod = null;
00054
00058 private static Method getHandlerRegistryMethod = null;
00059
00063 private static Method getPortQNameClass = null;
00064
00070 public JServiceProxy(JService service) throws ServiceException {
00071 this.service = service;
00072 try {
00073 getTypeMappingRegistryMethod = Service.class.getDeclaredMethod("getTypeMappingRegistry", new Class[]{});
00074 getHandlerRegistryMethod = Service.class.getDeclaredMethod("getHandlerRegistry", new Class[]{});
00075 getPortQNameClass = Service.class.getDeclaredMethod("getPort", new Class[]{QName.class, Class.class});
00076 } catch (Exception e) {
00077 throw new ServiceException(e);
00078 }
00079 }
00080
00084 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
00085
00086 if (getHandlerRegistryMethod.equals(method)) {
00087 throw new UnsupportedOperationException("J2EE components shouldn't use getHandlerRegistry method");
00088 }
00089
00090 if (getTypeMappingRegistryMethod.equals(method)) {
00091 throw new UnsupportedOperationException("J2EE components shouldn't use getTypeMappingRegistry method");
00092 }
00093
00094 if (getPortQNameClass.equals(method)) {
00095 return getPort(args);
00096 }
00097
00098 try {
00099 return method.invoke(service, args);
00100 } catch (InvocationTargetException ite) {
00101 throw ite.getTargetException();
00102 }
00103 }
00104
00110 private Object getPort(Object[] args) throws ServiceException {
00111 QName name = (QName) args[0];
00112 Class clazz = (Class) args[1];
00113 boolean portFound = false;
00114 for (Iterator ports = service.getPorts(); ports.hasNext() && !portFound;) {
00115 QName portName = (QName) ports.next();
00116 if (portName.equals(name)) {
00117 return service.getPort(name, clazz);
00118 }
00119 }
00120
00121
00122
00123 throw new ServiceException("Unknown Port : " + name);
00124 }
00125
00126 }