use of javax.xml.bind.annotation.XmlEnumValue in project enunciate by stoicflame.
the class EnumTypeDefinition method loadEnumValues.
protected List<EnumValue> loadEnumValues() {
List<VariableElement> enumConstants = enumValues();
List<EnumValue> enumValueMap = new ArrayList<EnumValue>();
HashSet<String> enumValues = new HashSet<String>(enumConstants.size());
for (VariableElement enumConstant : enumConstants) {
if (isIgnored(enumConstant)) {
continue;
}
String value = enumConstant.getSimpleName().toString();
if (context.isHonorJaxb()) {
XmlEnumValue enumValue = enumConstant.getAnnotation(XmlEnumValue.class);
if (enumValue != null) {
value = enumValue.value();
}
}
if (context.isHonorGson()) {
AnnotationValue av = JacksonUtil.findAnnotationValueByName(JacksonUtil.findAnnotationByClassName(enumConstant.getAnnotationMirrors(), JacksonUtil.GSON_SERIALIZED_NAME_CLASS), "value");
if (av != null) {
value = (String) av.getValue();
}
}
JsonProperty jsonProperty = enumConstant.getAnnotation(JsonProperty.class);
if (jsonProperty != null) {
value = jsonProperty.value();
}
if (!enumValues.add(value)) {
throw new EnunciateException(getQualifiedName() + ": duplicate enum value: " + value);
}
enumValueMap.add(new EnumValue(this, enumConstant, enumConstant.getSimpleName().toString(), value));
}
return enumValueMap;
}
use of javax.xml.bind.annotation.XmlEnumValue in project enunciate by stoicflame.
the class EnumTypeDefinition method loadEnumValues.
protected List<EnumValue> loadEnumValues() {
List<VariableElement> enumConstants = enumValues();
List<EnumValue> enumValues = new ArrayList<EnumValue>();
HashSet<String> enumValueNames = new HashSet<String>(enumConstants.size());
for (VariableElement enumConstant : enumConstants) {
if (isIgnored(enumConstant)) {
continue;
}
String value = enumConstant.getSimpleName().toString();
XmlEnumValue enumValue = enumConstant.getAnnotation(XmlEnumValue.class);
if (enumValue != null) {
value = enumValue.value();
}
if (!enumValueNames.add(value)) {
throw new EnunciateException(getQualifiedName() + ": duplicate enum value: " + value);
}
enumValues.add(new EnumValue(this, enumConstant, enumConstant.getSimpleName().toString(), value));
}
return enumValues;
}
use of javax.xml.bind.annotation.XmlEnumValue in project zm-mailbox by Zimbra.
the class ZmPairAnnotationIntrospector method findEnumValues.
// since 2.7
@Override
public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] names) {
HashMap<String, String> expl = null;
for (Field f : ClassUtil.getDeclaredFields(enumType)) {
if (!f.isEnumConstant()) {
continue;
}
XmlEnumValue enumValue = f.getAnnotation(XmlEnumValue.class);
if (enumValue == null) {
continue;
}
String n = enumValue.value();
if (expl == null) {
expl = new HashMap<String, String>();
}
expl.put(f.getName(), n);
}
// and then stitch them together if and as necessary
if (expl != null) {
int end = enumValues.length;
for (int i = 0; i < end; ++i) {
String defName = enumValues[i].name();
String explValue = expl.get(defName);
if (explValue != null) {
names[i] = explValue;
}
}
}
return names;
}
use of javax.xml.bind.annotation.XmlEnumValue in project cxf by apache.
the class AnnotationReader method getEnumValue.
public static String getEnumValue(Enum<?> enumConstant) {
@SuppressWarnings("rawtypes") Class<? extends Enum> enumClass = enumConstant.getClass();
try {
Field constantField = enumClass.getDeclaredField(enumConstant.name());
XmlEnumValue constantValueAnnotation = constantField.getAnnotation(XmlEnumValue.class);
if (constantValueAnnotation == null) {
return null;
}
return constantValueAnnotation.value();
} catch (NoSuchFieldException e) {
return null;
}
}
use of javax.xml.bind.annotation.XmlEnumValue in project axis-axis2-java-core by apache.
the class XMLRootElementUtil method getEnumValue.
/**
* @param clazz
* @return namespace of root element qname or null if this is object does not represent a root element
*/
public static String getEnumValue(Enum myEnum) {
Field f;
String value;
try {
f = myEnum.getClass().getField(myEnum.name());
f.setAccessible(true);
XmlEnumValue xev = (XmlEnumValue) getAnnotation(f, XmlEnumValue.class);
if (xev == null) {
value = f.getName();
} else {
value = xev.value();
}
} catch (SecurityException e) {
value = null;
} catch (NoSuchFieldException e) {
value = null;
}
return value;
}
Aggregations