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;
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 property
29   * of a persistence capable class. This dynamic implementation only
30   * stores values explicitly set by setter method. 
31   *
32   * @author Michael Bouschen
33   * @since 2.0
34   * @version 2.0
35   */
36  public class JDOPropertyImplDynamic
37      extends JDOFieldImplDynamic
38      implements JDOProperty
39  {
40      /*** Constructor. */
41      protected JDOPropertyImplDynamic(String name, JDOClass declaringClass) {
42          super(name, declaringClass);
43      }
44  
45      // ===== methods specified in JDOField =====
46  
47      /***
48       * Get the corresponding JavaField representation for this JDOProperty.
49       * @return the corresponding JavaProperty representation
50       */
51      public JavaField getJavaField() {
52          if (javaField != null) {
53              // return java field, if explicitly set by the setter
54              return javaField;
55          }
56          
57          // not set => calculate
58          JavaType javaType = getDeclaringClass().getJavaType();
59          return javaType.getJavaProperty(getName());
60      }
61  
62      /***
63       * Sets the corresponding JavaProperty representation for this JDOProperty.
64       * @param javaField the corresponding JavaProperty representation
65       * @throws ModelException if impossible
66       */
67      public void setJavaField(JavaField javaField) throws ModelException {
68          if (javaField instanceof JavaProperty) {
69              this.javaField = javaField;
70          }
71          else {
72              throw new ModelException(msg.msg(
73                  "EXC_InvalidJavaFieldForJDOProperty", javaField)); //NOI18N
74          }
75      }
76  
77      /***
78       * Convenience method to check whether this field represents a property.
79       * @return <code>true</code> if this field represents a property; 
80       * <code>false</code> otherwise
81       */
82      public boolean isProperty() {
83          return true;
84      }
85  
86      // ===== methods specified in JDOProperty =====
87  
88      /*** 
89       * Return the JDOField instance associated with this property, if
90       * available. If there is no JDOField instance associated, then the method
91       * returns <code>null</code>.
92       * <p>
93       * This implementation always retruns <code>null</code>.
94       * @return associated JDOField instance or <code>null</code> if not
95       * available.
96       */
97      public JDOField getAssociatedJDOField() {
98          return null;
99      }
100 }