/** * @param clazz * @param type * clazz and type should both point to the enum class * that this {@link EnumLeafInfo} represents. * Because of the type parameterization we have to take them separately. */ public EnumLeafInfoImpl(ModelBuilder<T,C,F,M> builder, Locatable upstream, C clazz, T type ) { super(builder,upstream); this.clazz = clazz; this.type = type; elementName = parseElementName(clazz); // compute the type name // TODO: I guess it must be allowed for enums to have @XmlElement typeName = parseTypeName(clazz); // locate the base type. // this can be done eagerly because there shouldn't be no cycle. XmlEnum xe = builder.reader.getClassAnnotation(XmlEnum.class, clazz, this); if(xe!=null) { T base = builder.reader.getClassValue(xe, "value"); baseType = builder.getTypeInfo(base,this); } else { baseType = builder.getTypeInfo(builder.nav.ref(String.class),this); } }
private static String _typeNormalizedDesc(final Class<?> type) { String dataTypeDesc = null; if (CollectionUtils.isMap(type)) { //@SuppressWarnings("unchecked") //Class<? extends Map<?,?>> mapType = (Class<? extends Map<?,?>>)type; // Map:(java.lang.Object,java.lang.Object) dataTypeDesc = "Map:" + type.getName() + "(" + Object.class.getCanonicalName() + "," + Object.class.getCanonicalName() + ")"; } else if (CollectionUtils.isCollection(type)) { //@SuppressWarnings("unchecked") //Class<? extends Collection<?>> colType = (Class<? extends Collection<?>>)type; dataTypeDesc = "Collection:" + type.getName() + "(" + Object.class.getCanonicalName() + ")"; } else if (type.isEnum() || type.getAnnotation(XmlEnum.class) != null) { dataTypeDesc = "Enum(" + type.getName() + ")"; } else { dataTypeDesc = type.getName(); } return dataTypeDesc; }
private static Method getConversionMethod(Class cls) { // Look for forName method that is generated by JAXB. Method m = fromValueMethod(cls, String.class); if (m != null) { return m; } // If cannot find forName(String) then look for @XmlEnum value if (log.isDebugEnabled()) { log.debug("try looking for @XmlEnum "); } XmlEnum xmlEnum = (XmlEnum) cls.getAnnotation(XmlEnum.class); if (xmlEnum != null) { Class argClass = xmlEnum.value(); m = fromValueMethod(cls, argClass); if (m !=null) { return m; } Class primitiveClass = getPrimitiveClass(argClass); if (primitiveClass != null) { m = fromValueMethod(cls, primitiveClass); if (m != null) { return m; } } } // Look for valueOf(String) method if (log.isDebugEnabled()) { log.debug("try looking for valueOf method "); } m = valueOfMethod(cls); if (m != null) { return m; } throw new IllegalArgumentException(); }
public XmlEnumQuick(Locatable upstream, XmlEnum core) { super(upstream); this.core = core; }
protected Quick newInstance(Locatable upstream, Annotation core) { return new XmlEnumQuick(upstream, ((XmlEnum) core)); }
public Class<XmlEnum> annotationType() { return XmlEnum.class; }
/** * Obtiene la descripci�n del tipo de un field en un formato normalizado a partir de ciertos datos de la clase, el field, etc * @param type el tipo que contiene el field * @param field el field * @param actualFieldType el tipo de dato actual del field (resolviendo gen�ricos, etc) * @return */ private static String _fieldTypeStandardDesc(final Class<?> type, final Field field,final Class<?> actualFieldType) { String dataTypeDesc = null; if (actualFieldType != Object.class && ReflectionUtils.isTypeDef(actualFieldType)) { // Definici�n de clase java dataTypeDesc = Class.class.getCanonicalName(); // "java.lang.Class"; } else if (ReflectionUtils.isImplementing(actualFieldType,LanguageTexts.class) && !actualFieldType.equals(LanguageTextsI18NBundleBacked.class)) { //"Map:(r01f.locale.Language,java.lang.String)"; dataTypeDesc = "Map:" + actualFieldType.getName() + "(" + Language.class.getCanonicalName() + "," + String.class.getCanonicalName() + ")"; } else if (CollectionUtils.isMap(actualFieldType)) { // Mapa Class<?> keyAndValueComponentTypes[] = _mapFieldKeyValueComponentTypes(type,field); if (keyAndValueComponentTypes != null && keyAndValueComponentTypes.length == 2) { String keyType = keyAndValueComponentTypes[0] != null ? keyAndValueComponentTypes[0].getName() : Object.class.getCanonicalName(); //"java.lang.Object"; String valueType = keyAndValueComponentTypes[1] != null ? keyAndValueComponentTypes[1].getName() : Object.class.getCanonicalName(); //"java.lang.Object"; dataTypeDesc = "Map:" + actualFieldType.getName() + "(" + keyType + "," + valueType + ")"; } else { dataTypeDesc = "Map:" + actualFieldType.getName(); } } else if (CollectionUtils.isCollection(actualFieldType)) { // Colecci�n Class<?> componentType = _collectionFieldComponentType(type,field); if (componentType != null) { dataTypeDesc = "Collection:" + actualFieldType.getName() + "(" + componentType.getName() + ")"; } else { dataTypeDesc = "Collection:" + actualFieldType.getName(); } } else if (CollectionUtils.isArray(actualFieldType)) { // Array dataTypeDesc = _collectionFieldComponentType(type,field).getName() + "[]"; } else if (actualFieldType.isEnum() || actualFieldType.getAnnotation(XmlEnum.class) != null) { // Enumeraci�n dataTypeDesc = "Enum(" + actualFieldType.getName() + ")"; } else if (!actualFieldType.isPrimitive() && !ReflectionUtils.isInstanciable(actualFieldType)) { // [C] Es un interfaz dataTypeDesc = field.getType().getName(); } else { // [D] Tipo NO generico (el caso m�s normal) dataTypeDesc = actualFieldType.getName(); } return dataTypeDesc; }
/** * @param e Class of enum * @return a base type that can be used for constructing the enum */ public static Class getConversionType(final Class e) { Class cls = null; if (log.isDebugEnabled()) { log.debug("getConversionType for " + e); } try { cls = (Class) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { // Look for forName method that is generated by JAXB. Method m = fromValueMethod(e, String.class); if (m != null) { return String.class; } // If we cannot find forName(String) then look for @XmlEnum value // and then look for a forName with the indicated base type if (log.isDebugEnabled()) { log.debug("try looking for @XmlEnum "); } XmlEnum xmlEnum = (XmlEnum) e.getAnnotation(XmlEnum.class); if (xmlEnum != null) { Class argClass = xmlEnum.value(); m = fromValueMethod(e, argClass); if (m !=null) { return argClass; } Class primitiveClass = getPrimitiveClass(argClass); if (primitiveClass != null) { m = fromValueMethod(e, primitiveClass); if (m != null) { return argClass; } } } // If still not found look for valueOf(String) method if (log.isDebugEnabled()) { log.debug("try looking for valueOf method "); } m = valueOfMethod(e); if (m != null) { return String.class; } throw ExceptionFactory.makeWebServiceException(new IllegalArgumentException()); }}); } finally { if (log.isDebugEnabled()) { log.debug("getConversionType is" + cls); } } return cls; }