@Override public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException { final DeploymentReflectionIndex index = context.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); ClassReflectionIndex classIndex = index.getClassIndex(WriteReplaceInterface.class); for (Method method : classIndex.getMethods()) { configuration.addClientInterceptor(method, StatelessWriteReplaceInterceptor.factory(configuration.getViewServiceName().getCanonicalName()), InterceptorOrder.Client.WRITE_REPLACE); } } });
@Override protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription description) throws DeploymentUnitProcessingException { final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX); //if we implement SessionSynchronization we can ignore any DD information if (SessionSynchronization.class.isAssignableFrom(componentClass)) { final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(SessionSynchronization.class); description.setAfterBegin(classIndex.getMethod(void.class, "afterBegin")); description.setAfterCompletion(classIndex.getMethod(void.class, "afterCompletion", boolean.class)); description.setBeforeCompletion(classIndex.getMethod(void.class,"beforeCompletion")); return; } SessionBeanMetaData data = description.getDescriptorData(); if (data instanceof SessionBean31MetaData) { SessionBean31MetaData metaData = (SessionBean31MetaData) data; if (metaData.getAfterBeginMethod() != null) description.setAfterBegin(MethodResolutionUtils.resolveMethod(metaData.getAfterBeginMethod(), componentClass,reflectionIndex)); if (metaData.getAfterCompletionMethod() != null) description.setAfterCompletion(MethodResolutionUtils.resolveMethod(metaData.getAfterCompletionMethod(), componentClass,reflectionIndex)); if (metaData.getBeforeCompletionMethod() != null) description.setBeforeCompletion(MethodResolutionUtils.resolveMethod(metaData.getBeforeCompletionMethod(), componentClass,reflectionIndex)); } } }
throw EeLogger.ROOT_LOGGER.cannotLoad(e, injectionTargetClassName); final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(injectionTargetClass); String methodName = "set" + injectionTargetName.substring(0, 1).toUpperCase(Locale.ENGLISH) + injectionTargetName.substring(1); Class<?> current = injectionTargetClass; while (current != Object.class && current != null && !methodFound) { final Collection<Method> methods = index.getAllMethods(methodName); for (Method m : methods) { if (m.getParameterTypes().length == 1) { current = injectionTargetClass; while (current != Object.class && current != null && field == null) { field = index.getField(injectionTargetName); if (field != null) { break;
static Method getMethod(final List<ClassReflectionIndex> classHierarchy, final String methodName, final Class<?>[] types, final boolean fail) { for (final ClassReflectionIndex classIndex : classHierarchy) { final Collection<Method> methods = classIndex.getMethods(methodName, types); if (methods.size() == 1) { return methods.iterator().next(); } } if (fail) { final String className = classHierarchy.get(0).getIndexedClass().getName(); throw SarLogger.ROOT_LOGGER.methodNotFound(methodName, parameterList(types), className); } else { return null; } }
while (c != null && c != Object.class) { final ClassReflectionIndex classIndex = index.getClassIndex(c); final Method method = classIndex.getMethod(entry.getKey()); if (method != null) { for (Method method : (Iterable<Method>)classIndex.getMethods()) { methodIdentifiers.add(MethodIdentifier.getIdentifierForMethod(method));
@Override public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException { final ClassReflectionIndex classIndex = context.getDeploymentUnit().getAttachment(Attachments.REFLECTION_INDEX).getClassIndex(configuration.getComponentClass()); final Constructor<?> ctor = classIndex.getConstructor(new String[0]); boolean noInterface = false; for(ViewDescription view : description.getViews()) { if(view.getViewClassName().equals(description.getComponentClassName())) { noInterface = true; } } EjbValidationsUtil.getBusinessMethods(configuration.getComponentClass()); EjbValidationsUtil.verifyEjbClassAndDefaultConstructor(ctor, configuration.getComponentClass().getEnclosingClass(), noInterface, description.getComponentName(), description.getComponentClassName(), configuration.getComponentClass().getModifiers()); EjbValidationsUtil.verifyEjbPublicMethodAreNotFinalNorStatic(configuration.getComponentClass().getDeclaredMethods(),description.getComponentClassName()); for ( Class<?> interfaceClass : configuration.getComponentClass().getInterfaces()) EjbValidationsUtil.verifyEjbPublicMethodAreNotFinalNorStatic(interfaceClass.getDeclaredMethods(), interfaceClass.getCanonicalName()); } }
@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA); final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); final DeploymentReflectionIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); final ClassReflectionIndex classIndex = index.getClassIndex(componentClass); Method resolvedMethod = null; if (methodData.getMethodParams() == null) { final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName()); if (methods.isEmpty()) { throw EjbLogger.ROOT_LOGGER.failToFindMethodInEjbJarXml(componentClass.getName(), methodData.getMethodName()); final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size()); for (final Method method : methods) { boolean match = true; final List<InterceptorBindingMetaData> methodBindings = entry.getValue(); boolean totalOrder = methodLevelAbsoluteOrder.containsKey(method); final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); final ApplicationClientMetaData appClientData = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_META_DATA); final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX); final DeploymentClassIndex classIndex = deploymentUnit.getAttachment(Attachments.CLASS_INDEX); final ApplicationClientComponentDescription component = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_COMPONENT); ClassReflectionIndex<?> index = deploymentReflectionIndex.getClassIndex(mainClass); Method method = index.getMethod(void.class, "main", String[].class); if (method == null) { throw MESSAGES.cannotStartAppClient(deploymentUnit.getName(), mainClass); phaseContext.getServiceTarget() .addService(deploymentUnit.getServiceName().append(ApplicationClientStartService.SERVICE_NAME), startService) .addDependency(ApplicationClientDeploymentService.SERVICE_NAME, ApplicationClientDeploymentService.class, startService.getApplicationClientDeploymentServiceInjectedValue())
@Override public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = context.getDeploymentUnit(); String contextID = deploymentUnit.getName(); if (deploymentUnit.getParent() != null) { contextID = deploymentUnit.getParent().getName() + "!" + contextID; configuration.addTimeoutViewInterceptor(new SecurityContextInterceptorFactory(securityRequired, policyContextID), InterceptorOrder.View.SECURITY_CONTEXT); final Set<Method> classMethods = configuration.getClassIndex().getClassMethods(); for (final Method method : classMethods) { configuration.addTimeoutViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(method)), InterceptorOrder.View.COMPONENT_DISPATCHER);
private Field getField(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException { final String name = getName(); final String className = getClassName(); final Module module = deploymentUnit.getAttachment(MODULE); final ModuleClassLoader classLoader = module.getClassLoader(); final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX); final ClassReflectionIndex classIndex; try { classIndex = reflectionIndex.getClassIndex(Class.forName(className, false, classLoader)); } catch (ClassNotFoundException e) { throw new DeploymentUnitProcessingException(e); } final Field field = classIndex.getField(name); if (field == null) { throw EeLogger.ROOT_LOGGER.fieldNotFound(name); } return field; } }
private Method translateMethod(final DeploymentReflectionIndex deploymentReflectionIndex, final OperationAnalysis op) { final Method nonMethod = op.getMethod(); return deploymentReflectionIndex.getClassIndex(nonMethod.getDeclaringClass()).getMethod(nonMethod); }
private void addDefaultMethods(final Class<?> componentClass, Set<MethodIdentifier> foundMethods, Map<Class<?>, Set<Method>> defaultMethodsByInterface, Class<?>[] interfaces) { for (Class<?> i : interfaces) { if (! defaultMethodsByInterface.containsKey(i)) { Set<Method> set = methodSet(); defaultMethodsByInterface.put(i, set); final ClassReflectionIndex interfaceIndex = deploymentReflectionIndex.getClassIndex(i); for (Method method : interfaceIndex.getMethods()) { final MethodIdentifier identifier = MethodIdentifier.getIdentifierForMethod(method); if ((method.getModifiers() & (STATIC | PUBLIC | ABSTRACT)) == PUBLIC && ! classContains(componentClass, identifier) && foundMethods.add(identifier)) { set.add(method); } } } addDefaultMethods(componentClass, foundMethods, defaultMethodsByInterface, i.getInterfaces()); } }
/** * Finds and returns all methods corresponding to the passed method <code>name</code>. * The passed <code>classReflectionIndex</code> will be used to traverse the class hierarchy while finding the method. * <p/> * Returns empty collection if no such method is found * * @param deploymentReflectionIndex The deployment reflection index * @param classReflectionIndex The class reflection index which will be used to traverse the class hierarchy to find the method * @param methodName The name of the method * @return */ public static Collection<Method> findAllMethodsByName(final DeploymentReflectionIndex deploymentReflectionIndex, final ClassReflectionIndex classReflectionIndex, final String methodName) { Collection<Method> methods = classReflectionIndex.getAllMethods(methodName); if (!methods.isEmpty()) { return methods; } // find on super class Class<?> superClass = classReflectionIndex.getIndexedClass().getSuperclass(); if (superClass != null) { ClassReflectionIndex superClassIndex = deploymentReflectionIndex.getClassIndex(superClass); if (superClassIndex != null) { return findAllMethodsByName(deploymentReflectionIndex, superClassIndex, methodName); } } return methods; } }
private Method findRealMethodForBridgeMethod(final Method componentMethod, final ComponentConfiguration componentConfiguration, final DeploymentReflectionIndex reflectionIndex, final MethodIdentifier methodIdentifier) { final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(componentMethod.getDeclaringClass()); //the non-bridge method will be on the same class as the bridge method final Collection<Method> methods = classIndex.getAllMethods(componentMethod.getName(), componentMethod.getParameterTypes().length); for(final Method method : methods) { if ((BRIDGE & method.getModifiers()) == 0) { if(componentMethod.getReturnType().isAssignableFrom(method.getReturnType())) { boolean ok = true; for(int i = 0; i < method.getParameterTypes().length; ++i) { if(!componentMethod.getParameterTypes()[i].isAssignableFrom(method.getParameterTypes()[i])) { ok = false; break; } } if(ok) { return method; } } } } return null; } }
final MethodIdentifier ejbRemoveIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbRemove"); final MethodIdentifier ejbActivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbActivate"); final MethodIdentifier ejbPassivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbPassivate"); final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(c); final Method method = index.getMethod(ejbActivateIdentifier); if(method != null) { final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(); final Method method = index.getMethod(ejbPassivateIdentifier); if(method != null) { final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(); final Method method = index.getMethod(ejbRemoveIdentifier); if(method != null) { final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
/** * Finds and returns methods corresponding to the passed method <code>name</code> and method <code>paramTypes</code>. * The passed <code>classReflectionIndex</code> will be used to traverse the class hierarchy while finding the method. * <p/> * Returns empty collection if no such method is found * * @param deploymentReflectionIndex The deployment reflection index * @param classReflectionIndex The class reflection index which will be used to traverse the class hierarchy to find the method * @param methodName The name of the method * @param paramTypes The param types accepted by the method * @return */ public static Collection<Method> findMethods(final DeploymentReflectionIndex deploymentReflectionIndex, final ClassReflectionIndex classReflectionIndex, final String methodName, final String... paramTypes) { final Collection<Method> methods = classReflectionIndex.getMethods(methodName, paramTypes); if (!methods.isEmpty()) { return methods; } // find on super class Class<?> superClass = classReflectionIndex.getIndexedClass().getSuperclass(); if (superClass != null) { ClassReflectionIndex superClassIndex = deploymentReflectionIndex.getClassIndex(superClass); if (superClassIndex != null) { return findMethods(deploymentReflectionIndex, superClassIndex, methodName, paramTypes); } } return methods; }
private String inferRemoteInterfaceFromHome(final String homeClassName, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final SessionBeanComponentDescription description) throws ClassNotFoundException, DeploymentUnitProcessingException { final Class<?> homeClass = module.getClassLoader().loadClass(homeClassName); final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(homeClass); Class<?> remote = null; for (final Method method : (Iterable<Method>)index.getMethods()) { if (method.getName().startsWith("create")) { if (remote != null && remote != method.getReturnType()) { throw EjbLogger.ROOT_LOGGER.multipleCreateMethod(homeClass); } remote = method.getReturnType(); } } if(remote == null) { throw EjbLogger.ROOT_LOGGER.couldNotDetermineRemoteInterfaceFromHome(homeClassName, description.getEJBName()); } return remote.getName(); }
@Override public void handle(final Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException { final InterceptorClassDescription interceptorConfig; if (classDescription != null) { interceptorConfig = InterceptorClassDescription.merge(classDescription.getInterceptorClassDescription(), moduleDescription.getInterceptorClassOverride(clazz.getName())); } else { interceptorConfig = InterceptorClassDescription.merge(null, moduleDescription.getInterceptorClassOverride(clazz.getName())); } // get the container-interceptor class' constructor final ClassReflectionIndex interceptorClassReflectionIndex = deploymentReflectionIndex.getClassIndex(interceptorClass); final Constructor<?> interceptorClassConstructor = interceptorClassReflectionIndex.getConstructor(EMPTY_CLASS_ARRAY); if (interceptorClassConstructor == null) { throw EeLogger.ROOT_LOGGER.defaultConstructorNotFound(interceptorClass); } final MethodIdentifier aroundInvokeMethodIdentifier = interceptorConfig.getAroundInvoke(); final InterceptorFactory aroundInvokeInterceptorFactory = createInterceptorFactory(clazz, aroundInvokeMethodIdentifier, interceptorClassConstructor); if (aroundInvokeInterceptorFactory != null) { this.aroundInvokeInterceptorFactories.add(aroundInvokeInterceptorFactory); } if (ejbComponentDescription.isTimerServiceRequired()) { final MethodIdentifier aroundTimeoutMethodIdentifier = interceptorConfig.getAroundTimeout(); final InterceptorFactory aroundTimeoutInterceptorFactory = createInterceptorFactory(clazz, aroundTimeoutMethodIdentifier, interceptorClassConstructor); if (aroundTimeoutInterceptorFactory != null) { this.aroundTimeoutInterceptorFactories.add(aroundTimeoutInterceptorFactory); } } }
@Override public Method getMethod(final String methodName, final Class<?> returnType, final Class<?>... parameters) throws NoSuchMethodException { return index.getMethod(returnType, methodName, parameters); }
@Override public Method lookup(ClassReflectionIndex index) { Collection<Method> methods = index.getAllMethods(name, 0); if (type == null) { if (methods.size() == 1) return methods.iterator().next(); else return null; } for (Method m : methods) { Class<?> pt = m.getReturnType(); if (pt.isAssignableFrom(type)) return m; } return null; } }, 0, Integer.MAX_VALUE);