ibilling.client
Class ElementFacade

java.lang.Object
  extended by ibilling.client.ElementFacade

public class ElementFacade
extends java.lang.Object

The class is used to abstract XML processing logic and simplify library's code porting onto other languages/platforms. The class implements several common XML related functionality using JDOM as its underlying tool. Every instance of the class acts as a wrapper around an Element

Since:
1.0

Field Summary
(package private)  org.jdom.Element element
          The element used as the base object for this facade
 
Constructor Summary
ElementFacade(org.jdom.Element element)
          Instantiates a new element facade using specified element as the base object
ElementFacade(java.lang.String elementName)
          Instantiates a new element facade and creates a new element with the given name
 
Method Summary
 void addContent(java.lang.String content)
          Assigns text content to the base element (creates a first child as text node with the specified value)
 ElementFacade createChild(java.lang.String childName)
          Creates and appends child Element node to the base element
 java.lang.String getAttributeValue(java.lang.String attributeName)
          Returns element's attribute value as string
 java.lang.Boolean getBoolean(java.lang.String attributeName)
          Returns value of the specified attribute as boolean
 ElementFacade getChild(java.lang.String name)
          Returns first child element with the specified name
 java.util.Date getDate(java.lang.String attributeName)
          Returns value of the specified attribute as Date.
 org.jdom.Document getDocument()
          Returns the document used to create the base element
 java.lang.Integer getInteger(java.lang.String attributeName)
          Returns value of the specified attribute as integer
 java.lang.Long getLong(java.lang.String attributeName)
          Returns value of the specified attribute as long
 java.lang.String getName()
          Returns the name of the element
 java.util.List<ElementFacade> getNodeList()
          Returns list of FacadeElement wrapped around child Element nodes of the base element
 java.lang.String getString(java.lang.String attributeName)
          Returns value of the specified attribute as string
 java.lang.String getText()
          Returns text content (content of the first child) of the base element
 boolean isAttributeValueNull(java.lang.String attributeName)
          Checks if is attribute value null.
 void setAttribute(java.lang.String attributeName, java.lang.Object value)
          Assigns value of the named attribute to the base element.
static void setAttributesToRoot(ElementFacade facade, java.lang.Integer merchantAccountCode, java.lang.String password, java.util.Map<java.lang.String,java.lang.Object> config)
          Assigns merchantAccount/password attributes and forms config element to the specified ElementFacade (usually representing the root)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

element

org.jdom.Element element
The element used as the base object for this facade

Constructor Detail

ElementFacade

public ElementFacade(org.jdom.Element element)
Instantiates a new element facade using specified element as the base object

Parameters:
element - the element

ElementFacade

public ElementFacade(java.lang.String elementName)
Instantiates a new element facade and creates a new element with the given name

Parameters:
elementName - the element name
Method Detail

getName

public java.lang.String getName()
Returns the name of the element

Returns:
element's name

getChild

public ElementFacade getChild(java.lang.String name)
Returns first child element with the specified name

Parameters:
name - name of the child element
Returns:
the child element if found, null otherwise

getText

public java.lang.String getText()
Returns text content (content of the first child) of the base element

Returns:
text of the first child node or null if there are no children or the first one is not a text node

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String attributeName)
Returns element's attribute value as string

Parameters:
attributeName - name of the attribute
Returns:
value of the attribute as string or null if attribute is not defined

createChild

public ElementFacade createChild(java.lang.String childName)
Creates and appends child Element node to the base element

Parameters:
childName - name of the child node to create
Returns:
instance of ElementFacade wrapped around the newly created element

getNodeList

public java.util.List<ElementFacade> getNodeList()
Returns list of FacadeElement wrapped around child Element nodes of the base element

Returns:
list of facades for child elements

setAttribute

public void setAttribute(java.lang.String attributeName,
                         java.lang.Object value)
Assigns value of the named attribute to the base element. Converts value to string using appropriate mechanism. Dates are converted using YYYYMMDD pattern. Boolean becomes 1 or 0.

Parameters:
attributeName - name of the attribute to assign
value - desired value of the attribute

addContent

public void addContent(java.lang.String content)
Assigns text content to the base element (creates a first child as text node with the specified value)

Parameters:
content - content of the element

getDocument

public org.jdom.Document getDocument()
Returns the document used to create the base element

Returns:
the document used to create base element

getString

public java.lang.String getString(java.lang.String attributeName)
Returns value of the specified attribute as string

Parameters:
attributeName - attribute's name
Returns:
attribute's value; null if not defined

getInteger

public java.lang.Integer getInteger(java.lang.String attributeName)
Returns value of the specified attribute as integer

Parameters:
attributeName - name of the attribute
Returns:
attribute's value as integer; null if not defined

getLong

public java.lang.Long getLong(java.lang.String attributeName)
Returns value of the specified attribute as long

Parameters:
attributeName - name of the attribute
Returns:
attribute's value as long; null if not defined

getBoolean

public java.lang.Boolean getBoolean(java.lang.String attributeName)
Returns value of the specified attribute as boolean

Parameters:
attributeName - name of the attribute
Returns:
attribute's value as boolean; null if not defined

getDate

public java.util.Date getDate(java.lang.String attributeName)
Returns value of the specified attribute as Date. Converts from String using YYYYMMDD format.

Parameters:
attributeName - name of the attribute
Returns:
attribute's value as Date; null if not defined

isAttributeValueNull

public boolean isAttributeValueNull(java.lang.String attributeName)
Checks if is attribute value null.

Parameters:
attributeName - name of the attribute to check
Returns:
true, if is attribute's value null

setAttributesToRoot

public static void setAttributesToRoot(ElementFacade facade,
                                       java.lang.Integer merchantAccountCode,
                                       java.lang.String password,
                                       java.util.Map<java.lang.String,java.lang.Object> config)
Assigns merchantAccount/password attributes and forms config element to the specified ElementFacade (usually representing the root)

Parameters:
facade - facade to be used for the assignment
merchantAccountCode - value of the merchant account code
password - value of the password
config - configuration settings to be sent to the server