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();
  }
Пример #2
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;
  }
Пример #3
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;
 }
 /**
  * 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);
 }
 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;
 }
Пример #6
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;
 }
Пример #7
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;
  }
Пример #8
0
 @Override
 public String getSuperclassName() {
   return classInfo.superName().toString();
 }