001: /*
002: Copyright (c) 2006, Dennis M. Sosnoski
003: All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without modification,
006: are permitted provided that the following conditions are met:
007:
008: * Redistributions of source code must retain the above copyright notice, this
009: list of conditions and the following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: * Neither the name of JiBX nor the names of its contributors may be used
014: to endorse or promote products derived from this software without specific
015: prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
018: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
019: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
021: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028:
029: package org.jibx.typeinfo;
030:
031: /**
032: * Descriptor for primitive "class". There's really nothing to record for a
033: * primitive type except the name and the actual type, so that's all this does.
034: */
035: public class PrimitiveTypeDescription extends TypeDescription {
036: public static final PrimitiveTypeDescription BOOLEAN_TYPE = new PrimitiveTypeDescription(
037: "Z", "boolean");
038: public static final PrimitiveTypeDescription BYTE_TYPE = new PrimitiveTypeDescription(
039: "B", "byte");
040: public static final PrimitiveTypeDescription CHAR_TYPE = new PrimitiveTypeDescription(
041: "C", "char");
042: public static final PrimitiveTypeDescription DOUBLE_TYPE = new PrimitiveTypeDescription(
043: "D", "double");
044: public static final PrimitiveTypeDescription FLOAT_TYPE = new PrimitiveTypeDescription(
045: "F", "float");
046: public static final PrimitiveTypeDescription INT_TYPE = new PrimitiveTypeDescription(
047: "I", "int");
048: public static final PrimitiveTypeDescription LONG_TYPE = new PrimitiveTypeDescription(
049: "J", "long");
050: public static final PrimitiveTypeDescription SHORT_TYPE = new PrimitiveTypeDescription(
051: "S", "short");
052: public static final PrimitiveTypeDescription VOID_TYPE = new PrimitiveTypeDescription(
053: "V", "void");
054:
055: /** Singleton instance of primitive type directory. */
056: private static final TypeDirectory s_instance;
057: static {
058: s_instance = new TypeDirectory();
059: s_instance.addType(BOOLEAN_TYPE);
060: s_instance.addType(BYTE_TYPE);
061: s_instance.addType(CHAR_TYPE);
062: s_instance.addType(DOUBLE_TYPE);
063: s_instance.addType(FLOAT_TYPE);
064: s_instance.addType(INT_TYPE);
065: s_instance.addType(LONG_TYPE);
066: s_instance.addType(SHORT_TYPE);
067: s_instance.addType(VOID_TYPE);
068: }
069:
070: /** External name for type. */
071: private final String m_externalName;
072:
073: /**
074: * Internal constructor.
075: *
076: * @param dtor descriptor
077: * @param xname external name
078: */
079: private PrimitiveTypeDescription(String dtor, String xname) {
080: super (dtor);
081: m_externalName = xname;
082: }
083:
084: //
085: // Base class overrides
086:
087: /* (non-Javadoc)
088: * @see org.jibx.typeinfo.TypeDescription#isPrimitive()
089: */
090: public boolean isPrimitive() {
091: return true;
092: }
093:
094: /* (non-Javadoc)
095: * @see org.jibx.typeinfo.TypeDescription#toString()
096: */
097: public String toString() {
098: return m_externalName;
099: }
100: }
|