com.flexive.shared
Class XPathElement

java.lang.Object
  extended by com.flexive.shared.XPathElement
All Implemented Interfaces:
java.io.Serializable

public class XPathElement
extends java.lang.Object
implements java.io.Serializable

A single XPath element (alias and multiplicity).

Author:
Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
See Also:
Serialized Form

Constructor Summary
XPathElement(java.lang.String alias, int index, boolean indexDefined)
          Ctor
 
Method Summary
static java.lang.String addDefaultIndices(java.lang.String xmult, int count)
          Add default indices (= 1) to a string representation.
static java.lang.String buildXPath(boolean leadingSlash, java.lang.String... elements)
          Build an XPath from the given elements
static java.lang.String changeIndex(java.lang.String XPath, int pos, int index)
          Change the index of an xpath (requires an xpath with all explicit indices set!) This method is optimized for performance and does not check for validity!
 boolean equals(java.lang.Object obj)
          
 java.lang.String getAlias()
          Getter for the alias
static int getDepth(java.lang.String xpath)
          Return the depth of the XPath element (= the number of slashes)
 int getIndex()
          Getter for the multiplicity
static int[] getIndices(java.lang.String XPath)
          Get the FQ indices of an XPath as an int array.
static FxPK getPK(java.lang.String xPath)
          Extract the primary key stored in the given XPath.
 int hashCode()
          
 boolean isIndexDefined()
          Was the multiplicity explicitly defined?
static boolean isValidXPath(java.lang.String XPath)
          Check if this XPath is valid.
static XPathElement lastElement(java.lang.String XPath)
          Get the last (rightmost) element of an XPath.
 void setIndex(int index)
          Setter for the multiplicity
static java.util.List<XPathElement> split(java.lang.String XPath)
          Split an XPath into its elements
static java.lang.String stripLastElement(java.lang.String XPath)
          Strip the last element (usually property) from an XPath
static java.lang.String stripType(java.lang.String XPath)
          Strip leading types from an XPath if present, and return the XPath in upper case.
static XPathElement toElement(java.lang.String XPath, java.lang.String alias)
          Convert an alias of an XPath to an element
 java.lang.String toString()
          get FQN of the alias
static java.lang.String toXPath(java.util.List<XPathElement> xpe)
          Get the XPath of an array of XPathElements with multiplicities
static java.lang.String toXPathMult(java.lang.String XPath)
          Get the given XPath with full multiplicity information
static java.lang.String toXPathMult(java.lang.String XPath, java.lang.String indices)
          Get the given XPath with full multiplicity information.
static java.lang.String toXPathNoMult(java.util.List<XPathElement> xpe)
          Get the XPath of an array of XPathElements without multiplicities
static java.lang.String toXPathNoMult(java.lang.String XPath)
          Get the given XPath with no indices
static java.lang.String xpToUpperCase(java.lang.String xpath)
          Optimized uppercase method for XPaths (characters are limited to a-z).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XPathElement

public XPathElement(java.lang.String alias,
                    int index,
                    boolean indexDefined)
Ctor

Parameters:
alias - alias to use
index - multiplicity to apply
indexDefined - was the multiplicity explicitly defined?
Method Detail

getAlias

public java.lang.String getAlias()
Getter for the alias

Returns:
alias

getIndex

public int getIndex()
Getter for the multiplicity

Returns:
multiplicity

setIndex

public void setIndex(int index)
Setter for the multiplicity

Parameters:
index - the multiplicity to apply

isIndexDefined

public boolean isIndexDefined()
Was the multiplicity explicitly defined?

Returns:
multiplicity explicitly defined

toString

public java.lang.String toString()
get FQN of the alias

Overrides:
toString in class java.lang.Object
Returns:
FQ alias

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

split

public static java.util.List<XPathElement> split(java.lang.String XPath)
Split an XPath into its elements

For performance reasons, this method expects that the xPath is already in upper case form.

Parameters:
XPath - the XPath
Returns:
XPathElement array

lastElement

public static XPathElement lastElement(java.lang.String XPath)
Get the last (rightmost) element of an XPath.

For performance reasons, this method expects that the xPath is already in upper case form.

Parameters:
XPath - the XPath
Returns:
last (rightmost) element of an XPath

