Resolve bean class for bean method action rule.

@param beanMethodActionRule the bean method action rule
@throws IllegalRuleException if an illegal rule is found
421456
public void resolveActionBeanClass(BeanMethodActionRule beanMethodActionRule) throws IllegalRuleException {
        String beanIdOrClass = beanMethodActionRule.getBeanId();
        if (beanIdOrClass != null) {
            Class<?> beanClass = resolveBeanClass(beanIdOrClass, beanMethodActionRule);
            if (beanClass != null) {
                beanMethodActionRule.setBeanClass(beanClass);
                reserveBeanReference(beanClass, beanMethodActionRule);
            } else {
                reserveBeanReference(beanIdOrClass, beanMethodActionRule);
            }
        }
    }
174735
public void resolveBeanClass(ScheduleRule scheduleRule) throws IllegalRuleException {
        String beanId = scheduleRule.getSchedulerBeanId();
        if (beanId != null) {
            Class<?> beanClass = resolveBeanClass(beanId, scheduleRule);
            if (beanClass != null) {
                scheduleRule.setSchedulerBeanClass(beanClass);
                reserveBeanReference(beanClass, scheduleRule);
            } else {
                reserveBeanReference(beanId, scheduleRule);
            }
        }
    }
1036420
private void initializeLifecycleInterceptorMethodMD(Method[] ejbMethods,
                                                        List<ContainerTransaction> transactionList,
                                                        List<ActivitySessionMethod> activitySessionList,
                                                        BeanMetaData bmd) throws EJBConfigurationException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "initializeLifecycleInterceptorMethodMD", (Object[]) ejbMethods);

        final int numMethods = LifecycleInterceptorWrapper.NUM_METHODS;
        String[] methodNames = new String[numMethods];
        Class<?>[][] methodParamTypes = new Class<?>[numMethods][];
        String[] methodSignatures = new String[numMethods];
        TransactionAttribute[] transactionAttrs = new TransactionAttribute[numMethods];
        ActivitySessionAttribute[] activitySessionAttrs = new ActivitySessionAttribute[numMethods];

        for (int i = 0; i < numMethods; i++) {
            if (ejbMethods[i] == null) {
                methodNames[i] = LifecycleInterceptorWrapper.METHOD_NAMES[i];
                methodParamTypes[i] = LifecycleInterceptorWrapper.METHOD_PARAM_TYPES[i];
                methodSignatures[i] = LifecycleInterceptorWrapper.METHOD_SIGNATURES[i];
                // The spec states that in order to specify a transaction attribute
                // for lifecycle interceptor methods, the method must be declared
                // on the bean class.  Afterwards, it states that if a transaction
                // attribute is not specified, then it must be REQUIRED.  This
                // implies that if the bean class specifies a class-level
                // transaction attribute of NOT_SUPPORT but does not specify a
                // lifecycle interceptor method, we still use REQUIRED for the
                // other lifecycle interceptors.
                //
                // By specifying the default transaction attribute here, we avoid
                // NPE in getAnnotationCMTransactions by using null ejbMethods[i].
                transactionAttrs[i] = bmd.type == InternalConstants.TYPE_STATEFUL_SESSION ? TransactionAttribute.TX_NOT_SUPPORTED : TransactionAttribute.TX_REQUIRED;
            } else {
                methodNames[i] = ejbMethods[i].getName();
                methodParamTypes[i] = ejbMethods[i].getParameterTypes();
                methodSignatures[i] = MethodAttribUtils.methodSignatureOnly(ejbMethods[i]);
            }
        }

        initializeBeanMethodTransactionAttributes(false,
                                                  false,
                                                  MethodInterface.LIFECYCLE_INTERCEPTOR,
                                                  ejbMethods,
                                                  null,
                                                  null,
                                                  transactionList,
                                                  activitySessionList,
                                                  methodNames,
                                                  methodParamTypes,
                                                  methodSignatures,
                                                  transactionAttrs,
                                                  activitySessionAttrs,
                                                  bmd);

        EJBMethodInfoImpl[] methodInfos = new EJBMethodInfoImpl[numMethods];

        int slotSize = bmd.container.getEJBRuntime().getMetaDataSlotSize(MethodMetaData.class);
        for (int i = 0; i < numMethods; i++) {
            String methodSig = ejbMethods[i] == null ? methodNames[i] + MethodAttribUtils.METHOD_ARGLIST_SEP
                                                       + methodSignatures[i] : MethodAttribUtils.methodSignature(ejbMethods[i]);
            String jdiMethodSig = ejbMethods[i] == null ? LifecycleInterceptorWrapper.METHOD_JDI_SIGNATURES[i] : MethodAttribUtils.jdiMethodSignature(ejbMethods[i]);

            EJBMethodInfoImpl methodInfo = bmd.createEJBMethodInfoImpl(slotSize);
            methodInfo.initializeInstanceData(methodSig, methodNames[i], bmd, MethodInterface.LIFECYCLE_INTERCEPTOR, transactionAttrs[i], false);
            methodInfo.setMethodDescriptor(jdiMethodSig);
            methodInfo.setActivitySessionAttribute(activitySessionAttrs[i]);
            methodInfos[i] = methodInfo;
        }

        bmd.lifecycleInterceptorMethodInfos = methodInfos;
        bmd.lifecycleInterceptorMethodNames = methodNames;

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "initializeLifecycleInterceptorMethodMD");
    }
