use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class EJBComponent method getEJBHome.
public EJBHome getEJBHome() throws IllegalStateException {
if (ejbHomeViewServiceName == null) {
throw EjbLogger.ROOT_LOGGER.beanHomeInterfaceIsNull(getComponentName());
}
final ServiceController<?> serviceController = currentServiceContainer().getRequiredService(ejbHomeViewServiceName);
final ComponentView view = (ComponentView) serviceController.getValue();
final String locatorAppName = earApplicationName == null ? "" : earApplicationName;
return EJBClient.createProxy(createHomeLocator(view.getViewClass().asSubclass(EJBHome.class), locatorAppName, moduleName, getComponentName(), distinctName));
}
use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class SessionObjectReferenceImpl method getBusinessObject.
@Override
@SuppressWarnings({ "unchecked" })
public synchronized <S> S getBusinessObject(Class<S> businessInterfaceType) {
final String businessInterfaceName = businessInterfaceType.getName();
ManagedReference managedReference = null;
if (businessInterfaceToReference == null) {
businessInterfaceToReference = new HashMap<String, ManagedReference>();
} else {
managedReference = businessInterfaceToReference.get(businessInterfaceName);
}
if (managedReference == null) {
if (viewServices.containsKey(businessInterfaceType)) {
final ServiceController<?> serviceController = currentServiceContainer().getRequiredService(viewServices.get(businessInterfaceType));
final ComponentView view = (ComponentView) serviceController.getValue();
try {
managedReference = view.createInstance();
businessInterfaceToReference.put(businessInterfaceType.getName(), managedReference);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw WeldLogger.ROOT_LOGGER.viewNotFoundOnEJB(businessInterfaceType.getName(), ejbName);
}
}
return (S) managedReference.getInstance();
}
use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class StatefulSessionObjectReferenceImpl method getBusinessObject.
@Override
@SuppressWarnings({ "unchecked" })
public synchronized <S> S getBusinessObject(Class<S> businessInterfaceType) {
if (isRemoved()) {
WeldEjbLogger.ROOT_LOGGER.ejbHashBeenRemoved(ejbComponent);
}
final String businessInterfaceName = businessInterfaceType.getName();
ManagedReference managedReference = null;
if (businessInterfaceToReference == null) {
businessInterfaceToReference = new HashMap<String, ManagedReference>();
} else {
managedReference = businessInterfaceToReference.get(businessInterfaceName);
}
if (managedReference == null) {
if (viewServices.containsKey(businessInterfaceType)) {
final ServiceController<?> serviceController = currentServiceContainer().getRequiredService(viewServices.get(businessInterfaceType));
final ComponentView view = (ComponentView) serviceController.getValue();
try {
managedReference = view.createInstance(Collections.<Object, Object>singletonMap(SessionID.class, id));
businessInterfaceToReference.put(businessInterfaceName, managedReference);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw WeldLogger.ROOT_LOGGER.viewNotFoundOnEJB(businessInterfaceType.getName(), ejbComponent.getComponentName());
}
}
return (S) managedReference.getInstance();
}
use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class WeldEjbInjectionServices method handleServiceLookup.
private ResourceReferenceFactory<Object> handleServiceLookup(ViewDescription viewDescription, InjectionPoint injectionPoint) {
/*
* Try to obtain ComponentView eagerly and validate the resource type
*/
final ComponentView view = getComponentView(viewDescription);
if (view != null && injectionPoint.getAnnotated().isAnnotationPresent(Produces.class)) {
Class<?> clazz = view.getViewClass();
Class<?> injectionPointRawType = Reflections.getRawType(injectionPoint.getType());
//we just compare names, as for remote views the actual classes may be loaded from different class loaders
Class<?> c = clazz;
boolean found = false;
while (c != null && c != Object.class) {
if (injectionPointRawType.getName().equals(c.getName())) {
found = true;
break;
}
c = c.getSuperclass();
}
if (!found) {
throw BeanLogger.LOG.invalidResourceProducerType(injectionPoint.getAnnotated(), clazz.getName());
}
return new ComponentViewToResourceReferenceFactoryAdapter<Object>(view);
} else {
return new LazyResourceReferenceFactory(viewDescription, serviceRegistry);
}
}
use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class WeldEjbInjectionServices method createLazyResourceReferenceFactory.
protected ResourceReferenceFactory<Object> createLazyResourceReferenceFactory(final ViewDescription viewDescription) {
return new ResourceReferenceFactory<Object>() {
@Override
public ResourceReference<Object> createResource() {
final ManagedReference instance;
try {
final ServiceController<?> controller = serviceRegistry.getRequiredService(viewDescription.getServiceName());
final ComponentView view = (ComponentView) controller.getValue();
instance = view.createInstance();
return new ResourceReference<Object>() {
@Override
public Object getInstance() {
return instance.getInstance();
}
@Override
public void release() {
instance.release();
}
};
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}
Aggregations