com.planetalia.dynject.sources
Class XMLContentSource

java.lang.Object
  extended by com.planetalia.dynject.sources.XMLContentSource
All Implemented Interfaces:
IValueSource<java.lang.String>

public class XMLContentSource
extends java.lang.Object
implements IValueSource<java.lang.String>

Represents a source that extracts the values of its properties from an XML tree using XPath expressions. The user provides a map between the property names and the XPath expressions used to extract that particular property. When the value of the property is needed, the XPath expression is processed and the result -evaluated as a string - is taken to be the value of the property

Author:
Alexander Hristov

Constructor Summary
XMLContentSource(org.w3c.dom.Document doc, java.util.Map<java.lang.String,java.lang.String> xpathMap)
          Creates and XMLContentSource using the specified XML document and Xpath expression map
 
Method Summary
protected  org.w3c.dom.Node getNode(java.lang.String propertyName)
          Returns the node corresponding to a property
 ClassPreferences getPropertyClass(java.lang.String propertyName)
          Returns the class preferences for a property
 java.util.Set<java.lang.String> getPropertyNames()
          Returns the set of all existing properties at the time of invocation.
 java.lang.Object getValue(java.lang.String propertyName)
          Provides the value of a specific property
 boolean propertyExists(java.lang.String propertyName)
          Checks whether a specific property exists.
 void setValue(java.lang.String propertyName, java.lang.String value)
          Sets the value of a specific property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLContentSource

public XMLContentSource(org.w3c.dom.Document doc,
                        java.util.Map<java.lang.String,java.lang.String> xpathMap)
Creates and XMLContentSource using the specified XML document and Xpath expression map

Parameters:
doc - Document to use
xpathMap - Map associating property names and XPath Expressions
Method Detail

getNode

protected org.w3c.dom.Node getNode(java.lang.String propertyName)
Returns the node corresponding to a property

Parameters:
propertyName - Name of the requested property
Returns:
Node associated to that property, obtained by evaluating the associated XPath expression and retaining the first node returned (if any)

getValue

public java.lang.Object getValue(java.lang.String propertyName)
Description copied from interface: IValueSource
Provides the value of a specific property

Specified by:
getValue in interface IValueSource<java.lang.String>
Parameters:
propertyName - Name of the requested property. Assumed to exist.
Returns:
Property value

propertyExists

public boolean propertyExists(java.lang.String propertyName)
Description copied from interface: IValueSource
Checks whether a specific property exists. Not that a nonexistant property and a proprerty with a null value are not the same situation

Specified by:
propertyExists in interface IValueSource<java.lang.String>
Parameters:
propertyName - Name of the requested property
Returns:
True if the property exists, false otherwise

getPropertyClass

public ClassPreferences getPropertyClass(java.lang.String propertyName)
Description copied from interface: IValueSource
Returns the class preferences for a property

Specified by:
getPropertyClass in interface IValueSource<java.lang.String>
Parameters:
propertyName - Name of the property
Returns:
List of class preferences for that property

getPropertyNames

public java.util.Set<java.lang.String> getPropertyNames()
Description copied from interface: IValueSource
Returns the set of all existing properties at the time of invocation.

Specified by:
getPropertyNames in interface IValueSource<java.lang.String>
Returns:
Set of property names

setValue

public void setValue(java.lang.String propertyName,
                     java.lang.String value)
Description copied from interface: IValueSource
Sets the value of a specific property. It's the callers responsability to provide a correct data type for that property. This is an optional operation. Some sources do not support writing properties to them

Specified by:
setValue in interface IValueSource<java.lang.String>
Parameters:
propertyName - Name of the requested property.
value - Property value.