use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class ApplicationClientComponentDescription method createConfiguration.
@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
final ComponentConfiguration configuration = super.createConfiguration(classIndex, moduleClassLoader, moduleLoader);
configuration.setInstanceFactory(new ComponentFactory() {
@Override
public ManagedReference create(final InterceptorContext context) {
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
return null;
}
};
}
});
return configuration;
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class LookupInjectionSource method getResourceValue.
/**
* {@inheritDoc}
*/
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) {
final String applicationName = resolutionContext.getApplicationName();
final String moduleName = resolutionContext.getModuleName();
final String componentName = resolutionContext.getComponentName();
final boolean compUsesModule = resolutionContext.isCompUsesModule();
final String scheme = org.jboss.as.naming.InitialContext.getURLScheme(lookupName);
if (scheme == null) {
// relative name, build absolute name and setup normal lookup injection
if (componentName != null && !compUsesModule) {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:comp/env/" + lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else if (compUsesModule) {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:module/env/" + lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:jboss/env/" + lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
}
} else {
if (scheme.equals("java")) {
// an absolute java name, setup normal lookup injection
if (compUsesModule && lookupName.startsWith("java:comp/")) {
// switch "comp" with "module"
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:module/" + lookupName.substring(10)).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, lookupName).setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
}
} else {
// an absolute non java name
final ManagedReferenceFactory managedReferenceFactory;
if (URL_SCHEMES.contains(scheme)) {
// a Java EE Standard Resource Manager Connection Factory for URLs, using lookup to define value of URL, inject factory that creates URL instances
managedReferenceFactory = new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
return new ImmediateManagedReference(new URL(lookupName));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
};
} else {
// lookup for a non java jndi resource, inject factory which does a true jndi lookup
managedReferenceFactory = new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
return new ImmediateManagedReference(new InitialContext().lookup(lookupName));
} catch (NamingException e) {
EeLogger.ROOT_LOGGER.tracef(e, "failed to lookup %s", lookupName);
return null;
}
}
};
}
injector.inject(managedReferenceFactory);
}
}
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class ManagedReferenceMethodInterceptor method processInvocation.
/**
* {@inheritDoc}
*/
public Object processInvocation(final InterceptorContext context) throws Exception {
final ManagedReference reference = (ManagedReference) context.getPrivateData(ComponentInstance.class).getInstanceData(contextKey);
final Object instance = reference.getInstance();
try {
return method.invoke(instance, context.getParameters());
} catch (IllegalAccessException e) {
final IllegalAccessError n = new IllegalAccessError(e.getMessage());
n.setStackTrace(e.getStackTrace());
throw n;
} catch (InvocationTargetException e) {
throw Interceptors.rethrow(e.getCause());
}
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class EjbLookupInjectionSource method getResourceValue.
@Override
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final Class<?> type;
if (targetType != null) {
type = targetType;
} else if (targetTypeName != null) {
try {
type = ClassLoadingUtils.loadClass(targetTypeName, phaseContext.getDeploymentUnit());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} else {
type = null;
}
injector.inject(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
final Object value = new InitialContext().lookup(lookup);
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
if (type != null && value instanceof org.omg.CORBA.Object) {
return PortableRemoteObject.narrow(value, type);
} else {
return value;
}
}
};
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
});
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class ComponentInstantiatorInterceptor method processInvocation.
public Object processInvocation(final InterceptorContext context) throws Exception {
final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
final ManagedReference existing = (ManagedReference) componentInstance.getInstanceData(contextKey);
if (existing == null) {
final ManagedReference reference = componentFactory.create(context);
boolean ok = false;
try {
componentInstance.setInstanceData(contextKey, reference);
if (setTarget) {
context.setTarget(reference.getInstance());
}
Object result = context.proceed();
ok = true;
return result;
} finally {
if (!ok) {
reference.release();
componentInstance.setInstanceData(contextKey, reference);
}
}
} else {
return context.proceed();
}
}
Aggregations