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.jdo.JDOClass;
23  import org.apache.jdo.model.jdo.JDOField;
24  import org.apache.jdo.impl.model.jdo.JDOAssociatedPropertyImplDynamic;
25  
26  /***
27   * An instance of this class represents the JDO metadata of a managed property
28   * of a persistence capable class. This JDOProperty implementation is used for
29   * persistent properties with an associated JDOField. All JDOField getter
30   * methods delegate to the associated JDOField, except methods getName,
31   * getDeclaringClass and getJavaField. All JDOField setter method throw a
32   * ModelException to avoid changing the associated JDOField through this
33   * JDOProperty instance. This caching implementation caches any calculated
34   * value to avoid re-calculating it if it is requested again. 
35   *
36   * @author Michael Bouschen
37   * @since 2.0
38   * @version 2.0
39   */
40  public class JDOAssociatedPropertyImplCaching
41      extends JDOAssociatedPropertyImplDynamic
42  {
43      /*** Constructor. */
44      protected JDOAssociatedPropertyImplCaching(
45          String name, JDOClass declaringClass, JDOField associatedJDOField)
46          throws ModelException {
47          super(name, declaringClass, associatedJDOField);
48      }
49      
50      // ===== Methods specified in JDOField =====
51  
52      /***
53       * Get the corresponding JavaProperty representation for this JDOProperty.
54       * @return the corresponding JavaProperty representation
55       */
56      public JavaField getJavaField() {
57          if (javaProperty == null) {
58              javaProperty = (JavaProperty)super.getJavaField();
59          }
60          return javaProperty;
61      }
62  }