EchoPoint
1.0

echopoint.util
Class IdKit

java.lang.Object
  extended byechopoint.util.IdKit

public class IdKit
extends java.lang.Object

IdKit provides functionality to parse an object's identifier and return specific information from it.

Its is primarily intended to be used with Component.getIndentifier() to allow multiple bits of data to be specified. This is needed because nextapp.echo.Component only has one identifier attribute. You can use this class for more general purposes as well.

If the identifier is a java.lang.String, then attribute values are separated by semi-colons.

The attribute values can optionally have attribute names. Leading and trailing white-space is removed from the attribute names and values.

Attribute names and values can be quoted with single or double quotes. Attribute names or values seprated by whitespace will be concatenated together, that is 'abc' 'def' will become 'abcdef'.

The general attributed form is :

[attrname:]attribute;[attrname:]attribute;[attrname:]attribute[;] [attrname=]attribute;[attrname=]attribute;[attrname=]attribute[;]

The ':' and '=' are treated exacly the same, as name / value breakers.

This allows you to have identifiers such as :

 "fieldname:suburb; group:input; allowed=true;"
 "class=redControls; type:friendly; visible=?"
 "class=;fieldname:surname"
 "class:;fieldname='surname or lastname'"
 "readonly; visible; tidy"
 "'quoted name' = 'quoted value';"
 

If the identifier is a java.util.Map or java.util.Dictionary, then attributes values are returned and set via the provided attrName key.

If the identifier is NOT a java.lang.String, java.util.Map or java.util.Dictionary, then null will be returned on the get methods.

The "dual nature" of this kit means you need to be aware of the "set" side effects when working with identifiers and attributes values that are not Strings.

If the identifier is a Map/Dictionary, then the set methods have the usual effects where objects are put under the specified attrName. Objects later retrived will be of their original type. However in order for a value to be stored, you must provide a non-null attribute name.

If the identifier is a String, but the attribute values not not Strings, then these values are first converted (via toString()) and then placed inside the identifier String. If they are later retrieved, they will now be String objects not the orignal type. You can however store attributes without attributes names in a String identifier.

The "dual nature" of this kit allows you to set identifiers in a varienty of styles for example :

 		Component c = new TextField();
 		...
 		IdKit.set(c,"style","dataEntry");
 		IdKit.set(c,"fieldName","income");
 		// or
 		c.setIdentifier("style:dataEntry;fieldName:income;");
 


Method Summary
static java.lang.Object get(nextapp.echo.Component c, java.lang.String attrName)
          Shortcut synonym for getAttribute(c,attrName).
static java.lang.Object get(java.lang.Object identifier, int index)
          Shortcut synonym for getAttribute(identifier,index).
static java.lang.Object get(java.lang.Object identifier, java.lang.String attrName)
          Shortcut synonym for getAttribute(identifier,attrName).
static java.lang.Object getAttribute(nextapp.echo.Component c, java.lang.String attrName)
          Takes the Component's identifier object and then tries to find the attribute with the specified name.
static java.lang.Object getAttribute(java.lang.Object identifier, int index)
          Finds an attribute, at the specified index, in the specified identifier.
static java.lang.Object getAttribute(java.lang.Object identifier, java.lang.String attrName)
          Finds an attribute in the specified identifier.
static int getAttributeCount(java.lang.Object identifier)
          Returns the number of attributes in the identifier.
static java.lang.String[] getAttributeNames(java.lang.Object identifier)
          Returns an String[] of attribute names in the identifier.
static boolean getBooleanAttribute(java.lang.Object identifier, int index)
          Returns a true if the attribute in the identifier at the specified index is equal to "true".
static boolean getBooleanAttribute(java.lang.Object identifier, java.lang.String attrName)
          Returns a true if the attribute in the identifier with the specified attribute name is equal to "true".
static int getIntegerAttribute(java.lang.Object identifier, int index, int defaultValue)
          Returns the integer value of the attribute in the identifier at the specified index, or defaultValue if the attribute cannot be found or converted to an integer.
static int getIntegerAttribute(java.lang.Object identifier, java.lang.String attrName, int defaultValue)
          Returns the integer value of the attribute in the identifier with the specified attribute name, or defaultValue if the attribute cannot be found or converted to an integer.
static void set(nextapp.echo.Component c, java.lang.String attrName, java.lang.Object attrValue)
          Shortcut synonym for setAttribute(c,attrName,attrValue).
