javax.xml.bind.annotation.XmlEnumValue Java Examples

The following examples show how to use javax.xml.bind.annotation.XmlEnumValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XLink.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Appends the given attribute in the given buffer if the attribute value is not null.
 * If the given value is an attribute, the XML name will be used rather than the Java
 * field name.
 */
private static void append(final StringBuilder buffer, final String label, Object value) {
    if (value != null) {
        if (buffer.charAt(buffer.length() - 1) != '[') {
            buffer.append(", ");
        }
        if (value instanceof Enum<?>) try {
            final XmlEnumValue xml = value.getClass().getField(((Enum<?>) value).name()).getAnnotation(XmlEnumValue.class);
            if (xml != null) {
                value = xml.value();
            }
        } catch (NoSuchFieldException e) {
            // Should never happen with Enums. But if it happen anyway, this is not a fatal error.
            Logging.unexpectedException(Logging.getLogger(Loggers.XML), XLink.class, "toString", e);
        }
        buffer.append(label).append("=\"").append(value).append('"');
    }
}
 
Example #2
Source File: EnumUtil.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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();
}
 
Example #3
Source File: Energiepass.java    From OpenEstate-IO with Apache License 2.0 6 votes vote down vote up
@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");
 
Example #4
Source File: XmlToEnumMapper.java    From nomulus with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #5
Source File: XmlEnumUtils.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/** Read the {@link XmlEnumValue} string off of an enum. */
public static String enumToXml(Enum<?> input) {
  try {
    return input
        .getDeclaringClass()
        .getField(input.name())
        .getAnnotation(XmlEnumValue.class)
        .value();
  } catch (NoSuchFieldException e) {
    throw new RuntimeException(e);
  }
}
 
Example #6
Source File: AnnotationReader.java    From cxf with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #7
Source File: OverseasSaleAdType.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
@XmlEnumValue("for-sale")
FOR_SALE("for-sale"),
@XmlEnumValue("sale-agreed")
SALE_AGREED("sale-agreed"),
@XmlEnumValue("sold")
SOLD("sold");
 
Example #8
Source File: EnumArrays.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("fish") FISH(String.valueOf("fish")), @XmlEnumValue("crab") CRAB(String.valueOf("crab"));


 
Example #9
Source File: JaxbEnumExtension.java    From raml-java-tools with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSpec.Builder enumValue(EnumerationPluginContext enumerationPluginContext, TypeDeclaration declaration, TypeSpec.Builder incoming, String value, EventType eventType) {

    return incoming.addAnnotation(AnnotationSpec.builder(XmlEnumValue.class).addMember("value", "$S", value)
            .build());
}
 
Example #10
Source File: EnumTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("UPPER") @JsonProperty("UPPER") UPPER(String.valueOf("UPPER")), 
@XmlEnumValue("lower") @JsonProperty("lower") LOWER(String.valueOf("lower")), 
@XmlEnumValue("") @JsonProperty("") EMPTY(String.valueOf(""));
 
Example #11
Source File: EnumTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("1.1") NUMBER_1_DOT_1(Double.valueOf(1.1)), @XmlEnumValue("-1.2") NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));


 
Example #12
Source File: Energiepass.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("wohn")
WOHN("wohn"),
@XmlEnumValue("nichtwohn")
NICHTWOHN("nichtwohn");
 
Example #13
Source File: EnumTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("1") NUMBER_1(Integer.valueOf(1)), @XmlEnumValue("-1") NUMBER_MINUS_1(Integer.valueOf(-1));


 
Example #14
Source File: EnumTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("UPPER") UPPER(String.valueOf("UPPER")), @XmlEnumValue("lower") LOWER(String.valueOf("lower")), @XmlEnumValue("") EMPTY(String.valueOf(""));


 
Example #15
Source File: OverseasRentalAdType.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("weekly")
WEEKLY("weekly"),
@XmlEnumValue("monthly")
MONTHLY("monthly");
 
Example #16
Source File: EnumArrays.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("fish") @JsonProperty("fish") FISH(String.valueOf("fish")), 
@XmlEnumValue("crab") @JsonProperty("crab") CRAB(String.valueOf("crab"));
 
Example #17
Source File: EnumTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("1.1") @JsonProperty("1.1") NUMBER_1_DOT_1(Double.valueOf(1.1)), 
@XmlEnumValue("-1.2") @JsonProperty("-1.2") NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));
 
Example #18
Source File: EnumTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@XmlEnumValue("1") @JsonProperty("1") NUMBER_1(Integer.valueOf(1)), 
@XmlEnumValue("-1") @JsonProperty("-1") NUMBER_MINUS_1(Integer.valueOf(-1));