uk.apl.jxc.mapper
Class AbstractXMLMapping

java.lang.Object
  extended by uk.apl.jxc.mapper.AbstractXMLMapping
Direct Known Subclasses:
XMLControl, XMLDefault, XMLMapping

public abstract class AbstractXMLMapping
extends java.lang.Object

Encapsulates the mapping of an XML element to another schema.

Author:
Andrew Leigh
See Also:
XMLControl, XMLDefault, XMLMapping

Constructor Summary
protected AbstractXMLMapping(java.lang.String sourcePath, java.lang.String targetPath, java.lang.String condition, XSLTFunction function, java.lang.String defaultValue)
          Constructs a new AbstractXMLMapping.
 
Method Summary
 boolean conditionsEqual(AbstractXMLMapping mapping)
          Returns true if the conditon attribute of this mapping is equal to the condition attribute of the mapping argument.
static AbstractXMLMapping create(java.lang.String sourcePath, java.lang.String targetPath, java.lang.String condition, XSLTFunction function, java.lang.String defaultValue)
          Factory method that returns the most appropriate AbstractXMLMapping sub-class for the specified arguments.
 java.lang.String getCondition()
          Returns the XPath mapping condition.
 java.lang.String getDefaultValue()
          Returns a literal value to be output instead of the data selected from sourcePath in the source schema.
 XSLTFunction getFunction()
          Returns the XSLT function to be applied to the mapping.
 java.lang.String getSelectString(java.lang.String currentContext)
          Returns a String suitable for an XSL select attribute based on the specified context.
 java.lang.String getSourcePath()
          Returns the path to and including the element or attribute in the source schema.
 java.lang.String getTargetElementName()
          Returns the name of the mapped element in the target schema.
 java.lang.String getTargetPath()
          Returns the path to and including the element or attribute in the target schema.
 boolean isAttribute()
          Determines if the mapping is to an attribute.
 boolean isConditional()
          Returns a boolean indicating whether the mapping is conditional or not.
abstract  boolean isDefault()
          When true the value of sourcePath will be defaulted as a literal value into the target instead of being used to select from the source schema.
 boolean isEmpty()
          Returns true if this is an empty mapping, i.e.
 boolean isRootElement()
          Returns true if the mapping is for the root element, otherwise false.
 boolean isTargetAttributeOrLeaf(java.util.List<AbstractXMLMapping> allMappings)
          Returns true mapping to an attribute or leaf element in the target schema.
 boolean targetsEqual(AbstractXMLMapping mapping)
          Returns true if the conditon attribute of this mapping is equal to the condition attribute of the mapping argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractXMLMapping

protected AbstractXMLMapping(java.lang.String sourcePath,
                             java.lang.String targetPath,
                             java.lang.String condition,
                             XSLTFunction function,
                             java.lang.String defaultValue)
Constructs a new AbstractXMLMapping.

Parameters:
sourcePath - path to and including the element or attribute in the source schema
targetPath - path to and including the element or attribute in the target schema
condition - a boolean XPath condition for the mapping, the mapping will only be performed if the condition evaluates to true
function - an XPath function to be applied to the mapping
defaultValue - a literal value to be output instead of the data selected from sourcePath in the source schema
Throws:
InvalidMappingException - if an attempt is made to construct an AbstractXMLMapping from invalid arguments
See Also:
create(java.lang.String, java.lang.String, java.lang.String, uk.apl.jxc.XSLTFunction, java.lang.String)
Method Detail

getSelectString

public java.lang.String getSelectString(java.lang.String currentContext)
Returns a String suitable for an XSL select attribute based on the specified context.

This method works according to the table below:

