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());
}
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);
}
}
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());
}
}
}
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));
}
}
}
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());
}
}
}
Aggregations