Search in sources :

Example 16 with ComponentView

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));
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView)

Example 17 with ComponentView

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();
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) ManagedReference(org.jboss.as.naming.ManagedReference)

Example 18 with ComponentView

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();
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) ManagedReference(org.jboss.as.naming.ManagedReference) IOException(java.io.IOException)

Example 19 with ComponentView

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);
    }
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) Produces(javax.enterprise.inject.Produces)

Example 20 with ComponentView

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);
            }
        }
    };
}
Also used : ResourceReferenceFactory(org.jboss.weld.injection.spi.ResourceReferenceFactory) ComponentView(org.jboss.as.ee.component.ComponentView) ManagedReference(org.jboss.as.naming.ManagedReference) ResourceReference(org.jboss.weld.injection.spi.ResourceReference) SimpleResourceReference(org.jboss.weld.injection.spi.helpers.SimpleResourceReference) NamingException(javax.naming.NamingException)

Aggregations

ComponentView (org.jboss.as.ee.component.ComponentView)24 ManagedReference (org.jboss.as.naming.ManagedReference)7 Method (java.lang.reflect.Method)6 Component (org.jboss.as.ee.component.Component)6 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)6 EjbDeploymentInformation (org.jboss.as.ejb3.deployment.EjbDeploymentInformation)4 HashMap (java.util.HashMap)3 MethodIntf (org.jboss.as.ejb3.component.MethodIntf)3 InterceptorContext (org.jboss.invocation.InterceptorContext)3 IOException (java.io.IOException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 HashSet (java.util.HashSet)2 NamingException (javax.naming.NamingException)2 StartupCountdown (org.jboss.as.ee.component.deployers.StartupCountdown)2 CancellationFlag (org.jboss.as.ejb3.component.interceptors.CancellationFlag)2 DeploymentModuleIdentifier (org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier)2 ModuleDeployment (org.jboss.as.ejb3.deployment.ModuleDeployment)2 SessionID (org.jboss.ejb.client.SessionID)2 InjectedValue (org.jboss.msc.value.InjectedValue)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1