Search in sources :

Example 1 with MethodIdentifier

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

the class PassivationAnnotationParsingProcessor method processPassivation.

private void processPassivation(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
    if (!(target instanceof MethodInfo)) {
        throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType);
    }
    final MethodInfo methodInfo = MethodInfo.class.cast(target);
    final ClassInfo classInfo = methodInfo.declaringClass();
    final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
    final Type[] args = methodInfo.args();
    if (args.length > 1) {
        ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name()));
        return;
    } else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) {
        ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)"));
        return;
    }
    final MethodIdentifier methodIdentifier;
    if (args.length == 0) {
        methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name());
    } else {
        methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name(), InvocationContext.class);
    }
    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
    if (annotationType == POST_ACTIVATE) {
        builder.setPostActivate(methodIdentifier);
    } else {
        builder.setPrePassivate(methodIdentifier);
    }
    classDescription.setInterceptorClassDescription(builder.build());
}
Also used : Type(org.jboss.jandex.Type) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) MethodInfo(org.jboss.jandex.MethodInfo) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) InvocationContext(javax.interceptor.InvocationContext) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with MethodIdentifier

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

the class AbstractEJBComponentRuntimeHandler method executeReadAttribute.

protected void executeReadAttribute(final String attributeName, final OperationContext context, final T component, final PathAddress address) {
    final boolean hasPool = componentType.hasPool();
    final ModelNode result = context.getResult();
    final EJBComponentDescription componentDescription = component.getComponentDescription();
    if (COMPONENT_CLASS_NAME.getName().equals(attributeName)) {
        result.set(component.getComponentClass().getName());
    } else if (JNDI_NAMES.getName().equals(attributeName)) {
        for (ViewDescription view : componentDescription.getViews()) {
            for (String binding : view.getBindingNames()) {
                result.add(binding);
            }
        }
    } else if (BUSINESS_LOCAL.getName().equals(attributeName)) {
        for (final ViewDescription view : componentDescription.getViews()) {
            final EJBViewDescription ejbViewDescription = (EJBViewDescription) view;
            if (!ejbViewDescription.isEjb2xView() && ejbViewDescription.getMethodIntf() == MethodIntf.LOCAL) {
                result.add(ejbViewDescription.getViewClassName());
            }
        }
    } else if (BUSINESS_REMOTE.getName().equals(attributeName)) {
        for (final ViewDescription view : componentDescription.getViews()) {
            final EJBViewDescription ejbViewDescription = (EJBViewDescription) view;
            if (!ejbViewDescription.isEjb2xView() && ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE) {
                result.add(ejbViewDescription.getViewClassName());
            }
        }
    } else if (TIMEOUT_METHOD.getName().equals(attributeName)) {
        final Method timeoutMethod = component.getTimeoutMethod();
        if (timeoutMethod != null) {
            result.set(timeoutMethod.toString());
        }
    } else if (ASYNC_METHODS.getName().equals(attributeName)) {
        final SessionBeanComponentDescription sessionBeanComponentDescription = (SessionBeanComponentDescription) componentDescription;
        final Set<MethodIdentifier> asynchronousMethods = sessionBeanComponentDescription.getAsynchronousMethods();
        for (MethodIdentifier m : asynchronousMethods) {
            result.add(m.getReturnType() + ' ' + m.getName() + '(' + String.join(", ", m.getParameterTypes()) + ')');
        }
    } else if (TRANSACTION_TYPE.getName().equals(attributeName)) {
        result.set(component.isBeanManagedTransaction() ? TransactionManagementType.BEAN.name() : TransactionManagementType.CONTAINER.name());
    } else if (SECURITY_DOMAIN.getName().equals(attributeName)) {
        EJBSecurityMetaData md = component.getSecurityMetaData();
        if (md != null && md.getSecurityDomainName() != null) {
            result.set(md.getSecurityDomainName());
        }
    } else if (RUN_AS_ROLE.getName().equals(attributeName)) {
        EJBSecurityMetaData md = component.getSecurityMetaData();
        if (md != null && md.getRunAs() != null) {
            result.set(md.getRunAs());
        }
    } else if (DECLARED_ROLES.getName().equals(attributeName)) {
        EJBSecurityMetaData md = component.getSecurityMetaData();
        if (md != null) {
            result.setEmptyList();
            Set<String> roles = md.getDeclaredRoles();
            if (roles != null) {
                for (String role : roles) {
                    result.add(role);
                }
            }
        }
    } else if (componentType.hasTimer() && TimerAttributeDefinition.INSTANCE.getName().equals(attributeName)) {
        TimerAttributeDefinition.addTimers(component, result);
    } else if (hasPool && POOL_AVAILABLE_COUNT.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getAvailableCount());
        }
    } else if (hasPool && POOL_CREATE_COUNT.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getCreateCount());
        }
    } else if (hasPool && POOL_NAME.getName().equals(attributeName)) {
        final String poolName = componentType.pooledComponent(component).getPoolName();
        if (poolName != null) {
            result.set(poolName);
        }
    } else if (hasPool && POOL_REMOVE_COUNT.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getRemoveCount());
        }
    } else if (hasPool && POOL_CURRENT_SIZE.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getCurrentSize());
        }
    } else if (hasPool && POOL_MAX_SIZE.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getMaxSize());
        }
    } else {
        // Bug; we were registered for an attribute but there is no code for handling it
        throw EjbLogger.ROOT_LOGGER.unknownAttribute(attributeName);
    }
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) Set(java.util.Set) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) Method(java.lang.reflect.Method) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) EJBSecurityMetaData(org.jboss.as.ejb3.security.EJBSecurityMetaData) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) Pool(org.jboss.as.ejb3.pool.Pool) ModelNode(org.jboss.dmr.ModelNode) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Example 3 with MethodIdentifier

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

