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