Example #1
0
 private static ClassInfo getModuleInfo(final Index index, final String moduleName) {
   // we need to escape any java keyword from the package list
   String quotedModuleName = JVMModuleUtil.quoteJavaKeywords(moduleName);
   DotName moduleClassName = DotName.createSimple(quotedModuleName + ".$module_");
   ClassInfo ret = index.getClassByName(moduleClassName);
   if (ret == null) {
     // read previous module descriptor name
     moduleClassName = DotName.createSimple(quotedModuleName + ".module_");
     ret = index.getClassByName(moduleClassName);
   }
   return ret;
 }
  @Test
  public void testDefaultCascadePersist() {
    Default defaults = new Default();
    defaults.setCascadePersist(true);
    Index index = getIndex();
    Map<DotName, List<AnnotationInstance>> annotations =
        new HashMap<DotName, List<AnnotationInstance>>();
    annotations.putAll(
        index.getClassByName(DotName.createSimple(Parent.class.getName())).annotations());
    assertEquals(4, annotations.size());
    assertEquals(1, annotations.get(JPADotNames.ENTITY).size());
    assertEquals(1, annotations.get(JPADotNames.ID).size());
    assertEquals(1, annotations.get(JPADotNames.ONE_TO_MANY).size());
    assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size());

    DefaultConfigurationHelper.INSTANCE.applyDefaults(annotations, defaults);

    assertEquals(4, annotations.size());
    assertEquals(1, annotations.get(JPADotNames.ENTITY).size());
    assertEquals(1, annotations.get(JPADotNames.ID).size());
    assertEquals(1, annotations.get(JPADotNames.ONE_TO_MANY).size());
    assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size());
    AnnotationInstance oneToMany = annotations.get(JPADotNames.ONE_TO_MANY).get(0);
    String[] cascadeTypes = oneToMany.value("cascade").asEnumArray();
    assertArrayEquals(new String[] {"ALL", "DETACH", "PERSIST"}, cascadeTypes);
    AnnotationInstance manyToOne = annotations.get(JPADotNames.MANY_TO_ONE).get(0);
    cascadeTypes = manyToOne.value("cascade").asEnumArray();
    assertArrayEquals(new String[] {"PERSIST"}, cascadeTypes);

    annotations.clear();
    annotations.putAll(
        index.getClassByName(DotName.createSimple(Child.class.getName())).annotations());
    assertEquals(3, annotations.size());
    assertEquals(1, annotations.get(JPADotNames.ENTITY).size());
    assertEquals(1, annotations.get(JPADotNames.ID).size());
    assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size());

    DefaultConfigurationHelper.INSTANCE.applyDefaults(annotations, defaults);

    assertEquals(3, annotations.size());
    assertEquals(1, annotations.get(JPADotNames.ENTITY).size());
    assertEquals(1, annotations.get(JPADotNames.ID).size());
    assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size());

    manyToOne = annotations.get(JPADotNames.MANY_TO_ONE).get(0);
    cascadeTypes = manyToOne.value("cascade").asEnumArray();
    assertArrayEquals(new String[] {"PERSIST", "ALL", "DETACH"}, cascadeTypes);
  }
  @Test
  public void testDefaultSchemaToAnnotationInstance() {
    Default defaults = new Default();
    defaults.setSchema("hib_schema");
    defaults.setCatalog("hib_catalog");
    Index index = getIndex();
    Map<DotName, List<AnnotationInstance>> annotations =
        new HashMap<DotName, List<AnnotationInstance>>();
    annotations.putAll(
        index.getClassByName(DotName.createSimple(Parent.class.getName())).annotations());
    assertEquals(4, annotations.size());
    assertEquals(1, annotations.get(JPADotNames.ENTITY).size());
    assertEquals(1, annotations.get(JPADotNames.ID).size());
    assertEquals(1, annotations.get(JPADotNames.ONE_TO_MANY).size());
    assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size());
    DefaultConfigurationHelper.INSTANCE.applyDefaults(annotations, defaults);
    assertEquals(5, annotations.size());
    assertEquals(1, annotations.get(JPADotNames.ENTITY).size());
    assertEquals(1, annotations.get(JPADotNames.ID).size());
    assertEquals(1, annotations.get(JPADotNames.ONE_TO_MANY).size());
    assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size());
    assertEquals(1, annotations.get(JPADotNames.TABLE).size());
    AnnotationInstance table = annotations.get(JPADotNames.TABLE).get(0);
    assertEquals("hib_schema", table.value("schema").asString());
    assertEquals("hib_catalog", table.value("catalog").asString());

    annotations.clear();
    annotations.putAll(
        index.getClassByName(DotName.createSimple(Name.class.getName())).annotations());
    DefaultConfigurationHelper.INSTANCE.applyDefaults(annotations, defaults);
    assertEquals(1, annotations.size());
    assertEquals(1, annotations.get(JPADotNames.SECONDARY_TABLES).size());
    AnnotationInstance[] secondaryTables =
        annotations.get(JPADotNames.SECONDARY_TABLES).get(0).value().asNestedArray();
    assertEquals(2, secondaryTables.length);
    AnnotationInstance secondaryTable = secondaryTables[0];
    String name = secondaryTable.value("name").asString();
    if (name.equals("sec1")) {
      assertSt1(secondaryTable);
      assertSt2(secondaryTables[1]);
    } else {
      assertSt1(secondaryTables[1]);
      assertSt2(secondaryTable);
    }
  }
Example #4
0
 /** @see {@link Index#getClassByName(org.jboss.jandex.DotName)} */
 public ClassInfo getClassByName(final DotName className) {
   for (Index index : indexes) {
     final ClassInfo info = index.getClassByName(className);
     if (info != null) {
       return info;
     }
   }
   return null;
 }
Example #5
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);
 }
Example #6
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;
 }
Example #7
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);
 }
Example #8
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;
  }
 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;
 }
 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;
 }
 public ClassInfo getIndexedClassInfo(DotName name) {
   return index.getClassByName(name);
 }