You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2004/12/01 20:34:02 UTC

cvs commit: jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/expression DynaBeanUpdater.java

rdonkin     2004/12/01 11:34:02

  Added:       betwixt/src/java/org/apache/commons/betwixt/expression
                        DynaBeanUpdater.java
  Log:
  Improved introspection support for dynabeans
  
  Revision  Changes    Path
  1.1                  jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/expression/DynaBeanUpdater.java
  
  Index: DynaBeanUpdater.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */ 
  package org.apache.commons.betwixt.expression;
  
  import org.apache.commons.beanutils.DynaBean;
  import org.apache.commons.beanutils.DynaProperty;
  
  /**
   * Updates <code>DynaBean</code>'s.
   * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
   */
  public class DynaBeanUpdater extends TypedUpdater {
  
      /** The name of the dyna property to be updated */
      private final String propertyName;
      
      /**
       * Constructs a <code>DynaBeanUpdater</code>
       * for given <code>DynaProperty</code>.
       * @param dynaProperty <code>DyanProperty</code>, not null
       */
      public DynaBeanUpdater(DynaProperty dynaProperty) {
          this(dynaProperty.getName(), dynaProperty.getType());
      }
      
      /**
       * Constructs a <code>DynaBeanUpdater</code>
       * for the given type and property name.
       * @param propertyName name of the dyan property
       * @param type type of the dyna property
       */
      public DynaBeanUpdater(String propertyName, Class type) {
          this.propertyName = propertyName;
          setValueType(type);
      }
      
      
      /**
       * Executes the update on the given code>DynaBean</code>
       * @see org.apache.commons.betwixt.expression.TypedUpdater#executeUpdate(java.lang.Object, java.lang.Object)
       */
      protected void executeUpdate(Context context, Object bean, Object value) throws Exception {
          if (bean instanceof DynaBean)
          {
              DynaBean dynaBean = (DynaBean) bean;
              dynaBean.set(propertyName, value);
          }
          else
          {
              handleException(context, new IllegalArgumentException("DynaBean required."));
          }
      }
  
      /**
       * Outputs something suitable for logging.
       */
      public String toString() {
          return "DynaBeanUpdater [property=" + propertyName + "]";
      }
      
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org