Ejemplo n.º 1
0
  /**
   * @param to
   * @param name
   * @return <code>true</code> if the name is equal to the fromName, or if the name represents a
   *     superclass or superinterface of the fromName, <code>false</code> otherwise
   */
  private boolean isAssignableTo(DotName name, Class<?> to) {
    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) {
      // We reached a class that is not in the index. Let's use reflection.
      final Class<?> clazz = loadClass(name.toString());
      return to.isAssignableFrom(clazz);
    }

    DotName superName = fromClassInfo.superName();

    if (superName != null && isAssignableTo(superName, to)) {
      return true;
    }

    if (fromClassInfo.interfaces() != null) {
      for (DotName interfaceName : fromClassInfo.interfaces()) {
        if (isAssignableTo(interfaceName, to)) {
          return true;
        }
      }
    }
    return false;
  }
  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 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 MESSAGES.mdbDoesNotImplementNorSpecifyMessageListener(beanClass);
    return interfaces.iterator().next().toString();
  }
  /**
   * 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);
    }
  }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
  private static AnnotationInstance getAnnotation(
      Index index, String moduleName, DotName annotationName) {
    final ClassInfo moduleClass = getModuleInfo(index, moduleName);
    if (moduleClass == null) return null;

    List<AnnotationInstance> annotations = moduleClass.annotations().get(annotationName);
    if (annotations == null || annotations.isEmpty()) return null;

    return annotations.get(0);
  }
Ejemplo n.º 8
0
 public static boolean isJaxwsService(final ClassInfo current, final Index index) {
   ClassInfo tmp = current;
   while (tmp != null) {
     final DotName superName = tmp.superName();
     if (JAXWS_SERVICE_CLASS.equals(superName)) {
       return true;
     }
     tmp = index.getClassByName(superName);
   }
   return false;
 }
Ejemplo n.º 9
0
 @Test
 public void testEntityMetadataComplete() {
   Index index = getMockedIndex("entity-metadata-complete.xml");
   DotName authorName = DotName.createSimple(Author.class.getName());
   ClassInfo authorClassInfo = index.getClassByName(authorName);
   assertHasAnnotation(index, authorName, JPADotNames.ENTITY);
   assertHasAnnotation(index, authorName, JPADotNames.ID_CLASS);
   assertEquals(2, authorClassInfo.annotations().size());
   DotName bookName = DotName.createSimple(Book.class.getName());
   assertHasAnnotation(index, bookName, JPADotNames.ENTITY);
 }
 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;
 }
Ejemplo n.º 11
0
  public static AnnotationTarget getTarget(
      ServiceRegistry serviceRegistry, ClassInfo classInfo, String name, TargetType type) {
    Class clazz =
        serviceRegistry.getService(ClassLoaderService.class).classForName(classInfo.toString());
    switch (type) {
      case FIELD:
        Field field = getField(clazz, name);
        if (field == null) {
          throw new HibernateException(
              "Unable to load field " + name + " of class " + clazz.getName());
        }

        return FieldInfo.create(
            classInfo, name, getType(field.getType()), (short) (field.getModifiers()));
      case METHOD:
        Method method = getMethod(clazz, name);
        if (method == null) {
          throw new HibernateException(
              "Unable to load method " + name + " of class " + clazz.getName());
        }
        return getMethodInfo(classInfo, method);
      case PROPERTY:
        method = getterMethod(clazz, name);
        if (method == null) {
          throw new HibernateException(
              "Unable to load property " + name + " of class " + clazz.getName());
        }
        return getMethodInfo(classInfo, method);
    }
    throw new HibernateException("");
  }
 /**
  * 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;
 }
Ejemplo n.º 13
0
  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;
  }
Ejemplo n.º 14
0
 @Test
 public void testPersistenceUnitMetadataMetadataComplete() {
   JaxbEntity author = new JaxbEntity();
   author.setClazz(Author.class.getName());
   IndexBuilder indexBuilder = getIndexBuilder();
   EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default();
   defaults.setMetadataComplete(true);
   EntityMocker entityMocker = new EntityMocker(indexBuilder, author, defaults);
   entityMocker.preProcess();
   entityMocker.process();
   Index index = indexBuilder.build(new EntityMappingsMocker.Default());
   DotName className = DotName.createSimple(Author.class.getName());
   ClassInfo classInfo = index.getClassByName(className);
   assertEquals(1, classInfo.annotations().size());
   assertHasAnnotation(index, className, JPADotNames.ENTITY);
 }
Ejemplo n.º 15
0
  private static boolean isWebserviceEndpoint(
      final ServletMetaData servletMD, final List<Index> annotationIndexes) {
    final String endpointClassName = ASHelper.getEndpointName(servletMD);
    if (isJSP(endpointClassName)) return false;

    final DotName endpointDN = DotName.createSimple(endpointClassName);
    ClassInfo endpointClassInfo = null;
    for (final Index index : annotationIndexes) {
      endpointClassInfo = index.getClassByName(endpointDN);
      if (endpointClassInfo != null) {
        if (endpointClassInfo.annotations().containsKey(WEB_SERVICE_ANNOTATION)) return true;
        if (endpointClassInfo.annotations().containsKey(WEB_SERVICE_PROVIDER_ANNOTATION))
          return true;
      }
    }

    return false;
  }
 private SessionType determineSessionType(
     final String ejbClass, final CompositeIndex compositeIndex) {
   if (ejbClass == null) {
     return null;
   }
   final ClassInfo info = compositeIndex.getClassByName(DotName.createSimple(ejbClass));
   if (info == null) {
     return null;
   }
   if (info.annotations().get(STATEFUL_ANNOTATION) != null) {
     return SessionType.Stateful;
   } else if (info.annotations().get(STATELESS_ANNOTATION) != null) {
     return SessionType.Stateless;
   } else if (info.annotations().get(SINGLETON_ANNOTATION) != null) {
     return SessionType.Singleton;
   }
   return null;
 }
  @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());
  }
Ejemplo n.º 18
0
 public Map<DotName, List<AnnotationInstance>> getIndexedAnnotations(DotName name) {
   Map<DotName, List<AnnotationInstance>> map = indexedClassInfoAnnotationsMap.get(name);
   if (map == null) {
     ClassInfo ci = index.getClassByName(name);
     if (ci == null || ci.annotations() == null) {
       map = Collections.emptyMap();
     } else {
       map = new HashMap<DotName, List<AnnotationInstance>>(ci.annotations());
       // here we ignore global annotations
       for (DotName globalAnnotationName : DefaultConfigurationHelper.GLOBAL_ANNOTATIONS) {
         if (map.containsKey(globalAnnotationName)) {
           map.put(globalAnnotationName, Collections.<AnnotationInstance>emptyList());
         }
       }
     }
     indexedClassInfoAnnotationsMap.put(name, map);
   }
   return map;
 }
Ejemplo n.º 19
0
  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());
  }
Ejemplo n.º 20
0
 ClassInfo createClassInfo(String className) {
   if (StringHelper.isEmpty(className)) {
     throw new AssertionFailure("Class Name used to create ClassInfo is empty.");
   }
   DotName classDotName = DotName.createSimple(className);
   if (classes.containsKey(classDotName)) {
     // classInfoAnnotationsMap.put( classDotName, new HashMap<DotName,
     // List<AnnotationInstance>>(classes.get( classDotName ).annotations()) );
     return classes.get(classDotName);
   }
   Class clazz = serviceRegistry.getService(ClassLoaderService.class).classForName(className);
   DotName superName = null;
   DotName[] interfaces = null;
   short access_flag;
   ClassInfo annClassInfo = index.getClassByName(classDotName);
   if (annClassInfo != null) {
     superName = annClassInfo.superName();
     interfaces = annClassInfo.interfaces();
     access_flag = annClassInfo.flags();
   } else {
     Class superClass = clazz.getSuperclass();
     if (superClass != null) {
       superName = DotName.createSimple(superClass.getName());
     }
     Class[] classInterfaces = clazz.getInterfaces();
     if (classInterfaces != null && classInterfaces.length > 0) {
       interfaces = new DotName[classInterfaces.length];
       for (int i = 0; i < classInterfaces.length; i++) {
         interfaces[i] = DotName.createSimple(classInterfaces[i].getName());
       }
     }
     access_flag = (short) (clazz.getModifiers() | 0x20); // (modifiers | ACC_SUPER)
   }
   Map<DotName, List<AnnotationInstance>> map = new HashMap<DotName, List<AnnotationInstance>>();
   classInfoAnnotationsMap.put(classDotName, map);
   ClassInfo classInfo = ClassInfo.create(classDotName, superName, access_flag, interfaces, map);
   classes.put(classDotName, classInfo);
   addSubClasses(superName, classInfo);
   addImplementors(interfaces, classInfo);
   return classInfo;
 }
 @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);
   }
 }
Ejemplo n.º 22
0
  @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());
  }
Ejemplo n.º 23
0
 static XMLAccessType getEntityAccess(DotName className, IndexBuilder indexBuilder) {
   Map<DotName, List<AnnotationInstance>> indexedAnnotations =
       indexBuilder.getIndexedAnnotations(className);
   Map<DotName, List<AnnotationInstance>> ormAnnotations =
       indexBuilder.getClassInfoAnnotationsMap(className);
   XMLAccessType accessType = getAccess(ormAnnotations);
   if (accessType == null) {
     accessType = getAccess(indexedAnnotations);
   }
   if (accessType == null) {
     ClassInfo parent = indexBuilder.getClassInfo(className);
     if (parent == null) {
       parent = indexBuilder.getIndexedClassInfo(className);
     }
     if (parent != null) {
       DotName parentClassName = parent.superName();
       accessType = getEntityAccess(parentClassName, indexBuilder);
     }
   }
   return accessType;
 }
Ejemplo n.º 24
0
 private boolean isAnnotationDeclared(ClassInfo classInfo, DotName requiredAnnotationName) {
   Map<DotName, List<AnnotationInstance>> annotationsMap = classInfo.annotations();
   List<AnnotationInstance> annotations = annotationsMap.get(requiredAnnotationName);
   if (annotations != null) {
     for (AnnotationInstance annotationInstance : annotations) {
       if (annotationInstance.target().equals(classInfo)) {
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 25
0
 private AnnotationInstance getClassAnnotation(ClassInfo cls, DotName annoName) {
   List<AnnotationInstance> annos = cls.annotations().get(annoName);
   if (annos != null) {
     // Just return the first one we can find on the class itself
     for (AnnotationInstance anno : annos) {
       if (anno.target() == cls) {
         return anno;
       }
     }
   }
   return null;
 }
 /**
  * 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;
 }
 private void processClass(
     final DeploymentUnit deploymentUnit,
     final EJBResourceWrapper annotation,
     final ClassInfo classInfo,
     final EEModuleDescription eeModuleDescription)
     throws DeploymentUnitProcessingException {
   if (isEmpty(annotation.name())) {
     throw MESSAGES.nameAttributeRequiredForEJBAnnotationOnClass(classInfo.toString());
   }
   if (isEmpty(annotation.beanInterface())) {
     throw MESSAGES.beanInterfaceAttributeRequiredForEJBAnnotationOnClass(classInfo.toString());
   }
   process(
       deploymentUnit,
       annotation.beanInterface(),
       annotation.beanName(),
       annotation.lookup(),
       classInfo,
       null,
       annotation.name(),
       eeModuleDescription);
 }
Ejemplo n.º 28
0
 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;
 }
Ejemplo n.º 29
0
  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()) {
      try {
        if (annotationClassAnnotationsCache
            .get(annotation)
            .contains(requiredAnnotationName.toString())) {
          return true;
        }
      } catch (ExecutionException e) {
        throw new RuntimeException(e);
      }
    }
    // 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 SEReflections.containsAnnotation(
            loadClass(superName.toString()), requiredAnnotation);
      }
      if (containsAnnotation(superClassInfo, requiredAnnotationName, requiredAnnotation)) {
        return true;
      }
    }
    return false;
  }
Ejemplo n.º 30
0
 /**
  * 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);
 }