@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()); } }
@SuppressWarnings("unchecked") public Object create() throws Throwable { Module module = bmd.getModule().getInjectedModule().getValue(); final SecurityManager sm = System.getSecurityManager(); ClassLoader moduleClassLoader; if (sm == null) { moduleClassLoader = module.getClassLoader(); } else { moduleClassLoader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> module.getClassLoader()); } Class<?> beanClass = moduleClassLoader.loadClass(bmd.getBeanClass()); DeploymentReflectionIndex index; if (sm == null) { index = DeploymentReflectionIndex.create(); } else { index = AccessController.doPrivileged((PrivilegedAction<DeploymentReflectionIndex>) () -> DeploymentReflectionIndex.create()); } BeanInfo beanInfo = new DefaultBeanInfo(index, beanClass); Object result = BeanUtils.instantiateBean(bmd, beanInfo, index, module); BeanUtils.configure(bmd, beanInfo, module, result, false); BeanUtils.dispatchLifecycleJoinpoint(beanInfo, result, bmd.getCreate(), "create"); BeanUtils.dispatchLifecycleJoinpoint(beanInfo, result, bmd.getStart(), "start"); return result; }
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); if (module == null || moduleDescription == null) { return; final ClassLoader oldCl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader()); final Iterator<ComponentDescription> iterator = moduleDescription.getComponentDescriptions().iterator(); while (iterator.hasNext()) { final ComponentConfiguration componentConfiguration; try { componentConfiguration = componentDescription.createConfiguration(reflectionIndex.getClassIndex(ClassLoadingUtils.loadClass(componentDescription.getComponentClassName(), module)), module.getClassLoader(), module.getModuleLoader()); for (final ComponentConfigurator componentConfigurator : componentDescription.getConfigurators()) { componentConfigurator.configure(phaseContext, componentDescription, componentConfiguration);
@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); componentClass = module.getClassLoader().loadClass(componentDescription.getComponentClassName()); } catch (ClassNotFoundException e) { throw EjbLogger.ROOT_LOGGER.failToLoadComponentClass(e, componentDescription.getComponentClassName()); 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;
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); Module module = deploymentUnit.getAttachment(Attachments.MODULE); if (module == null) { throw ServerLogger.ROOT_LOGGER.nullModuleAttachment(deploymentUnit); } if(deploymentUnit.getParent() == null) { final DeploymentReflectionIndex index = DeploymentReflectionIndex.create(); deploymentUnit.putAttachment(Attachments.REFLECTION_INDEX, index); deploymentUnit.putAttachment(Attachments.PROXY_REFLECTION_INDEX, new ProxyMetadataSource(index)); } else { final DeploymentReflectionIndex index = deploymentUnit.getParent().getAttachment(Attachments.REFLECTION_INDEX); deploymentUnit.putAttachment(Attachments.REFLECTION_INDEX, index); deploymentUnit.putAttachment(Attachments.PROXY_REFLECTION_INDEX, deploymentUnit.getParent().getAttachment(Attachments.PROXY_REFLECTION_INDEX)); } }
@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); SecurityActions.setContextClassLoader(module.getClassLoader()); configuration = new PropertiesBasedEJBClientConfiguration(properties); startService = new ApplicationClientStartService(method, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions, configuration); } finally { SecurityActions.setContextClassLoader(oldTccl); startService = new ApplicationClientStartService(method, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions, hostUrl, callbackHandler); 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 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 : (Collection<Method>)classIndex.getMethods()) { configuration.addClientInterceptor(method, StatelessWriteReplaceInterceptor.factory(configuration.getViewServiceName().getCanonicalName()), InterceptorOrder.Client.WRITE_REPLACE); } } });
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 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(); }
final String className = getClassName(); final String paramType = getDeclaredValueClassName(); 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);
@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)); } } }
private Method translateMethod(final DeploymentReflectionIndex deploymentReflectionIndex, final OperationAnalysis op) { final Method nonMethod = op.getMethod(); return deploymentReflectionIndex.getClassIndex(nonMethod.getDeclaringClass()).getMethod(nonMethod); }
/** * Finds and returns all methods corresponding to the passed method <code>name</code> and method <code>paramCount</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 paramCount The number of params accepted by the method * @return */ public static Collection<Method> findAllMethods(final DeploymentReflectionIndex deploymentReflectionIndex, final ClassReflectionIndex classReflectionIndex, final String methodName, int paramCount) { Collection<Method> methods = classReflectionIndex.getAllMethods(methodName, paramCount); 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 findAllMethods(deploymentReflectionIndex, superClassIndex, methodName, paramCount); } } return methods; }
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(clazz); for (Method method : (Iterable<Method>)index.getMethods()) { if (method.getName().startsWith("ejbCreate")) {
/** * 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 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; } }
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()); } }
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()) {
static List<ClassReflectionIndex> getClassHierarchy(final String className, final DeploymentReflectionIndex index, final ClassLoader classLoader) { final List<ClassReflectionIndex> retVal = new LinkedList<ClassReflectionIndex>(); Class<?> temp = getClass(className, classLoader); while (temp != null) { retVal.add(index.getClassIndex(temp)); temp = temp.getSuperclass(); } return Collections.unmodifiableList(retVal); }
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;