Search in sources :

Example 21 with MethodIdentifier

use of org.jboss.invocation.proxy.MethodIdentifier in project wildfly by wildfly.

the class SessionBeanMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
    if (SessionBean.class.isAssignableFrom(componentClass)) {
        // add the setSessionContext(SessionContext) method invocation interceptor for session bean implementing the javax.ejb.SessionContext
        // interface
        description.getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                if (SessionBean.class.isAssignableFrom(configuration.getComponentClass())) {
                    configuration.addPostConstructInterceptor(SessionBeanSetSessionContextMethodInvocationInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.EJB_SET_CONTEXT_METHOD_INVOCATION_INTERCEPTOR);
                }
            }
        });
        // now lifecycle callbacks
        final MethodIdentifier ejbRemoveIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbRemove");
        final MethodIdentifier ejbActivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbActivate");
        final MethodIdentifier ejbPassivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbPassivate");
        boolean ejbActivate = false, ejbPassivate = false, ejbRemove = false;
        Class<?> c = componentClass;
        while (c != null && c != Object.class) {
            final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(c);
            if (!ejbActivate) {
                final Method method = index.getMethod(ejbActivateIdentifier);
                if (method != null) {
                    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                    builder.setPostActivate(ejbActivateIdentifier);
                    description.addInterceptorMethodOverride(c.getName(), builder.build());
                    ejbActivate = true;
                }
            }
            if (!ejbPassivate) {
                final Method method = index.getMethod(ejbPassivateIdentifier);
                if (method != null) {
                    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                    builder.setPrePassivate(ejbPassivateIdentifier);
                    description.addInterceptorMethodOverride(c.getName(), builder.build());
                    ejbPassivate = true;
                }
            }
            if (!ejbRemove) {
                final Method method = index.getMethod(ejbRemoveIdentifier);
                if (method != null) {
                    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                    builder.setPreDestroy(ejbRemoveIdentifier);
                    description.addInterceptorMethodOverride(c.getName(), builder.build());
                    ejbRemove = true;
                }
            }
            c = c.getSuperclass();
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method) SessionBean(javax.ejb.SessionBean) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription)

Example 22 with MethodIdentifier

use of org.jboss.invocation.proxy.MethodIdentifier in project wildfly by wildfly.

the class DeploymentDescriptorMethodProcessor method handleStatelessSessionBean.

/**
 * Handles setting up the ejbCreate and ejbRemove methods  for stateless session beans and MDB's
 *
 * @param component       The component
 * @param module      The module
 * @param reflectionIndex The reflection index
 */
private void handleStatelessSessionBean(final EJBComponentDescription component, final Module module, final DeploymentReflectionIndex reflectionIndex) throws ClassNotFoundException, DeploymentUnitProcessingException {
    final Class<?> componentClass = ClassLoadingUtils.loadClass(component.getComponentClassName(), module);
    final MethodIdentifier ejbCreateId = MethodIdentifier.getIdentifier(void.class, "ejbCreate");
    final Method ejbCreate = ClassReflectionIndexUtil.findMethod(reflectionIndex, componentClass, ejbCreateId);
    if (ejbCreate != null) {
        final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
        builder.setPostConstruct(ejbCreateId);
        component.addInterceptorMethodOverride(ejbCreate.getDeclaringClass().getName(), builder.build());
    }
    final MethodIdentifier ejbRemoveId = MethodIdentifier.getIdentifier(void.class, "ejbRemove");
    final Method ejbRemove = ClassReflectionIndexUtil.findMethod(reflectionIndex, componentClass, ejbRemoveId);
    if (ejbRemove != null) {
        final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
        builder.setPreDestroy(ejbRemoveId);
        component.addInterceptorMethodOverride(ejbRemove.getDeclaringClass().getName(), builder.build());
    }
}
Also used : InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method)

Example 23 with MethodIdentifier

use of org.jboss.invocation.proxy.MethodIdentifier in project wildfly by wildfly.

the class DataSourceDefinitionInjectionSource method clearUnknownProperties.

