xmlBlaster 2.2.0 API

org.xmlBlaster.util
Class EncodableData

java.lang.Object
  extended by org.xmlBlaster.util.EncodableData
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ClientProperty

public class EncodableData
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

This class encapsulates one client property in a QoS.

Examples:

<clientProperty name='transactionId' type='int'>120001</clientProperty>
<clientProperty name='myKey'>Hello World</clientProperty>
<clientProperty name='myBlob' type='byte[]' encoding='base64'>OKFKAL==</clientProperty>
<clientProperty name='myText' type='String' encoding='base64' charset='cp1252'>Hello</clientProperty>
 
If the attribute type is missing we assume a 'String' property

The encoding charset must be "UTF-8", it can be locally overwritten for base64 encoded strings

See Also:
The client.qos.clientProperty requirement, Serialized Form

Field Summary
private  java.lang.String charset
          Mark the charset for a base64 encoded String
private  java.lang.String encoding
           
private  boolean forceCdata
           
static boolean isChunked
          Needed for Base64 encoding
protected  java.lang.String ME
           
private  java.lang.String name
           
private static long serialVersionUID
           
private  long size
           
protected  java.lang.String tagName
           
private  java.lang.String type
           
private  java.lang.String value
          The value encoded as specified with encoding
 
Constructor Summary
EncodableData(java.lang.String tagName, java.lang.String name, byte[] value)
          Set binary data, will be of type "byte[]" and base64 encoded
EncodableData(java.lang.String tagName, java.lang.String name, java.lang.String type, java.lang.String encoding)
           
EncodableData(java.lang.String tagName, java.lang.String name, java.lang.String type, java.lang.String encoding, java.lang.String value)
           
 
Method Summary
static java.lang.Object convertPropertyObject(java.lang.String type, java.lang.String val)
          Helper to convert 'val' to the given object of type 'type'.
 void forceCdata(boolean forceCdata)
           
 byte[] getBlobValue()
           
 boolean getBooleanValue()
           
 byte getByteValue()
           
 java.lang.String getCharset()
           
 double getDoubleValue()
           
 java.lang.String getEncoding()
           
 float getFloatValue()
           
 int getIntValue()
           
 long getLongValue()
           
 java.lang.String getName()
           
 java.lang.Object getObjectValue()
          Depending on the type we return a Float, Long, Integer, ...
static java.lang.String getPropertyType(java.lang.Object val)
          Helper which returns the type of the object as a string
 short getShortValue()
           
 long getSize()
          The real, raw content size (not the base64 size)
 java.lang.String getStringValue()
          The string representation of the value.
 java.lang.String getStringValue(java.lang.String defaultValue)
           
 java.lang.String getType()
           
private  java.lang.String getValidatedValueForXml()
           
 java.lang.String getValueRaw()
          The raw still encoded value
 boolean isBase64()
           
 boolean isStringType()
           
static void main(java.lang.String[] args)
           
 void setCharset(java.lang.String charset)
           
 void setSize(long size)
          The real, raw content size (not the base64 size)
 void setValue(byte[] value)
          Set binary data, will be of type "byte[]" and base64 encoded
 void setValue(java.lang.String value)
          Set the value, it will be encoded with the encoding specified in the constructor.
 void setValue(java.lang.String value, java.lang.String encoding)
          Set the real value which will be encoded as specified.
 void setValueRaw(java.lang.String value)
          Set the already correctly encoded value
 java.lang.String toXml()
          Dump state of this object into a XML ASCII string.
 java.lang.String toXml(java.lang.String offset)
          Dump state of this object into a XML ASCII string.
 java.lang.String toXml(java.lang.String extraOffset, java.lang.String tmpTagName)
          Dump state of this object into a XML ASCII string.
 java.lang.String toXml(java.lang.String extraOffset, java.lang.String tmpTagName, boolean forceReadable)
          You may set forceReadable==true to have nicer human readable output.
 java.lang.String toXml(java.lang.String extraOffset, java.lang.String tmpTagName, boolean forceReadable, boolean inhibitContentCDATAWrapper)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

ME

protected java.lang.String ME

name

private final java.lang.String name

type

private java.lang.String type

value

private java.lang.String value
The value encoded as specified with encoding


encoding

private java.lang.String encoding

charset

private java.lang.String charset
Mark the charset for a base64 encoded String


isChunked

public static final boolean isChunked
Needed for Base64 encoding

See Also:
Constant Field Values

tagName

protected java.lang.String tagName

size

private long size

forceCdata

private boolean forceCdata
Constructor Detail

EncodableData

public EncodableData(java.lang.String tagName,
                     java.lang.String name,
                     java.lang.String type,
                     java.lang.String encoding)
Parameters:
name - The unique property key
type - The data type of the value, Constants.TYPE_INT etc.
encoding - Constants.ENCODING_NONE=null or Constants.ENCODING_BASE64="base64"

EncodableData

