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