1 /** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Intalio, Inc. For written permission, 18 * please contact info@exolab.org. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Intalio, Inc. Exolab is a registered 23 * trademark of Intalio, Inc. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. 42 */ 43 package org.exolab.javasource; 44 45 /** 46 * Represents a primitive or class type. 47 * 48 * @author <a href="mailto:werner DOT guttmann AT gmx DOT net">Werner Guttmann</a> 49 * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a> 50 * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ 51 */ 52 public class JType { 53 //-------------------------------------------------------------------------- 54 55 /** JType for a boolean (Boolean). */ 56 public static final JPrimitiveType BOOLEAN = new JPrimitiveType("boolean", "java.lang.Boolean"); 57 58 /** JType instance for a byte (Byte). */ 59 public static final JPrimitiveType BYTE = new JPrimitiveType("byte", "java.lang.Byte"); 60 61 /** JType instance for a char (Char). */ 62 public static final JPrimitiveType CHAR = new JPrimitiveType("char", "java.lang.Character"); 63 64 /** JType instance for a double (Double). */ 65 public static final JPrimitiveType DOUBLE = new JPrimitiveType("double", "java.lang.Double"); 66 67 /** JType instance for a float (Float). */ 68 public static final JPrimitiveType FLOAT = new JPrimitiveType("float", "java.lang.Float"); 69 70 /** JType instance for a int (Integer). */ 71 public static final JPrimitiveType INT = new JPrimitiveType("int", "java.lang.Integer"); 72 73 /** JType instance for a long (Long). */ 74 public static final JPrimitiveType LONG = new JPrimitiveType("long", "java.lang.Long"); 75 76 /** JType instance for a short (Short). */ 77 public static final JPrimitiveType SHORT = new JPrimitiveType("short", "java.lang.Short"); 78 79 //-------------------------------------------------------------------------- 80 81 /** Fully qualified of the Java type represented. */ 82 private String _name = null; 83 84 //-------------------------------------------------------------------------- 85 86 /** 87 * Creates a new JType with the given name. 88 * 89 * @param name The name of the type. 90 */ 91 public JType(final String name) { 92 super(); 93 94 setName(name); 95 } 96 97 //-------------------------------------------------------------------------- 98 99 /** 100 * Returns the unqualified Java type name (i.e. without package). 101 * 102 * @return The unqualified Java type name. 103 */ 104 public final String getLocalName() { 105 // -- use getName method in case it's been overloaded 106 return JNaming.getLocalNameFromClassName(_name); 107 } 108 109 /** 110 * Returns the qualified Java type name. 111 * 112 * @return The qualified Java type name. 113 */ 114 public final String getName() { 115 return _name; 116 } 117 118 /** 119 * Returns true if this type represents an Array. 120 * 121 * @return True if this type represents an Array. 122 */ 123 public final boolean isArray() { 124 return (this instanceof JArrayType); 125 } 126 127 /** 128 * Returns true if this type represents a Java primitive type. 129 * 130 * @return True if this type represents a Java primitive type. 131 */ 132 public final boolean isPrimitive() { 133 return (this instanceof JPrimitiveType); 134 } 135 136 /** 137 * Sets the qualified name of this type. 138 * @param name the (qualified) name of the type 139 */ 140 protected void setName(final String name) { 141 this._name = name; 142 } 143 144 //-------------------------------------------------------------------------- 145 }