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 2003/03/08 18:07:45 UTC

cvs commit: jakarta-tapestry/framework/src/org/apache/tapestry/html Image.java

hlship      2003/03/08 09:07:45

  Modified:    framework/src/org/apache/tapestry TapestryStrings.properties
                        IEngine.java
               framework/src/org/apache/tapestry/engine AbstractEngine.java
                        BaseEngine.java
               framework/src/org/apache/tapestry/html Image.java
  Log:
  Fix minor errors in AbstractEngine exception messages.
  Eliminate NPE in Image component when binding value is null.
  
  Revision  Changes    Path
  1.3       +2 -5      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TapestryStrings.properties	6 Mar 2003 17:19:32 -0000	1.2
  +++ TapestryStrings.properties	8 Mar 2003 17:07:45 -0000	1.3
  @@ -121,11 +121,10 @@
   AbstractEngine.unknown-service=Engine does not implement a service name {0}.
   AbstractEngine.unable-to-begin-request=Tapestry unable to begin processing request.
   AbstractEngine.unable-to-cleanup-page=Unable to cleanup page {0}.
  -AbstractEngine.visit-class-property-not-specified=Could not create visit object because property {0} was not configured.
   AbstractEngine.unable-to-instantiate-visit=Unable to instantiate visit object from class {0}.
   AbstractEngine.unable-to-instantiate-global=Unable to instantiate global object from class {0}.
   AbstractEngine.unable-to-redirect=Unable to redirect to {0}.
  -AbstractEngine.service-name-mismatch=Class {1} is registerred as service {0} but provides service {2} instead.
  +AbstractEngine.service-name-mismatch=Class {1} is registered as service {0} but provides service {2} instead.
   AbstractEngine.unable-to-instantiate-service=Unable to instantiate class {1} as service {0}.
   AbstractEngine.unable-to-find-dispatcher=Unable to find a request dispatcher for local resource ''{0}''.
   AbstractEngine.unable-to-forward=Unable to forward to local resource ''{0}''.
  @@ -317,8 +316,6 @@
   PageRecorder.null-property-name=A change event for component {0} failed to specify the name of the updated property.
   
   RollbackException.message=Unable to set property {0} of component {1} to {2}.
  -
  -DefaultValuePersister.no-value-copier-for-class=No value copier has been registerred for class {0}.
   
   # net.sf.tapestry.resource
   
  
  
  
  1.2       +3 -6      jakarta-tapestry/framework/src/org/apache/tapestry/IEngine.java
  
  Index: IEngine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/IEngine.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IEngine.java	5 Mar 2003 22:59:22 -0000	1.1
  +++ IEngine.java	8 Mar 2003 17:07:45 -0000	1.2
  @@ -242,11 +242,8 @@
       /**
        *  Method invoked from the {@link org.apache.tapestry.ApplicationServlet} 
        *  to perform processing of the
  -     *  request.  The return value for this method indicates whether the state of the engine
  -     *  could possibly change during processing; in most cases this is true.  In a few
  -     *  possible cases, this is false.  The ApplicationServlet sometimes performs extra
  -     *  work to ensure that the engine is properly replicated in a clustering environment; if
  -     *  this method returns false, it can skip that extra work.
  +     *  request.  In release 2.4, this has become more of a dirty flag, indicating
  +     *  if any state stored by the engine instance itself has changed.
        *
        *  @return true if the state of the engine was, or could have been, changed during
        *  processing.
  
  
  
  1.2       +140 -33   jakarta-tapestry/framework/src/org/apache/tapestry/engine/AbstractEngine.java
  
  Index: AbstractEngine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/engine/AbstractEngine.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractEngine.java	5 Mar 2003 22:59:43 -0000	1.1
  +++ AbstractEngine.java	8 Mar 2003 17:07:45 -0000	1.2
  @@ -75,6 +75,8 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;
  +import javax.servlet.http.HttpSessionBindingEvent;
  +import javax.servlet.http.HttpSessionBindingListener;
   
   import org.apache.tapestry.ApplicationRuntimeException;
   import org.apache.tapestry.ApplicationServlet;
  @@ -107,6 +109,7 @@
   import org.apache.tapestry.util.pool.Pool;
   import org.apache.tapestry.util.prop.OgnlUtils;
   import org.apache.bsf.BSFManager;
  +import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -162,7 +165,8 @@
    * 
    **/
   
  -public abstract class AbstractEngine implements IEngine, IEngineServiceView, Externalizable
  +public abstract class AbstractEngine
  +    implements IEngine, IEngineServiceView, Externalizable, HttpSessionBindingListener
   {
       private static final Log LOG = LogFactory.getLog(AbstractEngine.class);
   
  @@ -312,7 +316,8 @@
        *
        **/
   
  -    protected static final String SPECIFICATION_SOURCE_NAME = "org.apache.tapestry.SpecificationSource";
  +    protected static final String SPECIFICATION_SOURCE_NAME =
  +        "org.apache.tapestry.SpecificationSource";
   
       /**
        *  Servlet context attribute name for the {@link IPageSource}
  @@ -432,6 +437,18 @@
       private transient IComponentClassEnhancer _enhancer;
   
       /**
  +     *  Set to true when there is a (potential)
  +     *  change to the internal state of the engine, set
  +     *  to false when the engine is stored into the
  +     *  {@link HttpSession}.  
  +     * 
  +     *  @since 2.4
  +     * 
  +     **/
  +
  +    private transient boolean _dirty;
  +
  +    /**
        *  Sets the Exception page's exception property, then renders the Exception page.
        *
        *  <p>If the render throws an exception, then copious output is sent to
  @@ -515,23 +532,16 @@
       /**
        *  Extends the description of the class generated by {@link #toString()}.
        *  If a subclass adds additional instance variables that should be described
  -     *  in the instance description, it may overide this method.  Subclasses
  -     *  should invoke this implementation first.  They should append a space
  -     *  before each value.
  +     *  in the instance description, it may overide this method. This implementation
  +     *  does nothing.
        *
        *  @see #toString()
  +     * 
        **/
   
  -    public void extendDescription(StringBuffer buffer)
  +    protected void extendDescription(ToStringBuilder builder)
       {
  -        // In rare cases, toString() may be invoked before
  -        // the engine has a change to obtain the specification
  -        // from the servlet.
   
  -        if (_specification == null)
  -            buffer.append(Tapestry.getString("AbstractEngine.unknown-specification"));
  -        else
  -            buffer.append(_specification.getName());
       }
   
       /**
  @@ -850,7 +860,16 @@
   
                   monitor.serviceBegin(serviceName, context.getRequestURI());
   
  -                return service.service(this, cycle, output);
  +                // Invoke the service, which returns true if it may have changed
  +                // the state of the engine (most do return true).
  +
  +                boolean serviceResult = service.service(this, cycle, output);
  +
  +                // Return true only if the engine is actually dirty.  This cuts down
  +                // on the number of times the engine is stored into the
  +                // session unceccesarily.
  +
  +                return serviceResult && _dirty;
               }
               catch (PageRedirectException ex)
               {
  @@ -930,7 +949,7 @@
           // When in doubt, assume that the request did cause some change
           // to the engine.
   
  -        return true;
  +        return _dirty;
       }
   
       /**
  @@ -1049,6 +1068,7 @@
           {
               _locale = value;
               _localeChanged = true;
  +            markDirty();
           }
       }
   
  @@ -1379,23 +1399,28 @@
        *  Invokes {@link #extendDescription(StringBuffer)}
        *  to fill in details about the instance.
        *
  -     *  @see #extendDescription(StringBuffer)
  +     *  @see #extendDescription(ToStringB)
        *
        **/
   
       public String toString()
       {
  -        StringBuffer buffer;
  -
  -        buffer = new StringBuffer(super.toString());
  +        ToStringBuilder builder = new ToStringBuilder(this);
   
  -        buffer.append('[');
  +        builder.append(
  +            "name",
  +            _specification == null
  +                ? Tapestry.getString("AbstractEngine.unknown-specification")
  +                : _specification.getName());
  +
  +        builder.append("dirty", _dirty);
  +        builder.append("locale", _locale);
  +        builder.append("stateful", _stateful);
  +        builder.append("visit", _visit);
   
  -        extendDescription(buffer);
  +        extendDescription(builder);
   
  -        buffer.append(']');
  -
  -        return buffer.toString();
  +        return builder.toString();
       }
   
       /**
  @@ -1420,10 +1445,19 @@
       /**
        *  Gets the visit object, if it has been created already.
        *
  +     *  <p>
  +     *  If the visit is non-null then
  +     *  the {@link #isDirty()} flag is set (because
  +     *  the engine can't tell what the caller will
  +     *  <i>do</i> with the visit).
  +     * 
        **/
   
       public Object getVisit()
       {
  +        if (_visit != null)
  +            markDirty();
  +
           return _visit;
       }
   
  @@ -1435,6 +1469,10 @@
        *  After creating the visit, but before returning,
        *  the {@link HttpSession} will be created, and
        *  {@link #setStateful()} will be invoked.
  +     * 
  +     *  <p>
  +     *  Sets the {@link #isDirty()} flag, if the return value
  +     *  is not null.
        *
        *
        **/
  @@ -1453,12 +1491,23 @@
               setStateful();
           }
   
  +        if (_visit != null)
  +            markDirty();
  +
           return _visit;
       }
   
  +    /**
  +     *  Updates the visit object and
  +     *  sets the {@link #isDirty() dirty flag}.
  +     * 
  +     **/
  +
       public void setVisit(Object value)
       {
           _visit = value;
  +
  +        markDirty();
       }
   
       public boolean getHasVisit()
  @@ -1483,11 +1532,6 @@
           Object result = null;
   
           visitClassName = _propertySource.getPropertyValue(VISIT_CLASS_PROPERTY_NAME);
  -        if (visitClassName == null)
  -            throw new ApplicationRuntimeException(
  -                Tapestry.getString(
  -                    "AbstractEngine.visit-class-property-not-specified",
  -                    VISIT_CLASS_PROPERTY_NAME));
   
           if (LOG.isDebugEnabled())
               LOG.debug("Creating visit object as instance of " + visitClassName);
  @@ -1744,7 +1788,7 @@
                           Tapestry.getString(
                               "AbstractEngine.service-name-mismatch",
                               name,
  -                            serviceClass,
  +                            className,
                               serviceName));
   
                   // Replace the class name with an instance
  @@ -1914,7 +1958,8 @@
        * 
        **/
   
  -    private static final String EXTENSION_PROPERTY_SOURCE_NAME = "org.apache.tapestry.property-source";
  +    private static final String EXTENSION_PROPERTY_SOURCE_NAME =
  +        "org.apache.tapestry.property-source";
   
       /**
        *  The name of an application extension that implements {@link IMonitor}.
  @@ -1972,7 +2017,8 @@
   
           // Lastly, add a final source to handle "factory defaults".
   
  -        ResourceBundle bundle = ResourceBundle.getBundle("org.apache.tapestry.ConfigurationDefaults");
  +        ResourceBundle bundle =
  +            ResourceBundle.getBundle("org.apache.tapestry.ConfigurationDefaults");
   
           result.addSource(new ResourceBundlePropertySource(bundle));
   
  @@ -2070,6 +2116,67 @@
       public IComponentClassEnhancer getComponentClassEnhancer()
       {
           return _enhancer;
  +    }
  +
  +    /**
  +     *  Returns true if the engine has (potentially) changed
  +     *  state since the last time it was stored
  +     *  into the {@link javax.servlet.http.HttpSession}.  Various
  +     *  events set this property to true.
  +     * 
  +     *  @since 2.4
  +     * 
  +     **/
  +
  +    public boolean isDirty()
  +    {
  +        return _dirty;
  +    }
  +
  +    /**
  +     *  Invoked to set the dirty flag, indicating that the
  +     *  engine should be stored into the 
  +     *  {@link javax.servlet.http.HttpSession}.
  +     * 
  +     * 
  +     *  @since 2.4
  +     * 
  +     **/
  +
  +    protected void markDirty()
  +    {
  +        if (!_dirty)
  +            LOG.debug("Setting dirty flag.");
  +
  +        _dirty = true;
  +    }
  +
  +    /** 
  +     * 
  +     *  Clears the dirty flag when a engine is stored into the 
  +     *  {@link HttpSession}.
  +     * 
  +     * 
  +     *  @since 2.4 
  +     * 
  +     **/
  +
  +    public void valueBound(HttpSessionBindingEvent arg0)
  +    {
  +        LOG.debug(_dirty ? "Clearing dirty flag." : "Dirty flag already cleared.");
  +
  +        _dirty = false;
  +    }
  +
  +    /**
  +     *  Does nothing.
  +     * 
  +     *  @since 2.4
  +     * 
  +     **/
  +
  +    public void valueUnbound(HttpSessionBindingEvent arg0)
  +    {
       }
   
   }
  
  
  
  1.2       +18 -1     jakarta-tapestry/framework/src/org/apache/tapestry/engine/BaseEngine.java
  
  Index: BaseEngine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/engine/BaseEngine.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseEngine.java	5 Mar 2003 22:59:43 -0000	1.1
  +++ BaseEngine.java	8 Mar 2003 17:07:45 -0000	1.2
  @@ -65,6 +65,7 @@
   import java.util.Map;
   import java.util.*;
   
  +import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.tapestry.ApplicationRuntimeException;
   import org.apache.tapestry.IRequestCycle;
   import org.apache.tapestry.Tapestry;
  @@ -104,6 +105,7 @@
           if (Tapestry.isEmpty(_recorders))
               return;
   
  +		boolean markDirty = false;
           Iterator i = _recorders.entrySet().iterator();
   
           while (i.hasNext())
  @@ -119,8 +121,13 @@
                   i.remove();
   
                   _activePageNames.remove(pageName);
  +      	
  +      			markDirty = true;
               }
           }
  +        
  +        if (markDirty)
  +        	markDirty();
       }
   
       public void forgetPage(String name)
  @@ -139,6 +146,8 @@
           recorder.discard();
           _recorders.remove(name);
           _activePageNames.remove(name);
  +        
  +        markDirty();
       }
   
       /**
  @@ -190,6 +199,7 @@
   
           cycle.getRequestContext().createSession();
           setStateful();
  +       
   
           IPageRecorder result = new SessionPageRecorder();
           result.initialize(pageName, cycle);
  @@ -200,6 +210,8 @@
               _activePageNames = new HashSet();
   
           _activePageNames.add(pageName);
  +        
  +        markDirty();
   
           return result;
       }
  @@ -257,6 +269,11 @@
   
               out.writeUTF(name);
           }
  +    }
  +
  +    public void extendDescription(ToStringBuilder builder)
  +    {
  +		builder.append("activePageNames", _activePageNames);
       }
   
   }
  
  
  
  1.2       +9 -3      jakarta-tapestry/framework/src/org/apache/tapestry/html/Image.java
  
  Index: Image.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/html/Image.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Image.java	5 Mar 2003 22:59:30 -0000	1.1
  +++ Image.java	8 Mar 2003 17:07:45 -0000	1.2
  @@ -60,6 +60,7 @@
   import org.apache.tapestry.IMarkupWriter;
   import org.apache.tapestry.IRequestCycle;
   import org.apache.tapestry.RequestCycleException;
  +import org.apache.tapestry.RequiredParameterException;
   
   /**
    *  Used to insert an image.  To create a rollover image, use the
  @@ -91,7 +92,12 @@
           if (cycle.isRewinding())
               return;
   
  -        String imageURL = getImage().buildURL(cycle);
  +        IAsset imageAsset = getImage();
  +
  +        if (imageAsset == null)
  +            throw new RequiredParameterException(this, "image", getBinding("image"));
  +
  +        String imageURL = imageAsset.buildURL(cycle);
   
           writer.beginEmpty("img");
   
  @@ -106,6 +112,6 @@
       }
   
       public abstract IAsset getImage();
  -    
  +
       public abstract int getBorder();
   }