本文整理汇总了Java中javax.xml.bind.annotation.XmlEnumValue类的典型用法代码示例。如果您正苦于以下问题:Java XmlEnumValue类的具体用法?Java XmlEnumValue怎么用?Java XmlEnumValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlEnumValue类属于javax.xml.bind.annotation包,在下文中一共展示了XmlEnumValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: XmlToEnumMapper
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
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();
}
示例2: toString
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
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);
}
}
示例3: valueOf
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
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);
}
示例4: calcConstants
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
/**
* 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;
}
示例5: getEnumValue
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
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();
}
示例6: findEnumFieldNameUncached
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
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;
}
示例7: findEnumFieldValueUncached
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
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;
}
示例8: enumToXml
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
/** 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);
}
}
示例9: BIS_APRIL_2014
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
@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");
示例10: FOR_SALE
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
@XmlEnumValue("for-sale")
FOR_SALE("for-sale"),
@XmlEnumValue("sale-agreed")
SALE_AGREED("sale-agreed"),
@XmlEnumValue("sold")
SOLD("sold");
示例11: extractXmlValueFromEnumAnnotations
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
/**
* 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;
}
示例12: setSubjectTypesSupported
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
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);
}
}
}
示例13: parseEnumAllowedValues
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
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;
}
示例14: WOHN
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
@XmlEnumValue("wohn")
WOHN("wohn"),
@XmlEnumValue("nichtwohn")
NICHTWOHN("nichtwohn");
示例15: WEEKLY
import javax.xml.bind.annotation.XmlEnumValue; //导入依赖的package包/类
@XmlEnumValue("weekly")
WEEKLY("weekly"),
@XmlEnumValue("monthly")
MONTHLY("monthly");