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