View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.impl.model.java;
18  
19  import org.apache.jdo.model.java.JavaField;
20  import org.apache.jdo.model.java.JavaProperty;
21  import org.apache.jdo.model.java.JavaType;
22  import org.apache.jdo.model.jdo.JDOClass;
23  
24  /***
25   * Abstract super class for JavaType implementations. It provides a
26   * default implementation for all methods except getName. The methods return
27   * the Java default value of the return type. 
28   * <p>
29   * A non-abstract subclass must implement method {@link #getName()} and
30   * needs to override any of the other methods where the default
31   * implementation is not appropriate.
32   * <p>
33   * Note, the class implements methods {@link #equals(Object obj)},
34   * {@link #hashCode()} and {@link #toString()}using the name of a JavaType.
35   *
36   * @author Michael Bouschen
37   * @since JDO 1.0.1
38   * @version JDO 2.0
39   */
40  abstract public class AbstractJavaType
41      implements JavaType 
42  {
43      public Object getUnderlyingObject() { return null; }
44      public boolean isPrimitive() { return false; }
45      public boolean isIntegral()  { return false; }
46      public boolean isFloatingPoint() { return false; }
47      public boolean isInterface()  { return false; }
48      public boolean isArray()      { return false; }
49      public boolean isWrapperClass() { return false; }
50      public boolean isJDOSupportedCollection() { return false; }
51      public boolean isJDOSupportedMap() { return false; }
52      public boolean isTrackable()  { return false; }
53      public boolean isValue() { return false; }
54      public boolean isOrderable() { return false; }
55      public boolean isPersistenceCapable() { return false; }
56      public boolean isCompatibleWith(JavaType javaType) { return false; }
57      abstract public String getName();
58      public int getModifiers() { return 0; }
59      public JavaType getSuperclass() { return null; }
60      public JDOClass getJDOClass() { return null; }
61      public JavaType getArrayComponentType() { return null; }
62      public JavaField getJavaField(String name) { return null; }
63      public JavaField[] getDeclaredJavaFields() { return null; }
64      public JavaProperty getJavaProperty(String name) { return null; }
65      public JavaProperty[] getDeclaredJavaProperties() { return null; }
66      
67      // ===== Methods not defined in JavaType =====
68  
69      /***
70       * Indicates whether some other object is "equal to" this one.
71       * @param obj the reference object with which to compare. 
72       * <p>
73       * This implementation compares the name of the specified object to be
74       * equal to the name of this JavaType.
75       * this 
76       * @return <code>true</code> if this object is the same as the obj
77       * argument; <code>false</code> otherwise. 
78       */
79      public boolean equals(Object obj)
80      {
81          // return true if obj is this
82          if (obj == this) return  true;
83          // return false if obj does not have the correct type
84          if ((obj == null) || !(obj instanceof JavaType)) return false;
85  
86          JavaType other = (JavaType)obj;
87          // compare names
88          String name = getName();
89          if (name == null) return other.getName() == null;
90          return name.equals(other.getName());
91      }
92      
93      /***
94       * Returns a hash code value for the object. 
95       * <p>
96       * This implementation returns the hashCode of the name of this
97       * JavaType. 
98       * @return a hash code value for this object.
99       */
100     public int hashCode()
101     {
102         String name = getName();
103         return (name == null) ? 0 : name.hashCode();
104     }
105     
106     /***
107      * Returns a string representation of the object. 
108      * @return a string representation of the object.
109      */
110     public String toString()
111     {
112         return getName();
113     }
114 }