private XmlToEnumMapper(T[] enumValues) {
ImmutableMap.Builder<String, T> mapBuilder = new ImmutableMap.Builder<>();
for (T value : enumValues) {
try {
XmlEnumValue xmlAnnotation = value
.getDeclaringClass()
.getField(value.name())
.getAnnotation(XmlEnumValue.class);
checkArgumentNotNull(xmlAnnotation, "Cannot map enum value to xml name: " + value);
String xmlName = xmlAnnotation.value();
mapBuilder = mapBuilder.put(xmlName, value);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
map = mapBuilder.build();
}
java类javax.xml.bind.annotation.XmlEnumValue的实例源码
XmlToEnumMapper.java 文件源码
项目:nomulus
阅读 16
收藏 0
点赞 0
评论 0
Util.java 文件源码
项目:openid-connect
阅读 20
收藏 0
点赞 0
评论 0
public static <E extends Enum<E>> String toString(final E value) {
final Class<E> enumType = value.getDeclaringClass();
try {
final XmlEnumValue xmlEnumValue = enumType.getField(value.name())
.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value() != null) {
return xmlEnumValue.value();
} else {
return value.name();
}
} catch (NoSuchFieldException
| SecurityException e1) {
throw new RuntimeException(e1);
}
}
Util.java 文件源码
项目:openid-connect
阅读 21
收藏 0
点赞 0
评论 0
public static <E extends Enum<E>> E valueOf(final Class<E> enumType,
final String name) {
if (!isNotNullOrEmpty(name)) {
return null;
}
try {
for (final E e : enumType.getEnumConstants()) {
String ename = e.name();
final XmlEnumValue xmlEnumValue = enumType.getField(ename)
.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value() != null) {
ename = xmlEnumValue.value();
}
if (name.equals(ename)) {
return e;
}
}
} catch (NoSuchFieldException
| SecurityException e1) {
throw new RuntimeException(e1);
}
throw new IllegalArgumentException("unable to find the value " + name + " in enum " + enumType);
}
EnumLeafInfoImpl.java 文件源码
项目:cxf-plus
阅读 32
收藏 0
点赞 0
评论 0
/**
* Build {@link EnumConstant}s and discover/report any error in it.
*/
protected void calcConstants() {
EnumConstantImpl<T,C,F,M> last = null;
F[] constants = nav().getEnumConstants(clazz);
for( int i=constants.length-1; i>=0; i-- ) {
F constant = constants[i];
String name = nav().getFieldName(constant);
XmlEnumValue xev = builder.reader.getFieldAnnotation(XmlEnumValue.class, constant, this);
String literal;
if(xev==null) literal = name;
else literal = xev.value();
last = createEnumConstant(name,literal,constant,last);
}
this.firstConstant = last;
}
EnumUtil.java 文件源码
项目:jpmml-evaluator
阅读 18
收藏 0
点赞 0
评论 0
static
public String getEnumValue(Enum<?> value){
Class<?> clazz = value.getClass();
Field field;
try {
field = clazz.getField(value.name());
} catch(NoSuchFieldException nsfe){
throw new RuntimeException(nsfe);
}
XmlEnumValue enumValue = field.getAnnotation(XmlEnumValue.class);
if(enumValue != null){
return enumValue.value();
}
throw new IllegalArgumentException();
}
PrismBeanInspector.java 文件源码
项目:engerek
阅读 18
收藏 0
点赞 0
评论 0
private <T> String findEnumFieldNameUncached(Class classType, T primValue){
for (Field field: classType.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value().equals(primValue)) {
return field.getName();
}
}
return null;
}
PrismBeanInspector.java 文件源码
项目:engerek
阅读 18
收藏 0
点赞 0
评论 0
public static String findEnumFieldValueUncached(Class classType, String toStringValue){
for (Field field: classType.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && field.getName().equals(toStringValue)) {
return xmlEnumValue.value();
}
}
return null;
}
XmlEnumUtils.java 文件源码
项目:nomulus
阅读 31
收藏 0
点赞 0
评论 0
/** Read the {@link XmlEnumValue} string off of an enum. */
public static String enumToXml(Enum<?> input) {
try {
return input.getClass().getField(input.name()).getAnnotation(XmlEnumValue.class).value();
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
Energiepass.java 文件源码
项目:OpenEstate-IO
阅读 16
收藏 0
点赞 0
评论 0
@XmlEnumValue("2008")
BIS_APRIL_2014("2008"),
@XmlEnumValue("2014")
AB_MAI_2014("2014"),
@XmlEnumValue("ohne")
OHNE("ohne"),
@XmlEnumValue("nicht_noetig")
NICHT_NOETIG("nicht_noetig"),
@XmlEnumValue("bei_besichtigung")
BEI_BESICHTIGUNG("bei_besichtigung");
OverseasSaleAdType.java 文件源码
项目:OpenEstate-IO
阅读 16
收藏 0
点赞 0
评论 0
@XmlEnumValue("for-sale")
FOR_SALE("for-sale"),
@XmlEnumValue("sale-agreed")
SALE_AGREED("sale-agreed"),
@XmlEnumValue("sold")
SOLD("sold");
RepositoryConfigurationBase.java 文件源码
项目:artifactory
阅读 16
收藏 0
点赞 0
评论 0
/**
* Extract from an Enum the {@link javax.xml.bind.annotation.XmlEnumValue} that are associated with its fields.
*
* @param clazz The class that is to be introspected
* @return A map that maps {@link javax.xml.bind.annotation.XmlEnumValue#value()} to the enum name itself.
*/
protected Map<String, String> extractXmlValueFromEnumAnnotations(Class clazz) {
Map<String, String> annotationToName = Maps.newHashMap();
Field[] fields = clazz.getFields();
for (Field field : fields) {
if (field.isAnnotationPresent(XmlEnumValue.class)) {
XmlEnumValue annotation = field.getAnnotation(XmlEnumValue.class);
annotationToName.put(annotation.value(), field.getName());
}
}
return annotationToName;
}
OpenIdProviderConfiguration.java 文件源码
项目:openid-connect
阅读 16
收藏 0
点赞 0
评论 0
public void setSubjectTypesSupported(final SubjectIdentifierType... subjectTypesSupported) {
this.subjectTypesSupported = new HashSet<>(subjectTypesSupported.length);
for (final SubjectIdentifierType subjectType : subjectTypesSupported) {
try {
this.subjectTypesSupported.add(subjectType.getClass().getField(((Enum<SubjectIdentifierType>) subjectType).name()).getAnnotation(XmlEnumValue.class).value());
} catch (NoSuchFieldException
| SecurityException e) {
throw new IllegalArgumentException(e);
}
}
}
PrismBeanInspector.java 文件源码
项目:midpoint
阅读 21
收藏 0
点赞 0
评论 0
private <T> String findEnumFieldNameUncached(Class classType, T primValue){
for (Field field: classType.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value().equals(primValue)) {
return field.getName();
}
}
return null;
}
PrismBeanInspector.java 文件源码
项目:midpoint
阅读 18
收藏 0
点赞 0
评论 0
public static String findEnumFieldValueUncached(Class classType, String toStringValue){
for (Field field: classType.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && field.getName().equals(toStringValue)) {
return xmlEnumValue.value();
}
}
return null;
}
PrismBeanInspector.java 文件源码
项目:midpoint
阅读 22
收藏 0
点赞 0
评论 0
private <T> String findEnumFieldNameUncached(Class classType, T primValue){
for (Field field: classType.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value().equals(primValue)) {
return field.getName();
}
}
return null;
}
PrismBeanInspector.java 文件源码
项目:midpoint
阅读 19
收藏 0
点赞 0
评论 0
public static String findEnumFieldValueUncached(Class classType, String toStringValue){
for (Field field: classType.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && field.getName().equals(toStringValue)) {
return xmlEnumValue.value();
}
}
return null;
}
DomToSchemaProcessor.java 文件源码
项目:engerek
阅读 16
收藏 0
点赞 0
评论 0
private <T> Collection<? extends DisplayableValue<T>> parseEnumAllowedValues(QName typeName,
ComplexTypeDefinition ctd, XSType xsType) {
if (xsType.isSimpleType()) {
if (xsType.asSimpleType().isRestriction()) {
XSRestrictionSimpleType restriction = xsType.asSimpleType().asRestriction();
List<XSFacet> enumerations = restriction.getDeclaredFacets(XSFacet.FACET_ENUMERATION);
List<DisplayableValueImpl<T>> enumValues = new ArrayList<DisplayableValueImpl<T>>(
enumerations.size());
for (XSFacet facet : enumerations) {
String value = facet.getValue().value;
Element descriptionE = SchemaProcessorUtil.getAnnotationElement(facet.getAnnotation(),
SCHEMA_DOCUMENTATION);
Element appInfo = SchemaProcessorUtil.getAnnotationElement(facet.getAnnotation(),
SCHEMA_APP_INFO);
Element valueE = null;
if (appInfo != null) {
NodeList list = appInfo.getElementsByTagNameNS(
PrismConstants.A_LABEL.getNamespaceURI(),
PrismConstants.A_LABEL.getLocalPart());
if (list.getLength() != 0) {
valueE = (Element) list.item(0);
}
}
String label = null;
if (valueE != null) {
label = valueE.getTextContent();
} else {
label = value;
}
DisplayableValueImpl<T> edv = null;
Class compileTimeClass = prismContext.getSchemaRegistry().getCompileTimeClass(typeName);
if (ctd != null && !ctd.isRuntimeSchema() && compileTimeClass != null) {
String fieldName = null;
for (Field field : compileTimeClass.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value() != null
&& xmlEnumValue.value().equals(value)) {
fieldName = field.getName();
}
}
if (fieldName != null) {
T enumValue = (T) Enum.valueOf((Class<Enum>) compileTimeClass, fieldName);
edv = new DisplayableValueImpl(enumValue, label,
descriptionE != null ? descriptionE.getTextContent() : null);
} else {
edv = new DisplayableValueImpl(value, label,
descriptionE != null ? descriptionE.getTextContent() : null);
}
} else {
edv = new DisplayableValueImpl(value, label,
descriptionE != null ? descriptionE.getTextContent() : null);
}
enumValues.add(edv);
}
if (enumValues != null && !enumValues.isEmpty()) {
return enumValues;
}
}
}
return null;
}
Energiepass.java 文件源码
项目:OpenEstate-IO
阅读 18
收藏 0
点赞 0
评论 0
@XmlEnumValue("wohn")
WOHN("wohn"),
@XmlEnumValue("nichtwohn")
NICHTWOHN("nichtwohn");
OverseasRentalAdType.java 文件源码
项目:OpenEstate-IO
阅读 15
收藏 0
点赞 0
评论 0
@XmlEnumValue("weekly")
WEEKLY("weekly"),
@XmlEnumValue("monthly")
MONTHLY("monthly");
SSRFTestUtility.java 文件源码
项目:lib-openssrf-test
阅读 19
收藏 0
点赞 0
评论 0
/**
* Query the Class type to find a WITH setter method for the indicated field.
* <p>
* @param type the class type
* @param field the field
* @return
* @throws ClassNotFoundException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
*/
private static Object getEnumEntry(Class<?> type, Field field) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
/**
* Inspect the WITH setter to determine if the field expects an enumerated
* input.
*/
Method with = SSRFUtility.findWithEnumMethod(type, field);
if (with != null) {
for (Class<?> parameterType : with.getParameterTypes()) {
if (parameterType.isEnum()) {
String fieldClassName = parameterType.toString().replace("class ", "").trim();
Class<?> fieldClass = Class.forName(fieldClassName); // throws ClassNotFoundException
/**
* Get a random instance of the enumerated class type.
*/
Enum fieldInstance = (Enum) fieldClass.getEnumConstants()[new Random().nextInt(fieldClass.getEnumConstants().length)];
/**
* If the instance has an XmlEnumValue annotation then return the XML
* value.
*/
XmlEnumValue xmlEnumValue = fieldInstance.getClass().getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null) {
return xmlEnumValue.value();
}
/**
* Otherwise try to call the value getter.
*/
for (Method method : fieldClass.getDeclaredMethods()) {
if (method.getName().equals("value")) {
return method.invoke(fieldInstance);
}
}
/**
* Finally just return the numerated instance name.
*/
return fieldInstance.name();
}
}
}
/**
* No enumerated instance found. Return null.
*/
return null;
}
Util.java 文件源码
项目:openid-connect
阅读 25
收藏 0
点赞 0
评论 0
public static JsonObject convertToJson(final Object obj) {
final JsonObjectBuilder b = Json.createObjectBuilder();
try {
final Class<?> objClass = obj.getClass();
for (final Field field : objClass.getDeclaredFields()) {
String name = field.getName();
if (field.getAnnotation(XmlTransient.class) != null) {
continue;
}
final XmlElement xmlElement = field.getAnnotation(XmlElement.class);
if (xmlElement != null && xmlElement.name() != null) {
name = xmlElement.name();
}
field.setAccessible(true);
final Object value = field.get(obj);
if (value == null) {
continue;
}
if (field.getType()
.isEnum()) {
final String enumValue = ((Enum<?>) value).name();
final XmlEnumValue xmlEnumValue = ((Enum<?>) value).getDeclaringClass()
.getField(enumValue)
.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value() != null) {
b.add(name, xmlEnumValue.value());
} else {
b.add(name, enumValue);
}
} else if (field.getType() == String.class) {
b.add(name, (String) value);
} else if (field.getType() == Integer.class) {
b.add(name, (Integer) value);
} else if (field.getType() == BigInteger.class) {
b.add(name, (BigInteger) value);
}
}
return b.build();
} catch (IllegalAccessException
| SecurityException
| NoSuchFieldException e1) {
throw new RuntimeException(e1);
}
}
DomToSchemaPostProcessor.java 文件源码
项目:midpoint
阅读 16
收藏 0
点赞 0
评论 0
private <T> Collection<? extends DisplayableValue<T>> parseEnumAllowedValues(QName typeName,
ComplexTypeDefinition ctd, XSType xsType) {
if (xsType.isSimpleType()) {
if (xsType.asSimpleType().isRestriction()) {
XSRestrictionSimpleType restriction = xsType.asSimpleType().asRestriction();
List<XSFacet> enumerations = restriction.getDeclaredFacets(XSFacet.FACET_ENUMERATION);
List<DisplayableValueImpl<T>> enumValues = new ArrayList<DisplayableValueImpl<T>>(
enumerations.size());
for (XSFacet facet : enumerations) {
String value = facet.getValue().value;
Element descriptionE = SchemaProcessorUtil.getAnnotationElement(facet.getAnnotation(),
SCHEMA_DOCUMENTATION);
Element appInfo = SchemaProcessorUtil.getAnnotationElement(facet.getAnnotation(),
SCHEMA_APP_INFO);
Element valueE = null;
if (appInfo != null) {
NodeList list = appInfo.getElementsByTagNameNS(
PrismConstants.A_LABEL.getNamespaceURI(),
PrismConstants.A_LABEL.getLocalPart());
if (list.getLength() != 0) {
valueE = (Element) list.item(0);
}
}
String label = null;
if (valueE != null) {
label = valueE.getTextContent();
} else {
label = value;
}
DisplayableValueImpl<T> edv = null;
Class compileTimeClass = prismContext.getSchemaRegistry().getCompileTimeClass(typeName);
if (ctd != null && !ctd.isRuntimeSchema() && compileTimeClass != null) {
String fieldName = null;
for (Field field : compileTimeClass.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value() != null
&& xmlEnumValue.value().equals(value)) {
fieldName = field.getName();
}
}
if (fieldName != null) {
T enumValue = (T) Enum.valueOf((Class<Enum>) compileTimeClass, fieldName);
edv = new DisplayableValueImpl(enumValue, label,
descriptionE != null ? descriptionE.getTextContent() : null);
} else {
edv = new DisplayableValueImpl(value, label,
descriptionE != null ? descriptionE.getTextContent() : null);
}
} else {
edv = new DisplayableValueImpl(value, label,
descriptionE != null ? descriptionE.getTextContent() : null);
}
enumValues.add(edv);
}
if (enumValues != null && !enumValues.isEmpty()) {
return enumValues;
}
}
}
return null;
}
DomToSchemaPostProcessor.java 文件源码
项目:midpoint
阅读 17
收藏 0
点赞 0
评论 0
private <T> Collection<? extends DisplayableValue<T>> parseEnumAllowedValues(QName typeName,
ComplexTypeDefinition ctd, XSType xsType) {
if (xsType.isSimpleType()) {
if (xsType.asSimpleType().isRestriction()) {
XSRestrictionSimpleType restriction = xsType.asSimpleType().asRestriction();
List<XSFacet> enumerations = restriction.getDeclaredFacets(XSFacet.FACET_ENUMERATION);
List<DisplayableValueImpl<T>> enumValues = new ArrayList<DisplayableValueImpl<T>>(
enumerations.size());
for (XSFacet facet : enumerations) {
String value = facet.getValue().value;
Element descriptionE = SchemaProcessorUtil.getAnnotationElement(facet.getAnnotation(),
SCHEMA_DOCUMENTATION);
Element appInfo = SchemaProcessorUtil.getAnnotationElement(facet.getAnnotation(),
SCHEMA_APP_INFO);
Element valueE = null;
if (appInfo != null) {
NodeList list = appInfo.getElementsByTagNameNS(
PrismConstants.A_LABEL.getNamespaceURI(),
PrismConstants.A_LABEL.getLocalPart());
if (list.getLength() != 0) {
valueE = (Element) list.item(0);
}
}
String label = null;
if (valueE != null) {
label = valueE.getTextContent();
} else {
label = value;
}
DisplayableValueImpl<T> edv = null;
Class compileTimeClass = prismContext.getSchemaRegistry().getCompileTimeClass(typeName);
if (ctd != null && !ctd.isRuntimeSchema() && compileTimeClass != null) {
String fieldName = null;
for (Field field : compileTimeClass.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value() != null
&& xmlEnumValue.value().equals(value)) {
fieldName = field.getName();
}
}
if (fieldName != null) {
T enumValue = (T) Enum.valueOf((Class<Enum>) compileTimeClass, fieldName);
edv = new DisplayableValueImpl(enumValue, label,
descriptionE != null ? descriptionE.getTextContent() : null);
} else {
edv = new DisplayableValueImpl(value, label,
descriptionE != null ? descriptionE.getTextContent() : null);
}
} else {
edv = new DisplayableValueImpl(value, label,
descriptionE != null ? descriptionE.getTextContent() : null);
}
enumValues.add(edv);
}
if (enumValues != null && !enumValues.isEmpty()) {
return enumValues;
}
}
}
return null;
}