View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software 
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License.
16   */
17  
18  package org.apache.jdo.impl.model.jdo.caching;
19  
20  import org.apache.jdo.model.ModelException;
21  import org.apache.jdo.model.java.JavaField;
22  import org.apache.jdo.model.java.JavaProperty;
23  import org.apache.jdo.model.java.JavaType;
24  import org.apache.jdo.model.jdo.JDOClass;
25  import org.apache.jdo.model.jdo.JDOField;
26  import org.apache.jdo.model.jdo.JDOProperty;
27  
28  /***
29   * An instance of this class represents the JDO metadata of a managed field 
30   * of a persistence capable class. This dynamic implementation only
31   * stores property values explicitly set by setter method. 
32   * <p>
33   * Please note, you cannot rely on the Java identity of the
34   * JDORelationship instance returned by {@link #getRelationship}.  
35   * The getter will always return a new Java Instance, unless the
36   * relationship is explicitly set by the setter 
37   * {@link #setRelationship(JDORelationship relationship)}.
38   *
39   * @author Michael Bouschen
40   * @since 2.0
41   * @version 2.0
42   */
43  public class JDOPropertyImplCaching
44      extends JDOFieldImplCaching
45      implements JDOProperty
46  {
47      /*** */
48      protected JDOPropertyImplCaching(String name, JDOClass declaringClass) {
49          super(name, declaringClass);
50      }
51  
52      /***
53       * Get the corresponding JavaField representation for this JDOProperty.
54       * @return the corresponding JavaProperty representation
55       */
56      public JavaField getJavaField() {
57          if (javaField == null) {
58              // not set => calculate
59              // Please note, cannot call super.getJavaField, because it
60              // returns a JavaField!
61              JavaType javaType = getDeclaringClass().getJavaType();
62              javaField = javaType.getJavaProperty(getName());
63          }
64          return javaField;
65      }
66  
67      /***
68       * Sets the corresponding JavaProperty representation for this JDOProperty.
69       * @param javaField the corresponding JavaProperty representation
70       * @throws ModelException if impossible
71       */
72      public void setJavaField(JavaField javaField) throws ModelException {
73          if (javaField instanceof JavaProperty) {
74              this.javaField = javaField;
75          }
76          else {
77              throw new ModelException(msg.msg(
78                  "EXC_InvalidJavaFieldForJDOProperty", javaField)); //NOI18N
79          }
80      }
81  
82      /***
83       * Convenience method to check whether this field represents a property.
84       * @return <code>true</code> if this field represents a property; 
85       * <code>false</code> otherwise
86       */
87      public boolean isProperty() {
88          return true;
89      }
90  
91      /*** 
92       * Return the JDOField instance associated with this property, if
93       * available. If there is no JDOField instance associated, then the method
94       * returns <code>null</code>.
95       * <p>
96       * This implementation always retruns <code>null</code>.
97       * @return associated JDOField instance or <code>null</code> if not
98       * available.
99       */
100     public JDOField getAssociatedJDOField() {
101         return null;
102     }
103 }