001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.enterprise.datatypes;
016:
017: import java.util.Properties;
018:
019: import com.metaboss.enterprise.datatypes.primitivetranslation.*;
020: import com.metaboss.enterprise.datatypes.sqltranslation.*;
021: import com.metaboss.enterprise.datatypes.xmltranslation.*;
022:
023: /** Each datatype has a translation metadata describing how to translate this datatype
024: * object to and from various storage and distribution protocols. This metadata is obtainable
025: * from every concrete DataType via public static DataTypeTranslationMetadata getTranslationMetadata()
026: * method. The translation metadata (and therefore each and every DataType) at the moment supports
027: * three types of translation :
028: * <UL>
029: * <LI>
030: * Primitive Translation is used to extract data content out of datatype instance in java
031: * primitive form and to create an instance of the datatype from java primitive value.
032: * This translation is used to store and retrieve or send and receive internals of datatypes (for example over CORBA)
033: * Each datatype has a mapping to certain java primitive type. The <A HREF="#getPrimitiveType()">getPrimitiveType()</A> method
034: * returns a descriptor of this primitive type. This descriptor has enough information to understand which
035: * primitive type this datatype can be extracted to and created from. The <A HREF="#getPrimitiveTypeProperties()">getPrimitiveTypeProperties()</A> method
036: * returns some properties pertained to the type (e.g. if primitive type is a String, the property
037: * with max length of the string might be passed here). The <A HREF="#getPrimitiveTranslator()">getPrimitiveTranslator()</A> method
038: * returns a utility class, which can be used to do translation. Each PrimitiveTranslator has
039: * two methods used for conversion: public DataType createFromPrimitiveValue(<primitive type>) and
040: * public <primitive type> getPrimitiveValue(DataType). These methods are "trusted"
041: * this means that they do not perform user input validation. They really expected to be used
042: * in tandem (Similar to Serialization mechanism). Consider for example that CORBA client packs the value using getPrimitiveValue() method and
043: * CORBA server restores the DataType instance using createFromPrimitiveValue() method. Validation is this case
044: * is really not necessary (we trust that underlying protocol will worry about corrupt data packets).
045: * This trust means that when createFromPrimitiveValue method discovers problem with data it must throw
046: * unchecked DataTypeInstanceCreationFailureException instead of checked DataTypeValidationException.
047: * On the other hand getPrimitiveValue() method must throw DataTypeInvalidOperationForConcealedInstanceException or DataTypeInvalidOperationForEmptyInstanceException if
048: * it is passed datatype instance containing concealed or empty value. This means that translator is not
049: * responsible for representation of these special values within range of values for the corresponding primitive type.
050: * </LI>
051: * <LI>
052: * Sql Translation is used to extract data content out of datatype instance in form acceptable
053: * for jdbc/sql operations and to create an instance of the datatype from jdbc/sql value.
054: * <i>The jdbc/sql type is simply any column data type. Such type has representation in SQL's table create statements.
055: * This type also typically has corresponding constant in the java.sql.Types class. Also this type has
056: * corresponding java type acceptable as parameter by java.sql.PreparedStatement and returnable by java.sql.ResultSet as column's value.</i>
057: * This translation is used to store and retrieve internals of datatypes on JDBC data sources.
058: * Each datatype has a mapping to certain jdbc/sql type. The <A HREF="#getSqlType()">getSqlType()</A> method
059: * returns descriptor of this type. This descriptor has enough information to understand which jdbc/sql
060: * type this datatype can be extracted to and created from. The <A HREF="#getSqlTypeProperties()">getSqlTypeProperties()</A> method
061: * returns some properties pertained to the type (e.g. if sql type is a VARCHAR, the property
062: * with max length of the string might be passed here). The <A HREF="#getSqlTranslator()">getSqlTranslator()</A> method
063: * returns a utility class, which can be used to do translation. Each SqlTranslator has two methods used
064: * for conversion: public DataType createFromSqlValue(<sql type>) and public <sql type> getSqlValue(DataType).
065: * These methods are "trusted" this means that they do not perform user input validation. They really expected to be used
066: * in tandem (Similar to Serialization mechanism). Consider for example that storage code packs the value using getSqlValue() when record is inserted
067: * and neighbouring storage code restores the DataType instance when record is read using createFromSqlValue() method.
068: * Validation is this case is really not necessary (we trust that any manual editing to database data is done by
069: * responsible person who is aware of datatype validation rules).
070: * This trust means that when createFromSqlValue method discovers problem with data it must throw
071: * unchecked DataTypeInstanceCreationFailureException instead of checked DataTypeValidationException.
072: * On the other hand getSqlValue() method must throw DataTypeInvalidOperationForConcealedInstanceException or DataTypeInvalidOperationForEmptyInstanceException if
073: * it is passed datatype instance containing concealed or empty value. This means that translator is not
074: * responsible for representation of these special values within range of values for the corresponding jdbc/sql type.
075: * </LI>
076: * <LI>
077: * XML Translation is used to extract data content out of datatype instance in form acceptable
078: * for xml elements or attributes and to create an instance of the datatype from xml elements or attributes.
079: * This translation is used to store and retrieve or transmit internals of datatypes using XML (i.e. JMS message).
080: * Each datatype has a mapping to certain type of xml value (at the moment only string is supported).
081: * The <A HREF="#getXmlType()">getXmlType()</A> method returns descriptor of this type.
082: * This descriptor has enough information to understand which xml type this datatype can be extracted to and created from.
083: * The <A HREF="#getXmlTypeProperties()">getXmlTypeProperties()</A> method returns some properties pertained to the type (no examples as of yet, but it is provided
084: * for consistency with other translations). The <A HREF="#getXmlTranslator()">getXmlTranslator()</A> method
085: * returns a utility class, which can be used to do translation. Each XmlConvertor has two methods used for conversion: public DataType createFromXmlValue(<xml type>) and
086: * public <xml type> getXmlValue(DataType). These methods are "trusted" this means that they do not perform user input validation. They really expected to be used
087: * in tandem (Similar to Serialization mechanism). Consider for example that storage code packs the value using getXmlValue() when record is inserted
088: * and neighbouring storage code restores the DataType instance when record is read using createFromXmlValue() method.
089: * Validation is this case is really not necessary (we trust that any manual xml editing is done by
090: * responsible person who is aware of datatype validation rules).
091: * This trust means that when createFromXmlValue method discovers problem with data it must throw
092: * unchecked DataTypeInstanceCreationFailureException instead of checked DataTypeValidationException.
093: * On the other hand getXmlValue() method must throw DataTypeInvalidOperationForConcealedInstanceException or DataTypeInvalidOperationForEmptyInstanceException if
094: * it is passed datatype instance containing concealed or empty value. This means that datatype is not
095: * responsible for representation of these special values within range of values for the corresponding xml type.
096: * </LI>
097: * </UL>
098: * <P>Valid question about this conversion mechanism is "Why all this complexity ?". The answer is that
099: * MetaBoss is trying give datatypes a very useful feature - ability to "Serialize" datatype
100: * in and out of types used in various storage and distribution technologies, but at the same time
101: * we try to avoid using java native Serialization (large size of data image) as well as reflection (somewhat slow).
102: * We also attempt to "hide" (at least remove out of sight) low level translation methods from application programmers
103: * so they do not use them without fully understanding implications (major one is that the datatype content is not validated).</P>
104: * */
105: public interface DataTypeTranslationMetadata {
106: /** The Sql type descriptor. Contains sql type definition */
107: public class SqlType {
108: private String mName;
109: private Class mJavaType;
110: private boolean mIsArray;
111: private Class mTranslatorType;
112:
113: /** Constructs SQL type descriptor
114: * Note that the decision not to use java.sql.Types constants was made,
115: * so we can have a definitive list of supported SQL types (and it is more readable.)
116: * @param pName - unique name of this sql type
117: * @param pJavaType - the type used in setting parameters and fetching values from the result sets
118: * @param pIsArray - supply true for arrays and false for singles
119: * @param pTranslatorType - the java.lang.Class of the Translator */
120: private SqlType(String pName, Class pJavaType,
121: boolean pIsArray, Class pTranslatorType) {
122: mName = pName;
123: mJavaType = pJavaType;
124: mIsArray = pIsArray;
125: mTranslatorType = pTranslatorType;
126: }
127:
128: /** Getter for the java type class */
129: public static SqlType createFromName(String pName) {
130: if (pName.equals(SQL_BLOB.getName()))
131: return SQL_BLOB;
132: if (pName.equals(SQL_CLOB.getName()))
133: return SQL_CLOB;
134: if (pName.equals(SQL_VARCHAR.getName()))
135: return SQL_VARCHAR;
136: if (pName.equals(SQL_BIT.getName()))
137: return SQL_BIT;
138: if (pName.equals(SQL_TINYINT.getName()))
139: return SQL_TINYINT;
140: if (pName.equals(SQL_SMALLINT.getName()))
141: return SQL_SMALLINT;
142: if (pName.equals(SQL_INTEGER.getName()))
143: return SQL_INTEGER;
144: if (pName.equals(SQL_BIGINT.getName()))
145: return SQL_BIGINT;
146: if (pName.equals(SQL_REAL.getName()))
147: return SQL_REAL;
148: if (pName.equals(SQL_DOUBLE.getName()))
149: return SQL_DOUBLE;
150: if (pName.equals(SQL_DECIMAL.getName()))
151: return SQL_DECIMAL;
152: if (pName.equals(SQL_DATE.getName()))
153: return SQL_DATE;
154: if (pName.equals(SQL_TIME.getName()))
155: return SQL_TIME;
156: if (pName.equals(SQL_TIMESTAMP.getName()))
157: return SQL_TIMESTAMP;
158: throw new IllegalArgumentException("Name " + pName
159: + " is not valid SqlType name");
160: }
161:
162: /** Getter for the java type class */
163: public Class getJavaType() {
164: return mJavaType;
165: }
166:
167: /** Getter for the type name */
168: public String getName() {
169: return mName;
170: }
171:
172: /** Getter for the array flag */
173: public boolean isArray() {
174: return mIsArray;
175: }
176:
177: /** Getter for the Translator type class */
178: public Class getTranslatorType() {
179: return mTranslatorType;
180: }
181:
182: public boolean equals(Object obj) {
183: // Must be exact same instance
184: return (obj == this );
185: }
186: }
187:
188: /** Base interface for all Sql Translators.
189: * Each DataType is able to be converted to and from Sql type (types accepted by java.sql.* package).
190: * The actual subtype of the SqlTranslator used for conversion depends on DataTypeTranslationMetadata (in
191: * particular on the kind of SqlType descriptor associated with the datatatype).
192: * The instance of the SqlTranslator is obtainable from DataType's Translation Metadata object */
193: public interface SqlTranslator {
194: }
195:
196: /** Refers to SQL type BLOB. No known type properties at the moment */
197: public static final SqlType SQL_BLOB = new SqlType("SQL_BLOB",
198: Byte.TYPE, true, SqlBlobTranslator.class);
199: /** Refers to SQL type CLOB. No known type properties at the moment */
200: public static final SqlType SQL_CLOB = new SqlType("SQL_CLOB",
201: java.lang.String.class, false, SqlClobTranslator.class);
202: /** Refers to SQL type VARCHAR. Allowed properties are :
203: * <ul>
204: * <li>'minsize' - this optional property requires to limit min size of the string
205: * if it is not present - minimum size is not constrained (i.e. can be empty string)</li>
206: * <li>'maxsize' - this optional property requires to limit max size of the string
207: * if it is not present - maxsize is only limited by data storage capabilities (i.e. some sort of default)</li>
208: * <ul>
209: */
210: public static final SqlType SQL_VARCHAR = new SqlType(
211: "SQL_VARCHAR", java.lang.String.class, false,
212: SqlVarcharTranslator.class);
213: /** Refers to SQL type BIT. No known type properties at the moment */
214: public static final SqlType SQL_BIT = new SqlType("SQL_BIT",
215: Boolean.TYPE, false, SqlBitTranslator.class);
216: /** Refers to SQL type TINYINT. No known type properties at the moment */
217: public static final SqlType SQL_TINYINT = new SqlType(
218: "SQL_TINYINT", Byte.TYPE, false, SqlTinyintTranslator.class);
219: /** Refers to SQL type SMALLINT. No known type properties at the moment */
220: public static final SqlType SQL_SMALLINT = new SqlType(
221: "SQL_SMALLINT", Short.TYPE, false,
222: SqlSmallintTranslator.class);
223: /** Refers to SQL type INTEGER. No known type properties at the moment */
224: public static final SqlType SQL_INTEGER = new SqlType(
225: "SQL_INTEGER", Integer.TYPE, false,
226: SqlIntegerTranslator.class);
227: /** Refers to SQL type BIGINT. No known type properties at the moment */
228: public static final SqlType SQL_BIGINT = new SqlType("SQL_BIGINT",
229: Long.TYPE, false, SqlBigintTranslator.class);
230: /** Refers to SQL type REAL. No known type properties at the moment */
231: public static final SqlType SQL_REAL = new SqlType("SQL_REAL",
232: Float.TYPE, false, SqlRealTranslator.class);
233: /** Refers to SQL type DOUBLE. No known type properties at the moment */
234: public static final SqlType SQL_DOUBLE = new SqlType("SQL_DOUBLE",
235: Double.TYPE, false, SqlDoubleTranslator.class);
236: /** Refers to SQL type DECIMAL. Allowed properties are :
237: * <ul>
238: * <li>'precision' - this optional property specifies precision of the number
239: * if it is not present - precision is determined and limited by data storage capabilities (i.e. some sort of default)</li>
240: * <li>'scale' - this optional property specifies scale
241: * if it is not present - scale is determined and limited by data storage capabilities (i.e. some sort of default)</li>
242: * <ul>
243: */
244: public static final SqlType SQL_DECIMAL = new SqlType(
245: "SQL_DECIMAL", java.math.BigDecimal.class, false,
246: SqlDecimalTranslator.class);
247: /** Refers to SQL type DATE. No known type properties at the moment */
248: public static final SqlType SQL_DATE = new SqlType("SQL_DATE",
249: java.sql.Date.class, false, SqlDateTranslator.class);
250: /** Refers to SQL type TIME. No known type properties at the moment */
251: public static final SqlType SQL_TIME = new SqlType("SQL_TIME",
252: java.sql.Time.class, false, SqlTimeTranslator.class);
253: /** Refers to SQL type TIMESTAMP. Allowed properties are :
254: * <ul>
255: * <li>'precision' - this optional property specifies the number of digits in the fractional part of the seconds
256: * if it is not present - precision is determined and limited by data storage capabilities (i.e. some sort of default)</li>
257: * <ul>
258: */
259: public static final SqlType SQL_TIMESTAMP = new SqlType(
260: "SQL_TIMESTAMP", java.sql.Timestamp.class, false,
261: SqlTimestampTranslator.class);
262:
263: /** Returns the class describing the sql type supported by the datatype.
264: * Looking at the type returned here client can find ot details about
265: * conversion of this datatype to and from sql/jdbc types */
266: public SqlType getSqlType();
267:
268: /** Returns the whole property bag pertained to particular SqlType.
269: * Available properties are documented next to the types.
270: * @return whole property bag. Should at least return empty property bag (do not return null) */
271: public Properties getSqlTypeProperties();
272:
273: /** Returns the instance of the SqlTranslator, which can be used to translate data
274: * between sql type and the instance of the datatype
275: * @return the instance of the translator */
276: public SqlTranslator getSqlTranslator();
277:
278: /** The Primitive type descriptor. Contains primitive type definition */
279: public class PrimitiveType {
280: private String mName;
281: private Class mJavaType;
282: private boolean mIsArray;
283: private Class mTranslatorType;
284:
285: /** Constructs primitive type descriptor
286: * @param pName - unique name of this sql type
287: * @param pJavaType - the java.lang.Class of the java type being described
288: * @param pIsArray - supply true for arrays and false for singles
289: * @param pTranslatorType - the java.lang.Class of the Translator */
290: private PrimitiveType(String pName, Class pJavaType,
291: boolean pIsArray, Class pTranslatorType) {
292: mName = pName;
293: mJavaType = pJavaType;
294: mIsArray = pIsArray;
295: mTranslatorType = pTranslatorType;
296: }
297:
298: /** Getter for the primitive type class */
299: public static PrimitiveType createFromName(String pName) {
300: if (pName.equals(PRIMITIVE_BOOLEAN.getName()))
301: return PRIMITIVE_BOOLEAN;
302: if (pName.equals(PRIMITIVE_BYTE.getName()))
303: return PRIMITIVE_BYTE;
304: if (pName.equals(PRIMITIVE_SHORTINT.getName()))
305: return PRIMITIVE_SHORTINT;
306: if (pName.equals(PRIMITIVE_INT.getName()))
307: return PRIMITIVE_INT;
308: if (pName.equals(PRIMITIVE_LONGINT.getName()))
309: return PRIMITIVE_LONGINT;
310: if (pName.equals(PRIMITIVE_DECIMAL.getName()))
311: return PRIMITIVE_DECIMAL;
312: if (pName.equals(PRIMITIVE_FLOAT.getName()))
313: return PRIMITIVE_FLOAT;
314: if (pName.equals(PRIMITIVE_DOUBLE.getName()))
315: return PRIMITIVE_DOUBLE;
316: if (pName.equals(PRIMITIVE_STRING.getName()))
317: return PRIMITIVE_STRING;
318: if (pName.equals(PRIMITIVE_BOOLEANARRAY.getName()))
319: return PRIMITIVE_BOOLEANARRAY;
320: if (pName.equals(PRIMITIVE_BYTEARRAY.getName()))
321: return PRIMITIVE_BYTEARRAY;
322: if (pName.equals(PRIMITIVE_SHORTINTARRAY.getName()))
323: return PRIMITIVE_SHORTINTARRAY;
324: if (pName.equals(PRIMITIVE_INTARRAY.getName()))
325: return PRIMITIVE_INTARRAY;
326: if (pName.equals(PRIMITIVE_LONGINTARRAY.getName()))
327: return PRIMITIVE_LONGINTARRAY;
328: if (pName.equals(PRIMITIVE_DECIMALARRAY.getName()))
329: return PRIMITIVE_DECIMALARRAY;
330: if (pName.equals(PRIMITIVE_FLOATARRAY.getName()))
331: return PRIMITIVE_FLOATARRAY;
332: if (pName.equals(PRIMITIVE_DOUBLEARRAY.getName()))
333: return PRIMITIVE_DOUBLEARRAY;
334: if (pName.equals(PRIMITIVE_STRINGARRAY.getName()))
335: return PRIMITIVE_STRINGARRAY;
336: throw new IllegalArgumentException("Name " + pName
337: + " does is not valid PrimitiveType name");
338: }
339:
340: /** Getter for the type name */
341: public String getName() {
342: return mName;
343: }
344:
345: /** Getter for the java type class */
346: public Class getJavaType() {
347: return mJavaType;
348: }
349:
350: /** Getter for the array flag */
351: public boolean isArray() {
352: return mIsArray;
353: }
354:
355: /** Getter for the Translator type class */
356: public Class getTranslatorType() {
357: return mTranslatorType;
358: }
359:
360: public boolean equals(Object obj) {
361: // Must be exact same instance
362: return obj == this ;
363: }
364: }
365:
366: /** Base interface for all Primitive Translators.
367: * Each DataType is able to be converted to and from Primitive type (java primitive types).
368: * The actual subtype of the PrimitiveTranslator used for conversion depends on DataTypeTranslationMetadata (in
369: * particular on the kind of PrimitiveType descriptor associated with the datatatype).
370: * The instance of the PrimitiveTranslator is obtainable from DataType's Translation Metadata object */
371: public interface PrimitiveTranslator {
372: }
373:
374: /** Constant describing non-array boolean primitive type */
375: public static final PrimitiveType PRIMITIVE_BOOLEAN = new PrimitiveType(
376: "PRIMITIVE_BOOLEAN", Boolean.TYPE, false,
377: PrimitiveBooleanTranslator.class);
378: /** Constant describing non-array byte primitive type */
379: public static final PrimitiveType PRIMITIVE_BYTE = new PrimitiveType(
380: "PRIMITIVE_BYTE", Byte.TYPE, false,
381: PrimitiveByteTranslator.class);
382: /** Constant describing non-array short integer primitive type */
383: public static final PrimitiveType PRIMITIVE_SHORTINT = new PrimitiveType(
384: "PRIMITIVE_SHORTINT", Short.TYPE, false,
385: PrimitiveShortintTranslator.class);
386: /** Constant describing non-array integer primitive type */
387: public static final PrimitiveType PRIMITIVE_INT = new PrimitiveType(
388: "PRIMITIVE_INT", Integer.TYPE, false,
389: PrimitiveIntTranslator.class);
390: /** Constant describing non-array long integer primitive type */
391: public static final PrimitiveType PRIMITIVE_LONGINT = new PrimitiveType(
392: "PRIMITIVE_LONGINT", Long.TYPE, false,
393: PrimitiveLongintTranslator.class);
394: /** Constant describing non-array decimal primitive type */
395: public static final PrimitiveType PRIMITIVE_DECIMAL = new PrimitiveType(
396: "PRIMITIVE_DECIMAL", java.math.BigDecimal.class, false,
397: PrimitiveDecimalTranslator.class);
398: /** Constant describing non-array floating point primitive type */
399: public static final PrimitiveType PRIMITIVE_FLOAT = new PrimitiveType(
400: "PRIMITIVE_FLOAT", Float.TYPE, false,
401: PrimitiveFloatTranslator.class);
402: /** Constant describing non-array double floating point primitive type */
403: public static final PrimitiveType PRIMITIVE_DOUBLE = new PrimitiveType(
404: "PRIMITIVE_DOUBLE", Double.TYPE, false,
405: PrimitiveDoubleTranslator.class);
406: /** Constant describing non-array string primitive type */
407: public static final PrimitiveType PRIMITIVE_STRING = new PrimitiveType(
408: "PRIMITIVE_STRING", java.lang.String.class, false,
409: PrimitiveStringTranslator.class);
410: /** Constant describing array of booleans primitive type */
411: public static final PrimitiveType PRIMITIVE_BOOLEANARRAY = new PrimitiveType(
412: "PRIMITIVE_BOOLEANARRAY", Boolean.TYPE, true,
413: PrimitiveBooleanArrayTranslator.class);
414: /** Constant describing array of bytes primitive type */
415: public static final PrimitiveType PRIMITIVE_BYTEARRAY = new PrimitiveType(
416: "PRIMITIVE_BYTEARRAY", Byte.TYPE, true,
417: PrimitiveByteArrayTranslator.class);
418: /** Constant describing array of short integers primitive type */
419: public static final PrimitiveType PRIMITIVE_SHORTINTARRAY = new PrimitiveType(
420: "PRIMITIVE_SHORTINTARRAY", Short.TYPE, true,
421: PrimitiveShortintArrayTranslator.class);
422: /** Constant describing array of integers primitive type */
423: public static final PrimitiveType PRIMITIVE_INTARRAY = new PrimitiveType(
424: "PRIMITIVE_INTARRAY", Integer.TYPE, true,
425: PrimitiveIntArrayTranslator.class);
426: /** Constant describing array of long integers primitive type */
427: public static final PrimitiveType PRIMITIVE_LONGINTARRAY = new PrimitiveType(
428: "PRIMITIVE_LONGINTARRAY", Long.TYPE, true,
429: PrimitiveLongintArrayTranslator.class);
430: /** Constant describing array of decimal primitive type */
431: public static final PrimitiveType PRIMITIVE_DECIMALARRAY = new PrimitiveType(
432: "PRIMITIVE_DECIMALARRAY", java.math.BigDecimal.class, true,
433: PrimitiveDecimalArrayTranslator.class);
434: /** Constant describing array array floating point primitive type */
435: public static final PrimitiveType PRIMITIVE_FLOATARRAY = new PrimitiveType(
436: "PRIMITIVE_FLOATARRAY", Float.TYPE, true,
437: PrimitiveFloatArrayTranslator.class);
438: /** Constant describing array of double floating point primitive type */
439: public static final PrimitiveType PRIMITIVE_DOUBLEARRAY = new PrimitiveType(
440: "PRIMITIVE_DOUBLEARRAY", Double.TYPE, true,
441: PrimitiveDoubleArrayTranslator.class);
442: /** Constant describing array of string primitive type */
443: public static final PrimitiveType PRIMITIVE_STRINGARRAY = new PrimitiveType(
444: "PRIMITIVE_STRINGARRAY", java.lang.String.class, true,
445: PrimitiveStringArrayTranslator.class);
446:
447: /** Returns the class describing the primitive type supported by the datatype.
448: * Looking at the type returned here client can find ot details about
449: * conversion of this datatype to and from primitive types */
450: public PrimitiveType getPrimitiveType();
451:
452: /** Returns the whole property bag pertained to particular Primitive Type.
453: * Available properties are documented next to the types.
454: * @return whole property bag. Should at least return empty property bag (do not return null) */
455: public Properties getPrimitiveTypeProperties();
456:
457: /** Returns the instance of the PrimitiveTranslator, which can be used to translate data
458: * between java primitive type and the instance of the datatype
459: * @return the instance of the translator */
460: public PrimitiveTranslator getPrimitiveTranslator();
461:
462: /** The Xml type descriptor. Contains xml type definition */
463: public class XmlType {
464: private String mName;
465: private Class mJavaType;
466: private boolean mIsArray;
467: private Class mTranslatorType;
468:
469: /** Constructs xml type descriptor
470: * @param pName - unique name of this xml type
471: * @param pJavaType - the java.lang.Class of the java type being described
472: * @param pIsArray - supply true for arrays and false for singles
473: * @param pTranslatorType - the java.lang.Class of the Translator */
474: private XmlType(String pName, Class pJavaType,
475: boolean pIsArray, Class pTranslatorType) {
476: mName = pName;
477: mJavaType = pJavaType;
478: mIsArray = pIsArray;
479: mTranslatorType = pTranslatorType;
480: }
481:
482: /** Getter for the xml type class */
483: public static XmlType createFromName(String pName) {
484: if (pName.equals(XML_TEXT.getName()))
485: return XML_TEXT;
486: throw new IllegalArgumentException("Name " + pName
487: + " is not valid XmlType name");
488: }
489:
490: /** Getter for the type name */
491: public String getName() {
492: return mName;
493: }
494:
495: /** Getter for the java type class */
496: public Class getJavaType() {
497: return mJavaType;
498: }
499:
500: /** Getter for the array flag */
501: public boolean isArray() {
502: return mIsArray;
503: }
504:
505: /** Getter for the Translator type class */
506: public Class getTranslatorType() {
507: return mTranslatorType;
508: }
509:
510: public boolean equals(Object obj) {
511: // Must be exact same instance
512: return obj == this ;
513: }
514: }
515:
516: /** Base interface for all Xml Translators.
517: * Each DataType is able to be converted to and from Xml type (types accepted by org.w3c.dom.* package).
518: * The actual subtype of the XmlTranslator used for conversion depends on DataTypeTranslationMetadata (in
519: * particular on the kind of XmlType descriptor associated with the datatatype).
520: * The instance of the XmlTranslator is obtainable from DataType's Translation Metadata object */
521: public interface XmlTranslator {
522: }
523:
524: /** Constant describing xml text type */
525: public static final XmlType XML_TEXT = new XmlType("XML_TEXT",
526: java.lang.String.class, false, XmlTextTranslator.class);
527:
528: /** Returns the class describing the xml type supported by the datatype.
529: * Looking at the type returned here client can find ot details about
530: * conversion of this datatype to and from xml supported types */
531: public XmlType getXmlType();
532:
533: /** Returns the whole property bag pertained to particular Xml Type.
534: * Available properties are documented next to the types.
535: * @return whole property bag. Should at least return empty property bag (do not return null) */
536: public Properties getXmlTypeProperties();
537:
538: /** Returns the instance of the XmlTranslator, which can be used to translate data
539: * between xml type and the instance of the datatype
540: * @return the instance of the translator */
541: public XmlTranslator getXmlTranslator();
542: }
|