public EncodableData(java.lang.String tagName,
                     java.lang.String name,
                     java.lang.String type,
                     java.lang.String encoding,
                     java.lang.String value)
Parameters:
name - The unique property key
type - The data type of the value, Constants.TYPE_INT etc.
encoding - Constants.ENCODING_NONE=null or Constants.ENCODING_BASE64="base64"

EncodableData

public EncodableData(java.lang.String tagName,
                     java.lang.String name,
                     byte[] value)
Set binary data, will be of type "byte[]" and base64 encoded

Parameters:
name - The unique property key
value - The binary data (will instantly be base64 encoded)
Method Detail

getName

public java.lang.String getName()

getType

public java.lang.String getType()

isStringType

public boolean isStringType()

getSize

public long getSize()
The real, raw content size (not the base64 size)

Returns:
-1 if not set

forceCdata

public void forceCdata(boolean forceCdata)

setSize

public void setSize(long size)
The real, raw content size (not the base64 size)

Parameters:
size - If set >= 0 force to dump the size attribute

isBase64

public boolean isBase64()

getValueRaw

public java.lang.String getValueRaw()
The raw still encoded value


getStringValue

public java.lang.String getStringValue()
The string representation of the value.

If the string is base64 encoded with a given charset, it is decoded and transformed to the default charset, typically "UTF-8"

Returns:
The value which is decoded (readable) in case it was base64 encoded, can be null

getStringValue

public java.lang.String getStringValue(java.lang.String defaultValue)

getBlobValue

public byte[] getBlobValue()
Returns:
Can be null

getIntValue

public int getIntValue()
Throws:
java.lang.NumberFormatException

getBooleanValue

public boolean getBooleanValue()

getDoubleValue

public double getDoubleValue()
Throws:
java.lang.NumberFormatException

getFloatValue

public float getFloatValue()
Throws:
java.lang.NumberFormatException

getByteValue

public byte getByteValue()

getLongValue

public long getLongValue()
Throws:
java.lang.NumberFormatException

getShortValue

public short getShortValue()
Throws:
java.lang.NumberFormatException

getObjectValue

public java.lang.Object getObjectValue()
Depending on the type we return a Float, Long, Integer, ...


getEncoding

public java.lang.String getEncoding()
Returns:
For example Constants.TYPE_INTEGER="int" or Constants.TYPE_BLOB="byte[]"

getCharset

public java.lang.String getCharset()
Returns:
Returns the charset, for example "cp1252" or "UTF-8", helpful if base64 encoded

setCharset

public void setCharset(java.lang.String charset)
Parameters:
charset - The charset to set.

setValue

public void setValue(java.lang.String value)
Set the value, it will be encoded with the encoding specified in the constructor.


setValue

public void setValue(byte[] value)
Set binary data, will be of type "byte[]" and base64 encoded


setValueRaw

public void setValueRaw(java.lang.String value)
Set the already correctly encoded value


setValue

public void setValue(java.lang.String value,
                     java.lang.String encoding)
Set the real value which will be encoded as specified. Currently only base64 is supported

Parameters:
value - The not encoded value
encoding - null or Constants.ENCODING_BASE64="base64"

getValidatedValueForXml

private java.lang.String getValidatedValueForXml()

getPropertyType

public static final java.lang.String getPropertyType(java.lang.Object val)
Helper which returns the type of the object as a string

Parameters:
val -
Returns:

convertPropertyObject

public static final java.lang.Object convertPropertyObject(java.lang.String type,
                                                           java.lang.String val)
Helper to convert 'val' to the given object of type 'type'.

Parameters:
type - the type of the object
val - the object itself
Returns:
null if the type is unrecognized or the value is null; A String object if the type is null (implicitly String) or the correct type (for example Float) if a mapping has been found.

toXml

public final java.lang.String toXml()
Dump state of this object into a XML ASCII string.


toXml

public final java.lang.String toXml(java.lang.String offset)
Dump state of this object into a XML ASCII string.


toXml

public final java.lang.String toXml(java.lang.String extraOffset,
                                    java.lang.String tmpTagName)
Dump state of this object into a XML ASCII string.

Parameters:
extraOffset - indenting of tags for nice output
tmpTagName - the tag name to be used for this output. If you specify 'null' the default will be used, i.e. what has been passed in the constructor.
Returns:
internal state of the EncodableData as a XML ASCII string

toXml

public final java.lang.String toXml(java.lang.String extraOffset,
                                    java.lang.String tmpTagName,
                                    boolean forceReadable)
You may set forceReadable==true to have nicer human readable output. For normal processing leave forceReadable==false.

Parameters:
extraOffset - The indenting prefix
tmpTagName - If null the default is chosen
forceReadable - If true the base64 is decoded to a 'readable' string
Returns:

toXml

public final java.lang.String toXml(java.lang.String extraOffset,
                                    java.lang.String tmpTagName,
                                    boolean forceReadable,
                                    boolean inhibitContentCDATAWrapper)

main

public static void main(java.lang.String[] args)

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.