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.JavaType;
20  
21  /***
22   * An instance of class NullType represents the type of the null expression
23   * in Java. It is compatible to all reference types.
24   * 
25   * @author Michael Bouschen
26   * @since JDO 1.0.1
27   */
28  public class NullType
29      extends AbstractJavaType
30  {
31      /*** The singleton NullType instance. */
32      public static final NullType nullType = new NullType();
33  
34      /*** 
35       * Creates new a NullType instance. This constructor should not be 
36       * called directly; instead, the singleton instance  {@link #nullType}
37       * should be used. 
38       */
39      protected NullType() {}
40  
41      /*** 
42       * Returns true if this JavaType is compatible with the specified
43       * JavaType. This implementation returns <code>true</code>, if the
44       * specified javaType is a not a primitive type, because the type of
45       * null is compatiple with all reference types.
46       * @param javaType the type this JavaType is checked with.
47       * @return <code>true</code> if this is compatible with the specified
48       * type; <code>false</code> otherwise.
49       */
50      public boolean isCompatibleWith(JavaType javaType)
51      {
52          return !javaType.isPrimitive();
53      }
54      
55      /*** 
56       * Returns the name of the type.  
57       * @return type name
58       */
59      public String getName()
60      {
61          return "<null type>"; //NOI18N
62      }
63  
64  }