public class Parsers
extends java.lang.Object
There are a number of default parsers for standard Java objects, that
this parser will load when it is initiated. These will parse a number of different
list types, XML elements, or other standard objects. You can then add your own parser
for any objects that you might pass as part of a communication process. The
addParser
method adds the parser here, in the form of the parser itself
and the name of the class that it will parse. To add a parser to a remote server,
you invoke the addParser method on the server instead. The parsing process will
also try to Base64 serialize objects if there is no XML parser available and they have
extended the Java Serializable
interface.
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
PARSE
Parser parse method
|
protected static java.lang.String |
SERIALIZE
Parser serialize method
|
Constructor and Description |
---|
Parsers()
Creates a new instance of Parsers
|
Modifier and Type | Method and Description |
---|---|
static boolean |
addParser(java.lang.String className,
java.lang.Object parser)
Add a new parser to the list, but do not overwrite an existing parser for that class.
|
static java.lang.Object |
createObject(java.lang.String className,
org.licas_xml.abs.Element xmlElem)
Create the object as specified by the element.
|
static java.lang.Object |
createObject(java.lang.String className,
java.lang.String value)
Create the object as specified by the string.
|
static void |
createParameterElement(java.lang.Object toSerialize,
org.licas_xml.abs.Element rootElem)
Create a specific
Const .PARAMTER element for the specified object. |
static java.util.ArrayList |
getParsedClasses()
Retrieve the list of classes that can be parsed by the parsers.
|
static org.ai_heuristic.def.ParserDef |
getParser(java.lang.String classType)
Return a parser for the specified class type if one exists.
|
static boolean |
hasParser(java.lang.String classType)
Return true if a parser for the specified class type exists.
|
static java.lang.Object |
parse(org.licas_xml.abs.Element toParse)
If a parser is available for the object then convert the element
back to the object.
|
static java.lang.Object |
parse(java.lang.String toParse)
If a parser is available for the object then convert the String-based
xml description of the element back to the object.
|
static java.lang.Object |
parseObject(java.lang.Object toParse)
Parse an object representation back into the correct object.
|
static java.lang.Object |
parseObject(java.lang.String className,
java.lang.Object toParse)
Parse an object representation back into the correct object.
|
static java.lang.String |
removeCoding(java.lang.String xmlStr)
Remove all element prefixes and extra coding to clean the string completely.
|
static boolean |
removeParser(java.lang.String className)
Add a new parser to the list.
|
static org.licas_xml.abs.Element |
serializeToElement(java.lang.Object toSerialize)
Convert the object into an xml Element if a parser exists.
|
static PacketInfo |
serializeToFile(java.lang.Object toSerialize)
Convert the object into an xml-based description if a parser exists and
save it to a file.
|
static java.lang.String |
serializeToString(java.lang.Object toSerialize)
Convert the object into an xml String format if a parser exists.
|
static boolean |
shouldConvert(java.lang.Class param,
java.lang.Object obj)
Check if the second parameter is an XML element type that should be
converted into an object.
|
protected static final java.lang.String PARSE
protected static final java.lang.String SERIALIZE
public static boolean hasParser(java.lang.String classType)
classType
- the class type of the object that needs parsing.public static boolean addParser(java.lang.String className, java.lang.Object parser)
className
- the class name of the object that the parser will parse.parser
- the parser. Must implement ParserDef interface.public static boolean removeParser(java.lang.String className)
className
- the class name of the object to parse.public static org.ai_heuristic.def.ParserDef getParser(java.lang.String classType)
classType
- the class type of the object that needs parsing.public static java.lang.Object parseObject(java.lang.Object toParse) throws java.lang.Exception
parse
methods, before calling them.
NOTE: The class type is assumed to be what the object itself is.toParse
- the object description to convert.java.lang.Exception
- any error.public static java.lang.Object parseObject(java.lang.String className, java.lang.Object toParse) throws java.lang.Exception
parse
methods, before calling them.className
- the object class name, in case different to the representation object.toParse
- the object description to convert.java.lang.Exception
- any error.public static java.lang.Object parse(java.lang.String toParse) throws java.lang.Exception
toParse
- the object description to parse back.toParse
is null.java.lang.Exception
- any error.public static java.lang.Object parse(org.licas_xml.abs.Element toParse) throws java.lang.Exception
toParse
- the object to parse back.java.lang.Exception
- any error.public static java.lang.String serializeToString(java.lang.Object toSerialize) throws java.lang.Exception
toSerialize
- the object to convert.java.lang.Exception
- any error.public static org.licas_xml.abs.Element serializeToElement(java.lang.Object toSerialize) throws java.lang.Exception
toSerialize
- the object to convert.Element
.java.lang.Exception
- any error.public static PacketInfo serializeToFile(java.lang.Object toSerialize) throws java.lang.Exception
PacketInfo
object to represent the file.toSerialize
- the object to convert.PacketInfo
object with the information. This can then be
read in parts, for example.java.lang.Exception
- any error.public static void createParameterElement(java.lang.Object toSerialize, org.licas_xml.abs.Element rootElem) throws java.lang.Exception
Const
.PARAMTER
element for the specified object.toSerialize
- the object to parse.rootElem
- root element, if the created element gets added to one.java.lang.Exception
- any error.public static java.lang.Object createObject(java.lang.String className, java.lang.String value) throws java.lang.Exception
className
- the object class name.value
- the object value as a String-based description.java.lang.Exception
- any error.public static java.lang.Object createObject(java.lang.String className, org.licas_xml.abs.Element xmlElem) throws java.lang.Exception
className
- the object class name.xmlElem
- root element if this stores the information and value is null.java.lang.Exception
- any error.public static boolean shouldConvert(java.lang.Class param, java.lang.Object obj)
param
- the first parameter class.obj
- the second parameter object.public static java.lang.String removeCoding(java.lang.String xmlStr)
xmlStr
- the string to remove prefixes from.public static java.util.ArrayList getParsedClasses()