Java 类javax.ejb.EJBLocalHome 实例源码

项目:tomee    文件:AnnotationDeployer.java   
/**
 * Checks that the values specified via @Local and @Remote are *not*:
 * <p/>
 * - classes
 * - derived from javax.ejb.EJBObject
 * - derived from javax.ejb.EJBHome
 * - derived from javax.ejb.EJBLocalObject
 * - derived from javax.ejb.EJBLocalHome
 *
 * @param interfce
 * @param validation
 * @param ejbName
 * @param annotationName
 * @return
 */
private boolean isValidInterface(final Class interfce, final ValidationContext validation, final String ejbName, final String annotationName) {
    if (!interfce.isInterface()) {
        validation.fail(ejbName, "ann.notAnInterface", annotationName, interfce.getName());
        return false;
    } else if (EJBHome.class.isAssignableFrom(interfce)) {
        validation.fail(ejbName, "ann.remoteOrLocal.ejbHome", annotationName, interfce.getName());
        return false;
    } else if (EJBObject.class.isAssignableFrom(interfce)) {
        validation.fail(ejbName, "ann.remoteOrLocal.ejbObject", annotationName, interfce.getName());
        return false;
    } else if (EJBLocalHome.class.isAssignableFrom(interfce)) {
        validation.fail(ejbName, "ann.remoteOrLocal.ejbLocalHome", annotationName, interfce.getName());
        return false;
    } else if (EJBLocalObject.class.isAssignableFrom(interfce)) {
        validation.fail(ejbName, "ann.remoteOrLocal.ejbLocalObject", annotationName, interfce.getName());
        return false;
    }
    return true;
}
项目:tomee    文件:CheckMethods.java   
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);
        }
    }