sourcePath currentContext function result
myroot/mytype/myelement myroot/mytype/   myelement
myroot/mytype/myelement myroot/   .//myelement
myroot/mytype/myelement myroot/ sum sum(.//myelement)

This allows a read ahead capability

Parameters:
currentContext - current context of the mapping
Returns:
String suitable for an XSL select attribute

getTargetPath

public final java.lang.String getTargetPath()
Returns the path to and including the element or attribute in the target schema.

Returns:
path to the element or attribute in the target schema

getCondition

public java.lang.String getCondition()
Returns the XPath mapping condition.

Returns:
the mapping condition

getFunction

public XSLTFunction getFunction()
Returns the XSLT function to be applied to the mapping.

Returns:
XSLT function to be applied to the mapping

isRootElement

public final boolean isRootElement()
Returns true if the mapping is for the root element, otherwise false.

Returns:
true if the mapping is for the root element, otherwise false

isTargetAttributeOrLeaf

public boolean isTargetAttributeOrLeaf(java.util.List<AbstractXMLMapping> allMappings)
Returns true mapping to an attribute or leaf element in the target schema.

Parameters:
allMappings - list of all mappings used in the mapping
Returns:
true mapping to an attribute or leaf element in the target schema

isAttribute

public boolean isAttribute()
Determines if the mapping is to an attribute.

Returns:
true if the mapping is to an attribute, false otherwise

getTargetElementName

public java.lang.String getTargetElementName()
Returns the name of the mapped element in the target schema.

I.e. without including the path to id.

Returns:
name of the mapped element in the target schema

getSourcePath

public java.lang.String getSourcePath()
Returns the path to and including the element or attribute in the source schema.

Returns:
path to and including the element or attribute in the source schema

isConditional

public boolean isConditional()
Returns a boolean indicating whether the mapping is conditional or not.

Returns:
true if the mapping is conditional, false otherwise

isDefault

public abstract boolean isDefault()
When true the value of sourcePath will be defaulted as a literal value into the target instead of being used to select from the source schema.

Returns:
true indicates this mapping is for a default value

getDefaultValue

public java.lang.String getDefaultValue()
Returns a literal value to be output instead of the data selected from sourcePath in the source schema.

Returns:
a literal default value for the mapping

isEmpty

public final boolean isEmpty()
Returns true if this is an empty mapping, i.e. its only purpose is to condition iteration over the source document and therefore will not result in any data being mapped.

Returns:
true if this is an empty mapping, otherwise false

conditionsEqual

public boolean conditionsEqual(AbstractXMLMapping mapping)
Returns true if the conditon attribute of this mapping is equal to the condition attribute of the mapping argument.

Parameters:
mapping - the mapping whose conditon is to be compared
Returns:
true if the conditions match, otherwise false

targetsEqual

public boolean targetsEqual(AbstractXMLMapping mapping)
Returns true if the conditon attribute of this mapping is equal to the condition attribute of the mapping argument.

Parameters:
mapping - the mapping whose conditon is to be compared
Returns:
true if the conditions match, otherwise false

create

public static AbstractXMLMapping create(java.lang.String sourcePath,
                                        java.lang.String targetPath,
                                        java.lang.String condition,
                                        XSLTFunction function,
                                        java.lang.String defaultValue)
Factory method that returns the most appropriate AbstractXMLMapping sub-class for the specified arguments.

defaultValuetargetPathsourcePathReturns
YesYesYesInvalidMappingException
NoYesNoInvalidMappingException
NoNoYesInvalidMappingException
NoNoYesXMLControl
YesYesNoXMLDefault
NoYesYesXMLMapping

Parameters:
sourcePath - path to and including the element or attribute in the source schema
targetPath - path to and including the element or attribute in the target schema
condition - a boolean XPath condition for the mapping, the mapping will only be performed if the condition evaluates to true
function - an XPath function to be applied to the mapping
defaultValue - a literal value to be output instead of the data selected from sourcePath in the source schema
Returns:
a new AbstractXMLMapping instance
See Also:
XMLControl, XMLDefault, XMLMapping


Copyright 2010 Andrew Leigh. All Rights Reserved.