static java.lang.Object set(java.lang.Object identifier, java.lang.String attrName, java.lang.Object attrValue)
          Shortcut synonym for setAttribute(identifier,attrName,attrValue).
static void setAttribute(nextapp.echo.Component c, java.lang.String attrName, java.lang.Object attrValue)
          This method sets the value of an attribute in the Components identifier.
static java.lang.Object setAttribute(java.lang.Object identifier, java.lang.String attrName, java.lang.Object attrValue)
          This method sets the value of an attribute in an identifier.
static void setBooleanAttribute(nextapp.echo.Component c, java.lang.String attrName, boolean attrValue)
          This method sets the boolean value of an attribute in the Components identifier.
static java.lang.Object setBooleanAttribute(java.lang.Object identifier, java.lang.String attrName, boolean attrValue)
          This method sets the boolean value of an attribute in an identifier.
static void setIntegerAttribute(nextapp.echo.Component c, java.lang.String attrName, int attrValue)
          This method sets the integer value of an attribute in the Components identifier.
static java.lang.Object setIntegerAttribute(java.lang.Object identifier, java.lang.String attrName, int attrValue)
          This method sets the integer value of an attribute in an identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttributeCount

public static int getAttributeCount(java.lang.Object identifier)
Returns the number of attributes in the identifier.

Parameters:
identifier - - the identifier object to use
Returns:
- the number of attribute entries available

getAttributeNames

public static java.lang.String[] getAttributeNames(java.lang.Object identifier)
Returns an String[] of attribute names in the identifier. Note that this may not correlate directly to the number of attributes, since it legal to have attributes without names.

Parameters:
identifier - - the identifier object to use
Returns:
and array of attributes name, gauranteed not to be null

getAttribute

public static java.lang.Object getAttribute(java.lang.Object identifier,
                                            java.lang.String attrName)
Finds an attribute in the specified identifier.

The identifier can be an instance of java.util.Map, or java.util.Dictionary, in which case the attrName is used as a key, or it can be an instance of java.lang.String in which case it should be in the general form :

   attrName1:attrValue1;attrName2:attrValue2;...

If its not either of these two types, then null is returned.

Parameters:
identifier - - the identifier object to use
attrName - - the attribute name to find
Returns:
the attribute value or the null if it cant be found

get

public static java.lang.Object get(java.lang.Object identifier,
                                   java.lang.String attrName)
Shortcut synonym for getAttribute(identifier,attrName).

See Also:
getAttribute(Object, String)

getAttribute

public static java.lang.Object getAttribute(java.lang.Object identifier,
                                            int index)
Finds an attribute, at the specified index, in the specified identifier.

The identifier can be an instance of java.util.Map or java.util.Dictionary, or it can be an instance of java.lang.String in which case it should be in the general form :

   attrName1:attrValue1;attrName2:attrValue2;...

If its not either of these two types, then null is returned.

Parameters:
identifier - - the identifier object to use
index - - the index of the attribute to return
Returns:
the attribute value or the null if it cant be found

get

public static java.lang.Object get(java.lang.Object identifier,
                                   int index)
Shortcut synonym for getAttribute(identifier,index).

See Also:
getAttribute(Object, int)

getBooleanAttribute

public static boolean getBooleanAttribute(java.lang.Object identifier,
                                          java.lang.String attrName)
Returns a true if the attribute in the identifier with the specified attribute name is equal to "true".

Parameters:
identifier - - the identifier object to use
attrName - - the attribute name to find
Returns:
true if the attribute value is "true"
See Also:
getAttribute(Object, String)

getBooleanAttribute

public static boolean getBooleanAttribute(java.lang.Object identifier,
                                          int index)
Returns a true if the attribute in the identifier at the specified index is equal to "true".

Parameters:
identifier - - the identifier object to use
index - - the index of the attribute in question
Returns:
true if the attribute values is "true"
See Also:
getAttribute(Object, int)

getIntegerAttribute

public static int getIntegerAttribute(java.lang.Object identifier,
                                      java.lang.String attrName,
                                      int defaultValue)
Returns the integer value of the attribute in the identifier with the specified attribute name, or defaultValue if the attribute cannot be found or converted to an integer.

Parameters:
identifier - - the identifier object to use
attrName - - the attribute name to find
defaultValue - - a default to use
Returns:
the integer value

getIntegerAttribute

public static int getIntegerAttribute(java.lang.Object identifier,
                                      int index,
                                      int defaultValue)
Returns the integer value of the attribute in the identifier at the specified index, or defaultValue if the attribute cannot be found or converted to an integer.

