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.util.ReflectionUtils;
020:
021: /** Default implementation of the DataTypeTranslationMetadata interface. It can be
022: * constructed in the static initialiser of the datatype and returned via
023: * getMetadata() method */
024: public class DefaultDataTypeTranslationMetadataImplementation implements
025: DataTypeTranslationMetadata {
026: private DataTypeTranslationMetadata.SqlType mSqlType;
027: private Properties mSqlTypeProperties;
028: private DataTypeTranslationMetadata.SqlTranslator mSqlTranslator;
029: private DataTypeTranslationMetadata.PrimitiveType mPrimitiveType;
030: private Properties mPrimitiveTypeProperties;
031: private DataTypeTranslationMetadata.PrimitiveTranslator mPrimitiveTranslator;
032: private DataTypeTranslationMetadata.XmlType mXmlType;
033: private Properties mXmlTypeProperties;
034: private DataTypeTranslationMetadata.XmlTranslator mXmlTranslator;
035:
036: /** Constructs the metadata object which will report given types
037: * @param pSqlType Sql type descriptor
038: * @param pSqlTypeProperties Sql type properties
039: * @param pSqlTranslator Sql type translator
040: * @param pPrimitiveType Primitive type descriptor
041: * @param pPrimitiveTypeProperties Primitive type properties
042: * @param pPrimitiveTranslator Primitive type translator
043: * @param pXmlType Xml type descriptor
044: * @param pXmlTypeProperties Xml type properties
045: * @param pXmlTranslator Xml type translator
046: * @exception java.lang.IllegalArgumentException thrown if supplied type descriptor
047: * does not match with supplied translator. */
048: public DefaultDataTypeTranslationMetadataImplementation(
049: DataTypeTranslationMetadata.SqlType pSqlType,
050: Properties pSqlTypeProperties,
051: DataTypeTranslationMetadata.SqlTranslator pSqlTranslator,
052: DataTypeTranslationMetadata.PrimitiveType pPrimitiveType,
053: Properties pPrimitiveTypeProperties,
054: DataTypeTranslationMetadata.PrimitiveTranslator pPrimitiveTranslator,
055: DataTypeTranslationMetadata.XmlType pXmlType,
056: Properties pXmlTypeProperties,
057: DataTypeTranslationMetadata.XmlTranslator pXmlTranslator) {
058: // Validate that translators match types (good idea just to eliminate unexpected condition)
059: if (!ReflectionUtils.isSubtype(pSqlTranslator.getClass(),
060: pSqlType.getTranslatorType()))
061: throw new IllegalArgumentException(
062: "Datatype translation metadata instantiation error. Actual type of SqlConvertor does not match type of SqlConvertor declared in Sql type metadata.");
063: if (!ReflectionUtils.isSubtype(pPrimitiveTranslator.getClass(),
064: pPrimitiveType.getTranslatorType()))
065: throw new IllegalArgumentException(
066: "Datatype translation metadata instantiation error. Actual type of PrimitiveConvertor does not match type of PrimitiveConvertor declared in Primitive type metadata.");
067: if (!ReflectionUtils.isSubtype(pXmlTranslator.getClass(),
068: pXmlType.getTranslatorType()))
069: throw new IllegalArgumentException(
070: "Datatype translation metadata instantiation error. Actual type of XmlConvertor does not match type of XmlConvertor declared in Xml type metadata.");
071: mSqlType = pSqlType;
072: mSqlTypeProperties = pSqlTypeProperties != null ? pSqlTypeProperties
073: : new Properties();
074: mSqlTranslator = pSqlTranslator;
075: mPrimitiveType = pPrimitiveType;
076: mPrimitiveTypeProperties = pPrimitiveTypeProperties != null ? pPrimitiveTypeProperties
077: : new Properties();
078: mPrimitiveTranslator = pPrimitiveTranslator;
079: mXmlType = pXmlType;
080: mXmlTypeProperties = pXmlTypeProperties != null ? pXmlTypeProperties
081: : new Properties();
082: mXmlTranslator = pXmlTranslator;
083: }
084:
085: /** Hidden default constructor */
086: private DefaultDataTypeTranslationMetadataImplementation() {
087: }
088:
089: /** Returns the SqlType associated with the datatype. */
090: public DataTypeTranslationMetadata.SqlType getSqlType() {
091: return mSqlType;
092: }
093:
094: /** Returns the property bag pertained to particular SqlType. */
095: public Properties getSqlTypeProperties() {
096: return mSqlTypeProperties;
097: }
098:
099: /** Returns the SqlTranslator for the datatype. */
100: public DataTypeTranslationMetadata.SqlTranslator getSqlTranslator() {
101: return mSqlTranslator;
102: }
103:
104: /** Returns the class describing the primitive supported by the datatype. */
105: public DataTypeTranslationMetadata.PrimitiveType getPrimitiveType() {
106: return mPrimitiveType;
107: }
108:
109: /** Returns the property bag pertained to particular PrimitiveType. */
110: public Properties getPrimitiveTypeProperties() {
111: return mPrimitiveTypeProperties;
112: }
113:
114: /** Returns the PrimitiveTranslator for the datatype. */
115: public DataTypeTranslationMetadata.PrimitiveTranslator getPrimitiveTranslator() {
116: return mPrimitiveTranslator;
117: }
118:
119: /** Returns the class describing the xml type supported by the datatype. */
120: public DataTypeTranslationMetadata.XmlType getXmlType() {
121: return mXmlType;
122: }
123:
124: /** Returns the property bag pertained to particular XmlType. */
125: public Properties getXmlTypeProperties() {
126: return mXmlTypeProperties;
127: }
128:
129: /** Returns the PrimitiveTranslator for the datatype. */
130: public DataTypeTranslationMetadata.XmlTranslator getXmlTranslator() {
131: return mXmlTranslator;
132: }
133: }
|