コード例 #1
0
 /**
  * Binds all {@link org.hibernate.annotations.TypeDef} and {@link TypeDefs} annotations to the
  * supplied metadata.
  *
  * @param metadata the global metadata
  * @param jandex the jandex jandex
  */
 public static void bind(MetadataImplementor metadata, Index jandex) {
   for (AnnotationInstance typeDef : jandex.getAnnotations(HibernateDotNames.TYPE_DEF)) {
     bind(metadata, typeDef);
   }
   for (AnnotationInstance typeDefs : jandex.getAnnotations(HibernateDotNames.TYPE_DEFS)) {
     AnnotationInstance[] typeDefAnnotations =
         JandexHelper.getValue(typeDefs, "value", AnnotationInstance[].class);
     for (AnnotationInstance typeDef : typeDefAnnotations) {
       bind(metadata, typeDef);
     }
   }
 }
コード例 #2
0
  private static void bind(MetadataImplementor metadata, AnnotationInstance typeDefAnnotation) {
    String name = JandexHelper.getValue(typeDefAnnotation, "name", String.class);
    String defaultForType =
        JandexHelper.getValue(typeDefAnnotation, "defaultForType", String.class);
    String typeClass = JandexHelper.getValue(typeDefAnnotation, "typeClass", String.class);

    boolean noName = StringHelper.isEmpty(name);
    boolean noDefaultForType =
        defaultForType == null || defaultForType.equals(void.class.getName());

    if (noName && noDefaultForType) {
      throw new AnnotationException(
          "Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass "
              + typeClass);
    }

    Map<String, String> parameterMaps = new HashMap<String, String>();
    AnnotationInstance[] parameterAnnotations =
        JandexHelper.getValue(typeDefAnnotation, "parameters", AnnotationInstance[].class);
    for (AnnotationInstance parameterAnnotation : parameterAnnotations) {
      parameterMaps.put(
          JandexHelper.getValue(parameterAnnotation, "name", String.class),
          JandexHelper.getValue(parameterAnnotation, "value", String.class));
    }

    if (!noName) {
      bind(name, typeClass, parameterMaps, metadata);
    }
    if (!noDefaultForType) {
      bind(defaultForType, typeClass, parameterMaps, metadata);
    }
  }