List of usage examples for org.apache.commons.lang.enums EnumUtils iterator
public static Iterator iterator(Class enumClass)
Gets an Iterator
over the Enum
objects in an Enum
class.
The iterator is in the order that the objects were created (source code order).
If the requested class has no enum objects an empty Iterator
is returned.
From source file:org.apache.cocoon.forms.datatype.EnumSelectionList.java
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { try {/*from w w w .ja va2 s . c o m*/ contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES); // Create void element if (nullable) { AttributesImpl voidAttrs = new AttributesImpl(); voidAttrs.addCDATAAttribute("value", ""); contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, voidAttrs); if (this.nullText != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES); contentHandler.startElement(FormsConstants.I18N_NS, TEXT_EL, FormsConstants.I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES); contentHandler.characters(nullText.toCharArray(), 0, nullText.length()); contentHandler.endElement(FormsConstants.I18N_NS, TEXT_EL, FormsConstants.I18N_PREFIX_COLON + TEXT_EL); contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); } contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); } // Test if we have an apache enum class boolean apacheEnumDone = false; if (Enum.class.isAssignableFrom(clazz)) { Iterator iter = EnumUtils.iterator(clazz); if (iter != null) { apacheEnumDone = true; while (iter.hasNext()) { Enum element = (Enum) iter.next(); String stringValue = clazz.getName() + "." + element.getName(); generateItem(contentHandler, stringValue); } } } // If it's not an apache enum or we didn't manage to read the enum list, then proceed with common method. if (!apacheEnumDone) { Field fields[] = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; ++i) { int mods = fields[i].getModifiers(); if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods) && fields[i].get(null).getClass().equals(clazz)) { String stringValue = clazz.getName() + "." + fields[i].getName(); generateItem(contentHandler, stringValue); } } } // End the selection-list contentHandler.endElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL); } catch (Exception e) { throw new SAXException("Got exception trying to get enum's values", e); } }