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); }
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 Method translateMethod(final DeploymentReflectionIndex deploymentReflectionIndex, final OperationAnalysis op) { final Method nonMethod = op.getMethod(); return deploymentReflectionIndex.getClassIndex(nonMethod.getDeclaringClass()).getMethod(nonMethod); }
/** * Do lazy lookup. * * @param lookup the lookup * @param start the start * @param depth the depth * @return reflection index result */ protected <U> U lookup(Lookup<U> lookup, int start, int depth) { int size; synchronized (indexes) { size = indexes.size(); for (int i = start; i < depth && i < size; i++) { U result = lookup.lookup(indexes.get(i)); if (result != null) return result; } } if (currentClass == null) return null; synchronized (indexes) { ClassReflectionIndex cri = index.getClassIndex(currentClass); indexes.add(cri); currentClass = currentClass.getSuperclass(); } return lookup(lookup, size, depth); }
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 ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(clazz); if (parameters == null) { final Collection<Method> methods = classIndex.getAllMethods(methodName);
private String inferLocalInterfaceFromLocalHome(final String localHomeClassName, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final SessionBeanComponentDescription description) throws ClassNotFoundException, DeploymentUnitProcessingException { final Class<?> localHomeClass = module.getClassLoader().loadClass(localHomeClassName); final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(localHomeClass); Class<?> localClass = null; for (final Method method : (Iterable<Method>)index.getMethods()) { if (method.getName().startsWith("create")) { if (localClass != null && localClass != method.getReturnType()) { throw EjbLogger.ROOT_LOGGER.multipleCreateMethod(localHomeClass); } localClass = method.getReturnType(); } } if (localClass == null) { throw EjbLogger.ROOT_LOGGER.couldNotDetermineLocalInterfaceFromLocalHome(localHomeClassName, description.getEJBName()); } return localClass.getName(); }
while (c != null && c != Object.class) { final ClassReflectionIndex classIndex = index.getClassIndex(c);
ClassReflectionIndex cri = index.getClassIndex(classInfo); Method result = locateMethod(cri, name, paramTypes, isStatic, isPublic, strict); if (result != null)
public Method getMethod(final DeploymentReflectionIndex reflectionIndex, final Class<?> clazz) throws DeploymentUnitProcessingException { final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(clazz); Collection<Method> methods = null; final String paramType = getDeclaredValueClassName(); final String name = getName(); final String className = getClassName(); if (paramType != null) { // find the methods with the specific name and the param types methods = ClassReflectionIndexUtil.findMethods(reflectionIndex, classIndex, name, paramType); } // either paramType is not set, or we may need to find autoboxing methods // e.g. setMyBoolean(boolean) for a Boolean if (methods == null || methods.isEmpty()) { // find all the methods with the specific name and which accept just 1 parameter. methods = ClassReflectionIndexUtil.findAllMethods(reflectionIndex, classIndex, name, 1); } Iterator<Method> iterator = methods.iterator(); if (!iterator.hasNext()) { throw EeLogger.ROOT_LOGGER.methodNotFound(name, paramType, className); } Method method = iterator.next(); if (iterator.hasNext()) { throw EeLogger.ROOT_LOGGER.multipleMethodsFound(name, paramType, className); } return method; } }
private Method resolveMethod(final DeploymentReflectionIndex index, final Class<?> currentClass, final Class<?> componentClass, final NamedMethodMetaData methodData) throws DeploymentUnitProcessingException { if (currentClass == null) { throw EjbLogger.ROOT_LOGGER.failToFindMethodWithParameterTypes(componentClass.getName(), methodData.getMethodName(), methodData.getMethodParams()); } final ClassReflectionIndex classIndex = index.getClassIndex(currentClass); if (methodData.getMethodParams() == null) { final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName()); if (methods.isEmpty()) { return resolveMethod(index, currentClass.getSuperclass(), componentClass, methodData); } else if (methods.size() > 1) { throw EjbLogger.ROOT_LOGGER.multipleMethodReferencedInEjbJarXml(methodData.getMethodName(), currentClass.getName()); } return methods.iterator().next(); } else { final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size()); for (final Method method : methods) { boolean match = true; for (int i = 0; i < method.getParameterTypes().length; ++i) { if (!method.getParameterTypes()[i].getName().equals(methodData.getMethodParams().get(i))) { match = false; break; } } if (match) { return method; } } } return resolveMethod(index, currentClass.getSuperclass(), componentClass, methodData); }
@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 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 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); } } });
@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 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, new StatefulWriteReplaceInterceptor.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; } }
Class<?> c = componentClass; while (c != null && c != Object.class) { final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(c);
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(clazz);
@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)); } } }