Hyperic HQ Plugin API v. 4.4.0.2

org.hyperic.util
Class HypericEnum

java.lang.Object
  extended by org.hyperic.util.HypericEnum
All Implemented Interfaces:
java.io.Serializable, JSON
Direct Known Subclasses:
AgentSortField, AlertAuxLogProvider, AlertDefSortField, AlertSeverity, AlertSortField, AttachType, AuditImportance, AuditNature, AuditPurpose, AuditSortField, AuthzSubjectField, AvailabilityType, ComparisonOperator, CPropResourceSortField, CritterPropType, DownResSortField, EscalationAlertType, EscalationStateChange, EventLogSortField, EventLogStatus, ExplorerViewType, FormatType, GalertDefPartition, GalertDefSortField, GalertLogSortField, MeasurementTemplateSortField, MixedGroupType, ResourceGroupSortField, ResourceSortField, RoleCalendarType, SizeComparator, UpdateStatusMode, ViewAdminCategory, ViewMastheadCategory, ViewResourceCategory, YesOrNo

public abstract class HypericEnum
extends java.lang.Object
implements JSON, java.io.Serializable

Utility class for typesafe enums. People implementing such enums should subclass this class. Enums have a code and a description. The code must be unique for enums of a specific class. This has great use in things like Web-UI where you need a code representation as well as a string (rendering a listbox) Each enumeration also provides a resource bundle and locale property to look up the 'value' of the enumeration in that bundle. This class can also be used as a dynamic enumeration as long as all the enumerations use a unique code. XXX: It would be good to implement the PersistentEnum stylee via a UserType in Hibernate, so we don't have to do the conversion in every class that uses an enum. Don't have the time now.. :-( http://www.hibernate.org/203.html

See Also:
Serialized Form

Constructor Summary
protected HypericEnum(java.lang.Class c, int code, java.lang.String desc, java.lang.String localeProp, java.util.ResourceBundle bundle)
           
protected HypericEnum(int code, java.lang.String desc, java.lang.String localeProp, java.util.ResourceBundle bundle)
           
 
Method Summary
static HypericEnum findByCode(java.lang.Class c, int code)
          Find an enum of a specific class type by code.
static HypericEnum findByDescription(java.lang.Class c, java.lang.String description)
          Find an enum of a specific class type by description.
static java.util.List getAll(java.lang.Class c)
          Return a list of HypericEnum objects for a specific class, sorted by their code.
static HypericEnum getByCode(java.lang.Class c, int code)
          Like findByCode(Class, int) except returns null instead of throwing an exception
 int getCode()
           
 java.lang.String getDescription()
           
 java.lang.String getJsonName()
           
 java.lang.String getValue()
          Returns the localized value of this enumeration.
 org.json.JSONObject toJSON()
          Convert the object to a Json object
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HypericEnum

protected HypericEnum(int code,
                      java.lang.String desc,
                      java.lang.String localeProp,
                      java.util.ResourceBundle bundle)

HypericEnum

protected HypericEnum(java.lang.Class c,
                      int code,
                      java.lang.String desc,
                      java.lang.String localeProp,
                      java.util.ResourceBundle bundle)
Method Detail

getCode

public int getCode()

getValue

public java.lang.String getValue()
Returns the localized value of this enumeration.


getDescription

public java.lang.String getDescription()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getJsonName

public java.lang.String getJsonName()
Specified by:
getJsonName in interface JSON

toJSON

public org.json.JSONObject toJSON()
Description copied from interface: JSON
Convert the object to a Json object

Specified by:
toJSON in interface JSON

getByCode

public static HypericEnum getByCode(java.lang.Class c,
                                    int code)
Like findByCode(Class, int) except returns null instead of throwing an exception


findByCode

public static HypericEnum findByCode(java.lang.Class c,
                                     int code)
Find an enum of a specific class type by code.

Parameters:
c - A subclass of HypericEnum
code - The integer code represented by the enum
Returns:
the enum, else null

findByDescription

public static HypericEnum findByDescription(java.lang.Class c,
                                            java.lang.String description)
Find an enum of a specific class type by description.

Parameters:
c - A subclass of HypericEnum
description - The description represented by the enum.
Returns:
The enum, else null.

getAll

public static java.util.List getAll(java.lang.Class c)
Return a list of HypericEnum objects for a specific class, sorted by their code.

Parameters:
c - Class to find enums for

Hyperic HQ Plugin API v. 4.4.0.2

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.