@Override public Collection<Annotation> getAnnotation(Class<?> annotationClass) { List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass .getName())); ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size()); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); Annotation annotation = null; if (target instanceof MethodInfo) { MethodInfo m = (MethodInfo) target; List<String> parameterTypes = new ArrayList<String>(m.args().length); for (Type type : m.args()) { parameterTypes.add(type.toString()); String declaringClass = m.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass); String declaringClass = f.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass); annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
private boolean containsAnnotation(ClassInfo classInfo, DotName requiredAnnotationName, Class<? extends Annotation> requiredAnnotation) { // Type and members if (classInfo.annotations().containsKey(requiredAnnotationName)) { return true; } // Meta-annotations for (DotName annotation : classInfo.annotations().keySet()) { if (annotationClassAnnotationsCache.getValue(annotation).contains(requiredAnnotationName.toString())) { return true; } } // Superclass final DotName superName = classInfo.superName(); if (superName != null && !OBJECT_NAME.equals(superName)) { final ClassInfo superClassInfo = index.getClassByName(superName); if (superClassInfo == null) { // we are accessing a class that is outside of the jandex index // fallback to using reflection return Reflections.containsAnnotation(loadClass(superName.toString()), requiredAnnotation); } if (containsAnnotation(superClassInfo, requiredAnnotationName, requiredAnnotation)) { return true; } } return false; }
private DotName getPackageName(DotName name) { if (name.isComponentized()) { while (name.isInner()) { name = name.prefix(); if (name == null) { throw new IllegalStateException("Could not determine package from corrupted class name"); } } return name.prefix(); } else { final int lastIndex = name.local().lastIndexOf("."); if (lastIndex == -1) { return name; } return DotName.createSimple(name.local().substring(0, name.local().lastIndexOf("."))); } }
private Set<String> findPersistenceTypeNames(PersistenceUnitMetadata pu) { synchronized (CACHED_TYPENAMES) { Set<String> typeNames = CACHED_TYPENAMES.get(pu); if (typeNames != null) { return typeNames; } } Set<String> persistenceTypeNames = new HashSet<String>(); for (Map.Entry<URL, Index> entry : pu.getAnnotationIndex().entrySet()) { List<AnnotationInstance> instances = entry.getValue().getAnnotations(DotName.createSimple(Entity.class.getName())); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); if (target instanceof ClassInfo) { ClassInfo classInfo = (ClassInfo) target; persistenceTypeNames.add(classInfo.name().toString()); } } } synchronized (CACHED_TYPENAMES) { CACHED_TYPENAMES.put(pu, persistenceTypeNames); } return persistenceTypeNames; }
if (to.getName().equals(name.toString())) { return true; if (OBJECT_NAME.equals(name)) { return false; // there's nothing assignable from Object.class except for Object.class ClassInfo fromClassInfo = index.getClassByName(name); if (fromClassInfo == null) { final Class<?> clazz = loadClass(name.toString()); return to.isAssignableFrom(clazz); DotName superName = fromClassInfo.superName(); if (fromClassInfo.interfaces() != null) { for (DotName interfaceName : fromClassInfo.interfaces()) { if (isAssignableTo(interfaceName, to)) { return true;
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); }
return; final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(RESOURCE_ANNOTATION_NAME); for (AnnotationInstance annotation : resourceAnnotations) { final AnnotationTarget annotationTarget = annotation.target(); final AnnotationValue nameValue = annotation.value("name"); final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null; final AnnotationValue typeValue = annotation.value("type"); final String type = typeValue != null ? typeValue.asClass().name().toString() : null; if (annotationTarget instanceof FieldInfo) { final FieldInfo fieldInfo = (FieldInfo) annotationTarget; final ClassInfo classInfo = fieldInfo.declaringClass(); EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processFieldResource(phaseContext, fieldInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); } else if (annotationTarget instanceof MethodInfo) { final MethodInfo methodInfo = (MethodInfo) annotationTarget; ClassInfo classInfo = methodInfo.declaringClass(); EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processMethodResource(phaseContext, methodInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); } else if (annotationTarget instanceof ClassInfo) { final ClassInfo classInfo = (ClassInfo) annotationTarget; EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); final String type = (typeValue != null) ? typeValue.asClass().name().toString() : null; EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
return; List<AnnotationInstance> applicationExceptionAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ApplicationException.class.getName())); if (applicationExceptionAnnotations == null || applicationExceptionAnnotations.isEmpty()) { return; deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS, descriptions); for (AnnotationInstance annotationInstance : applicationExceptionAnnotations) { AnnotationTarget target = annotationInstance.target(); if (!(target instanceof ClassInfo)) { throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(ApplicationException.class.getName(), target); String exceptionClassName = ((ClassInfo) target).name().toString(); boolean rollback = false; AnnotationValue rollBackAnnValue = annotationInstance.value("rollback"); if (rollBackAnnValue != null) { rollback = rollBackAnnValue.asBoolean(); AnnotationValue inheritedAnnValue = annotationInstance.value("inherited"); if (inheritedAnnValue != null) { inherited = inheritedAnnValue.asBoolean();
private void handleAnnotations(final CompositeIndex index, final Set<String> managedBeanClasses) throws DeploymentUnitProcessingException { final List<AnnotationInstance> annotations = index.getAnnotations(MANAGED_BEAN_ANNOTATION); if (annotations != null) { for (final AnnotationInstance annotation : annotations) { final AnnotationTarget target = annotation.target(); if (target instanceof ClassInfo) { final String className = ((ClassInfo) target).name().toString(); managedBeanClasses.add(className); } else { throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidManagedBeanAnnotation(target)); } } } }
protected Class<?> getPaClass(AnnotationInstance annotation) throws ClassNotFoundException { String paClassName = ((MethodInfo)annotation.target()).declaringClass().name().toString(); Class<?> paClass = paModule.getClassLoader().loadClass(paClassName); return paClass; }
final AnnotationTarget target = sessionBeanAnnotation.target(); if (!(target instanceof ClassInfo)) { EjbLogger.DEPLOYMENT_LOGGER.warn(EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(sessionBeanAnnotation.name().toString(), target).getMessage()); continue; continue; final String ejbName = sessionBeanClassInfo.name().local(); final AnnotationValue nameValue = sessionBeanAnnotation.value("name"); final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString()); final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class); final SessionBeanComponentDescription.SessionBeanType sessionBeanType; final String beanClassName; if (beanMetaData != null) { beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass()); sessionBeanType = override(annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType())); } else { beanClassName = sessionBeanClassInfo.name().toString(); sessionBeanType = annotatedSessionBeanType; final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean(); final Boolean passivationCapableDeploymentDescriptorValue; if ((beanMetaData instanceof SessionBean32MetaData)) {
return; final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME); if (instances == null || instances.isEmpty()) { return; AnnotationTarget target = instance.target(); if (!(target instanceof ClassInfo)) { throw EeLogger.ROOT_LOGGER.classOnlyAnnotation("@ManagedBean", target); continue; final String beanClassName = classInfo.name().toString(); final AnnotationValue nameValue = instance.value(); final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? beanClassName : replacer.replaceProperties(nameValue.asString()); final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());
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 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()); }
final AnnotationTarget target = messageBeanAnnotation.target(); final ClassInfo beanClassInfo = (ClassInfo) target; if (! EjbValidationsUtil.assertEjbClassValidity(beanClassInfo).isEmpty() ) { continue; final String ejbName = beanClassInfo.name().local(); final AnnotationValue nameValue = messageBeanAnnotation.value("name"); final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString()); final MessageDrivenBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, MessageDrivenBeanMetaData.class); final String beanClassName; final String messagingType; if (beanMetaData != null) { beanClassName = override(beanClassInfo.name().toString(), beanMetaData.getEjbClass()); deploymentDescriptorEnvironment = new DeploymentDescriptorEnvironment("java:comp/env/", beanMetaData); beanClassName = beanClassInfo.name().toString(); messageListenerInterfaceName = getMessageListenerInterface(compositeIndex, messageBeanAnnotation);
final List<AnnotationInstance> serverEndpoints = index.getAnnotations(SERVER_ENDPOINT); if (serverEndpoints != null) { for (AnnotationInstance endpoint : serverEndpoints) { if (endpoint.target() instanceof ClassInfo) { ClassInfo clazz = (ClassInfo) endpoint.target(); try { Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module); if (!Modifier.isAbstract(moduleClass.getModifiers())) { annotatedEndpoints.add(moduleClass); UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketEndpoint(clazz.name().toString(), e); Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module); if (!Modifier.isAbstract(moduleClass.getModifiers())) { annotatedEndpoints.add(moduleClass); UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketEndpoint(clazz.name().toString(), e); Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module); if (!Modifier.isAbstract(moduleClass.getModifiers())) { config.add((Class) moduleClass); UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketConfig(clazz.name().toString(), e); for (final ClassInfo clazz : epClasses) { try { Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module); if (!Modifier.isAbstract(moduleClass.getModifiers())) { endpoints.add((Class) moduleClass);
private String getMessageListenerInterface(final CompositeIndex compositeIndex, final AnnotationInstance messageBeanAnnotation) throws DeploymentUnitProcessingException { final AnnotationValue value = messageBeanAnnotation.value("messageListenerInterface"); if (value != null) return value.asClass().name().toString(); final ClassInfo beanClass = (ClassInfo) messageBeanAnnotation.target(); final Set<DotName> interfaces = new HashSet<DotName>(getPotentialViewInterfaces(beanClass)); // check super class(es) of the bean DotName superClassDotName = beanClass.superName(); while (interfaces.isEmpty() && superClassDotName != null && !superClassDotName.toString().equals(Object.class.getName())) { final ClassInfo superClass = compositeIndex.getClassByName(superClassDotName); if (superClass == null) { break; } interfaces.addAll(getPotentialViewInterfaces(superClass)); // move to next super class superClassDotName = superClass.superName(); } if (interfaces.size() != 1) throw EjbLogger.ROOT_LOGGER.mdbDoesNotImplementNorSpecifyMessageListener(beanClass); return interfaces.iterator().next().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; }
@Override protected String[] fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) { final Type[] classes = annotationInstance.value().asClassArray(); final String[] ret = new String[classes.length]; for(int i = 0; i < classes.length; ++i) { ret[i] = classes[i].name().toString(); } return ret; } }
private List<BindingConfiguration> getAnnotatedClassBindingConfigurations(EEModuleDescription moduleDescription, AnnotationInstance annotationInstance) throws DeploymentUnitProcessingException { final AnnotationTarget target = annotationInstance.target(); if (!(target instanceof ClassInfo)) { throw ROOT_LOGGER.classOnlyAnnotation(annotationInstance.toString(), target); } final ClassInfo classInfo = (ClassInfo) target; return moduleDescription.addOrGetLocalClassDescription(classInfo.name().toString()).getBindingConfigurations(); }