Search in sources :

Example 1 with NormalScope

use of javax.enterprise.context.NormalScope in project kernel by exoplatform.

the class MX4JComponentAdapter method create.

private T create(ContextManager manager, boolean retryAllowed) {
    Class<? extends Annotation> scope = getScope(true, false);
    if (scope.equals(Unknown.class) || scope.equals(Singleton.class) || scope.equals(Dependent.class) || scope.equals(ApplicationScoped.class)) {
        return create();
    }
    final Context ctx = manager.getContext(scope);
    if (ctx == null) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("The scope {} is unknown, thus we will create the component {} out of a scope context.", scope.getName(), getComponentImplementation().getName());
        }
        if (!retryAllowed)
            throw new IllegalArgumentException("The scope and the default scope of the class " + getComponentImplementation().getName() + " are unknown");
        try {
            Class<? extends Annotation> defaultScope = ContainerUtil.getScope(getComponentImplementation(), true);
            setScope(scope, defaultScope);
            return create(manager, false);
        } catch (DefinitionException e) {
            throw new IllegalArgumentException("The scope of the class " + getComponentImplementation().getName() + " is unknown and we cannot get a clear default scope: " + e.getMessage());
        }
    }
    NormalScope normalScope = scope.getAnnotation(NormalScope.class);
    if (normalScope != null) {
        // A proxy is expected
        if (normalScope.passivating() && !Serializable.class.isAssignableFrom(getComponentImplementation())) {
            throw new IllegalArgumentException("As the scope " + scope.getName() + " is a passivating scope, we expect only serializable objects and " + getComponentImplementation().getName() + " is not serializable.");
        }
        try {
            lock.lock();
            if (proxy != null)
                return proxy;
            T result = ContainerUtil.createProxy(getComponentImplementation(), new Provider<T>() {

                public T get() {
                    return createInstance(ctx);
                }
            });
            return proxy = result;
        } finally {
            lock.unlock();
        }
    }
    return createInstance(ctx);
}
Also used : Context(javax.enterprise.context.spi.Context) CreationalContext(javax.enterprise.context.spi.CreationalContext) NormalScope(javax.enterprise.context.NormalScope) Singleton(javax.inject.Singleton) DefinitionException(org.exoplatform.container.context.DefinitionException) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Aggregations

ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 NormalScope (javax.enterprise.context.NormalScope)1 Context (javax.enterprise.context.spi.Context)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 Singleton (javax.inject.Singleton)1 DefinitionException (org.exoplatform.container.context.DefinitionException)1