Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-1288

Java5 Enum for mbean and configurations

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Obsolete
    • Icon: Minor Minor
    • No Release
    • JBossAS-4.0.1 Final
    • JMX
    • None

      Whenever you try to get a PropertyEditor for something but none is there, do the following additional check:

      if (type.getSuperclass().getName().equals("java.lang.Enum"))
      {
      editor = new EnumPropertyEditor(type);
      }

      where the EnumPropertyEditor is:

      public class EnumPropertyEditor extends PropertyEditorSupport implements PropertyEditor
      {
      private final Class targetType;

      public EnumPropertyEditor(Class targetType)

      { this.targetType = targetType; }

      public void setAsText(String text) throws IllegalArgumentException
      {
      try
      {
      setValue(targetType.getMethod("valueOf",new Class[]

      {String.class}

      ).invoke(null,new Object[]

      {text}

      );
      } catch (IllegalAccessException e)

      { throw new IllegalStateException(e); } catch (InvocationTargetException e)
      { if (e.getTargetException() instanceof RuntimeException); throw (RuntimeException)e.getTargetException(); throw new IllegalStateException(e); } catch (NoSuchMethodException e)
      { String err = type.getName() + " does not contain the required method: public static " + type.getName() + " valueOf(String);"; throw new IllegalArgumentException(err,e); }

      }

      public String getAsText()
      {

      try
      { return targetType.getMethod("name",null).invoke(getValue(),null) } catch (IllegalAccessException e)
      { throw new IllegalStateException(e); }

      catch (InvocationTargetException e)

      { if (e.getTargetException() instanceof RuntimeException); throw (RuntimeException)e.getTargetException(); throw new IllegalStateException(e); }

      catch (NoSuchMethodException e)

      { String err = type.getName() + " does not contain the required method: public String name()"; throw new IllegalStateException(err,e); }

      }
      }

              Unassigned Unassigned
              greydeath_jira Michael Kopp (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: