javax.ejb.EJBLocalHome Java Examples

The following examples show how to use javax.ejb.EJBLocalHome. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProxyFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
public ProxyFactory(final BeanContext beanContext) {
    this.beanContext = beanContext;
    keyGenerator = beanContext.getKeyGenerator();

    remoteInterface = beanContext.getRemoteInterface();
    if (remoteInterface != null) {
        final EJBHome homeProxy = beanContext.getEJBHome();
        remoteHandler = (EntityEjbHomeHandler) ProxyManager.getInvocationHandler(homeProxy);
    } else {
        remoteHandler = null;
    }

    localInterface = beanContext.getLocalInterface();
    if (localInterface != null) {
        final EJBLocalHome localHomeProxy = beanContext.getEJBLocalHome();
        localHandler = (EntityEjbHomeHandler) ProxyManager.getInvocationHandler(localHomeProxy);
    } else {
        localHandler = null;
    }
}
 
Example #2
Source File: CheckMethods.java    From tomee with Apache License 2.0 6 votes vote down vote up
private void check_localHomeInterfaceMethods(final RemoteBean b) {
        Class home = null;
        Class bean = null;
        try {
            home = loadClass(b.getLocalHome());
            bean = loadClass(b.getEjbClass());
        } catch (final OpenEJBException e) {
            return;
        }

        if (!EJBLocalHome.class.isAssignableFrom(home)) {
            return;
        }

        if (check_hasCreateMethod(b, bean, home)) {
            check_createMethodsAreImplemented(b, bean, home);
//            check_postCreateMethodsAreImplemented(b, bean, home);
        }
    }
 
Example #3
Source File: LocalSlsbInvokerInterceptor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Check for EJB3-style home object that serves as EJB component directly.
 */
@Override
protected Method getCreateMethod(Object home) throws EjbAccessException {
	if (this.homeAsComponent) {
		return null;
	}
	if (!(home instanceof EJBLocalHome)) {
		// An EJB3 Session Bean...
		this.homeAsComponent = true;
		return null;
	}
	return super.getCreateMethod(home);
}
 
Example #4
Source File: MethodInfoUtil.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static boolean containerMethod(final Method method) {
    return (method.getDeclaringClass() == EJBObject.class ||
        method.getDeclaringClass() == EJBHome.class ||
        method.getDeclaringClass() == EJBLocalObject.class ||
        method.getDeclaringClass() == EJBLocalHome.class) &&
        !method.getName().equals("remove");
}
 
Example #5
Source File: BeanContext.java    From tomee with Apache License 2.0 5 votes vote down vote up
public EJBLocalHome getEJBLocalHome() {
    if (getLocalHomeInterface() == null) {
        throw new IllegalStateException("This component has no local home interface: " + getDeploymentID());
    }
    if (getLegacyView().ejbLocalHomeRef == null) {
        getLegacyView().ejbLocalHomeRef = (EJBLocalHome) EjbHomeProxyHandler.createHomeProxy(this, InterfaceType.EJB_LOCAL_HOME);
    }
    return getLegacyView().ejbLocalHomeRef;
}
 
Example #6
Source File: BeanContext.java    From tomee with Apache License 2.0 5 votes vote down vote up
public InterfaceType getInterfaceType(final Class clazz) {
    final InterfaceType type = interfaces.get(clazz);
    if (type != null) {
        return type;
    }

    if (EJBLocalHome.class.isAssignableFrom(clazz)) {
        return InterfaceType.EJB_LOCAL_HOME;
    }
    if (EJBLocalObject.class.isAssignableFrom(clazz)) {
        return InterfaceType.EJB_LOCAL;
    }
    if (EJBHome.class.isAssignableFrom(clazz)) {
        return InterfaceType.EJB_HOME;
    }
    if (EJBObject.class.isAssignableFrom(clazz)) {
        return InterfaceType.EJB_OBJECT;
    }

    for (final Entry<Class, InterfaceType> entry : interfaces.entrySet()) { // for @Remote case where the loaded interface can be different from the stored one
        if (entry.getKey().getName().equals(clazz.getName())) {
            return entry.getValue();
        }
    }

    return null;
}
 
