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.jdo.caching;
18  
19  import org.apache.jdo.model.ModelException;
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  import org.apache.jdo.model.jdo.JDOField;
25  import org.apache.jdo.model.jdo.JDOProperty;
26  
27  /***
28   * An instance of this class represents the JDO metadata of a managed field 
29   * of a persistence capable class. This dynamic implementation only
30   * stores property values explicitly set by setter method. 
31   * <p>
32   * Please note, you cannot rely on the Java identity of the
33   * JDORelationship instance returned by {@link #getRelationship}.  
34   * The getter will always return a new Java Instance, unless the
35   * relationship is explicitly set by the setter 
36   * {@link #setRelationship(JDORelationship relationship)}.
37   *
38   * @author Michael Bouschen
39   * @since 2.0
40   * @version 2.0
41   */
42  public class JDOPropertyImplCaching
43      extends JDOFieldImplCaching
44      implements JDOProperty
45  {
46      /*** */
47      protected JDOPropertyImplCaching(String name, JDOClass declaringClass) {
48          super(name, declaringClass);
49      }
50  
51      /***
52       * Get the corresponding JavaField representation for this JDOProperty.
53       * @return the corresponding JavaProperty representation
54       */
55      public JavaField getJavaField() {
56          if (javaField == null) {
57              // not set => calculate
58              // Please note, cannot call super.getJavaField, because it
59              // returns a JavaField!
60              JavaType javaType = getDeclaringClass().getJavaType();
61              javaField = javaType.getJavaProperty(getName());
62          }
63          return javaField;
64      }
65  
66      /***
67       * Sets the corresponding JavaProperty representation for this JDOProperty.
68       * @param javaField the corresponding JavaProperty representation
69       * @throws ModelException if impossible
70       */
71      public void setJavaField(JavaField javaField) throws ModelException {
72          if (javaField instanceof JavaProperty) {
73              this.javaField = javaField;
74          }
75          else {
76              throw new ModelException(msg.msg(
77                  "EXC_InvalidJavaFieldForJDOProperty", javaField)); //NOI18N
78          }
79      }
80  
81      /***
82       * Convenience method to check whether this field represents a property.
83       * @return <code>true</code> if this field represents a property; 
84       * <code>false</code> otherwise
85       */
86      public boolean isProperty() {
87          return true;
88      }
89  
90      /*** 
91       * Return the JDOField instance associated with this property, if
92       * available. If there is no JDOField instance associated, then the method
93       * returns <code>null</code>.
94       * <p>
95       * This implementation always retruns <code>null</code>.
96       * @return associated JDOField instance or <code>null</code> if not
97       * available.
98       */
99      public JDOField getAssociatedJDOField() {
100         return null;
101     }
102 }