Parameters:
index - - the index at which to find the attribute
identifier - - the identifier object to use
defaultValue - - a default to use
Returns:
the integer value

setAttribute

public static java.lang.Object setAttribute(java.lang.Object identifier,
                                            java.lang.String attrName,
                                            java.lang.Object attrValue)
This method sets the value of an attribute in an identifier.

The identifier can be an instance of java.util.Map or java.util.Dictionary, in which case the attrName is used as a key, or it can be an instance of java.lang.String in which case it should be in the general form :

   attrName1:attrValue1;attrName2:attrValue2;...

If the identifier is null, then a new java.lang.String is created as the identifier if the attribute value is a String or a java.util.Map is created if the attribute value is not a String.

If the identifier is neither an instance of java.util.Map, or an instance of java.util.String, then nothing will be set.

If attrName is null, then no attribute name is used when placing the new attribute info the identifier.

If attrValue is null, then any attribute value with the attrName will be removed.

Any trailing and leading white-space around attributes will be normalised out.

Parameters:
identifier - - The identifier to see the attribute into
attrName - - the optional name of the attribute
attrValue - the new value of the attribute or null to remove it
Returns:
the identifier object that may possibly be changed

set

public static java.lang.Object set(java.lang.Object identifier,
                                   java.lang.String attrName,
                                   java.lang.Object attrValue)
Shortcut synonym for setAttribute(identifier,attrName,attrValue).

See Also:
setAttribute(Object, String, Object)

setBooleanAttribute

public static java.lang.Object setBooleanAttribute(java.lang.Object identifier,
                                                   java.lang.String attrName,
                                                   boolean attrValue)
This method sets the boolean value of an attribute in an identifier.

Parameters:
identifier - - The identifier to see the attribute into
attrName - - the optional name of the attribute
attrValue - the new boolean value of the attribute
Returns:
the identifier object that may possibly be changed
See Also:
setAttribute(Object, String, Object)

setIntegerAttribute

public static java.lang.Object setIntegerAttribute(java.lang.Object identifier,
                                                   java.lang.String attrName,
                                                   int attrValue)
This method sets the integer value of an attribute in an identifier.

Parameters:
identifier - - The identifier to see the attribute into
attrName - - the optional name of the attribute
attrValue - the new integer value of the attribute
Returns:
the identifier object that may possibly be changed
See Also:
setAttribute(Object, String, Object)

getAttribute

public static java.lang.Object getAttribute(nextapp.echo.Component c,
                                            java.lang.String attrName)
Takes the Component's identifier object and then tries to find the attribute with the specified name. It will return null if it cannot be found.

If the identifier is null, then empty string "" is returned.

Parameters:
c - - the Component to check
attrName - - the attribute name to find
Returns:
the attribute value or the null if it cant be found
See Also:
getAttribute(Object, String)

get

public static java.lang.Object get(nextapp.echo.Component c,
                                   java.lang.String attrName)
Shortcut synonym for getAttribute(c,attrName).

See Also:
getAttribute(Component, String)

setAttribute

public static void setAttribute(nextapp.echo.Component c,
                                java.lang.String attrName,
                                java.lang.Object attrValue)
This method sets the value of an attribute in the Components identifier.

Parameters:
c - - the Component to set the identifier attribute into
attrName - - the new attribute name
attrValue - - the new value of the attribute

set

public static void set(nextapp.echo.Component c,
                       java.lang.String attrName,
                       java.lang.Object attrValue)
Shortcut synonym for setAttribute(c,attrName,attrValue).

See Also:
setAttribute(Component, String, Object)

setBooleanAttribute

public static void setBooleanAttribute(nextapp.echo.Component c,
                                       java.lang.String attrName,
                                       boolean attrValue)
This method sets the boolean value of an attribute in the Components identifier.

Parameters:
c - - the Component to set the identifier attribute into
attrName - - the new attribute name
attrValue - - the new boolean value of the attribute
See Also:
setAttribute(Object, String, Object), setBooleanAttribute(Object, String, boolean)

setIntegerAttribute

public static void setIntegerAttribute(nextapp.echo.Component c,
                                       java.lang.String attrName,
                                       int attrValue)
This method sets the integer value of an attribute in the Components identifier.

Parameters:
c - - the Component to set the identifier attribute into
attrName - - the new attribute name
attrValue - - the new integer value of the attribute
See Also:
setAttribute(Object, String, Object), setIntegerAttribute(Object, String, int)

EchoPoint
1.0