the class DataSourceDefinitionInjectionSource method setProperty.

private void setProperty(final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> dataSourceClass, final Map<String, String> properties, final String name, final Object value) {
    // Ignore defaulted values
    if (value == null || "".equals(value))
        return;
    if (value instanceof Integer && ((Integer) value).intValue() == -1)
        return;
    StringBuilder builder = new StringBuilder("set").append(name);
    builder.setCharAt(3, Character.toUpperCase(name.charAt(0)));
    final String methodName = builder.toString();
    final Class<?> paramType = value.getClass();
    MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, paramType);
    Method setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier);
    if (setterMethod != null) {
        properties.put(name, value.toString());
    } else if (paramType == Integer.class) {
        // if this is an Integer also look for int setters (WFLY-1364)
        methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, int.class);
        setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier);
        if (setterMethod != null) {
            properties.put(name, value.toString());
        }
    } else if (paramType == Boolean.class) {
        methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, boolean.class);
        setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier);
        if (setterMethod != null) {
            properties.put(name, value.toString());
        }
    }
}
Also used : MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method)

Example 4 with MethodIdentifier

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

the class InterceptorAnnotationProcessor method handleAnnotations.

private void handleAnnotations(final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final ComponentDescription description) {
    final List<Class> heirachy = new ArrayList<Class>();
    Class c = componentClass;
    while (c != Object.class && c != null) {
        heirachy.add(c);
        c = c.getSuperclass();
    }
    Collections.reverse(heirachy);
    final RuntimeAnnotationInformation<Boolean> excludeDefaultInterceptors = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, ExcludeDefaultInterceptors.class);
    if (excludeDefaultInterceptors.getClassAnnotations().containsKey(componentClass.getName())) {
        description.setExcludeDefaultInterceptors(true);
    }
    for (final Map.Entry<Method, List<Boolean>> entry : excludeDefaultInterceptors.getMethodAnnotations().entrySet()) {
        description.excludeDefaultInterceptors(MethodIdentifier.getIdentifierForMethod(entry.getKey()));
    }
    final RuntimeAnnotationInformation<Boolean> excludeClassInterceptors = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, ExcludeClassInterceptors.class);
    for (final Map.Entry<Method, List<Boolean>> entry : excludeClassInterceptors.getMethodAnnotations().entrySet()) {
        description.excludeClassInterceptors(MethodIdentifier.getIdentifierForMethod(entry.getKey()));
    }
    final RuntimeAnnotationInformation<String[]> interceptors = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Interceptors.class);
    // walk the class heirachy in reverse
    for (final Class<?> clazz : heirachy) {
        final List<String[]> classInterceptors = interceptors.getClassAnnotations().get(clazz.getName());
        if (classInterceptors != null) {
            for (final String interceptor : classInterceptors.get(0)) {
                description.addClassInterceptor(new InterceptorDescription(interceptor));
            }
        }
    }
    for (final Map.Entry<Method, List<String[]>> entry : interceptors.getMethodAnnotations().entrySet()) {
        final MethodIdentifier method = MethodIdentifier.getIdentifierForMethod(entry.getKey());
        for (final String interceptor : entry.getValue().get(0)) {
            description.addMethodInterceptor(method, new InterceptorDescription(interceptor));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 5 with MethodIdentifier

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

the class DescriptorEnvironmentLifecycleMethodProcessor method handleMethods.

public static void handleMethods(DeploymentDescriptorEnvironment env, EEModuleDescription eeModuleDescription, String defaultClassName) throws DeploymentUnitProcessingException {
    final RemoteEnvironment environment = env.getEnvironment();
    // post-construct(s) of the interceptor configured (if any) in the deployment descriptor
    LifecycleCallbacksMetaData postConstructs = environment.getPostConstructs();
    if (postConstructs != null) {
        for (LifecycleCallbackMetaData postConstruct : postConstructs) {
            String className = postConstruct.getClassName();
            if (className == null || className.isEmpty()) {
                if (defaultClassName == null) {
                    continue;
                } else {
                    className = defaultClassName;
                }
            }
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            String methodName = postConstruct.getMethodName();
            MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
            builder.setPostConstruct(methodIdentifier);
            eeModuleDescription.addInterceptorMethodOverride(className, builder.build());
        }
    }
    // pre-destroy(s) of the interceptor configured (if any) in the deployment descriptor
    LifecycleCallbacksMetaData preDestroys = environment.getPreDestroys();
    if (preDestroys != null) {
        for (LifecycleCallbackMetaData preDestroy : preDestroys) {
            String className = preDestroy.getClassName();
            if (className == null || className.isEmpty()) {
                if (defaultClassName == null) {
                    continue;
                } else {
                    className = defaultClassName;
                }
            }
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            String methodName = preDestroy.getMethodName();
            MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
            builder.setPreDestroy(methodIdentifier);
            eeModuleDescription.addInterceptorMethodOverride(className, builder.build());
        }
    }
}
Also used : RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) LifecycleCallbackMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) LifecycleCallbacksMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData)

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