You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/06/11 22:11:48 UTC

cvs commit: jakarta-tapestry/framework/src/java/org/apache/tapestry/bean LightweightBeanInitializer.java

hlship      2005/06/11 13:11:48

  Modified:    .        status.xml
               framework/src/java/org/apache/tapestry/parse
                        SpecificationParser.java
  Added:       framework/src/java/org/apache/tapestry/bean
                        LightweightBeanInitializer.java
  Log:
  TAPESTRY-321: Add lightweight initialization for managed beans.
  
  Revision  Changes    Path
  1.122     +1 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.121
  retrieving revision 1.122
  diff -u -r1.121 -r1.122
  --- status.xml	11 Jun 2005 20:04:13 -0000	1.121
  +++ status.xml	11 Jun 2005 20:11:47 -0000	1.122
  @@ -70,6 +70,7 @@
          <action type="fix" dev="HLS" fixes-bug="TAPESTRY-335">Injection uses actual type of injected object, which may not be available (due to AOP, or due to use of JDK Proxies).</action>
          <action type="add" dev="HLS">Add page listing the project voting history.</action>
          <action type="add" dev="HLS">Add annotation support (in tapestry-annotation module).</action>
  +       <action type="fix" dev="HLS" fixes-bug="TAPESTRY-321">Add lightweight initialization for managed beans.</action>
       </release>
       <release version="4.0-alpha-3" date="May 16 2005">
         <action type="add" dev="HLS">Add initial support for the validator: binding prefix.</action>
  
  
  
  1.29      +16 -1     jakarta-tapestry/framework/src/java/org/apache/tapestry/parse/SpecificationParser.java
  
  Index: SpecificationParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/parse/SpecificationParser.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- SpecificationParser.java	6 Jun 2005 22:28:19 -0000	1.28
  +++ SpecificationParser.java	11 Jun 2005 20:11:48 -0000	1.29
  @@ -38,6 +38,7 @@
   import org.apache.tapestry.INamespace;
   import org.apache.tapestry.Tapestry;
   import org.apache.tapestry.bean.BindingBeanInitializer;
  +import org.apache.tapestry.bean.LightweightBeanInitializer;
   import org.apache.tapestry.binding.BindingConstants;
   import org.apache.tapestry.binding.BindingSource;
   import org.apache.tapestry.coerce.ValueConverter;
  @@ -997,7 +998,15 @@
       private void enterBean()
       {
           String name = getValidatedAttribute("name", BEAN_NAME_PATTERN, "invalid-bean-name");
  -        String className = getAttribute("class");
  +
  +        String classAttribute = getAttribute("class");
  +
  +        // Look for the lightweight initialization
  +
  +        int commax = classAttribute.indexOf(',');
  +
  +        String className = commax < 0 ? classAttribute : classAttribute.substring(0, commax);
  +
           BeanLifecycle lifecycle = (BeanLifecycle) getConvertedAttribute(
                   "lifecycle",
                   BeanLifecycle.REQUEST);
  @@ -1012,6 +1021,12 @@
           bs.setLifecycle(lifecycle);
           bs.setPropertyName(propertyName);
   
  +        if (commax > 0)
  +        {
  +            String initializer = classAttribute.substring(commax + 1);
  +            bs.addInitializer(new LightweightBeanInitializer(initializer));
  +        }
  +
           IComponentSpecification cs = (IComponentSpecification) peekObject();
   
           cs.addBeanSpecification(name, bs);
  
  
  
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/bean/LightweightBeanInitializer.java
  
  Index: LightweightBeanInitializer.java
  ===================================================================
  // Copyright 2005 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.tapestry.bean;
  
  import org.apache.hivemind.ApplicationRuntimeException;
  import org.apache.hivemind.impl.BaseLocatable;
  import org.apache.hivemind.util.Defense;
  import org.apache.hivemind.util.PropertyUtils;
  import org.apache.tapestry.IBeanProvider;
  
  /**
   * Performs "lightweight" initialization of a bean; this is based on a term (and code) from
   * HiveMind, where the settings for a bean's properties are expressed as a single string.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class LightweightBeanInitializer extends BaseLocatable implements IBeanInitializer
  {
      private final String _initializer;
  
      public LightweightBeanInitializer(String initializer)
      {
          Defense.notNull(initializer, "initializer");
  
          _initializer = initializer;
      }
  
      public void setBeanProperty(IBeanProvider provider, Object bean)
      {
          try
          {
              PropertyUtils.configureProperties(bean, _initializer);
          }
          catch (Exception ex)
          {
              throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex);
          }
      }
  
      /**
       * Returns the initializer itself, rather than any single property name.
       */
      public String getPropertyName()
      {
          return _initializer;
      }
  
  }
  
  
  

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