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/form PropertySelection.java
Date Mon, 17 Mar 2003 03:20:18 GMT
hlship      2003/03/16 19:20:18

  Modified:    framework/src/org/apache/tapestry/enhance
                        DefaultComponentClassEnhancer.java
                        ComponentClassFactory.java
               framework/src/org/apache/tapestry/binding
                        ExpressionBinding.java
               framework/src/org/apache/tapestry TapestryStrings.properties
                        BindingException.java
               framework/src/org/apache/tapestry/valid FieldLabel.java
               framework/src/org/apache/tapestry/pageload PageLoader.java
               framework/src/org/apache/tapestry/form
                        PropertySelection.java
  Log:
  Tweak exceptions and exception location reporting.
  
  Revision  Changes    Path
  1.2       +13 -3     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultComponentClassEnhancer.java	5 Mar 2003 22:59:47 -0000	1.1
  +++ DefaultComponentClassEnhancer.java	17 Mar 2003 03:20:17 -0000	1.2
  @@ -58,6 +58,7 @@
   import java.util.HashMap;
   import java.util.Map;
   
  +import org.apache.tapestry.ApplicationRuntimeException;
   import org.apache.tapestry.IResourceResolver;
   import org.apache.tapestry.engine.IComponentClassEnhancer;
   import org.apache.tapestry.spec.ComponentSpecification;
  @@ -125,7 +126,7 @@
   
       protected synchronized Class getCachedClass(ComponentSpecification specification)
       {
  -        return(Class) _cachedClasses.get(specification);
  +        return (Class) _cachedClasses.get(specification);
       }
   
       /**
  @@ -136,7 +137,16 @@
   
       protected Class constructComponentClass(ComponentSpecification specification, String
className)
       {
  -        Class result = _resolver.findClass(className);
  +        Class result = null;
  +
  +        try
  +        {
  +           result = _resolver.findClass(className);
  +        }
  +        catch (Exception ex)
  +        {
  +            throw new ApplicationRuntimeException(ex.getMessage(), specification.getLocation(),
ex);
  +        }
   
           ComponentClassFactory factory = createComponentClassFactory(specification, result);
   
  
  
  
  1.3       +49 -33    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ComponentClassFactory.java	11 Mar 2003 15:24:15 -0000	1.2
  +++ ComponentClassFactory.java	17 Mar 2003 03:20:17 -0000	1.3
  @@ -68,6 +68,7 @@
   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;
  @@ -137,31 +138,31 @@
       {
           recordType("boolean", boolean.class, Type.BOOLEAN);
           recordType("boolean[]", boolean[].class, new ArrayType(Type.BOOLEAN, 1));
  -        
  +
           recordType("short", short.class, Type.SHORT);
           recordType("short[]", short[].class, new ArrayType(Type.SHORT, 1));
  -        
  +
           recordType("int", int.class, Type.INT);
           recordType("int[]", int[].class, new ArrayType(Type.INT, 1));
  -        
  +
           recordType("long", long.class, Type.LONG);
           recordType("long[]", long[].class, new ArrayType(Type.LONG, 1));
  -        
  +
           recordType("float", float.class, Type.FLOAT);
           recordType("float[]", float[].class, new ArrayType(Type.FLOAT, 1));
  -        
  +
           recordType("double", double.class, Type.DOUBLE);
           recordType("double[]", double[].class, new ArrayType(Type.DOUBLE, 1));
  -        
  +
           recordType("char", char.class, Type.CHAR);
           recordType("char[]", char[].class, new ArrayType(Type.CHAR, 1));
  -        
  +
           recordType("byte", byte.class, Type.BYTE);
           recordType("byte[]", byte.class, new ArrayType(Type.BYTE, 1));
  -        
  +
           recordType("java.lang.Object", Object.class, Type.OBJECT);
           recordType("java.lang.Object[]", Object[].class, new ArrayType(Type.OBJECT, 1));
  -        
  +
           recordType("java.lang.String", String.class, Type.STRING);
           recordType("java.lang.String[]", String[].class, new ArrayType(Type.STRING, 1));
       }
  @@ -324,13 +325,24 @@
           return Modifier.isAbstract(m.getModifiers());
       }
   
  -    protected Class convertPropertyType(String type)
  +    protected Class convertPropertyType(String type, Location location)
       {
           Class result = (Class) _typeMap.get(type);
   
           if (result == null)
           {
  -            result = _resolver.findClass(type);
  +            try
  +            {
  +
  +                result = _resolver.findClass(type);
  +            }
  +            catch (Exception ex)
  +            {
  +                throw new ApplicationRuntimeException(
  +                    Tapestry.getString("ComponentClassFactory.bad-property-type", type),
  +                    location,
  +                    ex);
  +            }
   
               _typeMap.put(type, result);
           }
  @@ -496,9 +508,13 @@
          * 
          **/
   
  -    protected void createProperty(String propertyName, String type, boolean persistent)
  +    protected void createProperty(
  +        String propertyName,
  +        String type,
  +        boolean persistent,
  +        Location location)
       {
  -        Class propertyType = convertPropertyType(type);
  +        Class propertyType = convertPropertyType(type, location);
   
           String readMethodName = checkAccessors(propertyName, propertyType);
   
  @@ -540,7 +556,7 @@
           if (LOG.isDebugEnabled())
               LOG.debug("Establishing connected parameter property " + propertyName);
   
  -        createProperty(propertyName, ps.getType(), false);
  +        createProperty(propertyName, ps.getType(), false, ps.getLocation());
       }
   
       /**
  @@ -555,7 +571,7 @@
           if (LOG.isDebugEnabled())
               LOG.debug("Establishing specified property " + propertyName);
   
  -        createProperty(propertyName, ps.getType(), ps.isPersistent());
  +        createProperty(propertyName, ps.getType(), ps.isPersistent(), ps.getLocation());
       }
   
       /**
  @@ -597,7 +613,7 @@
           return result;
       }
   
  -    private void createParameterBindingProperty(String parameterName)
  +    private void createParameterBindingProperty(String parameterName, Location location)
       {
           String propertyName = parameterName + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
   
  @@ -607,15 +623,15 @@
           if (LOG.isDebugEnabled())
               LOG.debug("Establishing parameter binding property " + propertyName);
   
  -        createProperty(propertyName, IBinding.class.getName(), false);
  +        createProperty(propertyName, IBinding.class.getName(), false, location);
       }
   
  -	/**
  -	 *  Creates any properties related to
  -	 *  {@link org.apache.tapestry.spec.PropertySpecification property specifications}.
  -	 * 
  -	 **/
  -	
  +    /**
  +     *  Creates any properties related to
  +     *  {@link org.apache.tapestry.spec.PropertySpecification property specifications}.
  +     * 
  +     **/
  +
       protected void createPropertySpecificationEnhancements()
       {
           List names = _specification.getPropertySpecificationNames();
  @@ -631,13 +647,13 @@
           }
       }
   
  -	/**
  -	 *  Creates new properties related to formal parameters.  This is one
  -	 *  property to store the binding, and a second property if the parameter
  -	 *  is connected.
  -	 * 
  -	 **/
  -	
  +    /**
  +     *  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()
       {
           List names = _specification.getParameterNames();
  @@ -647,9 +663,9 @@
           {
               String name = (String) names.get(i);
   
  -            createParameterBindingProperty(name);
  -
               ParameterSpecification ps = _specification.getParameter(name);
  +
  +            createParameterBindingProperty(name, ps.getLocation());
   
               createConnectedParameterProperty(ps);
           }
  
  
  
  1.3       +12 -5     jakarta-tapestry/framework/src/org/apache/tapestry/binding/ExpressionBinding.java
  
  Index: ExpressionBinding.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/binding/ExpressionBinding.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExpressionBinding.java	15 Mar 2003 21:22:15 -0000	1.2
  +++ ExpressionBinding.java	17 Mar 2003 03:20:17 -0000	1.3
  @@ -57,6 +57,8 @@
   
   import java.util.Map;
   
  +import ognl.Ognl;
  +import ognl.OgnlException;
   import org.apache.tapestry.BindingException;
   import org.apache.tapestry.IComponent;
   import org.apache.tapestry.IResourceResolver;
  @@ -66,8 +68,6 @@
   import org.apache.tapestry.spec.BeanSpecification;
   import org.apache.tapestry.util.StringSplitter;
   import org.apache.tapestry.util.prop.OgnlUtils;
  -import ognl.Ognl;
  -import ognl.OgnlException;
   
   /**
    *  Implements a dynamic binding, based on getting and fetching
  @@ -312,7 +312,14 @@
   
           _initialized = true;
   
  -        _parsedExpression = OgnlUtils.getParsedExpression(_expression);
  +        try
  +        {
  +            _parsedExpression = OgnlUtils.getParsedExpression(_expression);
  +        }
  +        catch (Exception ex)
  +        {
  +            throw new BindingException(ex.getMessage(), this, ex);
  +        }
   
           if (checkForConstant())
               return;
  @@ -546,7 +553,7 @@
           initialize();
   
           if (_invariant)
  -                  throw createReadOnlyBindingException(this);
  +            throw createReadOnlyBindingException(this);
   
           try
           {
  
  
  
  1.6       +4 -2      jakarta-tapestry/framework/src/org/apache/tapestry/TapestryStrings.properties
  
  Index: TapestryStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/TapestryStrings.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TapestryStrings.properties	15 Mar 2003 21:22:08 -0000	1.5
  +++ TapestryStrings.properties	17 Mar 2003 03:20:17 -0000	1.6
  @@ -170,6 +170,7 @@
   
   # net.sf.tapestry.enhance
   
  +ComponentClassFactory.bad-property-type=Unable to convert ''{0}'' to a property type.
   ComponentClassFactory.property-type-mismatch=Unable to enhance class {0} because it contains
property ''{1}'' of type {2}, not the expected type {3}.
   ComponentClassFactory.non-abstract-read=Unable to enhance class {0} because it implements
a non-abstract read method for property ''{1}''.
   ComponentClassFactory.non-abstract-write=Unable to enhance class {0} because it implements
a non-abstract write method for property ''{1}''.
  @@ -266,7 +267,8 @@
   PageLoader.page-not-allowed=Component {0} may not implement the IPage interface.
   PageLoader.class-not-page=Class {0} does not implement the IPage interface.
   PageLoader.unable-to-instantiate-component=Unable to instantiate component {0}: {1}
  -PageLoader.missing-asset=Unable to locate asset {0} (declared at {1}).
  +PageLoader.missing-asset=Unable to locate asset ''{0}'' of component {1} as {2}.
  +PageLoader.unable-to-initialize-property=Unable to initialize property {0} of {1}: {2}
   
   # net.sf.tapestry.parse
   
  
  
  
  1.3       +16 -2     jakarta-tapestry/framework/src/org/apache/tapestry/BindingException.java
  
  Index: BindingException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/BindingException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BindingException.java	15 Mar 2003 21:22:09 -0000	1.2
  +++ BindingException.java	17 Mar 2003 03:20:17 -0000	1.3
  @@ -84,7 +84,21 @@
           IBinding binding,
           Throwable rootCause)
       {
  -        super(message, component, binding.getLocation(), rootCause);
  +        this(message, component, null, binding, rootCause);
  +    }
  +
  +    public BindingException(
  +        String message,
  +        IComponent component,
  +        Location location,
  +        IBinding binding,
  +        Throwable rootCause)
  +    {
  +        super(
  +            message,
  +            component,
  +            Tapestry.findLocation(new Object[] { location, binding, component }),
  +            rootCause);
   
           _binding = binding;
       }
  
  
  
  1.3       +15 -7     jakarta-tapestry/framework/src/org/apache/tapestry/valid/FieldLabel.java
  
  Index: FieldLabel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/valid/FieldLabel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FieldLabel.java	15 Mar 2003 21:22:22 -0000	1.2
  +++ FieldLabel.java	17 Mar 2003 03:20:17 -0000	1.3
  @@ -56,7 +56,7 @@
   package org.apache.tapestry.valid;
   
   import org.apache.tapestry.AbstractComponent;
  -import org.apache.tapestry.ApplicationRuntimeException;
  +import org.apache.tapestry.BindingException;
   import org.apache.tapestry.IMarkupWriter;
   import org.apache.tapestry.IRequestCycle;
   import org.apache.tapestry.Tapestry;
  @@ -95,18 +95,26 @@
           IFormComponent field = getField();
           String displayName = getDisplayName();
   
  -        String finalDisplayName = (displayName != null) ? displayName : field.getDisplayName();
  +        if (displayName == null)
  +        {
  +            if (field == null)
  +                throw Tapestry.createRequiredParameterException(this, "field");
   
  -        if (finalDisplayName == null)
  -            throw new ApplicationRuntimeException(
  +            displayName = field.getDisplayName();
  +        }
  +
  +        if (displayName == null)
  +            throw new BindingException(
                   Tapestry.getString("FieldLabel.no-display-name", field.getExtendedId()),
  -                this);
  +                this,
  +                getBinding("field"),
  +                null);
   
           IValidationDelegate delegate = Form.get(cycle).getDelegate();
   
           delegate.writeLabelPrefix(field, writer, cycle);
   
  -        writer.print(finalDisplayName);
  +        writer.print(displayName);
   
           delegate.writeLabelSuffix(field, writer, cycle);
       }
  
  
  
  1.3       +59 -18    jakarta-tapestry/framework/src/org/apache/tapestry/pageload/PageLoader.java
  
  Index: PageLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/pageload/PageLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PageLoader.java	15 Mar 2003 21:22:24 -0000	1.2
  +++ PageLoader.java	17 Mar 2003 03:20:17 -0000	1.3
  @@ -339,7 +339,7 @@
                           name,
                           component.getExtendedId()),
                       component,
  -                    parameterSpec.getLocation(),
  +                    component.getLocation(),
                       null);
           }
   
  @@ -483,7 +483,7 @@
                           componentSpecification,
                           componentNamespace);
   
  -                component.setLocation(container.getLocation());
  +                component.setLocation(contained.getLocation());
   
                   // Add it, by name, to the container.
   
  @@ -519,6 +519,10 @@
   
               createPropertyInitializers(page, container, containerSpec);
           }
  +        catch (ApplicationRuntimeException ex)
  +        {
  +            throw ex;
  +        }
           catch (RuntimeException ex)
           {
               throw new ApplicationRuntimeException(
  @@ -584,7 +588,6 @@
           INamespace namespace)
       {
           IComponent result = null;
  -
           String className = spec.getComponentClassName();
   
           if (Tapestry.isNull(className))
  @@ -650,6 +653,7 @@
   
           String pageName = namespace.constructQualifiedName(name);
           String className = spec.getComponentClassName();
  +        Location location = spec.getLocation();
   
           if (Tapestry.isNull(className))
           {
  @@ -682,18 +686,20 @@
               result.setPageName(pageName);
               result.setPage(result);
               result.setLocale(_locale);
  -            result.setLocation(spec.getLocation());
  +            result.setLocation(location);
           }
           catch (ClassCastException ex)
           {
               throw new ApplicationRuntimeException(
                   Tapestry.getString("PageLoader.class-not-page", className),
  +                location,
                   ex);
           }
           catch (Exception ex)
           {
               throw new ApplicationRuntimeException(
                   Tapestry.getString("PageLoader.unable-to-instantiate", className),
  +                location,
                   ex);
           }
   
  @@ -794,7 +800,7 @@
           {
               String name = (String) i.next();
               AssetSpecification assetSpec = specification.getAsset(name);
  -            IAsset asset = convert(assetSpec, specLocation);
  +            IAsset asset = convert(name, component, assetSpec, specLocation);
   
               component.addAsset(name, asset);
           }
  @@ -830,17 +836,31 @@
               // property of the expression.  This may be null, or may be
               // a value set in finishLoad() (via an abstract accessor).
   
  -            if (Tapestry.isNull(expression))
  -            {
  -                initialValue = OgnlUtils.get(name, _resolver, component);
  -            }
  -            else
  +            try
               {
  -                // Evaluate the expression and update the property.
  +                if (Tapestry.isNull(expression))
  +                {
  +                    initialValue = OgnlUtils.get(name, _resolver, component);
  +                }
  +                else
  +                {
  +                    // Evaluate the expression and update the property.
   
  -                initialValue = OgnlUtils.get(expression, _resolver, component);
  +                    initialValue = OgnlUtils.get(expression, _resolver, component);
   
  -                OgnlUtils.set(name, _resolver, component, initialValue);
  +                    OgnlUtils.set(name, _resolver, component, initialValue);
  +                }
  +            }
  +            catch (Exception ex)
  +            {
  +                throw new ApplicationRuntimeException(
  +                    Tapestry.getString(
  +                        "PageLoader.unable-to-initialize-property",
  +                        name,
  +                        component,
  +                        ex.getMessage()),
  +                    ps.getLocation(),
  +                    ex);
               }
   
               PageDetachListener initializer =
  @@ -856,7 +876,11 @@
        *
        **/
   
  -    private IAsset convert(AssetSpecification spec, IResourceLocation specificationLocation)
  +    private IAsset convert(
  +        String assetName,
  +        IComponent component,
  +        AssetSpecification spec,
  +        IResourceLocation specificationLocation)
       {
           AssetType type = spec.getType();
           String path = spec.getPath();
  @@ -867,15 +891,25 @@
   
           if (type == AssetType.PRIVATE)
               return new PrivateAsset(
  -                (ClasspathResourceLocation) findAsset(specificationLocation, path, location),
  +                (ClasspathResourceLocation) findAsset(assetName,
  +                    component,
  +                    specificationLocation,
  +                    path,
  +                    location),
                   location);
   
           return new ContextAsset(
  -            (ContextResourceLocation) findAsset(_servletLocation, path, location),
  +            (ContextResourceLocation) findAsset(assetName,
  +                component,
  +                _servletLocation,
  +                path,
  +                location),
               location);
       }
   
       private IResourceLocation findAsset(
  +        String assetName,
  +        IComponent component,
           IResourceLocation baseLocation,
           String path,
           Location location)
  @@ -885,7 +919,14 @@
   
           if (localizedLocation == null)
               throw new ApplicationRuntimeException(
  -                Tapestry.getString("PageLoader.missing-asset", assetLocation, location));
  +                Tapestry.getString(
  +                    "PageLoader.missing-asset",
  +                    assetName,
  +                    component.getExtendedId(),
  +                    assetLocation),
  +                component,
  +                location,
  +                null);
   
           return localizedLocation;
       }
  
  
  
  1.3       +7 -3      jakarta-tapestry/framework/src/org/apache/tapestry/form/PropertySelection.java
  
  Index: PropertySelection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/form/PropertySelection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PropertySelection.java	15 Mar 2003 21:22:11 -0000	1.2
  +++ PropertySelection.java	17 Mar 2003 03:20:17 -0000	1.3
  @@ -58,6 +58,7 @@
   import org.apache.tapestry.IForm;
   import org.apache.tapestry.IMarkupWriter;
   import org.apache.tapestry.IRequestCycle;
  +import org.apache.tapestry.Tapestry;
   
   /**
    *  A component used to render a drop-down list of options that
  @@ -131,8 +132,8 @@
       {
           IForm form = getForm(cycle);
   
  -		updateDelegate(form);
  -		
  +        updateDelegate(form);
  +
           boolean rewinding = form.isRewinding();
   
           _name = form.getElementId(this);
  @@ -177,6 +178,9 @@
           writer.println();
   
           IPropertySelectionModel model = getModel();
  +
  +        if (model == null)
  +            throw Tapestry.createRequiredParameterException(this, "model");
   
           int count = model.getOptionCount();
           boolean foundSelected = false;
  
  
  

Mime
View raw message