How do I get all the Enum values ​​in XMLBeans?

Apache XMLBeans can be used to create Java classes and interfaces from XML Schema Definition (XSD) files. It also generates Enums based on StringEnumAbstractBase and StringEnumAbstractBase.Table to represent domain values. They are convenient for entering only valid values. However, I want to get all these values ​​to create a JCombobox, JTable or html.

Is there an XMLBeans API request to get all the Enum values ​​from the generated class? Is some kind of Java reflection available the only choice available?

thank

+1
java enums xmlbeans


source to share


2 answers


This worked for me:



for (int i = 1; i <= MyEnum.Enum.table.lastInt(); i++) 
{
  System.out.println(MyEnum.Enum.forInt(i));
}

      

+3


source to share


Here's another way to get it:

public static List<String> getEnumValueList(XmlString xmlString){
    List<String> values = new ArrayList<String>();
    SchemaStringEnumEntry valArr[] = xmlString.schemaType().getStringEnumEntries();
    for(SchemaStringEnumEntry val : valArr){
        values.add(val.getString());
    }
    return values;
}

      



So, to get a list of ModelType enum values, I do the following:

getEnumValueList(ModelType.Factory.newInstance());

      

+2


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics