Search in sources :

Example 1 with XmlEnumValue

use of jakarta.xml.bind.annotation.XmlEnumValue in project jaxb-ri by eclipse-ee4j.

the class EnumLeafInfoImpl method calcConstants.

/**
 * Build {@link EnumConstant}s and discover/report any error in it.
 */
protected void calcConstants() {
    EnumConstantImpl<T, C, F, M> last = null;
    // first check if we represent xs:token derived type
    Collection<? extends F> fields = nav().getDeclaredFields(clazz);
    for (F f : fields) {
        if (nav().isSameType(nav().getFieldType(f), nav().ref(String.class))) {
            XmlSchemaType schemaTypeAnnotation = builder.reader.getFieldAnnotation(XmlSchemaType.class, f, this);
            if (schemaTypeAnnotation != null) {
                if ("token".equals(schemaTypeAnnotation.name())) {
                    tokenStringType = true;
                    break;
                }
            }
        }
    }
    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;
}
Also used : XmlEnumValue(jakarta.xml.bind.annotation.XmlEnumValue) XmlSchemaType(jakarta.xml.bind.annotation.XmlSchemaType)

Aggregations

XmlEnumValue (jakarta.xml.bind.annotation.XmlEnumValue)1 XmlSchemaType (jakarta.xml.bind.annotation.XmlSchemaType)1