Example #7
Source File: SingletonPojoEjbLocalObjectTests.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void test02_getEjbLocalHome() {
    try {
        final EJBLocalHome localHome = ejbLocalObject.getEJBLocalHome();
        assertNotNull("The EJBLocalHome is null", localHome);
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
}
 
Example #8
Source File: StatelessPojoEjbLocalObjectTests.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void test02_getEjbLocalHome() {
    try {
        final EJBLocalHome localHome = ejbLocalObject.getEJBLocalHome();
        assertNotNull("The EJBLocalHome is null", localHome);
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
}
 
Example #9
Source File: StatefulPojoEjbLocalObjectTests.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void test02_getEjbLocalHome() {
    try {
        final EJBLocalHome localHome = ejbLocalObject.getEJBLocalHome();
        assertNotNull("The EJBHome is null", localHome);
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
}
 
Example #10
Source File: LocalSlsbInvokerInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Check for EJB3-style home object that serves as EJB component directly.
 */
@Override
protected Method getCreateMethod(Object home) throws EjbAccessException {
	if (this.homeAsComponent) {
		return null;
	}
	if (!(home instanceof EJBLocalHome)) {
		// An EJB3 Session Bean...
		this.homeAsComponent = true;
		return null;
	}
	return super.getCreateMethod(home);
}
 
Example #11
Source File: LocalSlsbInvokerInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check for EJB3-style home object that serves as EJB component directly.
 */
@Override
protected Method getCreateMethod(Object home) throws EjbAccessException {
	if (this.homeAsComponent) {
		return null;
	}
	if (!(home instanceof EJBLocalHome)) {
		// An EJB3 Session Bean...
		this.homeAsComponent = true;
		return null;
	}
	return super.getCreateMethod(home);
}
 
Example #12
Source File: LocalSlsbInvokerInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Check for EJB3-style home object that serves as EJB component directly.
 */
@Override
protected Method getCreateMethod(Object home) throws EjbAccessException {
	if (this.homeAsComponent) {
		return null;
	}
	if (!(home instanceof EJBLocalHome)) {
		// An EJB3 Session Bean...
		this.homeAsComponent = true;
		return null;
	}
	return super.getCreateMethod(home);
}
 
Example #13
Source File: BeanContext.java    From tomee with Apache License 2.0 4 votes vote down vote up
public BeanContext(final String id, final Context jndiContext, final ModuleContext moduleContext,
                   final Class beanClass, final Class homeInterface,
                   final Class remoteInterface,
                   final Class localHomeInterface,
                   final Class localInterface,
                   final Class proxy,
                   final Class serviceEndpointInterface, final List<Class> businessLocals, final List<Class> businessRemotes, final Class pkClass,
                   final BeanType componentType,
                   final boolean localBean,
                   final boolean passivable) throws SystemException {
    this(id, jndiContext, moduleContext, componentType, localBean, beanClass, passivable);

    this.proxyClass = proxy;

    if (homeInterface != null) {
        this.getLegacyView().homeInterface = homeInterface;
    }
    if (localInterface != null) {
        this.getLegacyView().localInterface = localInterface;
    }
    if (localHomeInterface != null) {
        this.getLegacyView().localHomeInterface = localHomeInterface;
    }
    if (remoteInterface != null) {
        this.getLegacyView().remoteInterface = remoteInterface;
    }

    if (businessLocals != null) {
        this.businessLocals.addAll(businessLocals);
    }
    if (businessRemotes != null) {
        this.businessRemotes.addAll(businessRemotes);
    }

    if (pkClass != null) {
        getCmp().pkClass = pkClass;
    }

    this.serviceEndpointInterface = serviceEndpointInterface;

    //        if (businessLocal != null && localHomeInterface == null){
    //            this.localHomeInterface = BusinessLocalHome.class;
    //        }
    //
    //        if (businessRemote != null && homeInterface == null){
    //            this.homeInterface = BusinessRemoteHome.class;
    //        }

    // createMethodMap();

    if (TimedObject.class.isAssignableFrom(beanClass)) {
        try {
            this.ejbTimeout = beanClass.getMethod("ejbTimeout", Timer.class);
        } catch (final NoSuchMethodException e) {
            throw new IllegalStateException(e);
        }
    }

    addInterface(getServiceEndpointInterface(), InterfaceType.SERVICE_ENDPOINT);

    addInterface(EJBHome.class, InterfaceType.EJB_HOME);
    addInterface(EJBObject.class, InterfaceType.EJB_OBJECT);

    addInterface(EJBLocalHome.class, InterfaceType.EJB_LOCAL_HOME);
    addInterface(EJBLocalObject.class, InterfaceType.EJB_LOCAL);

    addInterface(getHomeInterface(), InterfaceType.EJB_HOME);
    addInterface(getRemoteInterface(), InterfaceType.EJB_OBJECT);

    addInterface(getLocalHomeInterface(), InterfaceType.EJB_LOCAL_HOME);
    addInterface(getLocalInterface(), InterfaceType.EJB_LOCAL);

    addInterface(BeanContext.BusinessRemoteHome.class, InterfaceType.BUSINESS_REMOTE_HOME);
    for (final Class businessRemote : this.businessRemotes) {
        addInterface(businessRemote, InterfaceType.BUSINESS_REMOTE);
    }

    addInterface(BeanContext.BusinessLocalHome.class, InterfaceType.BUSINESS_LOCAL_HOME);
    for (final Class businessLocal : this.businessLocals) {
        addInterface(businessLocal, InterfaceType.BUSINESS_LOCAL);
    }
    if (localBean) {
        addInterface(beanClass, InterfaceType.LOCALBEAN);
    }

    this.initDefaultLock();
}
 
Example #14
Source File: TestSessionContext.java    From development with Apache License 2.0 4 votes vote down vote up
@Override
public EJBLocalHome getEJBLocalHome() {
    throw new UnsupportedOperationException();
}
 
Example #15
Source File: EntityContainer.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Object invoke(final Object deployID,
                     InterfaceType type,
                     final Class callInterface,
                     final Method callMethod,
                     final Object[] args,
                     final Object primKey) throws OpenEJBException {
    final BeanContext beanContext = this.getBeanContext(deployID);

    if (beanContext == null) {
        throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='" + deployID + "'), Container(id='" + containerID + "')");
    }

    // Use the backup way to determine call type if null was supplied.
    if (type == null) {
        type = beanContext.getInterfaceType(callInterface);
    }

    final ThreadContext callContext = new ThreadContext(beanContext, primKey);
    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {

        final boolean authorized = type == InterfaceType.TIMEOUT || getSecurityService().isCallerAuthorized(callMethod, type);

        if (!authorized) {
            throw new ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
        }

        final Class declaringClass = callMethod.getDeclaringClass();
        final String methodName = callMethod.getName();

        if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
            if (declaringClass != EJBHome.class && declaringClass != EJBLocalHome.class) {

                if (methodName.startsWith("create")) {

                    return createEJBObject(callMethod, args, callContext, type);
                } else if (methodName.startsWith("find")) {

                    return findMethod(callMethod, args, callContext, type);
                } else {

                    return homeMethod(callMethod, args, callContext, type);
                }
            } else if (methodName.equals("remove")) {
                removeEJBObject(callMethod, args, callContext, type);
                return null;
            }
        } else if ((EJBObject.class == declaringClass || EJBLocalObject.class == declaringClass) && methodName.equals("remove")) {
            removeEJBObject(callMethod, args, callContext, type);
            return null;
        }

        callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS);
        final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);

        callContext.set(Method.class, runMethod);

        return invoke(type, callMethod, runMethod, args, callContext);

    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
 
Example #16
Source File: BaseContext.java    From tomee with Apache License 2.0 4 votes vote down vote up
public EJBLocalHome getEJBLocalHome() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();

    return di.getEJBLocalHome();
}
 
