|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.text.Format
com.davisor.data.TupleFormat
TupleData data access services, and the whole range of
Type framework services.
TupleData instances are composite DataValue objects
that contain a number of other data values. Each data value has a
well formatted string representation, and therefore so does each
TupleData instance.
Tuple format instances control the exact string format of TupleData objects. In particular, tuple format tells which tuple
data members will appear in the text representation, in which
order, how many times, and in which format. Tuple formats may also
define constant text segments between the tuple data members, and
even fetch values from an external additionalValues
map.
setAdditionalValues(java.util.Map).
The formatter will then pass this map to the target tuple data
objects when their member values are accessed.
The map is quaranteed to be passed always by
reference to allow any changes to the map to affect the
formatting. As described by TupleData.get(Object,Map), all
map access will also always be synchronized with the map object
itself.
MessageFormat patterns:
formatPattern := ( [string] "{" formatElement "}" )* [string]
formatElement := elementKey [ "," elementType ]
elementType := typeName [ "," typeSpecs ]
string components are text strings that may not
contain unescaped curly brace or single quote characters. To
include these special characters into string bodies, the characters
must be escaped: curly braces must be enclosed within single quote
characters ("'{'"), while real single quote characters are
represented with two consequtive single quote characters ("''").
elementKey refers to tuple element identity, as
defined by TupleData.get(Object,Map) method. The
elementKey is used to select the tuple member or an
value from the current M_additionalValues} map whose value
is to replace the whole corresponding format element. If the key
does not match any tuple member or additional value, the format
element will be replaced with an empty string.
It is perfectly legal to refer to the same element multiple times, or not to refer to an element at all. Elemens referred to multiple times will be copied into the resulting strings as many times, while elements not referenced at all will be omitted alltogether.
typeName and typeSpecs pattern components
may be used to override the default tuple member value formatting
instructions. In particular, the type name and spesification, if
given, define together a new data type as described by Type.create(String,String,String,String) method. This type, if
any, is then applied to the corresponding tuple member or
additional value to convert it to a string. If no custom type is
created, either due missing or invalid type name or spesification,
the tuple member or additional value default string representation
is used.
It is perfectly legal to apply different formats and even new data types to the tuple elements and additional values. Each different reference will format the value according to the given format spesification. If new types are applied to tuple members and values, the result of the type conversion will be used. If type conversion fails, the original default formatting will be used instead.
createType(java.lang.String),
format(Object,StringBuffer,FieldPosition),
setAdditionalValues(java.util.Map),
TupleData,
TupleData.get(Object,Map),
TupleType,
Type.create(String,String,String,String),
Serialized Form| Nested Class Summary |
| Nested classes inherited from class java.text.Format |
java.text.Format.Field |
| Field Summary | |
protected static int |
ENC
Element index for field encoding component. |
static java.lang.String |
ENCODING_NONE
Do no encode macro expansions. |
static java.lang.String |
ENCODING_URL
URLEncode macro expansions. |
static java.lang.String |
ENCODING_XML
XML encode macro expansions. |
protected static int |
KEY
Element index for field key component. |
protected java.util.Map |
M_additionalValues
Additional values map. |
protected java.util.List |
M_fields
Format fields. |
protected java.util.Locale |
M_locale
Format locale. |
protected java.lang.String |
M_tail
Format trailing constant string. |
protected static int |
STRING
Element index for field string component. |
protected static int |
TYPE
Element index for field type component. |
| Constructor Summary | |
TupleFormat(java.lang.String pattern,
java.util.Locale locale,
java.util.Map additionalValues)
Creates a new tuple formatter. |
|
| Method Summary | |
protected Type |
createType(java.lang.String elementFormat)
Creates a type from element format string. |
java.lang.StringBuffer |
format(java.lang.Object object,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Formats a TupleData object to produce a string. |
java.util.Map |
getAdditionalValues()
Gets additional values map. |
java.lang.String |
getEncoding(int index)
Gets the encoding of given field. |
java.lang.String |
getKey(int index)
Gets the key of given field. |
java.lang.String |
getString(int index)
Gets the string of given field. |
Type |
getType(int index)
Gets the type of given field. |
protected com.davisor.core.IndexLabel |
indexOfStart(java.lang.String pattern,
int start)
Finds the next unescaped macro key start character from given pattern, and unescapes the string up to the found character. |
protected int |
indexOfStop(java.lang.String pattern,
int start)
Finds the next matching macro key stop characted index from given pattern. |
java.lang.Object |
parseObject(java.lang.String source,
java.text.ParsePosition status)
Parses a string to produce an object (not implemented). |
void |
setAdditionalValues(java.util.Map additionalValues)
Sets additional values map. |
int |
size()
Gets the number of fields. |
| Methods inherited from class java.text.Format |
clone, format, formatToCharacterIterator, parseObject |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final int STRING
protected static final int KEY
protected static final int TYPE
protected static final int ENC
public static final java.lang.String ENCODING_NONE
public static final java.lang.String ENCODING_URL
public static final java.lang.String ENCODING_XML
protected java.util.List M_fields
protected java.util.Locale M_locale
protected java.lang.String M_tail
protected java.util.Map M_additionalValues
| Constructor Detail |
public TupleFormat(java.lang.String pattern,
java.util.Locale locale,
java.util.Map additionalValues)
pattern - format spesification stringlocale - locale for locale sensitive formattingadditionalValues - additional values for tuple member value
resolvation (may be null)createType(java.lang.String),
format(Object,StringBuffer,FieldPosition),
indexOfStart(java.lang.String, int),
indexOfStop(java.lang.String, int),
setAdditionalValues(java.util.Map),
TupleData,
TupleData.get(Object,Map),
TupleType| Method Detail |
public java.lang.StringBuffer format(java.lang.Object object,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
TupleData object to produce a string. The
string is composed from the content of given tuple object
and current tuple format pattern.
For each format field in the current pattern, the tuple formatter makes a search to the given tuple data object, and substitutes found value, if any, with corresponding field key. Values not found show as empty strings.
The searches are carried out with tuple data TupleData.get(Object,Map) method, using the
formatElements in the current format pattern as
keys, and current additional values as additional value map.
object - the tuple data object to formattoAppendTo - where the text is to be appendedpos - ignored (may be null)
@return the value passed in as toAppendTo
java.lang.IllegalArgumentException - if object is not a tuple data objectsetAdditionalValues(java.util.Map),
TupleData.get(Object,Map)
public java.lang.Object parseObject(java.lang.String source,
java.text.ParsePosition status)
null
protected Type createType(java.lang.String elementFormat)
throws NoSuchTypeException
typeName { "," specs }
typeName and specs fields refer to
Type.create(String,String,String) method arguments
with the same names.
elementFormat - element format spesification
NoSuchTypeException - if type spesification was invalidType.create(String,String,String,String)
protected com.davisor.core.IndexLabel indexOfStart(java.lang.String pattern,
int start)
The result is packed into an index label that carries the
StringBuffer object the unescaped string was
collected into. The index of the found start character in given
pattern string is stored in index label index.
pattern - pattern to searchstart - index to start the search from
protected int indexOfStop(java.lang.String pattern,
int start)
pattern - pattern to searchstart - index to start the search from
public java.util.Map getAdditionalValues()
format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition),
setAdditionalValues(java.util.Map),
TupleData.get(Object,Map),
TupleType.getAdditionalValues()public java.lang.String getEncoding(int index)
index - field index
public java.lang.String getKey(int index)
index - field index
public java.lang.String getString(int index)
index - field index
public Type getType(int index)
index - field index.
public void setAdditionalValues(java.util.Map additionalValues)
format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition),
getAdditionalValues(),
TupleData.get(Object,Map),
TupleType.setAdditionalValues(java.util.Map)public int size()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||