/** * Get the component class. * * @return the component class */ public Class<?> getComponentClass() { return classIndex.getIndexedClass(); }
static Method getGetter(final List<ClassReflectionIndex> classHierarchy, final String propertyName) { final String getterName = "get" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); final String iserName = "is" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); for (final ClassReflectionIndex classIndex : classHierarchy) { final Iterator<Method> methods = classIndex.getMethods().iterator(); Method method = null; String methodName = null; while (methods.hasNext()) { method = methods.next(); methodName = method.getName(); if ((getterName.equals(methodName) || iserName.equals(methodName)) && method.getParameterTypes().length == 0) { return method; } } } final String className = classHierarchy.get(0).getIndexedClass().getName(); throw SarLogger.ROOT_LOGGER.propertyMethodNotFound("Get", propertyName, className); }
static Method getSetter(final List<ClassReflectionIndex> classHierarchy, final String propertyName) { final String setterName = "set" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); for (final ClassReflectionIndex classIndex : classHierarchy) { final Iterator<Method> methods = classIndex.getMethods().iterator(); Method method = null; String methodName = null; while (methods.hasNext()) { method = methods.next(); methodName = method.getName(); if (setterName.equals(methodName) && method.getParameterTypes().length == 1) { return method; } } } final String className = classHierarchy.get(0).getIndexedClass().getName(); throw SarLogger.ROOT_LOGGER.propertyMethodNotFound("Set", propertyName, className); }
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; } }
private static Object newInstance(final JBossServiceConfig serviceConfig, final List<ClassReflectionIndex> mBeanClassHierarchy, final ClassLoader deploymentClassLoader) throws DeploymentUnitProcessingException { // set TCCL so that the MBean instantiation happens in the deployment's classloader final ClassLoader oldTCCL = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(deploymentClassLoader); try { final JBossServiceConstructorConfig constructorConfig = serviceConfig.getConstructorConfig(); final int paramCount = constructorConfig != null ? constructorConfig.getArguments().length : 0; final Class<?>[] types = new Class<?>[paramCount]; final Object[] params = new Object[paramCount]; if (constructorConfig != null) { final Argument[] arguments = constructorConfig.getArguments(); for (int i = 0; i < paramCount; i++) { final Argument argument = arguments[i]; types[i] = ReflectionUtils.getClass(argument.getType(), deploymentClassLoader); params[i] = newValue(ReflectionUtils.getClass(argument.getType(), deploymentClassLoader), argument.getValue()); } } final Constructor<?> constructor = mBeanClassHierarchy.get(0).getConstructor(types); if(constructor == null){ throw SarLogger.ROOT_LOGGER.defaultConstructorNotFound(mBeanClassHierarchy.get(0).getIndexedClass()); } final Object mBeanInstance = ReflectionUtils.newInstance(constructor, params); return mBeanInstance; } finally { // switch back the TCCL WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTCCL); } }
/** * Get the component class. * * @return the component class */ public Class<?> getComponentClass() { return classIndex.getIndexedClass(); }
/** * Get the component class. * * @return the component class */ public Class<?> getComponentClass() { return classIndex.getIndexedClass(); }
private void handleClassMethod(final Class<?> clazz, final MethodIdentifier methodIdentifier, final List<InterceptorFactory> interceptors, boolean changeMethod, boolean lifecycleMethod) throws DeploymentUnitProcessingException { if (methodIdentifier != null) { final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, methodIdentifier); if (isNotOverriden(clazz, method, componentClassIndex.getIndexedClass(), deploymentReflectionIndex)) { InterceptorFactory interceptorFactory = new ManagedReferenceLifecycleMethodInterceptorFactory(instanceKey, method, changeMethod, lifecycleMethod); interceptors.add(interceptorFactory); } } } }.run();
/** * 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; }
/** * 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; } }
/** * 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; } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; } }
/** * 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; }