com.virtualweaver.xotics.datamodel
Class XoUtilities

java.lang.Object
  extended bycom.virtualweaver.xotics.datamodel.XoUtilities

public final class XoUtilities
extends java.lang.Object

contains some generic utility methods

Version:
4.1

Method Summary
static XoObject addChild(XoRegistry reg, XoObject child, XoContainer parent)
           
static XoObject addChild(XoRegistry reg, XoObject child, XoContainer parent, int index)
          Use this method to add a child to a parent container not belonging to any DM instance.
static java.lang.String collapseWhiteSpace(java.lang.String lexicalStr)
          Returns a new string where all occurrences of \\n, \\r and \\t are replaced by whitespace, and where following whitespace chars are replaced by a single one.
static XoContentModel createContentModelNode(byte cmtype)
          Creates a Content-Model description node.
static XoContentModel createContentModelNode(byte cmtype, int min, int max)
          Creates a Content-Model description node.
static XoContentModel createContentModelNode(java.lang.String nsref, int min, int max)
          Creates a Content-Model description node representing an ANY filter.
static XoContentModel createContentModelNode(java.lang.String nsref, java.lang.String elementRef, java.lang.String elementType, int min, int max)
          Creates a Content-Model description node representing an element reference (ELEMENT_REF).
static XoContentModel getContentModel(XoRegistry reg, XoContainer c)
          Returns the Content-Model for container c, as a tree of XoContentModel nodes.
static int getIndexOfChild(XoObject child)
          Gets index of child object in its parent children list.
static XoObject getPolymorphObject(XoRegistry registry, XoPolymorphWrapper child, XoContainer parent)
          Returns the appropriate XO object implementation held by polymorph wrapper child when added to parent.
static java.lang.String normalizeWhiteSpace(java.lang.String lexicalStr, byte ws)
          Normalizes string param lexicalStr depending on ws normalization directive : for XoConstants.WS_COLLAPSE calls collapseWhiteSpace(String), for XoConstants.WS_REPLACE calls replaceWhiteSpace(String), otherwise returns unchanged lexicalStr.
static java.lang.String replaceWhiteSpace(java.lang.String lexicalStr)
          Returns a new string where all occurrences of \\n, \\r and \\t are replaced by whitespace
static java.lang.String toString(XoObject xo)
          returns a standard XML string representation of param xo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addChild

public static XoObject addChild(XoRegistry reg,
                                XoObject child,
                                XoContainer parent,
                                int index)
                         throws XoException
Use this method to add a child to a parent container not belonging to any DM instance. It is not a mandatory method, but a useful method, as it notably handles specific constraints relative to multi-implemented elements (XoPolymorphWrapper).

Parameters:
reg - the current Registry
child - object to add as child
parent - parent of newly added child
index - insertion index
Returns:
effective added object (implementation resolved for polymorph objects)
Throws:
XoException - if some error occur during adding process

addChild

public static XoObject addChild(XoRegistry reg,
                                XoObject child,
                                XoContainer parent)
                         throws XoException
Throws:
XoException
See Also:
with index at -1 (append).

getPolymorphObject

public static XoObject getPolymorphObject(XoRegistry registry,
                                          XoPolymorphWrapper child,
                                          XoContainer parent)
                                   throws XoException
Returns the appropriate XO object implementation held by polymorph wrapper child when added to parent. Please use it only if parent doesn't belong to any DM instance.

Parameters:
registry - the current Registry
child - polymorph wrapper planned to be added as child
parent - target parent
Returns:
appropriate implementation if exists
Throws:
XoException - if no implementation is suitable or some error occur during process

getIndexOfChild

public static int getIndexOfChild(XoObject child)
Gets index of child object in its parent children list.

Parameters:
child - XO object whose index is wanted
Returns:
index of child or -1 if child has no parent

toString

public static java.lang.String toString(XoObject xo)
returns a standard XML string representation of param xo

Parameters:
xo - object to convert as string
Returns:
string representation based on its XML element name

normalizeWhiteSpace

public static java.lang.String normalizeWhiteSpace(java.lang.String lexicalStr,
                                                   byte ws)
Normalizes string param lexicalStr depending on ws normalization directive :

Parameters:
lexicalStr - the string to normalize
ws - the normalization directive
Returns:
the string normalized

replaceWhiteSpace

public static java.lang.String replaceWhiteSpace(java.lang.String lexicalStr)
Returns a new string where all occurrences of \\n, \\r and \\t are replaced by whitespace

Parameters:
lexicalStr - the string to transform
Returns:
a new string reflecting changes

collapseWhiteSpace

public static java.lang.String collapseWhiteSpace(java.lang.String lexicalStr)
Returns a new string where all occurrences of \\n, \\r and \\t are replaced by whitespace, and where following whitespace chars are replaced by a single one.

Parameters:
lexicalStr - the string to transform
Returns:
a new string reflecting changes

getContentModel

public static XoContentModel getContentModel(XoRegistry reg,
                                             XoContainer c)
Returns the Content-Model for container c, as a tree of XoContentModel nodes. Content-Model returned is either a dynamic CM resulting from a call to XoContainer.getXoContentModel() or a static CM coming from DMDL description of container's dialect implementation.

Parameters:
reg - the registry, needed to perform searching
c - the container whose Content-Model is wanted
Returns:
the offical Content-Model, valid at method call time.

createContentModelNode

public static XoContentModel createContentModelNode(byte cmtype,
                                                    int min,
                                                    int max)
Creates a Content-Model description node. This constructor is particularly adapted to nodes representing a Content-Model operator (SEQUENCE, CHOICE, ALL).

Parameters:
cmtype - Content-Model type
min - minimum occurrence
max - maximum occurrence
Returns:
the new Content-Model node.

createContentModelNode

public static XoContentModel createContentModelNode(byte cmtype)
Creates a Content-Model description node. Min and max occurrence are set to default value 1. This constructor is particularly adapted to nodes used as root of a Content-Model tree (CHILDREN, MIXED, EMPTY).

Parameters:
cmtype - Content-Model type
Returns:
the new Content-Model node.

createContentModelNode

public static XoContentModel createContentModelNode(java.lang.String nsref,
                                                    java.lang.String elementRef,
                                                    java.lang.String elementType,
                                                    int min,
                                                    int max)
Creates a Content-Model description node representing an element reference (ELEMENT_REF). All data relative to element reference description can be set here.

Parameters:
nsref - namespace of element referenced
elementRef - local name of element referenced
elementType - type identifying specific implementation of element (can be null)
min - minimum occurrence
max - maximum occurrence
Returns:
the new Content-Model node.

createContentModelNode

public static XoContentModel createContentModelNode(java.lang.String nsref,
                                                    int min,
                                                    int max)
Creates a Content-Model description node representing an ANY filter. An optional namespace nsref can be specified to represent "ns:*" (any element from a particular namespace). A null nsref means "*:*" (any element from any namespace).

Parameters:
nsref - a particular namespace
min - minimum occurrence
max - maximum occurrence
Returns:
the new Content-Model node.