List of usage examples for org.apache.commons.lang.enums Enum getName
public final String getName()
Retrieve the name of this Enum item, set in the constructor.
From source file:org.apache.cocoon.forms.datatype.EnumSelectionList.java
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { try {/*from w w w .jav a 2s . com*/ 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); } }
From source file:org.sipfoundry.sipxconfig.common.EnumUserType.java
/** * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, * java.lang.Object, int)/*ww w .j a v a 2 s . c om*/ */ public void nullSafeSet(PreparedStatement st, Object value, int index) throws SQLException { // make sure the received value is of the right type if ((value != null) && !returnedClass().isAssignableFrom(value.getClass())) { throw new IllegalArgumentException( "Received value is not a [" + returnedClass().getName() + "] but [" + value.getClass() + "]"); } if (value == null) { st.setNull(index, Types.VARCHAR); return; } Enum enumeration = (Enum) value; String enumCode = enumeration.getName(); st.setString(index, enumCode); }
From source file:org.sipfoundry.sipxconfig.components.EnumFormat.java
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos_) { Enum value = (Enum) obj; String name = value.getName(); if (m_messages == null) { toAppendTo.append(name);//from w w w . ja v a 2 s.c o m } else { String nameKey = name.replaceAll(" ", "_"); String key = m_prefix + m_prefixSeparator + nameKey; toAppendTo.append(m_messages.getMessage(key)); } return toAppendTo; }