toElement

public static XPathElement toElement(java.lang.String XPath,
                                     java.lang.String alias)
Convert an alias of an XPath to an element

Parameters:
XPath - full XPath, only used if exception is thrown
alias - alias to convert to an XPathElement
Returns:
XPathElement

isValidXPath

public static boolean isValidXPath(java.lang.String XPath)
Check if this XPath is valid.

For performance reasons, this method expects that the xPath is already in upper case form.

Parameters:
XPath - the XPath
Returns:
valid or not

toXPath

public static java.lang.String toXPath(java.util.List<XPathElement> xpe)
Get the XPath of an array of XPathElements with multiplicities

Parameters:
xpe - list containing XPathElement
Returns:
XPath

toXPathNoMult

public static java.lang.String toXPathNoMult(java.util.List<XPathElement> xpe)
Get the XPath of an array of XPathElements without multiplicities

Parameters:
xpe - list containing XPathElement
Returns:
XPath

toXPathMult

public static java.lang.String toXPathMult(java.lang.String XPath)
Get the given XPath with full multiplicity information

Parameters:
XPath - XPath
Returns:
XPath with full multiplicity information

toXPathMult

public static java.lang.String toXPathMult(java.lang.String XPath,
                                           java.lang.String indices)
Get the given XPath with full multiplicity information. Please note that no checks are performed and that the XPath is assumed to be uppercase and valid

Parameters:
XPath - valid XPath without type information and without indices
indices - indices to apply (comma separated)
Returns:
XPath with full multiplicity information

toXPathNoMult

public static java.lang.String toXPathNoMult(java.lang.String XPath)
Get the given XPath with no indices

Parameters:
XPath - XPath with indices
Returns:
XPath with indices stripped, in upper case

getIndices

public static int[] getIndices(java.lang.String XPath)
Get the FQ indices of an XPath as an int array. This method is optimized for performance and does not check for validity!

Parameters:
XPath - the xpath to examine
Returns:
FQ indices of an XPath as an int array

buildXPath

public static java.lang.String buildXPath(boolean leadingSlash,
                                          java.lang.String... elements)
Build an XPath from the given elements

Parameters:
leadingSlash - prepend a leading slash character?
elements - elements that build the XPath
Returns:
XPath

stripType

public static java.lang.String stripType(java.lang.String XPath)
Strip leading types from an XPath if present, and return the XPath in upper case.

Parameters:
XPath - the XPath
Returns:
XPath without leading type

stripLastElement

public static java.lang.String stripLastElement(java.lang.String XPath)
Strip the last element (usually property) from an XPath

Parameters:
XPath - the XPath
Returns:
XPath without the last element

getPK

public static FxPK getPK(java.lang.String xPath)
Extract the primary key stored in the given XPath. If no PK is contained in the XPath, a FxRuntimeException is thrown.

Parameters:
xPath - the xpath
Returns:
the primary key stored in the given XPath
Throws:
FxRuntimeException - if the given xpath is invalid or contains no PK

changeIndex

public static java.lang.String changeIndex(java.lang.String XPath,
                                           int pos,
                                           int index)
Change the index of an xpath (requires an xpath with all explicit indices set!) This method is optimized for performance and does not check for validity!

Parameters:
XPath - the xpath with all indices set
pos - position of the element (0-based)
index - the new index to apply
Returns:
xpath with the new index at the requested position
Since:
3.1.5

xpToUpperCase

public static java.lang.String xpToUpperCase(java.lang.String xpath)
Optimized uppercase method for XPaths (characters are limited to a-z).

Parameters:
xpath - the XPath
Returns:
the uppercased XPath
Since:
3.2.0

getDepth

public static int getDepth(java.lang.String xpath)
Return the depth of the XPath element (= the number of slashes)

Parameters:
xpath - the xpath
Returns:
the depth (min. 1 for valid xpaths)
Since:
3.2.0

addDefaultIndices

public static java.lang.String addDefaultIndices(java.lang.String xmult,
                                                 int count)
Add default indices (= 1) to a string representation.

Parameters:
xmult - the existing list of indices, comma-separated (may be empty)
count - the number of indices that should be added
Returns:
the new xmult string
Since:
3.2.0