views:

997

answers:

2

Hello

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

Is there a XMLBeans API call to get all Enum values from a generated class? Is the only choice available some sort of Java reflection?

Thanks

+1  A: 

This worked for me:

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

Here is 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 the list of enum values of ModelType, I do the following :

getEnumValueList(ModelType.Factory.newInstance());