private void clearUnknownProperties(final DeploymentReflectionIndex reflectionIndex, final Class<?> dataSourceClass, final Map<String, String> props) {
    final Iterator<Map.Entry<String, String>> it = props.entrySet().iterator();
    while (it.hasNext()) {
        final Map.Entry<String, String> entry = it.next();
        String value = entry.getKey();
        if (value == null || "".equals(value)) {
            it.remove();
        } else {
            StringBuilder builder = new StringBuilder("set").append(entry.getKey());
            builder.setCharAt(3, Character.toUpperCase(entry.getKey().charAt(0)));
            final String methodName = builder.toString();
            final Class<?> paramType = value.getClass();
            final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, paramType);
            final Method setterMethod = ClassReflectionIndexUtil.findMethod(reflectionIndex, dataSourceClass, methodIdentifier);
            if (setterMethod == null) {
                it.remove();
                ConnectorLogger.DS_DEPLOYER_LOGGER.methodNotFoundOnDataSource(methodName, dataSourceClass);
            }
        }
    }
}
Also used : MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method) Map(java.util.Map)

Example 24 with MethodIdentifier

use of org.jboss.invocation.proxy.MethodIdentifier in project wildfly by wildfly.

the class StatefulSessionBeanRuntimeHandler method executeReadAttribute.

@Override
protected void executeReadAttribute(String attributeName, OperationContext context, StatefulSessionComponent component, PathAddress address) {
    final StatefulComponentDescription componentDescription = (StatefulComponentDescription) component.getComponentDescription();
    final ModelNode result = context.getResult();
    if (STATEFUL_TIMEOUT.getName().equals(attributeName)) {
        final StatefulTimeoutInfo statefulTimeout = componentDescription.getStatefulTimeout();
        if (statefulTimeout != null) {
            result.set(statefulTimeout.getValue() + ' ' + statefulTimeout.getTimeUnit().toString());
        }
    } else if (AFTER_BEGIN_METHOD.getName().equals(attributeName)) {
        final Method afterBeginMethod = component.getAfterBeginMethod();
        if (afterBeginMethod != null) {
            result.set(afterBeginMethod.toString());
        }
    } else if (BEFORE_COMPLETION_METHOD.getName().equals(attributeName)) {
        final Method beforeCompletionMethod = component.getBeforeCompletionMethod();
        if (beforeCompletionMethod != null) {
            result.set(beforeCompletionMethod.toString());
        }
    } else if (AFTER_COMPLETION_METHOD.getName().equals(attributeName)) {
        final Method afterCompletionMethod = component.getAfterCompletionMethod();
        if (afterCompletionMethod != null) {
            result.set(afterCompletionMethod.toString());
        }
    } else if (PASSIVATION_CAPABLE.getName().equals(attributeName)) {
        result.set(componentDescription.isPassivationApplicable());
    } else if (REMOVE_METHODS.getName().equals(attributeName)) {
        final Collection<StatefulComponentDescription.StatefulRemoveMethod> removeMethods = componentDescription.getRemoveMethods();
        for (StatefulComponentDescription.StatefulRemoveMethod removeMethod : removeMethods) {
            ModelNode removeMethodNode = result.add();
            final ModelNode beanMethodNode = removeMethodNode.get(BEAN_METHOD.getName());
            final MethodIdentifier methodIdentifier = removeMethod.getMethodIdentifier();
            beanMethodNode.set(methodIdentifier.getReturnType() + ' ' + methodIdentifier.getName() + '(' + String.join(", ", methodIdentifier.getParameterTypes()) + ')');
            final ModelNode retainIfExceptionNode = removeMethodNode.get(RETAIN_IF_EXCEPTION.getName());
            retainIfExceptionNode.set(removeMethod.getRetainIfException());
        }
    } else {
        super.executeReadAttribute(attributeName, context, component, address);
    }
// TODO expose the cache
}
Also used : StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) StatefulTimeoutInfo(org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo) Collection(java.util.Collection) Method(java.lang.reflect.Method) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)24 Method (java.lang.reflect.Method)17 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)9 List (java.util.List)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)5 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5 HashSet (java.util.HashSet)4 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)4 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)4 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 Module (org.jboss.modules.Module)4 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 UserInterceptorFactory (org.jboss.as.ee.component.interceptors.UserInterceptorFactory)3 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)3 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)3