private boolean hasInjectConstructor() { List<AnnotationInstance> annotationInstances = classInfo.annotations().get(DOT_NAME_INJECT); if (annotationInstances != null) { for (AnnotationInstance instance : annotationInstances) { AnnotationTarget target = instance.target(); if (target instanceof MethodInfo) { MethodInfo methodInfo = (MethodInfo) target; if (methodInfo.name().equals(CONSTRUCTOR_METHOD_NAME)) { return true; } } } } return false; }
private MethodIdentifier getMethodIdentifier(Type[] args, MethodInfo methodInfo){ if (args.length == 0) { return MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name()); } else { return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), InvocationContext.class.getName()); } } }
private void validateArgumentType(final ClassInfo classInfo, final MethodInfo methodInfo) { final Type[] args = methodInfo.args(); switch (args.length) { case 0: throw new IllegalArgumentException(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), AROUND_INVOKE_ANNOTATION_NAME, classInfo.name(), "Object methodName(InvocationContext ctx)")); case 1: if (!InvocationContext.class.getName().equals(args[0].name().toString())) { throw new IllegalArgumentException(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), AROUND_INVOKE_ANNOTATION_NAME, classInfo.name(), "Object methodName(InvocationContext ctx)")); } break; default: throw new IllegalArgumentException(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), AROUND_INVOKE_ANNOTATION_NAME, classInfo.name())); } if (!methodInfo.returnType().name().toString().equals(Object.class.getName())) { throw EeLogger.ROOT_LOGGER.invalidReturnType(Object.class.getName(), methodInfo.name(), AROUND_INVOKE_ANNOTATION_NAME, classInfo.name()); } } }
private void validateArgumentType(final ClassInfo classInfo, final MethodInfo methodInfo) { final Type[] args = methodInfo.args(); switch (args.length) { case 0: throw EjbLogger.ROOT_LOGGER.aroundTimeoutMethodExpectedWithInvocationContextParam(methodInfo.name(), classInfo.toString()); case 1: if (!InvocationContext.class.getName().equals(args[0].name().toString())) { throw EjbLogger.ROOT_LOGGER.aroundTimeoutMethodExpectedWithInvocationContextParam(methodInfo.name(), classInfo.toString()); } break; default: throw EjbLogger.ROOT_LOGGER.aroundTimeoutMethodExpectedWithInvocationContextParam(methodInfo.name(), classInfo.toString()); } if (!methodInfo.returnType().name().toString().equals(Object.class.getName())) { throw EjbLogger.ROOT_LOGGER.aroundTimeoutMethodMustReturnObjectType(methodInfo.name(), classInfo.toString()); } } }
/** * Returns true if the passed <code>mdbClass</code> meets the requirements set by the EJB3 spec about bean implementation * classes. The passed <code>mdbClass</code> must not be an interface and must be public and not final and not abstract. If * it passes these requirements then this method returns true. Else it returns false. * * @param mdbClass The MDB class * @return * @throws DeploymentUnitProcessingException */ public static Collection<MdbValidityStatus> assertEjbClassValidity(final ClassInfo mdbClass) throws DeploymentUnitProcessingException { Collection<MdbValidityStatus> mdbComplianceIssueList = new ArrayList<>(MdbValidityStatus.values().length); final String className = mdbClass.name().toString(); verifyModifiers(className, mdbClass.flags(), mdbComplianceIssueList); for (MethodInfo method : mdbClass.methods()) { if ("onMessage".equals(method.name())) { verifyOnMessageMethod(className, method.flags(), mdbComplianceIssueList); } if ("finalize".equals(method.name())) { EjbLogger.DEPLOYMENT_LOGGER.mdbCantHaveFinalizeMethod(className); mdbComplianceIssueList.add(MdbValidityStatus.MDB_SHOULD_NOT_HAVE_FINALIZE_METHOD); } } return mdbComplianceIssueList; }
private void processMethod(final DeploymentUnit deploymentUnit, final EJBResourceWrapper annotation, final MethodInfo methodInfo, final EEModuleDescription eeModuleDescription) { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { throw EjbLogger.ROOT_LOGGER.onlySetterMethodsAllowedToHaveEJBAnnotation(methodInfo); } final String methodParamType = methodInfo.args()[0].name().toString(); final InjectionTarget targetDescription = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodParamType); final String localContextName = isEmpty(annotation.name()) ? methodInfo.declaringClass().name().toString() + "/" + methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4) : annotation.name(); final String beanInterfaceType = isEmpty(annotation.beanInterface()) || annotation.beanInterface().equals(Object.class.getName()) ? methodParamType : annotation.beanInterface(); process(deploymentUnit, beanInterfaceType, annotation.beanName(), annotation.lookup(), methodInfo.declaringClass(), targetDescription, localContextName, eeModuleDescription); }
protected void processMethodResource(final DeploymentPhaseContext phaseContext, final MethodInfo methodInfo, final String name, final String type, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { throw EeLogger.ROOT_LOGGER.setterMethodOnly("@Resource", methodInfo); } final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4); final String localContextName = isEmpty(name) ? methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix : name; final String injectionType = isEmpty(type) || type.equals(Object.class.getName()) ? methodInfo.args()[0].name().toString() : type; final InjectionTarget targetDescription = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString()); process(phaseContext, classDescription, annotation, injectionType, localContextName, targetDescription, eeModuleDescription, module, applicationClasses, replacer); }
private MethodIdentifier getMethodIdentifier(final AnnotationTarget target) { final MethodInfo methodInfo = MethodInfo.class.cast(target); final String[] args = new String[methodInfo.args().length]; for (int i = 0; i < methodInfo.args().length; i++) { args[i] = methodInfo.args()[i].name().toString(); } return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), args); }
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name())); return; } else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) { ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)")); return; methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name()); } else { methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name(), InvocationContext.class);
private void processAroundInvoke(final EEModuleDescription eeModuleDescription, final AnnotationTarget target) throws DeploymentUnitProcessingException { if (!(target instanceof MethodInfo)) { throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(AROUND_INVOKE_ANNOTATION_NAME); } final MethodInfo methodInfo = MethodInfo.class.cast(target); final ClassInfo classInfo = methodInfo.declaringClass(); final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); final List<AnnotationInstance> classAroundInvokes = classInfo.annotations().get(AROUND_INVOKE_ANNOTATION_NAME); if(classAroundInvokes.size() > 1) { throw EeLogger.ROOT_LOGGER.aroundInvokeAnnotationUsedTooManyTimes(classInfo.name(), classAroundInvokes.size()); } validateArgumentType(classInfo, methodInfo); InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription()); builder.setAroundInvoke(MethodIdentifier.getIdentifier(Object.class, methodInfo.name(), InvocationContext.class)); classDescription.setInterceptorClassDescription(builder.build()); }
annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass);
private void processAroundInvoke(final AnnotationTarget target, final EEModuleDescription eeModuleDescription) { if (!(target instanceof MethodInfo)) { throw EjbLogger.ROOT_LOGGER.annotationApplicableOnlyForMethods(AROUND_TIMEOUT_ANNOTATION_NAME.toString()); } final MethodInfo methodInfo = MethodInfo.class.cast(target); final ClassInfo classInfo = methodInfo.declaringClass(); final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); validateArgumentType(classInfo, methodInfo); final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription()); builder.setAroundTimeout(MethodIdentifier.getIdentifier(Object.class, methodInfo.name(), InvocationContext.class)); classDescription.setInterceptorClassDescription(builder.build()); }
private void processLifeCycle(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException { if (!(target instanceof MethodInfo)) { throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType); } final MethodInfo methodInfo = MethodInfo.class.cast(target); final ClassInfo classInfo = methodInfo.declaringClass(); final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); final Type[] args = methodInfo.args(); if (args.length > 1) { ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name())); return; } else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) { ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)")); return; } final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription()); if (annotationType == POST_CONSTRUCT_ANNOTATION) { builder.setPostConstruct(getMethodIdentifier(args, methodInfo)); } else if (annotationType == PRE_DESTROY_ANNOTATION) { builder.setPreDestroy(getMethodIdentifier(args, methodInfo)); } else if(annotationType == AROUND_CONSTRUCT_ANNOTATION){ builder.setAroundConstruct(getMethodIdentifier(args, methodInfo)); } classDescription.setInterceptorClassDescription(builder.build()); }
private MethodIdentifier getMethodIdentifier(Type[] args, MethodInfo methodInfo){ if (args.length == 0) { return MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name()); } else { return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), InvocationContext.class.getName()); } } }
protected void processMethodResource(final DeploymentPhaseContext phaseContext, final MethodInfo methodInfo, final String name, final String type, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { throw EeLogger.ROOT_LOGGER.setterMethodOnly("@Resource", methodInfo); } final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4); final String localContextName = isEmpty(name) ? methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix : name; final String injectionType = isEmpty(type) || type.equals(Object.class.getName()) ? methodInfo.args()[0].name().toString() : type; final InjectionTarget targetDescription = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString()); process(phaseContext, classDescription, annotation, injectionType, localContextName, targetDescription, eeModuleDescription, module, applicationClasses, replacer); }
protected void processMethodResource(final DeploymentPhaseContext phaseContext, final MethodInfo methodInfo, final String name, final String type, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { throw MESSAGES.setterMethodOnly("@Resource", methodInfo); } final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4); final String localContextName = isEmpty(name) ? methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix : name; final String injectionType = isEmpty(type) || type.equals(Object.class.getName()) ? methodInfo.args()[0].name().toString() : type; final InjectionTarget targetDescription = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString()); process(phaseContext, classDescription, annotation, injectionType, localContextName, targetDescription, eeModuleDescription, module, applicationClasses); }
protected void processMethodResource(final DeploymentPhaseContext phaseContext, final MethodInfo methodInfo, final String name, final String type, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { throw EeLogger.ROOT_LOGGER.setterMethodOnly("@Resource", methodInfo); } final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4); final String localContextName = isEmpty(name) ? methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix : name; final String injectionType = isEmpty(type) || type.equals(Object.class.getName()) ? methodInfo.args()[0].name().toString() : type; final InjectionTarget targetDescription = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString()); process(phaseContext, classDescription, annotation, injectionType, localContextName, targetDescription, eeModuleDescription, module, applicationClasses, replacer); }
private static void processMethodRef(final DeploymentUnit unit, final WSRefAnnotationWrapper annotation, final MethodInfo methodInfo) throws DeploymentUnitProcessingException { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { throw WSLogger.ROOT_LOGGER.invalidServiceRefSetterMethodName(methodInfo); } final String injectionType = isEmpty(annotation.type()) || annotation.type().equals(Object.class.getName()) ? methodInfo.args()[0].name().toString() : annotation.type(); final InjectionTarget injectionTarget = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, injectionType); final String bindingName = isEmpty(annotation.name()) ? methodInfo.declaringClass().name().toString() + "/" + methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4) : annotation.name(); processRef(unit, injectionType, annotation, methodInfo.declaringClass(), injectionTarget, bindingName); }
private MethodIdentifier getMethodIdentifier(final AnnotationTarget target) { final MethodInfo methodInfo = MethodInfo.class.cast(target); final String[] args = new String[methodInfo.args().length]; for (int i = 0; i < methodInfo.args().length; i++) { args[i] = methodInfo.args()[i].name().toString(); } return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), args); }
private MethodIdentifier getMethodIdentifier(final AnnotationTarget target) { final MethodInfo methodInfo = MethodInfo.class.cast(target); final String[] args = new String[methodInfo.args().length]; for (int i = 0; i < methodInfo.args().length; i++) { args[i] = methodInfo.args()[i].name().toString(); } return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), args); }