public class PropertyIndex
- Object
- PropertyIndex
ImplementsIterable<PropertyBase>
Maps the properties that are in a class/object and provides access to them so tools such as ORM
can implicitly access them for us. This class also holds the class level meta-data for a specific property
or class. It also provides utility level tools e.g. toString implementation etc.
Constructors
public PropertyIndex(PropertyBusinessObject parent, String name, PropertyBase... properties) | The constructor is essential for a proper property business object |
Methods
Inherited methods
Constructor details
PropertyIndex
public PropertyIndex(PropertyBusinessObject parent, String name, PropertyBase... properties)The constructor is essential for a proper property business object
Parameters
parentPropertyBusinessObject- the parent object instance
nameString- the name of the parent class
propertiesPropertyBase...- the list of properties in the object
Method details
storeJSONList
public static void storeJSONList(String name, List<? extends PropertyBusinessObject> objs)Writes the JSON string to storage, it’s a shortcut for writing/generating the JSON
Parameters
nameString- the name of the storage file
objsList<? extends PropertyBusinessObject>- a list of business objects
toJSONList
public static String toJSONList(List<? extends PropertyBusinessObject> objs)Creates a JSON string, containing the list of property business objects
Parameters
objsList<? extends PropertyBusinessObject>- a list of business objects
Returns
the JSON string
getName
public String getName()The name of the parent business object
Returns
a unique name for the parent
get
public PropertyBase get(String name)Returns a property by its name
Parameters
nameString- the name of the property (case sensitive)
Returns
the property or null
getIgnoreCase
public PropertyBase getIgnoreCase(String name)Returns a property by its name regardless of case sensitivity for the name
Parameters
nameString- the name of the property (case insensitive)
Returns
the property or null
get
public PropertyBase get(int i)Allows us to get an individual property within the object instance
Parameters
iint- the index of the property
Returns
the property instance
getSize
public int getSize()The number of properties in the class
Returns
number of properties in the class
iterator
public Iterator<PropertyBase> iterator()Allows us to traverse the properties with a for-each statement
Returns
an iterator instance
getMetaDataOfClass
public Object getMetaDataOfClass(String meta)Allows us to fetch class meta data not to be confused with standard properties
Parameters
metaString- the meta data unique name
Returns
the object instance
putMetaDataOfClass
public void putMetaDataOfClass(String meta, Object o)Sets class specific metadata
Parameters
metaString- the name of the meta data
oObject- object value for the meta data
toString
public String toString()Returns a user readable printout of the property values which is useful for debugging
Returns
user readable printout of the property values which is useful for debugging
toString
public String toString(boolean includeNewline)Returns a user readable printout of the property values which is useful for debugging
Parameters
includeNewlineboolean- true to indicate that newline characters should be included
Returns
user readable printout of the property values which is useful for debugging
populateFromMap
public void populateFromMap(Map<String, Object> m)This is useful for JSON parsing, it allows converting JSON map data to objects
Parameters
mMap<String, Object>- the map
setSimpleObject
public boolean setSimpleObject(PropertyBase p, Object val)Sets one of the builtin simple objects into a property
Parameters
pPropertyBase- the property base
valObject- the object value
Returns
true if successful
populateFromMap
public void populateFromMap(Map<String, Object> m, Class<? extends PropertyBusinessObject> recursiveType)This is useful for JSON parsing, it allows converting JSON map data to objects
Parameters
mMap<String, Object>- the map
recursiveTypeClass<? extends PropertyBusinessObject>- when running into map types we create this object type
toMapRepresentation
public Map<String, Object> toMapRepresentation()This is useful in converting a property object to JSON
Returns
a map representation of the properties
toJSON
public String toJSON()Converts the object to a JSON representation
Returns
a JSON String
asElement
public Element asElement()Returns an element object mapping to the current object hierarchy similar
to the map object
Returns
an XML parser element
toXML
public String toXML()Converts the object to an XML representation
Returns
an XML String
setXmlTextElement
public void setXmlTextElement(PropertyBase p, boolean t)Toggles whether a given property should act as a text element for this
object
Parameters
pPropertyBase- the property that should act as a text element
tboolean- true to activate the text element false to remove it
isXmlTextElement
public boolean isXmlTextElement(PropertyBase p)Toggles whether a given property should act as a text element for this
object
Parameters
pPropertyBase- the property
Returns
true if this is a text element
getXmlTextElement
public PropertyBase getXmlTextElement()Returns the property that contains the XML text e.g.
property valueReturns
the property representing text XML or null if no such property was set
fromXml
public void fromXml(Element e)Converts the XML element to this object hierarchy
Parameters
eElement- the element
init
public void init(Object... values)This method works similarly to a constructor, it accepts the values for the properties in the order
they appear within the index
Parameters
valuesObject...- values of properties in the order they appear in the index
storeJSON
public void storeJSON(String name)Writes the JSON string to storage, it’s a shortcut for writing/generating the JSON
Parameters
nameString- the name of the storage file
loadJSONList
public <X extends PropertyBusinessObject> List<X> loadJSONList(String name)Loads JSON containing a list of property objects of this type
Parameters
nameString- the name of the storage
Returns
list of property objects matching this type
loadJSONList
public <X extends PropertyBusinessObject> List<X> loadJSONList(InputStream stream)
throws IOExceptionLoads JSON containing a list of property objects of this type
Parameters
streamInputStream- the input stream
Returns
list of property objects matching this type
Throws
newInstance
public PropertyBusinessObject newInstance()Creates a new instance of the parent class
Returns
an instance of the parent class or null if this failed
fromJSON
public void fromJSON(String jsonString)Populates the object from a JSON string
Parameters
jsonStringString- the JSON String
loadJSON
public void loadJSON(String name)Loads JSON for the object from storage with the given name if it exists. If the storage
file doesn’t exist getResources() will be used to find a default JSON file in the root
of the package
Parameters
nameString- the name of the storage
loadJSON
public void loadJSON(InputStream stream)
throws IOExceptionLoads JSON for the object from the given input stream
Parameters
streamInputStream- the input stream containing the JSON file
Throws
equals
public boolean equals(Object o)Returns true if the given object equals the property index
Parameters
oObject- the object
Returns
true if equals
hashCode
public int hashCode()The hashcode of the object
Returns
a composite of the hashcodes of the properties
setExcludeFromJSON
public void setExcludeFromJSON(PropertyBase pb, boolean exclude)Allows us to exclude a specific property from the toJSON process
Parameters
pbPropertyBase- the property
excludeboolean- true to exclude and false to reinclude
isExcludeFromMap
public boolean isExcludeFromMap(PropertyBase pb)Indicates whether the given property is excluded from the
#toMapRepresentation()
method outputParameters
pbPropertyBase- the property
Returns
true if the property is excluded and false otherwise
setExcludeFromMap
public void setExcludeFromMap(PropertyBase pb, boolean exclude)Allows us to exclude a specific property from the
#toMapRepresentation() processParameters
pbPropertyBase- the property
excludeboolean- true to exclude and false to reinclude
isExcludeFromJSON
public boolean isExcludeFromJSON(PropertyBase pb)Indicates whether the given property is excluded from the
#toJSON() method outputParameters
pbPropertyBase- the property
Returns
true if the property is excluded and false otherwise
registerExternalizable
public void registerExternalizable()Invoking this method will allow a property object to be serialized seamlessly
asExternalizable
public Externalizable asExternalizable()Returns an externalizable object for serialization of this business object, unlike regular
externalizables this implementation is robust to changes, additions and removals of
properties
Returns
an externalizable instance