1321774
public void setRootMethodAdapter(JavaRootMethodAdapter rootMethodAdapter) {
        if (rootMethodAdapter == null) {
            throw new NullPointerException();
        }
        if (acceptableTestFramework == null) {
            throw new IllegalStateException("acceptableTestFramework is not set");
        }
        if (acceptableTestFramework.equals(rootMethodAdapter.getName())) {
            this.rootMethodAdapter = rootMethodAdapter;
        }
    }
1025665
private static Method findSetMethod(Class<? extends Bean> beanType, String setterName, Class<?> fieldType) {
        try {
            return beanType.getDeclaredMethod(setterName, fieldType);
        } catch (NoSuchMethodException ex) {
            Method[] methods = beanType.getMethods();
            List<Method> potential = new ArrayList<>();
            for (Method method : methods) {
                if (method.getName().equals(setterName) && method.getParameterTypes().length == 1) {
                    potential.add(method);
                }
            }
            if (potential.size() == 1) {
                return potential.get(0);
            }
            for (Method method : potential) {
                if (method.getParameterTypes()[0].equals(fieldType)) {
                    return method;
                }
            }
            return null;
        }
    }
1295967
private boolean isHandledByFilter(Method method) {
        // "Resource classes are POJOs that have at least one method annotated
        // with @Path or a request method designator. [...]
        //
        // Resource methods are methods of a resource class annotated with a
        // request method designator. [...] A request method designator is a
        // runtime annotation that is annotated with the @HttpMethod
        // annotation."
        for (Annotation annotation : method.getAnnotations()) {
            if (HttpMethod.class.isAssignableFrom(annotation.annotationType())) {
                return true;
            }
        }

        if (method.isAnnotationPresent(Path.class)) {
            return true;
        }

        return false;
    }
1331258
private function createMethodRule(string $class, string $method): RuleInterface
    {
        $rule = (new Rule())
            ->setName($method)
            ->setTarget($this->target(RequestProperties::REQ_ACTION, $method))
            ->setEffect(new Logical([$class, $method]))
            ->setName("$class::$method");

        return $rule;
    }
593329
public static BeanParser getBeanParser(Method method) {
    Type returnType = method.getReturnType();
    if (isCompletableFutureType(method.getReturnType())) {
      returnType = getActualReturnType(method);
    }
    BeanParser beanParser = typeBeanParserMap.get(returnType);
    if (beanParser != null) {
      return beanParser;
    }
    return defaultBeanParser;
  }
1158916
public void executeAround(Object interceptor, Method method) {
		if (method != null) {
			Object[] params = parametersResolver.parametersFor(method);
			stepInvoker.tryToInvoke(interceptor, method, params);
		} else {
			simpleInterceptorStack.get().next();
		}
	}
1227607
public void executeMethods(final List<Method> methods) throws Exception {

        for (final Method method : methods) {

            // TODO - curious about the findSuitableInstancesOf ? won't
            // method.getDeclaringClass be ok??

            for (final Object object : findSuitableInstancesOf(method.getDeclaringClass())) {

                method.invoke(object);

            }
        }
    }
1117147
public static void validateReturnType(Method method, Class<? extends Annotation> annotationType,
                                          Class<?> expectedReturnType) {
        if (!method.getReturnType().equals(expectedReturnType)) {
            throw new BeanCreationException("Method " + method.getName() + " annotated with @"
                  + annotationType.getName() + " must have a return type of "
                  + expectedReturnType.getName());
        }
    }
62849
@SuppressWarnings("unused")
    @Internal
    protected final void injectBeanField(BeanResolutionContext resolutionContext, DefaultBeanContext context, int index, Object bean) {
        FieldInjectionPoint fieldInjectionPoint = fieldInjectionPoints.get(index);
        boolean isInject = fieldInjectionPoint.getAnnotationMetadata().hasDeclaredAnnotation(Inject.class);
        try {
            Object value;
            if (isInject) {
                value = getBeanForField(resolutionContext, context, fieldInjectionPoint);
            } else {
                value = getValueForField(resolutionContext, context, index);
            }
            if (value != null) {
                //noinspection unchecked
                fieldInjectionPoint.set(bean, value);
            }
        } catch (Throwable e) {
            if (e instanceof BeanContextException) {
                throw (BeanContextException) e;
            } else {
                throw new DependencyInjectionException(resolutionContext, fieldInjectionPoint, "Error setting field value: " + e.getMessage(), e);
            }
        }
    }
794819
public static void asserTrueOrMissedAnnotationOnClassException(boolean expression, TypeElement daoElement,
			String entityName) {
		if (!expression) {
			String msg = String.format("Dao '%s' referes a bean '%s' without @%s or @%s annotation",
					daoElement.getQualifiedName(), TypeUtility.className(entityName), BindType.class.getSimpleName(),
					BindSqlType.class.getSimpleName());
			throw (new MissedAnnotationOnClass(msg));
		}

	}
