tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-tapestry/framework/src/org/apache/tapestry/enhance IEnhancer.java CreatePropertyEnhancer.java DefaultComponentClassEnhancer.java ComponentClassFactory.java MethodFabricator.java ClassFabricator.java
Date Sun, 23 Mar 2003 01:26:41 GMT
hlship      2003/03/22 17:26:41

  Modified:    framework/src/org/apache/tapestry/enhance
                        DefaultComponentClassEnhancer.java
                        ComponentClassFactory.java MethodFabricator.java
                        ClassFabricator.java
  Added:       framework/src/org/apache/tapestry/enhance IEnhancer.java
                        CreatePropertyEnhancer.java
  Log:
  Refactor class enhancement to make it easier to extend in the future.
  
  Revision  Changes    Path
  1.3       +10 -1     jakarta-tapestry/framework/src/org/apache/tapestry/enhance/DefaultComponentClassEnhancer.java
  
  Index: DefaultComponentClassEnhancer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/enhance/DefaultComponentClassEnhancer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultComponentClassEnhancer.java	17 Mar 2003 03:20:17 -0000	1.2
  +++ DefaultComponentClassEnhancer.java	23 Mar 2003 01:26:41 -0000	1.3
  @@ -160,6 +160,15 @@
           return result;
       }
   
  +	/**
  +	 *  Constructs a new factory for enhancing the specified class. Advanced users
  +	 *  may want to provide thier own enhancements to classes and this method
  +	 *  is the hook that allows them to provide a subclass of
  +	 *  {@link org.apache.tapestry.enhance.ComponentClassFactory} adding those
  +	 *  enhancements.
  +	 * 
  +	 **/
  +	
       protected ComponentClassFactory createComponentClassFactory(
           ComponentSpecification specification,
           Class componentClass)
  
  
  
  1.7       +228 -221  jakarta-tapestry/framework/src/org/apache/tapestry/enhance/ComponentClassFactory.java
  
  Index: ComponentClassFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/enhance/ComponentClassFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ComponentClassFactory.java	17 Mar 2003 18:09:32 -0000	1.6
  +++ ComponentClassFactory.java	23 Mar 2003 01:26:41 -0000	1.7
  @@ -61,31 +61,31 @@
   import java.beans.PropertyDescriptor;
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
  +import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
   
  -import org.apache.tapestry.ApplicationRuntimeException;
  -import org.apache.tapestry.IBinding;
  -import org.apache.tapestry.IResourceResolver;
  -import org.apache.tapestry.Location;
  -import org.apache.tapestry.Tapestry;
  -import org.apache.tapestry.spec.ComponentSpecification;
  -import org.apache.tapestry.spec.Direction;
  -import org.apache.tapestry.spec.ParameterSpecification;
  -import org.apache.tapestry.spec.PropertySpecification;
   import org.apache.bcel.Constants;
   import org.apache.bcel.classfile.JavaClass;
   import org.apache.bcel.generic.ArrayType;
   import org.apache.bcel.generic.BasicType;
   import org.apache.bcel.generic.InstructionConstants;
   import org.apache.bcel.generic.InstructionFactory;
  -import org.apache.bcel.generic.InstructionList;
   import org.apache.bcel.generic.ObjectType;
   import org.apache.bcel.generic.PUSH;
   import org.apache.bcel.generic.Type;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.tapestry.ApplicationRuntimeException;
  +import org.apache.tapestry.IBinding;
  +import org.apache.tapestry.IResourceResolver;
  +import org.apache.tapestry.Location;
  +import org.apache.tapestry.Tapestry;
  +import org.apache.tapestry.spec.ComponentSpecification;
  +import org.apache.tapestry.spec.Direction;
  +import org.apache.tapestry.spec.ParameterSpecification;
  +import org.apache.tapestry.spec.PropertySpecification;
   
   /**
    *  Contains the logic for analyzing and enhancing a single component class.
  @@ -119,6 +119,13 @@
       private String _subclassName;
   
       /**
  +     *  List of {@link IEnhancer}.
  +     * 
  +     **/
  +
  +    private List _enhancers;
  +
  +    /**
        *  Map of type (as Class), keyed on type name. 
        * 
        **/
  @@ -213,103 +220,37 @@
           }
       }
   
  -    private PropertyDescriptor getPropertyDescriptor(String name)
  +    protected PropertyDescriptor getPropertyDescriptor(String name)
       {
           return (PropertyDescriptor) _beanProperties.get(name);
       }
   
       /**
  -    *  Examines the specification, identifies if any enhancements will be needed.
  -    *  This implementation looks for the presence of any
  -    *  {@link org.apache.tapestry.spec.PropertySpecification}s, or any
  -    *  connected parameters where the property is missing or abstract.
  -    * 
  -    **/
  -
  -    public boolean needsEnhancement()
  -    {
  -        if (!_specification.getPropertySpecificationNames().isEmpty())
  -            return true;
  -
  -        if (checkParameters())
  -            return true;
  -
  -        return false;
  -    }
  -
  -    /**
  -     *  Checks the formal parameters, returns true if any connected parameter
  -     *  has a missing or abstract property, or any parameter has a 
  -     *  missing or abstract binding property.
  -     * 
  -     **/
  -
  -    private boolean checkParameters()
  -    {
  -        List names = _specification.getParameterNames();
  -        int count = names.size();
  -
  -        for (int i = 0; i < count; i++)
  -        {
  -            String name = (String) names.get(i);
  -            ParameterSpecification pspec = _specification.getParameter(name);
  -
  -            if (checkParameterProperty(name))
  -                return true;
  -
  -            if (checkConnectedParameter(pspec))
  -                return true;
  -        }
  -
  -        return false;
  -    }
  -
  -    /**
  -     *  Returns true if the parameter is connected (has a non-custom direction) and the
  -     *  corresponding property is either missing or abstract.
  +     *  Invokes {@link #scanForEnhancements()} to identify any
  +     *  enhancements needed on the class, returning true
  +     *  if there are any enhancements to be performed. 
        * 
        **/
   
  -    private boolean checkConnectedParameter(ParameterSpecification spec)
  +    public boolean needsEnhancement()
       {
  -        Direction direction = spec.getDirection();
  -
  -        if (direction == Direction.CUSTOM)
  -            return false;
  +        scanForEnhancements();
   
  -        String propertyName = spec.getPropertyName();
  -
  -        PropertyDescriptor d = getPropertyDescriptor(propertyName);
  -
  -        return isAbstract(d);
  +        return _enhancers != null;
       }
   
       /**
  -     *  Checks for a property that will store the
  -     *  {@link org.apache.tapestry.IBinding binding} for the (formal)
  -     *  parameter.
  -     *  
  -     *  <p>
  -     *  Returns false is present, true if missing or abstract.
  +     *  Returns true if the {@link PropertyDescriptor} is null, or
  +     *  (if non-null), if both accessor methods are abstract.
        * 
        **/
   
  -    private boolean checkParameterProperty(String parameterName)
  -    {
  -        String propertyName = parameterName + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
  -
  -        PropertyDescriptor d = getPropertyDescriptor(propertyName);
  -
  -        return isAbstract(d);
  -
  -    }
  -
  -    private boolean isAbstract(PropertyDescriptor d)
  +    public boolean isAbstract(PropertyDescriptor pd)
       {
  -        if (d == null)
  +        if (pd == null)
               return true;
   
  -        return isAbstract(d.getReadMethod()) && isAbstract(d.getWriteMethod());
  +        return isAbstract(pd.getReadMethod()) && isAbstract(pd.getWriteMethod());
       }
   
       /**
  @@ -317,7 +258,7 @@
        * 
        **/
   
  -    private boolean isAbstract(Method m)
  +    public boolean isAbstract(Method m)
       {
           if (m == null)
               return true;
  @@ -325,7 +266,17 @@
           return Modifier.isAbstract(m.getModifiers());
       }
   
  -    protected Class convertPropertyType(String type, Location location)
  +    /**
  +     *  Given a class name, returns the corresponding class.  In addition,
  +     *  scalar types, arrays of scalar types, java.lang.Object[] and
  +     *  java.lang.String[] are supported.
  +     * 
  +     *  @param type to convert to a Class
  +     *  @param location of the involved specification element (for exception reporting)
  +     * 
  +     **/
  +
  +    public Class convertPropertyType(String type, Location location)
       {
           Class result = (Class) _typeMap.get(type);
   
  @@ -350,7 +301,14 @@
           return result;
       }
   
  -    protected Type getObjectType(String type)
  +    /**
  +     *  Given the name of a class, returns the equivalent {@link Type}.  In addition,
  +     *  knows about scalar types, arrays of scalar types, java.lang.Object[] and
  +     *  java.lang.String[].
  +     * 
  +     **/
  +
  +    public Type getObjectType(String type)
       {
           Type result = (Type) _objectTypeMap.get(type);
   
  @@ -363,6 +321,11 @@
           return result;
       }
   
  +    /**
  +     *  Constructs an accessor method name.
  +     * 
  +     **/
  +
       protected String buildMethodName(String prefix, String propertyName)
       {
           StringBuffer result = new StringBuffer(prefix);
  @@ -376,6 +339,21 @@
           return result.toString();
       }
   
  +    protected void checkPropertyType(PropertyDescriptor pd, Class propertyType, Location
location)
  +    {
  +        if (!pd.getPropertyType().equals(propertyType))
  +            throw new ApplicationRuntimeException(
  +                Tapestry.getString(
  +                    "ComponentClassFactory.property-type-mismatch",
  +                    new Object[] {
  +                        _componentClass.getName(),
  +                        pd.getName(),
  +                        pd.getPropertyType().getName(),
  +                        propertyType.getName()}),
  +                location,
  +                null);
  +    }
  +
       /**
        *  Checks to see that that class either doesn't provide the property, or does
        *  but the accessor(s) are abstract.  Returns the name of the read accessor,
  @@ -392,41 +370,30 @@
           if (d == null)
               return null;
   
  -        if (!d.getPropertyType().equals(propertyType))
  -            throw new ApplicationRuntimeException(
  -                Tapestry.getString(
  -                    "ComponentClassFactory.property-type-mismatch",
  -                    new Object[] {
  -                        _componentClass.getName(),
  -                        propertyName,
  -                        d.getPropertyType().getName(),
  -                        propertyType.getName()}),
  -                location,
  -                null);
  +        checkPropertyType(d, propertyType, location);
   
  -        Method m = d.getWriteMethod();
  +        Method write = d.getWriteMethod();
  +        Method read = d.getReadMethod();
   
  -        if (!isAbstract(m))
  +        if (!isAbstract(write))
               throw new ApplicationRuntimeException(
                   Tapestry.getString(
                       "ComponentClassFactory.non-abstract-write",
  -                    m.getDeclaringClass().getName(),
  +                    write.getDeclaringClass().getName(),
                       propertyName),
                   location,
                   null);
   
  -        m = d.getReadMethod();
  -
  -        if (!isAbstract(m))
  +        if (!isAbstract(read))
               throw new ApplicationRuntimeException(
                   Tapestry.getString(
                       "ComponentClassFactory.non-abstract-read",
  -                    m.getDeclaringClass().getName(),
  +                    read.getDeclaringClass().getName(),
                       propertyName),
                   location,
                   null);
   
  -        return m == null ? null : m.getName();
  +        return read == null ? null : read.getName();
       }
   
       /**
  @@ -443,7 +410,17 @@
           return Type.OBJECT;
       }
   
  -    protected void createMutator(
  +    /**
  +     *  Creates a mutator (aka "setter") method.
  +     * 
  +     *  @param fieldType type of field value (and type of parameter value)
  +     *  @param fieldName name of field (not property!)
  +     *  @param propertyName name of property (used to construct method name)
  +     *  @param isPersistent if true, adds a call to fireObservedChange()
  +     * 
  +     **/
  +
  +    public void createMutator(
           Type fieldType,
           String fieldName,
           String propertyName,
  @@ -451,27 +428,29 @@
       {
           String methodName = buildMethodName("set", propertyName);
   
  +        if (LOG.isDebugEnabled())
  +            LOG.debug("Creating mutator: " + methodName);
  +
           MethodFabricator mf = _classFabricator.createMethod(methodName);
           mf.addArgument(fieldType, propertyName);
   
  -        InstructionList il = mf.getInstructionList();
           InstructionFactory factory = _classFabricator.getInstructionFactory();
   
  -        il.append(factory.createThis());
  -        il.append(factory.createLoad(fieldType, 1));
  -        il.append(factory.createPutField(_subclassName, fieldName, fieldType));
  +        mf.append(factory.createThis());
  +        mf.append(factory.createLoad(fieldType, 1));
  +        mf.append(factory.createPutField(_subclassName, fieldName, fieldType));
   
  -        // Persistent properties must invoke fireObservedChange
  +        // Persistent properties must invoke fireObservedChange()
   
           if (isPersistent)
           {
  -            il.append(factory.createThis());
  -            il.append(new PUSH(_classFabricator.getConstantPool(), propertyName));
  -            il.append(factory.createLoad(fieldType, 1));
  +            mf.append(factory.createThis());
  +            mf.append(new PUSH(_classFabricator.getConstantPool(), propertyName));
  +            mf.append(factory.createLoad(fieldType, 1));
   
               Type argumentType = convertToArgumentType(fieldType);
   
  -            il.append(
  +            mf.append(
                   factory.createInvoke(
                       _subclassName,
                       "fireObservedChange",
  @@ -480,12 +459,22 @@
                       Constants.INVOKEVIRTUAL));
           }
   
  -        il.append(InstructionConstants.RETURN);
  +        mf.append(InstructionConstants.RETURN);
   
           mf.commit();
       }
   
  -    protected void createAccessor(
  +    /**
  +     *  Creates an accessor (getter) method for the property.
  +     * 
  +     *  @param fieldType the return type for the method
  +     *  @param fieldName the name of the field (not the name of the property)
  +     *  @param propertyName the name of the property (used to build the name of the method)
  +     *  @param readMethodName if not null, the name of the method to use
  +     * 
  +     **/
  +
  +    public void createAccessor(
           Type fieldType,
           String fieldName,
           String propertyName,
  @@ -494,46 +483,21 @@
           String methodName =
               readMethodName == null ? buildMethodName("get", propertyName) : readMethodName;
   
  +        if (LOG.isDebugEnabled())
  +            LOG.debug("Creating accessor: " + methodName);
  +
           MethodFabricator mf =
               _classFabricator.createMethod(Constants.ACC_PUBLIC, fieldType, methodName);
   
  -        InstructionList il = mf.getInstructionList();
           InstructionFactory factory = _classFabricator.getInstructionFactory();
   
  -        il.append(factory.createThis());
  -        il.append(factory.createGetField(_subclassName, fieldName, fieldType));
  -        il.append(factory.createReturn(fieldType));
  +        mf.append(factory.createThis());
  +        mf.append(factory.createGetField(_subclassName, fieldName, fieldType));
  +        mf.append(factory.createReturn(fieldType));
   
           mf.commit();
       }
   
  -    /**
  -       *  Checks that the superclass provides
  -       *  either abstract accessors or none at all.  Creates the file, creates 
  -       *  the accessors, creates initialization code.
  -       * 
  -       **/
  -
  -    protected void createProperty(
  -        String propertyName,
  -        String type,
  -        boolean persistent,
  -        Location location)
  -    {
  -        Class propertyType = convertPropertyType(type, location);
  -
  -        String readMethodName = checkAccessors(propertyName, propertyType, location);
  -
  -        String fieldName = "_$" + propertyName;
  -
  -        Type fieldType = getObjectType(type);
  -
  -        _classFabricator.addField(fieldType, fieldName);
  -
  -        createAccessor(fieldType, fieldName, propertyName, readMethodName);
  -        createMutator(fieldType, fieldName, propertyName, persistent);
  -    }
  -
       protected boolean isMissingProperty(String propertyName)
       {
           PropertyDescriptor pd = getPropertyDescriptor(propertyName);
  @@ -542,45 +506,6 @@
       }
   
       /**
  -     *  Creates a property for a connected
  -     *  parameter from a parameter specification.
  -     * 
  -     **/
  -
  -    protected void createConnectedParameterProperty(ParameterSpecification ps)
  -    {
  -        if (ps.getDirection() == Direction.CUSTOM)
  -            return;
  -
  -        String propertyName = ps.getPropertyName();
  -
  -        // Yes, but does it *need* a property created?
  -
  -        if (!isMissingProperty(propertyName))
  -            return;
  -
  -        if (LOG.isDebugEnabled())
  -            LOG.debug("Establishing connected parameter property " + propertyName);
  -
  -        createProperty(propertyName, ps.getType(), false, ps.getLocation());
  -    }
  -
  -    /**
  -     *  Invoked to create a specified property. 
  -     * 
  -     **/
  -
  -    protected void createSpecifiedProperty(PropertySpecification ps)
  -    {
  -        String propertyName = ps.getName();
  -
  -        if (LOG.isDebugEnabled())
  -            LOG.debug("Establishing specified property " + propertyName);
  -
  -        createProperty(propertyName, ps.getType(), ps.isPersistent(), ps.getLocation());
  -    }
  -
  -    /**
        *  Invoked by {@link org.apache.tapestry.enhance.DefaultComponentClassEnhancer} to
        *  create, as a {@link org.apache.bcel.classfile.JavaClass}, an enahanced
        *  subclass of the component class.  This means creating a default constructor,
  @@ -607,9 +532,14 @@
   
           _classFabricator.addDefaultConstructor();
   
  -        createPropertySpecificationEnhancements();
  +        int count = _enhancers.size();
  +
  +        for (int i = 0; i < count; i++)
  +        {
  +            IEnhancer enhancer = (IEnhancer) _enhancers.get(i);
   
  -        createParameterEnhancements();
  +            enhancer.performEnhancement(this);
  +        }
   
           JavaClass result = _classFabricator.commit();
   
  @@ -619,61 +549,138 @@
           return result;
       }
   
  -    private void createParameterBindingProperty(String parameterName, Location location)
  +    protected void addEnhancer(IEnhancer enhancer)
       {
  -        String propertyName = parameterName + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
  +        if (_enhancers == null)
  +            _enhancers = new ArrayList();
   
  -        if (!isMissingProperty(propertyName))
  -            return;
  +        _enhancers.add(enhancer);
  +    }
   
  -        if (LOG.isDebugEnabled())
  -            LOG.debug("Establishing parameter binding property " + propertyName);
  +    /**
  +     *  Invoked by {@link #needsEnhancement()} to find any enhancements
  +     *  that may be needed.  Should create an {@link org.apache.tapestry.enhance.IEnhancer}
  +     *  for each one, and add it to the queue using {@link #addEnhancer(IEnhancer)}.
  +     * 
  +     **/
   
  -        createProperty(propertyName, IBinding.class.getName(), false, location);
  +    protected void scanForEnhancements()
  +    {
  +        scanForParameterEnhancements();
  +        scanForSpecifiedPropertyEnhancements();
       }
   
       /**
  -     *  Creates any properties related to
  -     *  {@link org.apache.tapestry.spec.PropertySpecification property specifications}.
  +     *  Invoked by {@link #scanForEnhancements()} to locate
  +     *  any enhancements needed for component parameters (this includes
  +     *  binding properties and connected parameter property).
        * 
        **/
   
  -    protected void createPropertySpecificationEnhancements()
  +    protected void scanForParameterEnhancements()
       {
  -        List names = _specification.getPropertySpecificationNames();
  +        List names = _specification.getParameterNames();
           int count = names.size();
   
           for (int i = 0; i < count; i++)
           {
               String name = (String) names.get(i);
   
  -            PropertySpecification ps = _specification.getPropertySpecification(name);
  +            ParameterSpecification ps = _specification.getParameter(name);
   
  -            createSpecifiedProperty(ps);
  +            scanForBindingProperty(name, ps);
  +
  +            scanForParameterProperty(ps);
           }
  -    }
   
  -    /**
  -     *  Creates new properties related to formal parameters.  This is one
  -     *  property to store the binding, and a second property if the parameter
  -     *  is connected.
  -     * 
  -     **/
  +    }
   
  -    protected void createParameterEnhancements()
  +    protected void scanForSpecifiedPropertyEnhancements()
       {
  -        List names = _specification.getParameterNames();
  +        List names = _specification.getPropertySpecificationNames();
           int count = names.size();
   
           for (int i = 0; i < count; i++)
           {
               String name = (String) names.get(i);
   
  -            ParameterSpecification ps = _specification.getParameter(name);
  -
  -            createParameterBindingProperty(name, ps.getLocation());
  +            PropertySpecification ps = _specification.getPropertySpecification(name);
   
  -            createConnectedParameterProperty(ps);
  +            scanForSpecifiedProperty(ps);
           }
       }
  +
  +    protected void scanForBindingProperty(String parameterName, ParameterSpecification
ps)
  +    {
  +        String propertyName = parameterName + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
  +        PropertyDescriptor pd = getPropertyDescriptor(propertyName);
  +
  +        if (!isAbstract(pd))
  +            return;
  +
  +        // Need to create the property.
  +
  +        Type propertyType = getObjectType(IBinding.class.getName());
  +
  +        IEnhancer enhancer =
  +            new CreatePropertyEnhancer(propertyName, propertyType, ps.getLocation());
  +
  +        addEnhancer(enhancer);
  +    }
  +
  +    protected void scanForParameterProperty(ParameterSpecification ps)
  +    {
  +        if (ps.getDirection() == Direction.CUSTOM)
  +            return;
  +
  +        String propertyName = ps.getPropertyName();
  +
  +        // Yes, but does it *need* a property created?
  +
  +        if (!isMissingProperty(propertyName))
  +            return;
  +
  +        Location location = ps.getLocation();
  +
  +        Class propertyType = convertPropertyType(ps.getType(), location);
  +
  +        String readMethodName = checkAccessors(propertyName, propertyType, location);
  +
  +        Type fieldType = getObjectType(ps.getType());
  +
  +        IEnhancer enhancer =
  +            new CreatePropertyEnhancer(propertyName, fieldType, readMethodName, false,
location);
  +
  +        addEnhancer(enhancer);
  +    }
  +
  +    protected void scanForSpecifiedProperty(PropertySpecification ps)
  +    {
  +        String propertyName = ps.getName();
  +        Location location = ps.getLocation();
  +        Class propertyType = convertPropertyType(ps.getType(), location);
  +
  +        String readMethodName = checkAccessors(propertyName, propertyType, location);
  +
  +        Type fieldType = getObjectType(ps.getType());
  +
  +        IEnhancer enhancer =
  +            new CreatePropertyEnhancer(
  +                propertyName,
  +                fieldType,
  +                readMethodName,
  +                ps.isPersistent(),
  +                location);
  +
  +        addEnhancer(enhancer);
  +    }
  +
  +    public void createField(Type fieldType, String fieldName)
  +    {
  +        if (LOG.isDebugEnabled())
  +            LOG.debug("Creating field: " + fieldName);
  +
  +        _classFabricator.addField(fieldType, fieldName);
  +    }
  +
   }
  
  
  
  1.2       +23 -1     jakarta-tapestry/framework/src/org/apache/tapestry/enhance/MethodFabricator.java
  
  Index: MethodFabricator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/enhance/MethodFabricator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MethodFabricator.java	5 Mar 2003 22:59:48 -0000	1.1
  +++ MethodFabricator.java	23 Mar 2003 01:26:41 -0000	1.2
  @@ -61,6 +61,8 @@
   import org.apache.tapestry.Tapestry;
   import org.apache.bcel.classfile.Method;
   import org.apache.bcel.generic.ClassGen;
  +import org.apache.bcel.generic.CompoundInstruction;
  +import org.apache.bcel.generic.Instruction;
   import org.apache.bcel.generic.InstructionHandle;
   import org.apache.bcel.generic.InstructionList;
   import org.apache.bcel.generic.LocalVariableGen;
  @@ -161,6 +163,26 @@
       {
           return _instructionList;
       }
  +
  +    /**
  +     *  Convienience method for adding instructions.
  +     * 
  +     **/
  +
  +    public InstructionHandle append(Instruction instruction)
  +    {
  +        return _instructionList.append(instruction);
  +    }
  +
  +	/**
  +	 *  Convienience method for adding instructions.
  +	 * 
  +	 **/
  +	
  +	public InstructionHandle append(CompoundInstruction instruction)
  +	{
  +		return _instructionList.append(instruction);
  +	}
   
       /**
        *  Commits the method; this is invoked last.  It updates
  
  
  
  1.2       +1 -11     jakarta-tapestry/framework/src/org/apache/tapestry/enhance/ClassFabricator.java
  
  Index: ClassFabricator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/enhance/ClassFabricator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassFabricator.java	5 Mar 2003 22:59:48 -0000	1.1
  +++ ClassFabricator.java	23 Mar 2003 01:26:41 -0000	1.2
  @@ -195,16 +195,6 @@
       }
       
       /**
  -     *  Returns the fully qualified class name.
  -     * 
  -     **/
  -    
  -    public String getClassName()
  -    {
  -    	return _classGen.getClassName();
  -    }
  -    
  -    /**
        *  Returns the mutable constant pool.
        * 
        **/
  
  
  
  1.1                  jakarta-tapestry/framework/src/org/apache/tapestry/enhance/IEnhancer.java
  
  Index: IEnhancer.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation", "Tapestry" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" 
   *    or "Tapestry", nor may "Apache" or "Tapestry" appear in their 
   *    name, without prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.tapestry.enhance;
  
  /**
   *  Defines an object which may work with a 
   *  {@link org.apache.tapestry.enhance.ComponentClassFactory}
   *  to create an enhancement to a class.  These enhancements are
   *  typically in the form of adding new fields and methods.
   *
   *  @author Howard Lewis Ship
   *  @version $Id: IEnhancer.java,v 1.1 2003/03/23 01:26:41 hlship Exp $
   *  @since 2.4
   *
   **/
  
  public interface IEnhancer
  {
  	public void performEnhancement(ComponentClassFactory factory);
  }
  
  
  
  1.1                  jakarta-tapestry/framework/src/org/apache/tapestry/enhance/CreatePropertyEnhancer.java
  
  Index: CreatePropertyEnhancer.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation", "Tapestry" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" 
   *    or "Tapestry", nor may "Apache" or "Tapestry" appear in their 
   *    name, without prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.tapestry.enhance;
  
  import org.apache.bcel.generic.Type;
  import org.apache.tapestry.Location;
  
  public class CreatePropertyEnhancer implements IEnhancer
  {
      private String _propertyName;
      private Type _propertyType;
      private boolean _persistent;
      private String _readMethodName;
      private Location _location;
  
      public CreatePropertyEnhancer(String propertyName, Type propertyType, Location location)
      {
          this(propertyName, propertyType, null, false, location);
      }
  
      public CreatePropertyEnhancer(
          String propertyName,
          Type propertyType,
          String readMethodName,
          boolean persistent,
          Location location)
      {
          _propertyName = propertyName;
          _propertyType = propertyType;
          _readMethodName = readMethodName;
          _persistent = persistent;
          _location = location;
      }
  
      public void performEnhancement(ComponentClassFactory factory)
      {
          String fieldName = "_$" + _propertyName;
  
    		factory.createField(_propertyType, fieldName);
          factory.createAccessor(_propertyType, fieldName, _propertyName, _readMethodName);
          factory.createMutator(_propertyType, fieldName, _propertyName, _persistent);
      }
  
  }
  
  
  

Mime
View raw message