项目:tomee    文件:ProxyFactory.java   
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;
    }
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:Ejb21StateEngineLocalBean.java   
public void log() {
    Principal principal = context.getCallerPrincipal();
    Map<String, Object> contextData = context.getContextData();
    EJBLocalHome ejbLocalHome = context.getEJBLocalHome();
    EJBLocalObject ejbLocalObject = context.getEJBLocalObject();
    Ejb21StateLocal stateLocalEngine = context.getBusinessObject(Ejb21StateLocal.class);
    boolean isCallerInRole = context.isCallerInRole("admin");
    logger.info("stateLocalEngineBean principal: " + principal);
    logger.info("stateLocalEngineBean contextData:" + contextData);
    logger.info("stateLocalEngineBean ejbLocalHome:" + ejbLocalHome);
    logger.info("stateLocalEngineBean ejbLocalObject:" + ejbLocalObject);
    logger.info("stateLocalEngineBean stateLocalEngineBean:" + stateLocalEngine);
    logger.info("stateLocalEngineBean isCallerInRole:" + isCallerInRole);
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:Ejb21EngineLocalBean.java   
public void log() {
    Principal principal = context.getCallerPrincipal();
    Map<String, Object> contextData = context.getContextData();
    EJBLocalHome ejbLocalHome = context.getEJBLocalHome();
    EJBLocalObject ejbLocalObject = context.getEJBLocalObject();
    Ejb21Local LocalEngine = context.getBusinessObject(Ejb21Local.class);
    boolean isCallerInRole = context.isCallerInRole("admin");
    logger.info("ejb21LocalEngineBean principal: " + principal);
    logger.info("ejb21LocalEngineBean contextData:" + contextData);
    logger.info("ejb21LocalEngineBean ejbLocalHome:" + ejbLocalHome);
    logger.info("ejb21LocalEngineBean ejbLocalObject:" + ejbLocalObject);
    logger.info("ejb21LocalEngineBean LocalEngineBean:" + LocalEngine);
    logger.info("ejb21LocalEngineBean isCallerInRole:" + isCallerInRole);
}
项目:lams    文件:LocalSlsbInvokerInterceptor.java   
/**
 * 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);
}
项目:spring4-understanding    文件:LocalSlsbInvokerInterceptor.java   
/**
 * 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);
}
项目:my-spring-cache-redis    文件:LocalSlsbInvokerInterceptor.java   
/**
 * 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);
}
项目:BJAF3.x    文件:HomeFactoryHelper.java   
/**
 * 找出本地Home对象
 * 
 * @param jndiName
 *            ejb的本地jndi名称
 * @return EJBLocalHome
 */
public static EJBLocalHome findLocalHome(String jndiName) {
    EJBLocalHome ejbLocalHome = (EJBLocalHome) HOME_INTERFACES_LOCAL
            .get(jndiName);
    if (ejbLocalHome == null) {
        ejbLocalHome = getLocalHome(jndiName);
    }
    return ejbLocalHome;

}
项目:BJAF3.x    文件:HomeFactoryHelper.java   
private static synchronized EJBLocalHome getLocalHome(String jndiName) {
    try {
        Context ctx = ContainerUtil.getLocalEJBContainerContext();
        EJBLocalHome ejbLocalHome = (EJBLocalHome) ctx.lookup(jndiName);
        HOME_INTERFACES_LOCAL.put(jndiName, ejbLocalHome);
        return ejbLocalHome;
    } catch (NamingException e) {
        e.printStackTrace();
        if (HOME_INTERFACES_LOCAL.containsKey(jndiName)) {
            HOME_INTERFACES_LOCAL.remove(jndiName);
        }
        return null;
    }

}
项目:spring    文件:LocalSlsbInvokerInterceptor.java   
/**
 * 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);
}
项目:r01fb    文件:EJB2HomeLocator.java   
/**
 * Obtiene el Home local del ejb 
 * El acceso a este m�todo �nicamente puede hacerse a partir de la instancia del singleton:
 *      <code>EJB2ServiceLocator.getInstance().getLocalHome(jndiName,"com.acme.ejb.MyHome");</code>
 * @param jndiName Nombre jndi del ejb
 * @param homeClassName Nombre de la Clase (Class) para devolver el objeto tipado
 * @return El objeto tipado
 */
public EJBLocalHome getLocalHome(final String jndiName,
                                 final String homeClassName) {
    EJBLocalHome home = null;
    try {
        home = this.getLocalHome(jndiName,Reflection.type(homeClassName).getType());
    } catch (ReflectionException cnfEx) {
        // TODO logging
        String err = Strings.of("NO se ha encontrado la clase {} para hacer un narrow del objeto home > {}")
                            .customizeWith(homeClassName,cnfEx.getMessage()).asString();
        System.out.println(err);
    }
    return home;
}
项目:class-guard    文件:LocalSlsbInvokerInterceptor.java   
/**
 * 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);
}
项目:tomee    文件:StatefulPojoEjbLocalObjectTests.java   
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());
    }
}
项目:tomee    文件:StatelessPojoEjbLocalObjectTests.java   
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());
    }
}
项目:tomee    文件:SingletonPojoEjbLocalObjectTests.java   
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());
    }
}
项目:tomee    文件:BeanContext.java   
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;
}
项目:tomee    文件:BeanContext.java   
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;
}
项目:tomee    文件:MethodInfoUtil.java   
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");
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:Ejb21StateEngineLocalBean.java   
@Override
public EJBLocalHome getEJBLocalHome() throws EJBException {
    logger.info("getEJBLocalHome");
    return null;
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:Ejb21EngineLocalBean.java   
@Override
public EJBLocalHome getEJBLocalHome() throws EJBException {
    logger.info("getEJBLocalHome");
    return null;
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:OldSpecsBean.java   
@Override
public EJBLocalHome getEJBLocalHome() throws EJBException {
    return null;
}
项目:oscm    文件:TestSessionContext.java   
@Override
public EJBLocalHome getEJBLocalHome() {
    throw new UnsupportedOperationException();
}
项目:development    文件:TestSessionContext.java   
@Override
public EJBLocalHome getEJBLocalHome() {
    throw new UnsupportedOperationException();
}
项目:tomee    文件:EntityContainer.java   
@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);
    }
}
项目:tomee    文件:BaseContext.java   
public EJBLocalHome getEJBLocalHome() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();

    return di.getEJBLocalHome();
}
项目:tomee    文件:CmpContainer.java   
@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);
    }
}
项目:tomee    文件:SingletonContainer.java   
@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();
        }
    }
}
项目:tomee    文件:MdbContext.java   
@Override
public EJBLocalHome getEJBLocalHome() {
    throw new IllegalStateException();
}
项目:caarray    文件:SessionContextStub.java   
/**
 * {@inheritDoc}
 */
public EJBLocalHome getEJBLocalHome() {
    // no-op
    return null;
}
项目:nyla    文件:Locator.java   
/**
 * 
 * @return the EJB local home object
 * @throws Exception
 */
protected EJBLocalHome locateLocalHome()
throws Exception
{

    InitialContext context = getContext();

    Object homeObject = context.lookup(jndi);

    return (EJBLocalHome)homeObject;

}
项目:tomee    文件:CheckClasses.java   
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;
    }
项目:r01fb    文件:EJB2HomeLocator.java   
/**
 * Obtiene el Home local del ejb
 * El acceso a este m�todo �nicamente puede hacerse a partir de la instancia del singleton:
 *      <code>EJB2ServiceLocator.getInstance().getLocalHome(jndiName);</code>
 * @param jndiName Nombre jndi del interfaz home local
 * @return una referencia al interfaz home
 */
public EJBLocalHome getLocalHome(final String jndiName) {
    Object home = _retrieveHomeReference(null,jndiName,true);
    return (EJBLocalHome)home;
}