FileDocCategorySizeDatePackage
EJBLocalObjectInvocationHandler.javaAPI DocGlassfish v2 API9444Fri May 04 22:32:58 BST 2007com.sun.ejb.containers

EJBLocalObjectInvocationHandler

public final class EJBLocalObjectInvocationHandler extends EJBLocalObjectImpl implements InvocationHandler
Handler for EJBLocalObject invocations through EJBLocalObject proxy.
author
Kenneth Saks

Fields Summary
private static final Logger
logger
private static com.sun.enterprise.util.LocalStringManagerImpl
localStrings
private Object
proxy_
private com.sun.ejb.containers.util.MethodMap
invocationInfoMap_
private Class
localIntf_
Constructors Summary
public EJBLocalObjectInvocationHandler(com.sun.ejb.containers.util.MethodMap invocationInfoMap, Class localIntf)
Constructor used for Local Home view


               
      
                                            
          

        invocationInfoMap_ = invocationInfoMap;
        
        localIntf_ = localIntf;
        setIsLocalHomeView(true);

        // NOTE : Container is not set on super-class until after 
        // constructor is called.
    
public EJBLocalObjectInvocationHandler(com.sun.ejb.containers.util.MethodMap invocationInfoMap)
Constructor used for Local Business view.


        invocationInfoMap_ = invocationInfoMap;
        
        setIsLocalHomeView(false);

        // NOTE : Container is not set on super-class until after 
        // constructor is called.
    
Methods Summary
public java.lang.ObjectgetClientObject()

        return proxy_;
    
public java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
This entry point is only used for Local Home view.


        return invoke(localIntf_, method, args);
    
java.lang.Objectinvoke(java.lang.Class clientInterface, java.lang.reflect.Method method, java.lang.Object[] args)


        // NOTE : be careful with "args" parameter.  It is null
        //        if method signature has 0 arguments.
        try {
        container.onEnteringContainer();
        Class methodClass = method.getDeclaringClass();
        if( methodClass == java.lang.Object.class ) {
            return InvocationHandlerUtil.invokeJavaObjectMethod(this, method, args);
        } else if( methodClass == IndirectlySerializable.class ) {
            return this.getSerializableObjectFactory();
        }

        // Use optimized version of get that takes param count as an argument.
        InvocationInfo invInfo = (InvocationInfo)
            invocationInfoMap_.get(method, ((args != null) ? args.length : 0));
            
        if( invInfo == null ) {
            throw new IllegalStateException("Unknown method :" + method);
        }

        if( (methodClass == javax.ejb.EJBLocalObject.class) ||
            invInfo.ejbIntfOverride ) {
            return invokeEJBLocalObjectMethod(method.getName(), args);
        } else if( invInfo.targetMethod1 == null ) {
            Object [] params = new Object[] 
                { invInfo.ejbName, "Local", invInfo.method.toString() };
            String errorMsg = localStrings.getLocalString
                ("ejb.bean_class_method_not_found", "", params);              
            logger.log(Level.SEVERE, "ejb.bean_class_method_not_found",
                       params);                                   
            throw new EJBException(errorMsg);
        }

        // Process application-specific method.

        Object returnValue = null;

        Invocation inv = new Invocation();
        
        inv.isLocal   = true;
        inv.isBusinessInterface = !isLocalHomeView();
        inv.isHome    = false;
        inv.ejbObject = this;
        inv.method    = method;
        inv.methodParams = args;

        inv.clientInterface = clientInterface;

        // Set cached invocation params.  This will save additional lookups
        // in BaseContainer.
        inv.transactionAttribute = invInfo.txAttr;
        inv.securityPermissions = invInfo.securityPermissions;
        inv.invocationInfo = invInfo;
        inv.beanMethod = invInfo.targetMethod1;

        try {
            container.preInvoke(inv);

            returnValue = container.intercept(inv);

        } catch(InvocationTargetException ite) {
            inv.exception = ite.getCause();
            inv.exceptionFromBeanMethod = inv.exception;
        } catch(Throwable t) {
            inv.exception = t;
        } finally {
            container.postInvoke(inv);
        }
        if (inv.exception != null) {
            InvocationHandlerUtil.throwLocalException
                (inv.exception, method.getExceptionTypes());
        }

        return returnValue;
        } finally {
            container.onLeavingContainer();
        }
    
private java.lang.ObjectinvokeEJBLocalObjectMethod(java.lang.String methodName, java.lang.Object[] args)

        // Return value is null if target method returns void.
        Object returnValue = null;

        // Can only be remove, isIdentical, getEJBLocalHome, or getPrimaryKey,
        // so optimize by comparing as few characters as possible.
        switch(methodName.charAt(0)) {
            case 'r" :

                // void remove();

                super.remove();
                break;

            case 'i" :

                // boolean isIdentical(EJBLocalObject)

                // Convert the param into an EJBLocalObjectImpl.  Can't 
                // assume it's an EJBLocalObject for an ejb that was deployed
                // using dynamic proxies.
                EJBLocalObject other = (EJBLocalObject) args[0];
                EJBLocalObjectImpl otherImpl = 
                    EJBLocalObjectImpl.toEJBLocalObjectImpl(other);
                    
                returnValue = new Boolean(super.isIdentical(otherImpl));
                break;

            case 'g" :

                if( methodName.charAt(3) == 'E" ) {
                    // EJBLocalHome getEJBLocalHome();
                    returnValue = super.getEJBLocalHome(); 
                } else {
                    // Object getPrimaryKey();
                    returnValue = super.getPrimaryKey();
                }
                break;

            default :

                throw new EJBException("unknown method = " + methodName);
        }

        return returnValue;
    
public voidsetProxy(java.lang.Object proxy)

        proxy_ = proxy;