380820
@Override
    protected void createForwardingMethodBody(ClassMethod classMethod, final MethodInformation methodInfo, ClassMethod staticConstructor) {
        final Method method = methodInfo.getMethod();
        // we can only use bytecode based invocation for some methods
        // at the moment we restrict it solely to public methods with public
        // return and parameter types
        boolean bytecodeInvocationAllowed = Modifier.isPublic(method.getModifiers()) && Modifier.isPublic(method.getReturnType().getModifiers());
        for (Class<?> paramType : method.getParameterTypes()) {
            if (!Modifier.isPublic(paramType.getModifiers())) {
                bytecodeInvocationAllowed = false;
                break;
            }
        }
        if (!bytecodeInvocationAllowed) {
            createInterceptorBody(classMethod, methodInfo, staticConstructor);
            return;
        }

        // create a new interceptor invocation context whenever we invoke a method on a client proxy
        // we use a try-catch block in order to make sure that endInterceptorContext() is invoked regardless whether
        // the method has succeeded or not

        new RunWithinInterceptionDecorationContextGenerator(classMethod, this) {

            @Override
            void doWork(CodeAttribute b, ClassMethod classMethod) {
                loadBeanInstance(classMethod.getClassFile(), methodInfo, b);
                //now we should have the target bean instance on top of the stack
                // we need to dup it so we still have it to compare to the return value
                b.dup();

                //lets create the method invocation
                String methodDescriptor = methodInfo.getDescriptor();
                b.loadMethodParameters();
                if (method.getDeclaringClass().isInterface()) {
                    b.invokeinterface(methodInfo.getDeclaringClass(), methodInfo.getName(), methodDescriptor);
                } else {
                    b.invokevirtual(methodInfo.getDeclaringClass(), methodInfo.getName(), methodDescriptor);
                }
            }

            @Override
            void doReturn(CodeAttribute b, ClassMethod classMethod) {
                // assumes doWork() result is on top of the stack
                // if this method returns a primitive we just return
                if (method.getReturnType().isPrimitive()) {
                    b.returnInstruction();
                } else {
                    // otherwise we have to check that the proxy is not returning 'this;
                    // now we need to check if the proxy has return 'this' and if so return
                    // an
                    // instance of the proxy.
                    // currently we have result, beanInstance on the stack.
                    b.dupX1();
                    // now we have result, beanInstance, result
                    // we need to compare result and beanInstance

                    // first we need to build up the inner conditional that just returns
                    // the
                    // result
                    final BranchEnd returnInstruction = b.ifAcmpeq();
                    b.returnInstruction();
                    b.branchEnd(returnInstruction);

                    // now add the case where the proxy returns 'this';
                    b.aload(0);
                    b.checkcast(methodInfo.getMethod().getReturnType().getName());
                    b.returnInstruction();
                }
            }
        }.runStartIfNotEmpty();
    }
1361484
private Class getTargetClass(Method setMethod) {
        Class[] params = setMethod.getParameterTypes();
        if (params == null || params.length != 1) {
            throw new BeanMappingException("illegal set method[" + setMethod.getName() + "] for ParameterType");
        }
        return params[0];
    }
1071071
private static Map<String, Method> createOperationMethods(BeanInfo beanInfo) throws ManagementException {
        Set<Method> allAccessors = allAccessors(beanInfo);
        Map<String, Method> operationMethods = new HashMap<String, Method>();
        for (MethodDescriptor descriptor : beanInfo.getMethodDescriptors()) {
            Method method = descriptor.getMethod();
            ManagedOperation operationAnnotation = method.getAnnotation(ManagedOperation.class);
            if (operationAnnotation != null && allAccessors.contains(method)) {
                throw new ManagementException(
                        String.format("Accessor method %s is annotated as an @%s", method, ManagedOperation.class.getName()));
            }
            /* consider the Method an automatic operation if it satisfies all of:
             * 1. its class is annotated with @MBean(automatic=OPERATION)
             * 2. it is a public instance (non static) method
             * 3. it is NOT considered a bean accessor (getter/setter)
             */
            boolean isAutomatic = isAutomatic(method.getDeclaringClass(), AutomaticType.OPERATION);
            boolean autoOperation = (isAutomatic && isPublicInstance(method) && !allAccessors.contains(method));
            if (operationAnnotation != null || autoOperation) {
                // This method is an operation
                Method old = operationMethods.put(method.getName(), method);
                if (old != null) {
                    //TODO support multiple identically named operation methods
                    throw new ManagementException(format("Multiple Operation annotations for operation %s of %s",
                            method.getName(), old.getDeclaringClass()));
                }
            }
        }
        return operationMethods;
    }
331966
@Override
    public void setMethod(byte[] method) throws UnsupportedMethodException {
        MethodValues val = MethodValues.match(method, 0, method.length);
        if (null == val) {
            throw new UnsupportedMethodException("Illegal method " + GenericUtils.getEnglishString(method));
        }
        setMethod(val);
    }