Example #17
Source File: CmpContainer.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Object invoke(final Object deployID,
                     InterfaceType type,
                     final Class callInterface,
                     final Method callMethod,
                     final Object[] args,
                     final Object primKey) throws OpenEJBException {
    final BeanContext beanContext = this.getBeanContext(deployID);

    if (beanContext == null) {
        throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='" + deployID + "'), Container(id='" + containerID + "')");
    }

    // Use the backup way to determine call type if null was supplied.
    if (type == null) {
        type = beanContext.getInterfaceType(callInterface);
    }

    final ThreadContext callContext = new ThreadContext(beanContext, primKey);

    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {

        final boolean authorized = securityService.isCallerAuthorized(callMethod, type);

        if (!authorized) {
            throw new ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
        }

        final Class declaringClass = callMethod.getDeclaringClass();
        final String methodName = callMethod.getName();

        if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
            if (declaringClass != EJBHome.class && declaringClass != EJBLocalHome.class) {
                if (methodName.startsWith("create")) {
                    return createEJBObject(callMethod, args, callContext, type);
                } else if (methodName.equals("findByPrimaryKey")) {
                    return findByPrimaryKey(callMethod, args, callContext, type);
                } else if (methodName.startsWith("find")) {
                    return findEJBObject(callMethod, args, callContext, type);
                } else {
                    return homeMethod(callMethod, args, callContext, type);
                }
            } else if (methodName.equals("remove")) {
                removeEJBObject(callMethod, callContext, type);
                return null;
            }
        } else if ((EJBObject.class == declaringClass || EJBLocalObject.class == declaringClass) && methodName.equals("remove")) {
            removeEJBObject(callMethod, callContext, type);
            return null;
        }

        // business method
        callContext.setCurrentOperation(Operation.BUSINESS);
        final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);

        callContext.set(Method.class, runMethod);

        return businessMethod(callMethod, runMethod, args, callContext, type);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
 
