Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)

com.lapetus_ltd.api.common
Class TLptsXmlUtil

java.lang.Object
  extended by com.lapetus_ltd.api.common.TLptsXmlUtil

public class TLptsXmlUtil
extends java.lang.Object

Class Description : The XML Manager is responsible for dealing with XML files and data.

The main functions of this class are the marshal and unmarshal, which in affect read and write
XML data structures to and from streams (files or communication streams).

The unmarshal capabilities is designed to read from files, jar files or URLs.
Refer to the javadoc below, on the unmarshal function for specific details.
unmarshal(java.lang.String, java.lang.Class)


$LastChangedRevision: 1210 $
$LastChangedDate:: 2010-11-29 15:22:58#$


Method Summary
static java.util.List<java.lang.String> getDelimitedKeyList(java.lang.String delimitedString, char delimiter)
           Extracts the keys of a delimited string with KVP.
static java.util.List<java.lang.String> getDelimitedValueList(java.lang.String delimitedString, char delimiter)
           Extracts the values of a delimited string with KVP.
static java.lang.String getIdentifier()
          Gets a unique GUUID string in the form of 8-4-4-4-12 hexadecimal characters.
static java.util.List<java.lang.String> getTokens(java.lang.String line, char delimiter)
           Extracts the tokens of a delimited string.
static
<T> boolean
marshal(java.lang.String path, java.lang.Class<T> typeObject, java.lang.Object jaxbElement)
           This writes a XML file to the hard disk.
static
<T> java.lang.Object
unmarshal(java.lang.String path, java.lang.Class<T> typeObject)
           Reads a XML file from a path on the disk, a URL or the jar resource.
static void zI()
          Obfuscated, as it is not required by the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDelimitedKeyList

public static java.util.List<java.lang.String> getDelimitedKeyList(java.lang.String delimitedString,
                                                                   char delimiter)

Extracts the keys of a delimited string with KVP.

Notes :

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Never. An empty list is returned in the worst case.

Example :

 

String input = "key1=value1;key2=value2;key3=value3"; List keys = TLptsXmlUtil.getDelimitedKeyList(input,';'); for (String key : keys) System.out.print(key + " ");

Result : key1 key2 key3

Parameters:
delimitedString - in the format key=value;key1=value1; (where ; is the delimiter)
delimiter - this is the character used to break up the tokens of a line
Returns:
returns the keys of the delimitedString. Call the getDelimitedValueList for the value list.

getDelimitedValueList

public static java.util.List<java.lang.String> getDelimitedValueList(java.lang.String delimitedString,
                                                                     char delimiter)

Extracts the values of a delimited string with KVP.

Notes :

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Never. An empty list is returned in the worst case.

Example :

 

String input = "key1=value1;key2=value2;key3=value3"; List values = TLptsXmlUtil.getDelimitedValueList(input,';'); for (String value : values) System.out.print(value + " ");

Result : value1 value2 value3

Parameters:
delimitedString - in the format key=value;key1=value1; (where ; is the delimiter)
delimiter - this is the character used to break up the tokens of a line
Returns:
returns the values of the delimitedString. Call the getDelimitedKeyList for the key list.

getIdentifier

public static java.lang.String getIdentifier()
Gets a unique GUUID string in the form of 8-4-4-4-12 hexadecimal characters.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : N/A

Notes : This is widely used in the system. It provides all the ID types of XLpts... with unique ID values.

Example :

 

Returns:
The unique id string (01234567-89ab-cdef-0123-456789abcdef)

getTokens

public static java.util.List<java.lang.String> getTokens(java.lang.String line,
                                                         char delimiter)

Extracts the tokens of a delimited string.

Notes :

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Never. An empty list is returned in the worst case.

Example :

 

String input = "string1:string2:string3=string4:string5"; List strings = TLptsXmlUtil.getTokens(input,':'); for (String string : strings) System.out.print(string + " ");

