Package org.apache.openejb.core

Examples of org.apache.openejb.core.ThreadContext


        ContextManager.popCallers(null);
        return null;
    }

    public boolean isCallerAuthorized(Method method, InterfaceType typee) {
        ThreadContext threadContext = ThreadContext.getThreadContext();

        try {
            CoreDeploymentInfo deploymentInfo = threadContext.getDeploymentInfo();

            // if security is not enabled we are autorized
            EjbDeployment ejbDeployment = deploymentInfo.get(EjbDeployment.class);
            if (ejbDeployment == null || !ejbDeployment.isSecurityEnabled()) {
                return true;
View Full Code Here


    }

    public boolean isCallerInRole(String role) {
        if (role == null) throw new IllegalArgumentException("Role must not be null");

        ThreadContext threadContext = ThreadContext.getThreadContext();

        CoreDeploymentInfo deploymentInfo = threadContext.getDeploymentInfo();

        // if security is not enabled we are not in that role
        EjbDeployment ejbDeployment = deploymentInfo.get(EjbDeployment.class);
        if (ejbDeployment == null || !ejbDeployment.isSecurityEnabled()) {
            return false;
View Full Code Here

        return ContextManager.isCallerInRole(deploymentInfo.getEjbName(), role);
    }

    public Principal getCallerPrincipal() {
        // if security is not enabled, we don't have a principal
        ThreadContext threadContext = ThreadContext.getThreadContext();
        CoreDeploymentInfo deploymentInfo = threadContext.getDeploymentInfo();
        EjbDeployment ejbDeployment = deploymentInfo.get(EjbDeployment.class);
        if (ejbDeployment == null || !ejbDeployment.isSecurityEnabled()) {
            return null;
        }
View Full Code Here

    @RemoteHome(ColorEjbHome.class)
    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public static class Color implements ColorLocal, ColorRemote {

        public String attribute() {
            ThreadContext context = ThreadContext.getThreadContext();
            return context.getTransactionPolicy().toString();
        }
View Full Code Here

    public String getNameInNamespace() throws NamingException {
        return URL_PREFIX;
    }

    private Context getThreadContext() throws NamingException {
        ThreadContext threadContext = ThreadContext.getThreadContext();
        Context context = threadContext.getDeploymentInfo().getJndiEnc();
        return context;
    }
View Full Code Here

        }
        return beanClass;
    }

    public InstanceContext newInstance() throws Exception {
        ThreadContext callContext = new ThreadContext(this, null, Operation.INJECTION);
        ThreadContext oldContext = ThreadContext.enter(callContext);

        WebBeansContext webBeansContext = null;
        AbstractInjectionTargetBean<Object> beanDefinition = null;

        webBeansContext = getModuleContext().getAppContext().getWebBeansContext();
View Full Code Here

        private StatelessSupplier(BeanContext beanContext) {
            this.beanContext = beanContext;
        }

        public void discard(Instance instance, Pool.Event reason) {
            ThreadContext ctx = new ThreadContext(beanContext, null);
            ThreadContext oldCallContext = ThreadContext.enter(ctx);
            try {
                freeInstance(ctx, instance);
            } finally {
                 ThreadContext.exit(oldCallContext);
            }
View Full Code Here

                 ThreadContext.exit(oldCallContext);
            }
        }

        public Instance create() {
            ThreadContext ctx = new ThreadContext(beanContext, null);
            ThreadContext oldCallContext = ThreadContext.enter(ctx);
            try {
                return ceateInstance(ctx, ctx.getBeanContext());
            } catch (OpenEJBException e) {
                logger.error("Unable to fill pool: for deployment '" + beanContext.getDeploymentID() + "'", e);
            } finally {
View Full Code Here

    protected ProxyInfo createEJBObject(BeanContext beanContext, Method callMethod, Object[] args, InterfaceType interfaceType) throws OpenEJBException {
        // generate a new primary key
        Object primaryKey = newPrimaryKey();


        ThreadContext createContext = new ThreadContext(beanContext, primaryKey);
        ThreadContext oldCallContext = ThreadContext.enter(createContext);
        try {
            // Security check
            checkAuthorization(callMethod, interfaceType);

            // Create the extended entity managers for this instance
            Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> entityManagers = createEntityManagers(beanContext);

            // Register the newly created entity managers
            if (entityManagers != null) {
                try {
                    entityManagerRegistry.addEntityManagers((String) beanContext.getDeploymentID(), primaryKey, entityManagers);
                } catch (EntityManagerAlreadyRegisteredException e) {
                    throw new EJBException(e);
                }
            }

            createContext.setCurrentOperation(Operation.CREATE);
            createContext.setCurrentAllowedStates(null);

            // Start transaction
            TransactionPolicy txPolicy = createTransactionPolicy(createContext.getBeanContext().getTransactionType(callMethod, interfaceType), createContext);

            Instance instance = null;
            try {
                // Create new instance

                try {
                    final InstanceContext context = beanContext.newInstance();

                    // Wrap-up everthing into a object
                    instance = new Instance(beanContext, primaryKey, context.getBean(),  context.getCreationalContext(), context.getInterceptors(), entityManagers);

                } catch (Throwable throwable) {
                    ThreadContext callContext = ThreadContext.getThreadContext();
                    handleSystemException(callContext.getTransactionPolicy(), throwable, callContext);
                    throw new IllegalStateException(throwable); // should never be reached
                }

                // add to cache
                if (!containsExtendedPersistenceContext(beanContext)) { // no need to cache it it will never expires
View Full Code Here

        }


        final boolean internalRemove = BeanContext.Removable.class == callMethod.getDeclaringClass();

        ThreadContext callContext = new ThreadContext(beanContext, primKey);
        ThreadContext oldCallContext = ThreadContext.enter(callContext);
        try {
            // Security check
            if (!internalRemove) checkAuthorization(callMethod, interfaceType);

            // If a bean managed transaction is active, the bean can not be removed
View Full Code Here

TOP

Related Classes of org.apache.openejb.core.ThreadContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.