Home » openejb-3.1.2-src » org.apache » openejb » util » proxy » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.openejb.util.proxy;
   18   
   19   import java.lang.reflect.Method;
   20   
   21   public abstract class Proxy implements java.io.Serializable {
   22   
   23       public InvocationHandler handler;
   24   
   25       public InvocationHandler getInvocationHandler() {
   26           return handler;
   27       }
   28   
   29       public InvocationHandler setInvocationHandler(InvocationHandler newHandler) {
   30           InvocationHandler oldHandler = handler;
   31           handler = newHandler;
   32           return oldHandler;
   33       }
   34   
   35       protected static final Class[] NO_ARGS_C = new Class[0];
   36   
   37       protected static final Object[] NO_ARGS_O = new Object[0];
   38   
   39       protected final void _proxyMethod$throws_default$returns_void(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
   40           _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
   41           return;
   42       }
   43   
   44       protected final Object _proxyMethod$throws_default$returns_Object(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
   45           java.lang.reflect.Method method = _proxyMethod$lookupMethod(methodNumber, methodName, argTypes);
   46           try {
   47               return handler.invoke(this, method, args);
   48           } catch (Throwable t) {
   49   
   50               if (t instanceof java.rmi.RemoteException)
   51                   throw (java.rmi.RemoteException) t;
   52               if (t instanceof java.lang.RuntimeException)
   53                   throw (java.lang.RuntimeException) t;
   54               else
   55                   throw _proxyError$(t);
   56           }
   57       }
   58   
   59       protected final void _proxyMethod$throws_AppException$returns_void(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
   60           _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
   61           return;
   62       }
   63   
   64       protected final Object _proxyMethod$throws_AppException$returns_Object(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
   65           java.lang.reflect.Method method = _proxyMethod$lookupMethod(methodNumber, methodName, argTypes);
   66           try {
   67               return handler.invoke(this, method, args);
   68           } catch (Throwable t) {
   69   
   70               if (t instanceof java.rmi.RemoteException)
   71                   throw (java.rmi.RemoteException) t;
   72               if (t instanceof java.lang.RuntimeException)
   73                   throw (java.lang.RuntimeException) t;
   74               if (t instanceof org.apache.openejb.ApplicationException)
   75                   throw (org.apache.openejb.ApplicationException) t;
   76               else
   77                   throw _proxyError$(t);
   78   
   79           }
   80       }
   81   
   82       protected final int _proxyMethod$throws_default$returns_int(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
   83           Integer retval = (Integer) _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
   84           return retval.intValue();
   85       }
   86   
   87       protected final double _proxyMethod$throws_default$returns_double(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
   88           Double retval = (Double) _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
   89           return retval.doubleValue();
   90       }
   91   
   92       protected final long _proxyMethod$throws_default$returns_long(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
   93           Long retval = (Long) _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
   94           return retval.longValue();
   95       }
   96   
   97       protected final boolean _proxyMethod$throws_default$returns_boolean(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
   98           Boolean retval = (Boolean) _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
   99           return retval.booleanValue();
  100       }
  101   
  102       protected final float _proxyMethod$throws_default$returns_float(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
  103           Float retval = (Float) _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
  104           return retval.floatValue();
  105       }
  106   
  107       protected final char _proxyMethod$throws_default$returns_char(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
  108           Character retval = (Character) _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
  109           return retval.charValue();
  110       }
  111   
  112       protected final byte _proxyMethod$throws_default$returns_byte(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
  113           Byte retval = (Byte) _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
  114           return retval.byteValue();
  115       }
  116   
  117       protected final short _proxyMethod$throws_default$returns_short(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException {
  118           Short retval = (Short) _proxyMethod$throws_default$returns_Object(methodNumber, methodName, argTypes, args);
  119           return retval.shortValue();
  120       }
  121   
  122       protected final int _proxyMethod$throws_AppException$returns_int(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
  123           Integer retval = (Integer) _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
  124           return retval.intValue();
  125       }
  126   
  127       protected final double _proxyMethod$throws_AppException$returns_double(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
  128           Double retval = (Double) _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
  129           return retval.doubleValue();
  130       }
  131   
  132       protected final long _proxyMethod$throws_AppException$returns_long(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
  133           Long retval = (Long) _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
  134           return retval.longValue();
  135       }
  136   
  137       protected final boolean _proxyMethod$throws_AppException$returns_boolean(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
  138           Boolean retval = (Boolean) _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
  139           return retval.booleanValue();
  140       }
  141   
  142       protected final float _proxyMethod$throws_AppException$returns_float(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
  143           Float retval = (Float) _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
  144           return retval.floatValue();
  145       }
  146   
  147       protected final char _proxyMethod$throws_AppException$returns_char(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
  148           Character retval = (Character) _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
  149           return retval.charValue();
  150       }
  151   
  152       protected final byte _proxyMethod$throws_AppException$returns_byte(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
  153           Byte retval = (Byte) _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
  154           return retval.byteValue();
  155       }
  156   
  157       protected final short _proxyMethod$throws_AppException$returns_short(int methodNumber, String methodName, Class[] argTypes, Object[] args) throws java.rmi.RemoteException, org.apache.openejb.ApplicationException {
  158           Short retval = (Short) _proxyMethod$throws_AppException$returns_Object(methodNumber, methodName, argTypes, args);
  159           return retval.shortValue();
  160       }
  161   
  162       protected abstract Method _proxyMethod$lookupMethod(int index, String methodName, Class[] argTypes);
  163   
  164       protected final Method _proxyMethod$lookupMethod(Class interfce, Method [] methodMap, int index, String methodName, Class[] argTypes) {
  165   
  166           java.lang.reflect.Method method = methodMap[index];
  167           if (method == null) {
  168               try {
  169                   method = interfce.getMethod(methodName, argTypes);
  170                   methodMap[index] = method;
  171               } catch (NoSuchMethodException nsme) {
  172                   throw new RuntimeException("Method not found:  " + nsme.getMessage(), nsme);
  173               }
  174           }
  175           return method;
  176       }
  177   
  178       protected final java.rmi.RemoteException _proxyError$(Throwable throwable) {
  179           return new java.rmi.RemoteException("[OpenEJB]  Proxy Error: ", throwable);
  180       }
  181   
  182       protected final java.rmi.RemoteException _proxyError$(org.apache.openejb.ApplicationException ae) {
  183           return new java.rmi.RemoteException("[OpenEJB]  Proxy Error: The returned application exception is not defined in the throws clause.  ", ae.getRootCause());
  184       }
  185   
  186   }

Home » openejb-3.1.2-src » org.apache » openejb » util » proxy » [javadoc | source]