Result : string1 string2 string3=string4 string5

Parameters:
line - in the format key=value;key1=value1; (where ; is the delimiter)
delimiter - this is the character used to break up the tokens of a line
Returns:
returns the tokens of line. Call the getDelimitedValueList for the value list.

marshal

public static <T> boolean marshal(java.lang.String path,
                                  java.lang.Class<T> typeObject,
                                  java.lang.Object jaxbElement)

This writes a XML file to the hard disk.

Notes :

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Never

Example :

 

TLptsWorkspaceType myWs = new TLptsDBWorkspaceType(anotherWorkspace); myWs.SetSplit1Location(100); // change the value ObjectFactory of = new ObjectFactory(); // write it to file. TLptsXmlUtil.marshal("my.file.xml", XLptsDBWorkspaceType.class,of.createXLptsDBWorkspaceType(myWs));

Parameters:
path - The path and filename on the disk to write to.
typeObject - This is normally a file XLptsXXXX.class, but it can be any generated XSD to class.
jaxbElement - This is the object that needs to be written. The ObjectFactory needs to be employed to create the object. ie: ObjectFactory of = new ObjectFactory(); Object jaxbEelement = of.createXXXType(object));
Returns:
Returns true if the file was written, false otherwise. All exceptions and errors are captured and reported to the Logger TLptsLogger.

unmarshal

public static <T> java.lang.Object unmarshal(java.lang.String path,
                                             java.lang.Class<T> typeObject)

Reads a XML file from a path on the disk, a URL or the jar resource.

Notes : This function tries to read the provided path with many combinations.
The order or processing is as follows:
If the path is a URL with any of the following protocols (http,https,shttp,ldap,ldaps,telnet,xmpp,
jar,urn,chrome,cvs,svnfile,ssh,ftps,ftp), then the path is processes as a URL with no other processing.
A failure to read the URL will cause an error in the logger TLptsLogger
If the path is a normal disk path (/ or \ or c:/ etc) then the path is accesses as is.
If that is unsuccessful then any prevailing slashes are removed and the path is accessed from the current directory.
If this is unsuccessful then the path is looked for in the resources of the current JAR file (the application JAR).
If this is unsuccessful then the path is looked for as a URL again (just in case of an unlisted protocol).

Is it important to note that this function provides great flexibility in providing default JAR resources, which can
then be replaced by files in the application directory.
In other words, if we bundle our application with a default driver.loader.xml file in the resources of the JAR application
then it can be accessed as "/driver.loader.xml".
If the user of the application decides to create his/her own version of the file (by copying the resource into the database
directory in the application folder), then that file will be accessed before the JAR resource version of the file.

Thread Safe : Yes

Spawns its own Thread : No

May Return NULL : Yes

Example :

 

String pathToWorkspace = "users/me/lapetus/workspace.xml" XLptsDBWorkspaceType ws = (XLptsDBWorkspaceType) TLptsXmlUtil.unmarshal(pathToWorkspace, XLptsDBWorkspaceType.class); TLptsWorkspaceType myWs = new TLptsDBWorkspaceType(ws); // now it is initialised and I can work with it. myWs.set...

Type Parameters:
T - The object of the class type specified in the call to unmarshal.
Parameters:
path - the path of the source of the xml data. This can be a URL like http://... or a directory file /mydir/myfile.xml or it can be inside a jar file within the application class loaded jars (we just supply the path /path/to/xml/in/jar.xml), or we supply the whole jar path, ie. file:jar://my.jar!/path/to/my.file.xml if it is elsewhere in a jar file (not loaded by the current class loader)
typeObject - The class of the object to be read and verified from the xml file. This is supplied so that the xml subsystem can verify the xml file as being the correct type.
Returns:
The object of the supplied class type or null if there was any sort of issue with reading the file. All exceptions and errors are captured and reported to the Logger TLptsLogger.

zI

public static void zI()
Obfuscated, as it is not required by the application.



Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)