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);
}
Aggregations