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

Save This Page
Home » jdo2-model-2.3-ea-src » org.apache.jdo.impl.model.jdo » [javadoc | source]