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.JDOArray;
   25   import org.apache.jdo.model.jdo.JDOClass;
   26   import org.apache.jdo.model.jdo.JDOCollection;
   27   import org.apache.jdo.model.jdo.JDOField;
   28   import org.apache.jdo.model.jdo.JDOMap;
   29   import org.apache.jdo.model.jdo.JDOProperty;
   30   import org.apache.jdo.model.jdo.JDOReference;
   31   import org.apache.jdo.model.jdo.JDORelationship;
   32   import org.apache.jdo.util.I18NHelper;
   33   
   34   /**
   35    * An instance of this class represents the JDO metadata of a managed property
   36    * of a persistence capable class. This JDOProperty implementation is used for
   37    * persistent properties with an associated JDOField. All JDOField getter
   38    * methods delegate to the associated JDOField, except methods getName,
   39    * getDeclaringClass and getJavaField. All JDOField setter method throw a
   40    * ModelException to avoid changing the associated JDOField through this
   41    * JDOProperty instance. This dynamic implementation only stores values
   42    * explicitly set by setter method. 
   43    *
   44    * @author Michael Bouschen
   45    * @since 2.0
   46    * @version 2.0
   47    */
   48   public class JDOAssociatedPropertyImplDynamic
   49       extends JDOMemberImpl 
   50       implements JDOProperty
   51   {
   52       /** The associated JDOField instance. */
   53       private final JDOField associatedJDOField;
   54   
   55       /** The corresponding JavaProperty instance. */
   56       protected JavaProperty javaProperty;
   57   
   58      /** I18N support. */
   59       protected final static I18NHelper msg =  
   60           I18NHelper.getInstance(JDOAssociatedPropertyImplDynamic.class);
   61       
   62       /** Constrcutor. */
   63       protected JDOAssociatedPropertyImplDynamic(
   64           String name, JDOClass declaringClass, JDOField associatedJDOField)
   65           throws ModelException {
   66           super(name, declaringClass);
   67           this.associatedJDOField = associatedJDOField;
   68           if (associatedJDOField == null) {
   69               throw new ModelException(
   70                   msg.msg("EXC_InvalidNullAssociatedJDOField")); //NOI18N
   71           }
   72       }
   73       
   74       // ===== Methods specified in JDOField =====
   75   
   76       /**
   77        * Get the corresponding JavaProperty representation for this JDOProperty.
   78        * @return the corresponding JavaProperty representation
   79        */
   80       public JavaField getJavaField() {
   81           if (javaProperty != null) {
   82               // return javaProperty, if explicitly set by the setter
   83               return javaProperty;
   84           }
   85           
   86           // not set => calculate
   87           JavaType javaType = getDeclaringClass().getJavaType();
   88           return javaType.getJavaProperty(getName());
   89       }
   90   
   91       /**
   92        * Sets the corresponding JavaProperty representation for this JDOProperty.
   93        * @param javaField the corresponding JavaProperty representation
   94        * @throws ModelException if impossible
   95        */
   96       public void setJavaField(JavaField javaField) throws ModelException {
   97           
   98           if (javaField instanceof JavaProperty) {
   99               this.javaProperty = (JavaProperty)javaField;
  100           }
  101           else {
  102               throw new ModelException(msg.msg(
  103                   "EXC_InvalidJavaFieldForJDOProperty", javaField)); //NOI18N
  104           }
  105       }
  106   
  107       /**
  108        * Convenience method to check whether this field represents a property.
  109        * @return <code>true</code> if this field represents a property; 
  110        * <code>false</code> otherwise
  111        */
  112       public boolean isProperty() {
  113           return true;
  114       }
  115   
  116       // ===== Methods specified in JDOField delegate to associatedJDOField =====
  117   
  118       /** Deletegate to associatedJDOField. */
  119       public int getPersistenceModifier() {
  120           return associatedJDOField.getPersistenceModifier();
  121       }
  122   
  123       /** Throws ModelException. */
  124       public void setPersistenceModifier (int persistenceModifier)
  125           throws ModelException {
  126           throw new ModelException(
  127               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  128       }
  129       
  130       /** Deletegate to associatedJDOField. */
  131       public boolean isPrimaryKey() {
  132           return associatedJDOField.isPrimaryKey();
  133       }
  134       
  135       /** Throws ModelException. */
  136       public void setPrimaryKey(boolean primaryKey)
  137           throws ModelException {
  138           throw new ModelException(
  139               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  140       }
  141       
  142       /** Deletegate to associatedJDOField. */
  143       public int getNullValueTreatment() {
  144           return associatedJDOField.getNullValueTreatment();
  145       }
  146       
  147       /** Throws ModelException. */
  148       public void setNullValueTreatment(int nullValueTreament)
  149           throws ModelException {
  150           throw new ModelException(
  151               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  152       }
  153       
  154       /** Deletegate to associatedJDOField. */
  155       public boolean isDefaultFetchGroup() {
  156           return associatedJDOField.isDefaultFetchGroup();
  157       }
  158   
  159       /** Throws ModelException. */
  160       public void setDefaultFetchGroup(boolean defaultFetchGroup)
  161           throws ModelException {
  162           throw new ModelException(
  163               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  164       }
  165   
  166       /** Deletegate to associatedJDOField. */
  167       public boolean isEmbedded() {
  168           return associatedJDOField.isEmbedded();
  169       }
  170       
  171       /** Throws ModelException. */
  172       public void setEmbedded(boolean embedded)
  173           throws ModelException {
  174           throw new ModelException(
  175               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  176       }
  177   
  178       /** Deletegate to associatedJDOField. */
  179       public boolean isSerializable() {
  180           return associatedJDOField.isSerializable();
  181       }
  182   
  183       /** Throws ModelException. */
  184       public void setSerializable(boolean serializable)
  185           throws ModelException {
  186           throw new ModelException(
  187               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  188       }
  189   
  190       /** Deletegate to associatedJDOField. */
  191       public String getMappedByName() {
  192           return associatedJDOField.getMappedByName();
  193       }
  194   
  195       /** Throws ModelException. */
  196       public void setMappedByName(String mappedByName)
  197           throws ModelException {
  198           throw new ModelException (
  199               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  200       }
  201   
  202       /** Deletegate to associatedJDOField. */
  203       public JDORelationship getRelationship() {
  204           return associatedJDOField.getRelationship();
  205       }
  206   
  207       /** Throws ModelException. */
  208       public void setRelationship(JDORelationship relationship)
  209           throws ModelException {
  210           throw new ModelException(
  211               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  212       }
  213   
  214       /** Throws ModelException. */
  215       public JDOReference createJDOReference()
  216           throws ModelException {
  217           throw new ModelException(
  218               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  219       }
  220   
  221       /** Throws ModelException. */
  222       public JDOCollection createJDOCollection()
  223           throws ModelException {
  224           throw new ModelException(
  225               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  226       }
  227   
  228       /** Throws ModelException. */
  229       public JDOArray createJDOArray()
  230           throws ModelException {
  231           throw new ModelException(
  232               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  233       }
  234       
  235       /** Throws ModelException. */
  236       public JDOMap createJDOMap()
  237           throws ModelException {
  238           throw new ModelException(
  239               msg.msg("EXC_CannotModifyJDOProperty")); //NOI18N
  240       }
  241       
  242       /** Deletegate to associatedJDOField. */
  243       public boolean isPersistent() {
  244           return associatedJDOField.isPersistent();
  245       }
  246       
  247       /** Deletegate to associatedJDOField. */
  248       public boolean isTransactional() {
  249           return associatedJDOField.isTransactional();
  250       }
  251   
  252       /** Deletegate to associatedJDOField. */
  253       public boolean isManaged() {
  254           return associatedJDOField.isManaged();
  255       }
  256   
  257       /** Deletegate to associatedJDOField. */
  258       public boolean isRelationship() {
  259           return associatedJDOField.isRelationship();
  260       }
  261   
  262       /** Deletegate to associatedJDOField. */
  263       public JavaType getType() {
  264           return associatedJDOField.getType();
  265       }
  266   
  267       /** Deletegate to associatedJDOField. */
  268       public int getFieldNumber() {
  269           return associatedJDOField.getFieldNumber();
  270       }
  271   
  272       /** Deletegate to associatedJDOField. */
  273       public int getRelativeFieldNumber() {
  274           return associatedJDOField.getRelativeFieldNumber();
  275       }
  276   
  277       // ===== Methods specified in JDOProperty =====
  278   
  279       /** 
  280        * Return the JDOField instance associated with this property, if
  281        * available. If there is no JDOField instance associated, then the method
  282        * returns <code>null</code>.
  283        * @return associated JDOField instance or <code>null</code> if not
  284        * available.
  285        */
  286       public JDOField getAssociatedJDOField() {
  287           return associatedJDOField;
  288       }
  289   }

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