private void processPersistenceAnnotations( final DeploymentUnit deploymentUnit, final EEModuleDescription eeModuleDescription, List<AnnotationInstance> persistenceContexts, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException { for (AnnotationInstance annotation : persistenceContexts) { ClassInfo declaringClass = null; final AnnotationTarget annotationTarget = annotation.target(); if (annotationTarget instanceof FieldInfo) { FieldInfo fieldInfo = (FieldInfo) annotationTarget; declaringClass = fieldInfo.declaringClass(); EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString()); this.processField(deploymentUnit, annotation, fieldInfo, eeModuleClassDescription); } else if (annotationTarget instanceof MethodInfo) { MethodInfo methodInfo = (MethodInfo) annotationTarget; declaringClass = methodInfo.declaringClass(); EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString()); this.processMethod(deploymentUnit, annotation, methodInfo, eeModuleClassDescription); } else if (annotationTarget instanceof ClassInfo) { declaringClass = (ClassInfo) annotationTarget; EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString()); this.processClass(deploymentUnit, annotation, eeModuleClassDescription); } } }
private BindingDescription processClassResource( final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final ClassInfo classInfo, final AbstractComponentDescription componentDescription, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final AnnotationValue nameValue = annotation.value("name"); if (nameValue == null || nameValue.asString().isEmpty()) { throw new IllegalArgumentException("Class level annotations must provide a name."); } final String name = nameValue.asString(); final String type = classInfo.name().toString(); final BindingDescription bindingDescription = new BindingDescription(); bindingDescription.setDependency(true); bindingDescription.setBindingName(name); bindingDescription.setBindingType(type); ServiceName injectorName = getInjectorServiceName( deploymentUnit, annotation, componentDescription, phaseContext, name, type); bindingDescription.setReferenceSourceDescription( new ServiceBindingSourceDescription(injectorName)); return bindingDescription; }
/** * Check the deployment annotation index for all classes with the @ManagedBean annotation. For * each class with the annotation, collect all the required information to create a managed bean * instance, and attach it to the context. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); final String applicationName = moduleDescription.getAppName(); final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (compositeIndex == null) { return; } final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME); if (instances == null || instances.isEmpty()) { return; } for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); if (!(target instanceof ClassInfo)) { throw new DeploymentUnitProcessingException( "The ManagedBean annotation is only allowed at the class level: " + target); } final ClassInfo classInfo = (ClassInfo) target; final String beanClassName = classInfo.name().toString(); // Get the managed bean name from the annotation final AnnotationValue nameValue = instance.value(); final String beanName = nameValue == null || nameValue.asString().isEmpty() ? beanClassName : nameValue.asString(); final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription( beanName, beanClassName, moduleDescription.getModuleName(), applicationName); final ServiceName baseName = deploymentUnit.getServiceName().append("component").append(beanName); // Add the view componentDescription.getViewClassNames().add(beanClassName); // Bind the view to its two JNDI locations // TODO - this should be a bit more elegant final BindingDescription moduleBinding = new BindingDescription(); moduleBinding.setAbsoluteBinding(true); moduleBinding.setBindingName("java:module/" + beanName); moduleBinding.setBindingType(beanClassName); moduleBinding.setReferenceSourceDescription( new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName))); componentDescription.getBindings().add(moduleBinding); final BindingDescription appBinding = new BindingDescription(); appBinding.setAbsoluteBinding(true); appBinding.setBindingName("java:app/" + moduleDescription.getModuleName() + "/" + beanName); appBinding.setBindingType(beanClassName); appBinding.setReferenceSourceDescription( new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName))); componentDescription.getBindings().add(appBinding); moduleDescription.addComponent(componentDescription); } }
public static boolean hasClassesFromPackage(final Index index, final String pck) { for (ClassInfo ci : index.getKnownClasses()) { if (ci.name().toString().startsWith(pck)) { return true; } } return false; }
private Set<String> getMembers(Index index) { HashSet<String> members = new HashSet<>(); for (ClassInfo cls : index.getKnownClasses()) { if (shouldAddMember(cls)) { members.add(classNameToDeclName(cls.name().toString())); } } return members; }
@Test public void testSingleEntity() { Index index = JandexHelper.indexForClass( service, Paper.class, Stuff.class, Item.class, PricedStuff.class); Set<ConfiguredClassHierarchy> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies(index, serviceRegistry); assertEquals("There should be only one hierarchy", 1, hierarchies.size()); Iterator<ConfiguredClass> iter = hierarchies.iterator().next().iterator(); ConfiguredClass configuredClass = iter.next(); ClassInfo info = configuredClass.getClassInfo(); assertEquals("wrong class", DotName.createSimple(Stuff.class.getName()), info.name()); MappedAttribute property = configuredClass.getMappedProperty("value"); assertEquals(Price.class, property.getType()); assertTrue(iter.hasNext()); configuredClass = iter.next(); info = configuredClass.getClassInfo(); assertEquals("wrong class", DotName.createSimple(PricedStuff.class.getName()), info.name()); assertFalse( "PricedStuff should not mapped properties", configuredClass.getMappedAttributes().iterator().hasNext()); assertTrue(iter.hasNext()); configuredClass = iter.next(); info = configuredClass.getClassInfo(); assertEquals("wrong class", DotName.createSimple(Item.class.getName()), info.name()); // properties are alphabetically ordered! property = configuredClass.getMappedProperty("owner"); assertEquals(SomeGuy.class, property.getType()); property = configuredClass.getMappedProperty("type"); assertEquals(PaperType.class, property.getType()); assertTrue(iter.hasNext()); configuredClass = iter.next(); info = configuredClass.getClassInfo(); assertEquals("wrong class", DotName.createSimple(Paper.class.getName()), info.name()); assertFalse( "Paper should not mapped properties", configuredClass.getMappedAttributes().iterator().hasNext()); assertFalse(iter.hasNext()); }
@Test public void testTablePerClassDefaultTableName() { @Entity @Inheritance(strategy = javax.persistence.InheritanceType.TABLE_PER_CLASS) class A { @Id @GeneratedValue private int id; } @Entity class B extends A {} Index index = JandexHelper.indexForClass(service, A.class, B.class); AnnotationBindingContext context = new AnnotationBindingContext(index, serviceRegistry); Set<ConfiguredClassHierarchy<EntityClass>> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies(context); assertEquals("There should be only one hierarchy", 1, hierarchies.size()); Iterator<EntityClass> iter = hierarchies.iterator().next().iterator(); EntityClass entityClass = iter.next(); ClassInfo info = entityClass.getClassInfo(); assertEquals("wrong class", DotName.createSimple(A.class.getName()), info.name()); assertTrue(entityClass.hasOwnTable()); Assert.assertEquals( "wrong inheritance type", InheritanceType.TABLE_PER_CLASS, entityClass.getInheritanceType()); Assert.assertEquals("wrong table name", "A", entityClass.getPrimaryTableName()); assertTrue(iter.hasNext()); entityClass = iter.next(); info = entityClass.getClassInfo(); assertEquals("wrong class", DotName.createSimple(B.class.getName()), info.name()); assertTrue(entityClass.hasOwnTable()); Assert.assertEquals( "wrong inheritance type", InheritanceType.TABLE_PER_CLASS, entityClass.getInheritanceType()); Assert.assertEquals("wrong table name", "B", entityClass.getPrimaryTableName()); assertFalse(iter.hasNext()); }
public static boolean isJaxwsEndpoint(final ClassInfo clazz, final CompositeIndex index) { // assert JAXWS endpoint class flags final short flags = clazz.flags(); if (Modifier.isInterface(flags)) return false; if (Modifier.isAbstract(flags)) return false; if (!Modifier.isPublic(flags)) return false; if (isJaxwsService(clazz, index)) return false; final boolean hasWebServiceAnnotation = clazz.annotations().containsKey(WEB_SERVICE_ANNOTATION); final boolean hasWebServiceProviderAnnotation = clazz.annotations().containsKey(WEB_SERVICE_PROVIDER_ANNOTATION); if (!hasWebServiceAnnotation && !hasWebServiceProviderAnnotation) { return false; } if (hasWebServiceAnnotation && hasWebServiceProviderAnnotation) { ROOT_LOGGER.mutuallyExclusiveAnnotations(clazz.name().toString()); return false; } if (Modifier.isFinal(flags)) { ROOT_LOGGER.finalEndpointClassDetected(clazz.name().toString()); return false; } return true; }
private Set<Class<?>> loadClassInfoSet(Set<ClassInfo> classInfos, ClassLoader classLoader) throws DeploymentUnitProcessingException { Set<Class<?>> classes = new HashSet<Class<?>>(); for (ClassInfo classInfo : classInfos) { Class<?> type; try { type = classLoader.loadClass(classInfo.name().toString()); classes.add(type); } catch (Exception e) { UndertowLogger.ROOT_LOGGER.cannotLoadDesignatedHandleTypes(classInfo, e); } } return classes; }
private boolean isVetoedTypeOrPackage() { if (isAnnotationDeclared(classInfo, DOT_NAME_VETOED)) { return true; } ClassInfo packageInfo = index.getClassByName( DotName.createSimple( getPackageName(classInfo.name()) + DOT_SEPARATOR + PACKAGE_INFO_NAME)); if (packageInfo != null && isAnnotationDeclared(packageInfo, DOT_NAME_VETOED)) { return true; } return false; }
/** * 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 */ private boolean assertMDBClassValidity(final ClassInfo mdbClass) { final short flags = mdbClass.flags(); final String className = mdbClass.name().toString(); // must *not* be a interface if (Modifier.isInterface(flags)) { EjbLogger.EJB3_LOGGER.mdbClassCannotBeAnInterface(className); return false; } // bean class must be public, must *not* be abstract or final if (!Modifier.isPublic(flags) || Modifier.isAbstract(flags) || Modifier.isFinal(flags)) { EjbLogger.EJB3_LOGGER.mdbClassMustBePublicNonAbstractNonFinal(className); return false; } // valid class return true; }
private BeanDeploymentArchiveImpl createBeanDeploymentArchive( final Index index, BeanArchiveMetadata beanArchiveMetadata, Module module, String beanArchivePrefix) throws DeploymentUnitProcessingException { Set<String> classNames = new HashSet<String>(); // index may be null if a war has a beans.xml but no WEB-INF/classes if (index != null) { for (ClassInfo classInfo : index.getKnownClasses()) { classNames.add(classInfo.name().toString()); } } return new BeanDeploymentArchiveImpl( classNames, beanArchiveMetadata.getBeansXml(), module, beanArchivePrefix + beanArchiveMetadata.getResourceRoot().getRoot().getPathName()); }
@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); } if (target instanceof FieldInfo) { FieldInfo f = (FieldInfo) target; String declaringClass = f.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass); } if (target instanceof ClassInfo) { ClassInfo c = (ClassInfo) target; annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass); } if (annotation != null) { annotations.add(annotation); } } annotations.trimToSize(); if (annotations.size() == 0) { return null; } else { return Collections.unmodifiableList(annotations); } }
/** * Returns true if the passed <code>sessionBeanClass</code> meets the requirements set by the EJB3 * spec about bean implementation classes. The passed <code>sessionBeanClass</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 sessionBeanClass The session bean class * @return */ private static boolean assertSessionBeanClassValidity(final ClassInfo sessionBeanClass) { final short flags = sessionBeanClass.flags(); final String className = sessionBeanClass.name().toString(); // must *not* be a interface if (Modifier.isInterface(flags)) { logger.warn( "[EJB3.1 spec, section 4.9.2] Session bean implementation class MUST NOT be a interface - " + className + " is an interface, hence won't be considered as a session bean"); return false; } // bean class must be public, must *not* be abstract or final if (!Modifier.isPublic(flags) || Modifier.isAbstract(flags) || Modifier.isFinal(flags)) { logger.warn( "[EJB3.1 spec, section 4.9.2] Session bean implementation class MUST be public, not abstract and not final - " + className + " won't be considered as a session bean, since it doesn't meet that requirement"); return false; } // valid class return true; }
/** * Build new {@link Index} with mocked annotations from orm.xml. This method should be only called * once per {@org.hibernate.metamodel.source.annotations.xml.mocker.IndexBuilder IndexBuilder} * instance. * * @param globalDefaults Global defaults from <persistence-unit-metadata>, or null. * @return Index. */ Index build(EntityMappingsMocker.Default globalDefaults) { // merge annotations that not overrided by xml into the new Index for (ClassInfo ci : index.getKnownClasses()) { DotName name = ci.name(); if (indexedClassInfoAnnotationsMap.containsKey(name)) { // this class has been overrided by orm.xml continue; } if (ci.annotations() != null && !ci.annotations().isEmpty()) { Map<DotName, List<AnnotationInstance>> tmp = new HashMap<DotName, List<AnnotationInstance>>(ci.annotations()); DefaultConfigurationHelper.INSTANCE.applyDefaults(tmp, globalDefaults); mergeAnnotationMap(tmp, annotations); classes.put(name, ci); if (ci.superName() != null) { addSubClasses(ci.superName(), ci); } if (ci.interfaces() != null && ci.interfaces().length > 0) { addImplementors(ci.interfaces(), ci); } } } return Index.create(annotations, subclasses, implementors, classes); }
private void process( final DeploymentUnit deploymentUnit, final String beanInterface, final String beanName, final String lookup, final ClassInfo classInfo, final InjectionTarget targetDescription, final String localContextName, final EEModuleDescription eeModuleDescription) { if (!isEmpty(lookup) && !isEmpty(beanName)) { logger.debug( "Both beanName = " + beanName + " and lookup = " + lookup + " have been specified in @EJB annotation." + " lookup will be given preference. Class: " + classInfo.name()); } final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); final InjectionSource valueSource; EjbInjectionSource ejbInjectionSource = null; // give preference to lookup if (!isEmpty(lookup)) { if (!lookup.startsWith("java:")) { valueSource = new EjbLookupInjectionSource(lookup, targetDescription.getDeclaredValueClassName()); } else { valueSource = createLookup(lookup, appclient); } } else if (!isEmpty(beanName)) { valueSource = ejbInjectionSource = new EjbInjectionSource( beanName, beanInterface, localContextName, deploymentUnit, appclient); } else { valueSource = ejbInjectionSource = new EjbInjectionSource(beanInterface, localContextName, deploymentUnit, appclient); } if (ejbInjectionSource != null) { deploymentUnit.addToAttachmentList( EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource); } // our injection comes from the local lookup, no matter what. final ResourceInjectionConfiguration injectionConfiguration = targetDescription != null ? new ResourceInjectionConfiguration( targetDescription, createLookup(localContextName, appclient)) : null; // Create the binding from whence our injection comes. final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, valueSource); classDescription.getBindingConfigurations().add(bindingConfiguration); if (injectionConfiguration != null) { classDescription.addResourceInjection(injectionConfiguration); } }
@Override public String getClassName() { return classInfo.name().toString(); }
private void processSessionBeans( final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) { final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit); final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName(); // process these session bean annotations and create component descriptions out of it for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) { final AnnotationTarget target = sessionBeanAnnotation.target(); if (!(target instanceof ClassInfo)) { // Let's just WARN and move on. No need to throw an error EjbMessages.MESSAGES.annotationOnlyAllowedOnClass( sessionBeanAnnotation.name().toString(), target); continue; } final ClassInfo sessionBeanClassInfo = (ClassInfo) target; // skip if it's not a valid class for session bean if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) { continue; } final String ejbName = sessionBeanClassInfo.name().local(); final AnnotationValue nameValue = sessionBeanAnnotation.value("name"); final String beanName = nameValue == null || nameValue.asString().isEmpty() ? ejbName : 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 SessionBeanComponentDescription sessionBeanDescription; switch (sessionBeanType) { case STATELESS: sessionBeanDescription = new StatelessComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData); break; case STATEFUL: sessionBeanDescription = new StatefulComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData); // If passivation is disabled for the SFSB, either via annotation or via DD, then setup // the component // description appropriately final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean(); // TODO: Pass the DD value as first param for override final boolean passivationApplicable = override(null, passivationCapableAnnotationValue); ((StatefulComponentDescription) sessionBeanDescription) .setPassivationApplicable(passivationApplicable); break; case SINGLETON: sessionBeanDescription = new SingletonComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData); break; default: throw EjbMessages.MESSAGES.unknownSessionBeanType(sessionBeanType.name()); } addComponent(deploymentUnit, sessionBeanDescription); } EjbDeploymentMarker.mark(deploymentUnit); }
private void processSessionBeans( final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) { final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit); final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName(); // process these session bean annotations and create component descriptions out of it for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) { final AnnotationTarget target = sessionBeanAnnotation.target(); if (!(target instanceof ClassInfo)) { // Let's just WARN and move on. No need to throw an error logger.warn( sessionBeanAnnotation.name() + " annotation is expected to be applied on class level. " + target + " is not a class"); continue; } final ClassInfo sessionBeanClassInfo = (ClassInfo) target; // skip if it's not a valid class for session bean if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) { continue; } final String ejbName = sessionBeanClassInfo.name().local(); final AnnotationValue nameValue = sessionBeanAnnotation.value("name"); final String beanName = nameValue == null || nameValue.asString().isEmpty() ? ejbName : nameValue.asString(); final EnterpriseBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName); final SessionBeanComponentDescription.SessionBeanType sessionBeanType; final String beanClassName; if (beanMetaData != null && beanMetaData instanceof SessionBeanMetaData) { sessionBeanType = override( annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType())); } else { sessionBeanType = annotatedSessionBeanType; } if (beanMetaData != null) { beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass()); } else { beanClassName = sessionBeanClassInfo.name().toString(); } final SessionBeanComponentDescription sessionBeanDescription; switch (sessionBeanType) { case STATELESS: sessionBeanDescription = new StatelessComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName); break; case STATEFUL: sessionBeanDescription = new StatefulComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName); break; case SINGLETON: sessionBeanDescription = new SingletonComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName); break; default: throw new IllegalArgumentException("Unknown session bean type: " + sessionBeanType); } if (appclient) { deploymentUnit.addToAttachmentList( Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS, sessionBeanDescription); } else { // Add this component description to module description ejbJarDescription.getEEModuleDescription().addComponent(sessionBeanDescription); } } EjbDeploymentMarker.mark(deploymentUnit); }
private JandexPivot pivotAnnotations(DotName typeName) { if (jandexIndex == null) { return NO_JANDEX_PIVOT; } final ClassInfo jandexClassInfo = jandexIndex.getClassByName(typeName); if (jandexClassInfo == null) { return NO_JANDEX_PIVOT; } final Map<DotName, List<AnnotationInstance>> annotations = jandexClassInfo.annotations(); final JandexPivot pivot = new JandexPivot(); for (Map.Entry<DotName, List<AnnotationInstance>> annotationInstances : annotations.entrySet()) { for (AnnotationInstance annotationInstance : annotationInstances.getValue()) { if (MethodParameterInfo.class.isInstance(annotationInstance.target())) { continue; } if (FieldInfo.class.isInstance(annotationInstance.target())) { final FieldInfo fieldInfo = (FieldInfo) annotationInstance.target(); Map<DotName, AnnotationInstance> fieldAnnotations = pivot.fieldAnnotations.get(fieldInfo.name()); if (fieldAnnotations == null) { fieldAnnotations = new HashMap<DotName, AnnotationInstance>(); pivot.fieldAnnotations.put(fieldInfo.name(), fieldAnnotations); fieldAnnotations.put(annotationInstance.name(), annotationInstance); } else { final Object oldEntry = fieldAnnotations.put(annotationInstance.name(), annotationInstance); if (oldEntry != null) { log.debugf( "Encountered duplicate annotation [%s] on field [%s]", annotationInstance.name(), fieldInfo.name()); } } } else if (MethodInfo.class.isInstance(annotationInstance.target())) { final MethodInfo methodInfo = (MethodInfo) annotationInstance.target(); final String methodKey = buildBuildKey(methodInfo); Map<DotName, AnnotationInstance> methodAnnotations = pivot.methodAnnotations.get(methodKey); if (methodAnnotations == null) { methodAnnotations = new HashMap<DotName, AnnotationInstance>(); pivot.methodAnnotations.put(methodKey, methodAnnotations); methodAnnotations.put(annotationInstance.name(), annotationInstance); } else { final Object oldEntry = methodAnnotations.put(annotationInstance.name(), annotationInstance); if (oldEntry != null) { log.debugf( "Encountered duplicate annotation [%s] on method [%s -> %s]", annotationInstance.name(), jandexClassInfo.name(), methodKey); } } } else if (ClassInfo.class.isInstance(annotationInstance.target())) { // todo : validate its the type we are processing? final Object oldEntry = pivot.typeAnnotations.put(annotationInstance.name(), annotationInstance); if (oldEntry != null) { log.debugf( "Encountered duplicate annotation [%s] on type [%s]", annotationInstance.name(), jandexClassInfo.name()); } } } } return pivot; }
@Override public boolean isTopLevelClass() { // TODO This is not portable per the JSL // TODO Modify jandex to contain isTopLevelClass attribute return !classInfo.name().local().contains("$"); }
private void processMessageBeans( final DeploymentUnit deploymentUnit, final Collection<AnnotationInstance> messageBeanAnnotations, final CompositeIndex compositeIndex) throws DeploymentUnitProcessingException { if (messageBeanAnnotations.isEmpty()) return; final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit); final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName(); DeploymentDescriptorEnvironment deploymentDescriptorEnvironment = null; for (final AnnotationInstance messageBeanAnnotation : messageBeanAnnotations) { final AnnotationTarget target = messageBeanAnnotation.target(); final ClassInfo beanClassInfo = (ClassInfo) target; if (!assertMDBClassValidity(beanClassInfo)) { continue; } final String ejbName = beanClassInfo.name().local(); final AnnotationValue nameValue = messageBeanAnnotation.value("name"); final String beanName = nameValue == null || nameValue.asString().isEmpty() ? ejbName : nameValue.asString(); final MessageDrivenBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, MessageDrivenBeanMetaData.class); final String beanClassName; final String messageListenerInterfaceName; boolean replacement = deploymentUnit.getAttachment(Attachments.EJB_ANNOTATION_PROPERTY_REPLACEMENT); final Properties activationConfigProperties = getActivationConfigProperties(messageBeanAnnotation, replacement); final String messagingType; if (beanMetaData != null) { beanClassName = override(beanClassInfo.name().toString(), beanMetaData.getEjbClass()); deploymentDescriptorEnvironment = new DeploymentDescriptorEnvironment("java:comp/env/", beanMetaData); if (beanMetaData instanceof MessageDrivenBeanMetaData) { // It may actually be GenericBeanMetadata instance final MessageDrivenBeanMetaData mdb = (MessageDrivenBeanMetaData) beanMetaData; messagingType = mdb.getMessagingType(); final ActivationConfigMetaData activationConfigMetaData = mdb.getActivationConfig(); if (activationConfigMetaData != null) { final ActivationConfigPropertiesMetaData propertiesMetaData = activationConfigMetaData.getActivationConfigProperties(); if (propertiesMetaData != null) { for (final ActivationConfigPropertyMetaData propertyMetaData : propertiesMetaData) { activationConfigProperties.put( propertyMetaData.getKey(), propertyMetaData.getValue()); } } } } else if (beanMetaData instanceof JBossGenericBeanMetaData) { // TODO: fix the hierarchy so this is not needed final JBossGenericBeanMetaData mdb = (JBossGenericBeanMetaData) beanMetaData; messagingType = mdb.getMessagingType(); final ActivationConfigMetaData activationConfigMetaData = mdb.getActivationConfig(); if (activationConfigMetaData != null) { final ActivationConfigPropertiesMetaData propertiesMetaData = activationConfigMetaData.getActivationConfigProperties(); if (propertiesMetaData != null) { for (final ActivationConfigPropertyMetaData propertyMetaData : propertiesMetaData) { activationConfigProperties.put( propertyMetaData.getKey(), propertyMetaData.getValue()); } } } } else { messagingType = null; } messageListenerInterfaceName = messagingType != null ? messagingType : getMessageListenerInterface(compositeIndex, messageBeanAnnotation); } else { beanClassName = beanClassInfo.name().toString(); messageListenerInterfaceName = getMessageListenerInterface(compositeIndex, messageBeanAnnotation); } final String defaultResourceAdapterName = this.getDefaultResourceAdapterName(deploymentUnit.getServiceRegistry()); final MessageDrivenComponentDescription beanDescription = new MessageDrivenComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, messageListenerInterfaceName, activationConfigProperties, defaultResourceAdapterName, beanMetaData); beanDescription.setDeploymentDescriptorEnvironment(deploymentDescriptorEnvironment); addComponent(deploymentUnit, beanDescription); } EjbDeploymentMarker.mark(deploymentUnit); }
protected void scan( final DeploymentUnit du, final ClassLoader classLoader, final ResteasyDeploymentData resteasyDeploymentData) throws DeploymentUnitProcessingException, ModuleLoadException { final CompositeIndex index = du.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (!resteasyDeploymentData.shouldScan()) { return; } final Set<ClassInfo> applicationClass = index.getAllKnownSubclasses(APPLICATION); try { if (applicationClass.size() > 1) { StringBuilder builder = new StringBuilder(); Set<ClassInfo> aClasses = new HashSet<ClassInfo>(); for (ClassInfo c : applicationClass) { if (!Modifier.isAbstract(c.flags())) { aClasses.add(c); } builder.append(" ").append(c.name().toString()); } if (aClasses.size() > 1) { throw new DeploymentUnitProcessingException( MESSAGES.onlyOneApplicationClassAllowed(builder)); } else if (aClasses.size() == 1) { ClassInfo aClass = applicationClass.iterator().next(); resteasyDeploymentData.setScannedApplicationClass( (Class<? extends Application>) classLoader.loadClass(aClass.name().toString())); } } else if (applicationClass.size() == 1) { ClassInfo aClass = applicationClass.iterator().next(); resteasyDeploymentData.setScannedApplicationClass( (Class<? extends Application>) classLoader.loadClass(aClass.name().toString())); } } catch (ClassNotFoundException e) { throw MESSAGES.cannotLoadApplicationClass(e); } List<AnnotationInstance> resources = null; List<AnnotationInstance> providers = null; if (resteasyDeploymentData.isScanResources()) { resources = index.getAnnotations(JaxrsAnnotations.PATH.getDotName()); } if (resteasyDeploymentData.isScanProviders()) { providers = index.getAnnotations(JaxrsAnnotations.PROVIDER.getDotName()); } if ((resources == null || resources.isEmpty()) && (providers == null || providers.isEmpty())) return; final Set<ClassInfo> pathInterfaces = new HashSet<ClassInfo>(); if (resources != null) { for (AnnotationInstance e : resources) { final ClassInfo info; if (e.target() instanceof ClassInfo) { info = (ClassInfo) e.target(); } else if (e.target() instanceof MethodInfo) { // ignore continue; } else { JAXRS_LOGGER.classOrMethodAnnotationNotFound("@Path", e.target()); continue; } if (!Modifier.isInterface(info.flags())) { resteasyDeploymentData.getScannedResourceClasses().add(info.name().toString()); } else { pathInterfaces.add(info); } } } if (providers != null) { for (AnnotationInstance e : providers) { if (e.target() instanceof ClassInfo) { ClassInfo info = (ClassInfo) e.target(); if (!Modifier.isInterface(info.flags())) { resteasyDeploymentData.getScannedProviderClasses().add(info.name().toString()); } } else { JAXRS_LOGGER.classAnnotationNotFound("@Provider", e.target()); } } } // look for all implementations of interfaces annotated @Path for (final ClassInfo iface : pathInterfaces) { final Set<ClassInfo> implementors = index.getAllKnownImplementors(iface.name()); for (final ClassInfo implementor : implementors) { resteasyDeploymentData.getScannedResourceClasses().add(implementor.name().toString()); } } }
@Override public boolean isAssignableTo(Class<?> toClass) { return isAssignableTo(classInfo.name(), toClass); }