|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.myjavatools.xml.BasicXmlData
| Nested Class Summary | |
static class |
BasicXmlData.Expression
An abstract class that stores an expression used in XmlData search/filtering. |
static class |
BasicXmlData.Policy
Class Policy defines three different casting policies. |
| Nested classes inherited from class com.myjavatools.xml.XmlData |
XmlData.Condition |
| Field Summary | |
static java.lang.Class |
XmlDataClass
|
| Constructor Summary | |
BasicXmlData()
Default constructor. |
|
BasicXmlData(java.io.File in)
Creates an instance from the data read from a file. |
|
BasicXmlData(java.io.InputStream in)
Creates an instance from the data read from input stream. |
|
BasicXmlData(java.lang.String type)
Creates an instance of BasicXmlData of specified type. |
|
BasicXmlData(java.lang.String type,
java.lang.String value)
Creates an instance of specified type and with the specified value. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
org.xml.sax.AttributeList attributes)
Creates an instance of specified type, with the specified value, attributes that are listed in the provided AttributeList. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
org.xml.sax.AttributeList attributes,
BasicXmlData[] kids)
Creates an instance of specified type, with the specified value, attributes that are listed in the provided AttributeList, and the kids that are listed in the provided array of XmlData. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
org.xml.sax.AttributeList attributes,
java.util.Collection kids)
Creates an instance of specified type, with the specified value, attributes that are listed in the provided AttributeList, and the kids that are listed in the provided collection. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
BasicXmlData[] kids)
Creates an instance of specified type, with the specified value and the kids that are listed in the provided array. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
java.util.Collection kids)
Creates an instance of specified type, with the specified value and the kids that are listed in the provided collection. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
java.util.Map attributes,
java.util.Collection kids)
Creates an instance of specified type, with the specified value, attributes that are listed in the provided map (name -> value), and the kids that are listed in the provided collection. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
java.lang.String[] attributes)
Creates an instance of specified type, with the specified value and the attributes that are listed in the provided array as name-value pairs. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
java.lang.String[] attributes,
BasicXmlData[] kids)
Creates an instance of BasicXmlData of specified type, with the specified value, attributes that are listed in the provided array as name-value pairs, and the kids that are listed in the provided array of XmlData. |
|
BasicXmlData(java.lang.String type,
java.lang.String value,
java.lang.String[] attributes,
java.util.Collection kids)
Creates an instance of specified type, with the specified value, attributes that are listed in the provided array as name-value pairs, and the kids that are listed in the provided collection. |
|
BasicXmlData(java.net.URL url)
Creates an instance from the data read from URL. |
|
BasicXmlData(XmlData org)
Creates an instance from another XmlData object (deep copy). |
|
| Method Summary | |
XmlData |
addKid(XmlData kid)
Adds a kid to the set of kids. |
void |
addKids(java.util.Collection kids)
Adds all XmlData elements from given Collection to the set of kids, skipping elements that are not XmlData. |
void |
addKids(java.util.Iterator kids)
Adds all XmlData elements from given Iterator to the collection of kids, skipping elements that are not BasicXmlData. |
XmlData |
cast(java.util.Map typemap,
BasicXmlData.Policy policy)
Casts XmlData and its kids, recursively, to specified classes, according to the typemap. |
static XmlData |
cast(XmlData object,
java.util.Map typemap,
BasicXmlData.Policy policy)
Casts XmlData and its kids, recursively, to specified classes, according to the typemap. |
boolean |
castKids(java.lang.String type,
java.lang.Class clazz)
Casts kids of specified type to a specified class (actually replacing them with the new instances). |
XmlData |
castToPackage(java.lang.String packageName,
BasicXmlData.Policy policy)
Casts XmlData and its kids, recursively, to classes in specified package. |
static XmlData |
castToPackage(XmlData object,
java.lang.String packageName,
BasicXmlData.Policy policy)
Casts XmlData and its kids, recursively, to classes in specified package. |
void |
cleanAttributes()
cleans attributes map Just removes all the attributes except xmlns (because) |
java.lang.Object |
clone()
Clones of XmlData, same thing as deepCopy. |
static void |
debug(boolean doit)
|
XmlData |
deepCopy()
Deep copy of XmlData. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this XmlData for equality. |
java.util.Collection |
getAllKids()
Gets a collection of all kids of XmlData. |
java.lang.String |
getAttribute(java.lang.String name)
Gets the value of a specified attribute. |
java.lang.String |
getAttribute(java.lang.String name,
java.lang.String defaultValue)
Gets the value of a specified attribute; if there is none, returns default value. |
java.util.Map |
getAttributes()
Gets a Map of attributes. |
java.lang.String |
getId()
Gets the id of XmlData, which is the value of attribute "id". |
XmlData |
getKid(int position)
Gets a kid at specified position. |
XmlData |
getKid(java.lang.String type)
Gets a kid of specified type, if any. |
XmlData |
getKid(java.lang.String type,
java.lang.String id)
Gets a kid having specified type and specified id. |
XmlData |
getKid(java.lang.String type,
java.lang.String attribute,
java.lang.String value)
Gets a kid of specified type that has an attribute with a specified value. |
java.lang.String |
getKidAttribute(java.lang.String type,
java.lang.String attribute)
Gets the value of specified attribute of a kid of specified type, if any |
int |
getKidCount(java.lang.String type)
Gets the number of kids of specified type. |
java.util.Collection |
getKids(java.lang.String type)
Gets a Collection of kids of specified type. |
java.util.Collection |
getKidTypes()
Gets a collection of kid types |
java.lang.String |
getKidValue(java.lang.String type)
Gets the value of a kid of specified type, if any. |
java.lang.String |
getName()
Gets the name of XmlData, which is the value of attribute "name". |
java.lang.String |
getType()
Gets XmlData type, which is just a String. |
java.lang.String |
getValue()
Gets a value of XmlData, which is just a String. |
XmlData |
getXmlContent()
Gets the contents of this XmlData (that is, itself). |
int |
indexOf(XmlData kid)
returns the position of kid in the list of kids |
XmlData |
insertKid(int position,
XmlData kid)
Insertes a kid into the list of kids. |
XmlData |
insertKid(XmlData before,
XmlData kid)
Insertes a kid before a specified kid. |
void |
removeKid(XmlData kid)
Removes a kid from the set of kids. |
java.util.Collection |
removeKids(java.lang.String type)
Removes all kids of given type. |
void |
replaceKid(XmlData oldKid,
XmlData newKid)
Replaces a kid with another. |
boolean |
satisfies(java.lang.String expression)
Checks whether this XmlData node satisfies given expression (presented as string). |
boolean |
satisfies(XmlData.Condition condition)
Checks whether this XmlData node satisfies given condition. |
void |
save(java.io.File file)
Saves XmlData to a file. |
void |
save(java.io.OutputStream os)
Saves XmlData to an output stream. |
void |
save(java.lang.String filename)
Saves XmlData to a file. |
XmlData |
selectTree(java.lang.String expression)
Selects a subtree from XmlData, that is, the tree of those nodes that satisfy a condition. |
XmlData |
selectTree(XmlData.Condition condition)
Selects a subtree from XmlData, that is, the tree of those nodes that satisfy a condition. |
void |
setAttribute(java.lang.String name,
java.lang.String value)
Sets an attribute value. |
void |
setAttributes(org.xml.sax.AttributeList attributes)
Sets attributes from an AttributeList. |
void |
setAttributes(java.util.Map attributes)
Sets attributes from a Map. |
void |
setAttributes(java.lang.String[] attributes)
Sets attributes from an array of name-value pairs. |
void |
setKidValue(java.lang.String type,
java.lang.String value)
Sets the value of a kid of specified type, creating it if necessary |
void |
setType(java.lang.String type)
|
XmlData |
setValue(java.lang.String v)
Sets the value of XmlData. |
void |
setXmlContent(XmlData org)
Sets the contents from another XmlData. |
void |
trim()
Tries to trim the set of kids, so that there are no spare slots left. |
| Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final java.lang.Class XmlDataClass
| Constructor Detail |
public BasicXmlData()
Creates an empty instance.
public BasicXmlData(java.lang.String type)
type - the type of data, an arbitrary identifier string.
public BasicXmlData(java.lang.String type,
java.lang.String value)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.
Example:
new BasicXmlData("example", "This is an example").save(filename)
<?xml version="1.0" encoding="UTF-8"?> <example>This is an example</example>
public BasicXmlData(java.lang.String type,
java.lang.String value,
java.util.Collection kids)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.kids - a Collection of XmlData that attach themselves as kids to the instance being created
Example:
new BasicXmlData("example", "This is an example",
Arrays.asList(new BasicXmlData[] {new BasicXmlData("subexample", "This is a kid of example")}).save(filename)
<?xml version="1.0" encoding="UTF-8"?> <example> <subexample>This is a kid of example</subexample>This is an example</example>
public BasicXmlData(java.lang.String type,
java.lang.String value,
BasicXmlData[] kids)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.kids - an array of XmlData that attach themselves as kids to the instance being created
Example:
new BasicXmlData("example", "This is an example",
new BasicXmlData[] {new BasicXmlData("subexample", "This is a kid of example")}).save(filename)
<?xml version="1.0" encoding="UTF-8"?> <example> <subexample>This is a kid of example</subexample>This is an example</example>
public BasicXmlData(java.lang.String type,
java.lang.String value,
java.lang.String[] attributes)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.attributes - an String array of name-value pairs
Example:
new BasicXmlData("example", "This is an example", new String[] {"id", "0123dx", "name", "Whittman"}).save(filename)
<?xml version="1.0" encoding="UTF-8"?> <example id="0123dx" name="Whittman">This is an example</example>
public BasicXmlData(java.lang.String type,
java.lang.String value,
java.lang.String[] attributes,
java.util.Collection kids)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.attributes - an String array of name-value pairskids - a Collection of XmlData that attach themselves as kids to the instance being created
Example:
new BasicXmlData("example", "This is an example",
new String[] {"id", "007", "name", "Bond"},
Arrays.asList(new BasicXmlData[] {new BasicXmlData("subexample", "This is a kid of example")}).save(filename)
<?xml version="1.0" encoding="UTF-8"?> <example id="007" name="Bond"> <subexample>This is a kid of example</subexample>This is an example</example>
public BasicXmlData(java.lang.String type,
java.lang.String value,
java.lang.String[] attributes,
BasicXmlData[] kids)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.attributes - an String array of name-value pairskids - an array of XmlData that attach themselves as kids to the instance being created
Example:
new BasicXmlData("example", "This is an example",
new String[] {"id", "007", "name", "Bond"},
new BasicXmlData[] {new BasicXmlData("subexample", "This is a kid of example")}).save(filename)
<?xml version="1.0" encoding="UTF-8"?> <example id="007" name="Bond"> <subexample>This is a kid of example</subexample>This is an example</example>
public BasicXmlData(java.lang.String type,
java.lang.String value,
org.xml.sax.AttributeList attributes)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.attributes - an AttributeList (@see org.xml.sax.AttributeList)
public BasicXmlData(java.lang.String type,
java.lang.String value,
org.xml.sax.AttributeList attributes,
java.util.Collection kids)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.attributes - an AttributeList (@see org.xml.sax.AttributeList)kids - a Collection of XmlData that attach themselves as kids to the instance being created
public BasicXmlData(java.lang.String type,
java.lang.String value,
org.xml.sax.AttributeList attributes,
BasicXmlData[] kids)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.attributes - an AttributeList (@see org.xml.sax.AttributeList)kids - an array of XmlData that attach themselves as kids to the instance being created
public BasicXmlData(java.lang.String type,
java.lang.String value,
java.util.Map attributes,
java.util.Collection kids)
type - the type of data, an arbitrary identifier string.value - the value of data, any string.attributes - a Map that maps attributes names to valueskids - a Collection of XmlData that attach themselves as kids to the instance being createdpublic BasicXmlData(XmlData org)
org - original XmlData
public BasicXmlData(java.io.InputStream in)
throws java.io.IOException,
java.lang.InstantiationException
in - input stream
java.io.IOException
java.lang.InstantiationiException
java.lang.InstantiationException
public BasicXmlData(java.io.File in)
throws java.io.IOException,
java.lang.InstantiationException
in - file containing XML data
java.io.IOException
java.lang.InstantiationiException
java.lang.InstantiationException
public BasicXmlData(java.net.URL url)
throws java.io.IOException,
java.lang.InstantiationException
url - url pointing to XML data
java.io.IOException
java.lang.InstantiationiException
java.lang.InstantiationException| Method Detail |
public static void debug(boolean doit)
public void setXmlContent(XmlData org)
setXmlContent in interface XmlDataorg - original XmlDatapublic XmlData getXmlContent()
getXmlContent in interface XmlDatapublic XmlData deepCopy()
public java.lang.Object clone()
clone in interface XmlDatapublic boolean equals(java.lang.Object o)
equals in interface XmlDatao - object to be compared for equality with this XmlData.
Example:
<?xml version="1.0" encoding="UTF-8"?> <example a1="v1" a2="v2"> <sub1 ax="vx" ay="vy"/> <sub2 aa="va" ab="vb"/> </example>and
<?xml version="1.0" encoding="UTF-8"?> <example a2="v2" a1="v1"> <sub2 ab="vb" aa="va"/> <sub1 ay="vy" ax="vx"/> </example>are equal.
public void save(java.lang.String filename)
throws java.io.IOException
filename - name of the file to write to
java.io.IOException
public void save(java.io.File file)
throws java.io.IOException
file - file to write to
java.io.IOException
public void save(java.io.OutputStream os)
throws java.io.IOException
os - output stream to write to
java.io.IOExceptionpublic void cleanAttributes()
cleanAttributes in interface XmlData
public void setAttribute(java.lang.String name,
java.lang.String value)
setAttribute in interface XmlDataname - attribute namevalue - attribute valuepublic void setAttributes(java.lang.String[] attributes)
setAttributes in interface XmlDataattributes - a String array consisting of name-value pairs.public void setAttributes(java.util.Map attributes)
setAttributes in interface XmlDataattributes - a Map, name -> value.public void setAttributes(org.xml.sax.AttributeList attributes)
setAttributes in interface XmlDataattributes - AttributeListpublic java.util.Map getAttributes()
getAttributes in interface XmlDatapublic java.lang.String getType()
getType in interface XmlDatapublic void setType(java.lang.String type)
public java.lang.String getValue()
getValue in interface XmlDatapublic XmlData setValue(java.lang.String v)
setValue in interface XmlDatav - new value for XmlData
public java.lang.String getAttribute(java.lang.String name)
getAttribute in interface XmlDataname - attribute name
public java.lang.String getAttribute(java.lang.String name,
java.lang.String defaultValue)
getAttribute in interface XmlDataname - attribute namedefaultValue -
public java.lang.String getName()
Same thing as getAttribute("name").
getName in interface XmlDatapublic java.lang.String getId()
Same thing as getAttribute("id").
getId in interface XmlDatapublic java.util.Collection getAllKids()
getAllKids in interface XmlDatapublic java.util.Collection getKids(java.lang.String type)
getKids in interface XmlDatatype - type of the kids to choose
public int getKidCount(java.lang.String type)
getKidCount in interface XmlDatatype -
public XmlData getKid(java.lang.String type)
getKid in interface XmlDatatype - type of the kid to chose
public XmlData getKid(int position)
getKid in interface XmlDataposition - position of the kid to retrieve, starting with 0;
public java.lang.String getKidValue(java.lang.String type)
getKidValue in interface XmlDatatype -
public void setKidValue(java.lang.String type,
java.lang.String value)
setKidValue in interface XmlDatatype - value -
public java.lang.String getKidAttribute(java.lang.String type,
java.lang.String attribute)
getKidAttribute in interface XmlDatatype - Stringattribute - String
public XmlData getKid(java.lang.String type,
java.lang.String attribute,
java.lang.String value)
getKid in interface XmlDatatype - type of the kid to chooseattribute - attribute namevalue - attribute value
public XmlData getKid(java.lang.String type,
java.lang.String id)
getKid in interface XmlDatatype - kid typeid - kid id
public XmlData addKid(XmlData kid)
addKid in interface XmlDatakid - kid to add
public int indexOf(XmlData kid)
kid - XmlData
public XmlData insertKid(int position,
XmlData kid)
position - int the position where to insert the kidkid - kid to add
public XmlData insertKid(XmlData before,
XmlData kid)
before - the kid before which this one should be insertedkid - kid to add
public void removeKid(XmlData kid)
removeKid in interface XmlDatakid - kid to remove
public void replaceKid(XmlData oldKid,
XmlData newKid)
replaceKid in interface XmlDataoldKid - kid to removenewKid - kid to insert in its placepublic void addKids(java.util.Iterator kids)
kids - kids to add; can be nullpublic void addKids(java.util.Collection kids)
addKids in interface XmlDatakids - kids to add; can be nullpublic java.util.Collection removeKids(java.lang.String type)
removeKids in interface XmlDatatype - type of kids to remove
public boolean castKids(java.lang.String type,
java.lang.Class clazz)
castKids in interface XmlDatatype - type of the kids to castclazz - class to cast to
public static XmlData cast(XmlData object,
java.util.Map typemap,
BasicXmlData.Policy policy)
throws java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.ClassNotFoundException
object - the objec to casttypemap - maps types to classes. Type is what XmlData considers a type:
a string value of type property.policy - one of the following: Policy.THROW_ON_ERROR (causes an exception
in case of any error), Policy.KEEP_ON_ERROR (keeps nodes that cannot be cast),
Policy.SKIP_ON_ERROR (ignores nodes that cannot be cast).
InstantiationException
NoSuchMethodException
InvocationTargetException
IllegalArgumentException
IllegalAccessException - Exception are thrown only if policy is Policy.THROW_ON_ERROR
java.lang.ClassNotFoundException
public static XmlData castToPackage(XmlData object,
java.lang.String packageName,
BasicXmlData.Policy policy)
throws java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.ClassNotFoundException
object - the objec to castpackageName - the name of the package for casting. XmlData types
are mapped to classes with the same name inside specified package.
packageName can be null: then it is ignored.policy - one of the following: Policy.THROW_ON_ERROR (causes an exception
in case of any error), Policy.KEEP_ON_ERROR (keeps nodes that cannot be cast),
Policy.SKIP_ON_ERROR (ignores nodes that cannot be cast).
InstantiationException
NoSuchMethodException
InvocationTargetException
IllegalArgumentException
IllegalAccessException - Exception are thrown only if policy is Policy.THROW_ON_ERROR
java.lang.ClassNotFoundException
public XmlData cast(java.util.Map typemap,
BasicXmlData.Policy policy)
throws java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.ClassNotFoundException
typemap - maps types to classes. Type is what XmlData considers a type:
a string value of type property.policy - one of the following: Policy.THROW_ON_ERROR (causes an exception
in case of any error), Policy.KEEP_ON_ERROR (keeps nodes that cannot be cast),
Policy.SKIP_ON_ERROR (ignores nodes that cannot be cast).
InstantiationException
NoSuchMethodException
InvocationTargetException
IllegalArgumentException
IllegalAccessException - Exception are thrown only if policy is Policy.THROW_ON_ERROR
java.lang.ClassNotFoundException
public XmlData castToPackage(java.lang.String packageName,
BasicXmlData.Policy policy)
throws java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.ClassNotFoundException
packageName - the name of the package for casting. XmlData types
are mapped to classes with the same name inside specified package.
packageName can be null: then it is ignored.policy - one of the following: Policy.THROW_ON_ERROR (causes an exception
in case of any error), Policy.KEEP_ON_ERROR (keeps nodes that cannot be cast),
Policy.SKIP_ON_ERROR (ignores nodes that cannot be cast).
InstantiationException
NoSuchMethodException
InvocationTargetException
IllegalArgumentException
IllegalAccessException
ClassNotFoundException - Exception are thrown only if policy is Policy.THROW_ON_ERRORpublic void trim()
This operation does not go deep, since it is assumed that you apply it in the process of building XmlData, and the kids are already trimmed.
public boolean satisfies(XmlData.Condition condition)
condition -
public boolean satisfies(java.lang.String expression)
the string is parsed first, and then the node is checked against the parsed expression.
expression -
public XmlData selectTree(XmlData.Condition condition)
The node is included into the resulting tree iff it satisfies the condition; this filtering operation is applied recursively to its kids.
selectTree in interface XmlDatacondition -
public XmlData selectTree(java.lang.String expression)
The node is included into the resulting tree iff it satisfies the condition; this filtering operation is applied recursively to its kids.
expression - the string that contains a filtering expression
Example:
<?xml version="1.0" encoding="UTF-8"?> <example a1="v1" a2="v2"> <sub1 ax="vx" ay="vy"/> <sub2 aa="va" ab="vb"/> </example>
selectTree("ax != \"vx\"") and
selectTree("a1 == \"v1\" || ab == \"vb\"")
<?xml version="1.0" encoding="UTF-8"?> <example a1="v1" a2="v2"> <sub2 aa="va" ab="vb"/> </example>
public java.util.Collection getKidTypes()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||