Ejemplo n.º 1
0
  protected AegisType createUserType(TypeClassInfo info) {
    try {
      AegisType type = info.getAegisTypeClass().newInstance();

      QName name = info.getTypeName();
      if (name == null) {
        // We do not want to use the java.lang.whatever schema type.
        // If the @ annotation or XML file didn't specify a schema type,
        // but the natural type has a schema type mapping, we use that rather
        // than create nonsense.
        Class<?> typeClass = TypeUtil.getTypeRelatedClass(info.getType());
        if (typeClass.getPackage().getName().startsWith("java")) {
          name = tm.getTypeQName(typeClass);
        }
        // if it's still null, we'll take our lumps, but probably end up with
        // an invalid schema.
        if (name == null) {
          name = createQName(typeClass);
        }
      }

      type.setSchemaType(name);
      type.setTypeClass(info.getType());
      type.setTypeMapping(getTypeMapping());

      return type;
    } catch (InstantiationException e) {
      throw new DatabindingException(
          "Couldn't instantiate type classs " + info.getAegisTypeClass().getName(), e);
    } catch (IllegalAccessException e) {
      throw new DatabindingException(
          "Couldn't access type classs " + info.getAegisTypeClass().getName(), e);
    }
  }