Example #18
Source File: SingletonContainer.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Object invoke(final Object deployID,
                     InterfaceType type,
                     final Class callInterface,
                     final Method callMethod,
                     final Object[] args,
                     final Object primKey) throws OpenEJBException {
    final BeanContext beanContext = this.getBeanContext(deployID);

    if (beanContext == null) {
        throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='" + deployID + "'), Container(id='" + containerID + "')");
    }

    // Use the backup way to determine call type if null was supplied.
    if (type == null) {
        type = beanContext.getInterfaceType(callInterface);
    }

    final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);

    final ThreadContext callContext = new ThreadContext(beanContext, primKey);
    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    final CurrentCreationalContext currentCreationalContext = beanContext.get(CurrentCreationalContext.class);
    Object runAs = null;
    try {
        if (oldCallContext != null) {
            final BeanContext oldBc = oldCallContext.getBeanContext();
            if (oldBc.getRunAsUser() != null || oldBc.getRunAs() != null) {
                runAs = AbstractSecurityService.class.cast(securityService).overrideWithRunAsContext(callContext, beanContext, oldBc);
            }
        }

        final boolean authorized = type == InterfaceType.TIMEOUT || getSecurityService().isCallerAuthorized(callMethod, type);

        if (!authorized) {
            throw new org.apache.openejb.ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
        }

        final Class declaringClass = callMethod.getDeclaringClass();
        if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
            if (callMethod.getName().startsWith("create")) {
                return createEJBObject(beanContext, callMethod);
            } else {
                return null;// EJBHome.remove( ) and other EJBHome methods are not process by the container
            }
        } else if (EJBObject.class == declaringClass || EJBLocalObject.class == declaringClass) {
            return null;// EJBObject.remove( ) and other EJBObject methods are not process by the container
        }

        final Instance instance = instanceManager.getInstance(callContext);

        callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS);
        callContext.setCurrentAllowedStates(null);
        callContext.set(Method.class, runMethod);
        callContext.setInvokedInterface(callInterface);

        if (currentCreationalContext != null) {
            //noinspection unchecked
            currentCreationalContext.set(instance.creationalContext);
        }

        return _invoke(callMethod, runMethod, args, instance, callContext, type);

    } finally {
        if (runAs != null) {
            try {
                securityService.associate(runAs);
            } catch (final LoginException e) {
                // no-op
            }
        }
        ThreadContext.exit(oldCallContext);
        if (currentCreationalContext != null) {
            currentCreationalContext.remove();
        }
    }
}
 
Example #19
Source File: MdbContext.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public EJBLocalHome getEJBLocalHome() {
    throw new IllegalStateException();
}
 
Example #20
Source File: CheckClasses.java    From tomee with Apache License 2.0 2 votes vote down vote up
private boolean isValidInterface(final RemoteBean b, final Class clazz, final Class beanClass, final String tag) {

        if (clazz.equals(beanClass)) {

            fail(b, "xml." + tag + ".beanClass", clazz.getName());

        } else if (!clazz.isInterface()) {

            fail(b, "xml." + tag + ".notInterface", clazz.getName());

        } else if (EJBHome.class.isAssignableFrom(clazz)) {

            if (tag.equals("home")) {
                return true;
            }

            fail(b, "xml." + tag + ".ejbHome", clazz.getName());

        } else if (EJBLocalHome.class.isAssignableFrom(clazz)) {

            if (tag.equals("localHome")) {
                return true;
            }

            fail(b, "xml." + tag + ".ejbLocalHome", clazz.getName());

        } else if (EJBObject.class.isAssignableFrom(clazz)) {

            if (tag.equals("remote")) {
                return true;
            }

            fail(b, "xml." + tag + ".ejbObject", clazz.getName());

        } else if (EJBLocalObject.class.isAssignableFrom(clazz)) {

            if (tag.equals("local")) {
                return true;
            }

            fail(b, "xml." + tag + ".ejbLocalObject", clazz.getName());

        } else {
            if (tag.equals("businessLocal") || tag.equals("businessRemote")) {

                return true;

            } else if (clazz.isAnnotationPresent(Local.class)) {

                fail(b, "xml." + tag + ".businessLocal", clazz.getName());

            } else if (clazz.isAnnotationPresent(Remote.class)) {

                fail(b, "xml." + tag + ".businessRemote", clazz.getName());

            } else {

                fail(b, "xml." + tag + ".unknown", clazz.getName());

            }

        }

        // must be tagged as <home>, <local-home>, <remote>, or <local>

        return false;
    }