You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2004/02/09 14:39:42 UTC

cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl ApplicationCopletAdapter.java CachingURICopletAdapter.java

cziegeler    2004/02/09 05:39:42

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl
                        ApplicationCopletAdapter.java
                        CachingURICopletAdapter.java
  Log:
  Fixing event handling
  
  Revision  Changes    Path
  1.3       +20 -28    cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/ApplicationCopletAdapter.java
  
  Index: ApplicationCopletAdapter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/ApplicationCopletAdapter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ApplicationCopletAdapter.java	20 Oct 2003 13:36:41 -0000	1.2
  +++ ApplicationCopletAdapter.java	9 Feb 2004 13:39:42 -0000	1.3
  @@ -95,41 +95,33 @@
           }
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.cocoon.portal.event.Subscriber#inform(org.apache.cocoon.portal.event.Event)
  -     */
  -    public void inform(Event e) {
  -        if (e instanceof CopletLinkEvent) {
  -            getLogger().info(
  -                "CopletLinkEvent " + e + " caught by ApplicationCopletAdapter");
  -            handleCopletLinkEvent(e);
  -        }
  -    }
  -
       /**
        * This adapter listens for CopletLinkEvents. If it catches one the link uri is saved in
        * the coplet instance data for further handling in the ProxyTransformer.
        * There is a special CopletLinkEvent with the uri "createNewCopletInstance", which is the
        * trigger to create a new instance of the one that is the target of the event.
        */
  -    public void handleCopletLinkEvent(Event e) {
  -        CopletLinkEvent event = (CopletLinkEvent) e;
  -        super.handleCopletLinkEvent(event);
  -        CopletInstanceData coplet = (CopletInstanceData) event.getTarget();
  -        String link = event.getLink();
  -
  -        if ("createNewCopletInstance".equals(link)) {
  -            try {
  -                createNewInstance(coplet);
  +    public void handleCopletInstanceEvent(Event e) {
  +        super.handleCopletInstanceEvent(e);
  +        
  +        if ( e instanceof CopletLinkEvent ) {
  +            CopletLinkEvent event = (CopletLinkEvent) e;
  +            CopletInstanceData coplet = (CopletInstanceData) event.getTarget();
  +            String link = event.getLink();
  +    
  +            if ("createNewCopletInstance".equals(link)) {
  +                try {
  +                    createNewInstance(coplet);
  +                }
  +                catch (ProcessingException ex) {
  +                    getLogger().error("Could not create new coplet instance", ex);
  +                }
               }
  -            catch (ProcessingException ex) {
  -                getLogger().error("Could not create new coplet instance", ex);
  +            else {
  +                // this is a normal link event, so save the url in the instance data
  +                // for ProxyTransformer
  +                coplet.setAttribute(ProxyTransformer.LINK, event.getLink());
               }
  -        }
  -        else {
  -            // this is a normal link event, so save the url in the instance data
  -            // for ProxyTransformer
  -            coplet.setAttribute(ProxyTransformer.LINK, event.getLink());
           }
       }
   
  
  
  
  1.2       +50 -62    cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
  
  Index: CachingURICopletAdapter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CachingURICopletAdapter.java	25 Aug 2003 07:41:18 -0000	1.1
  +++ CachingURICopletAdapter.java	9 Feb 2004 13:39:42 -0000	1.2
  @@ -55,8 +55,8 @@
   import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
   import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
  +import org.apache.cocoon.portal.event.CopletInstanceEvent;
   import org.apache.cocoon.portal.event.Event;
  -import org.apache.cocoon.portal.event.impl.CopletLinkEvent;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
   
  @@ -71,6 +71,7 @@
   public class CachingURICopletAdapter
       extends URICopletAdapter
       implements Parameterizable {
  +    
       /**
        * The cache for saving the coplet data
        */
  @@ -101,49 +102,45 @@
        */
       private boolean disableCaching = false;
   
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
  +     */
       public void parameterize(Parameters parameters) {
           if (parameters != null) {
  -            disableCaching =
  -                parameters.getParameterAsBoolean(
  -                    PARAMETER_DISABLE_CACHING,
  -                    false);
  +            this.disableCaching = parameters.getParameterAsBoolean(PARAMETER_DISABLE_CACHING, false);
               if (disableCaching) {
  -                getLogger().info(
  -                    this.getClass().getName() + " Caching is disabled.");
  -            }
  -            else {
  -                getLogger().info(
  -                    this.getClass().getName() + " Caching is enabled.");
  +                getLogger().info(this.getClass().getName() + " Caching is disabled.");
  +            } else {
  +                getLogger().info(this.getClass().getName() + " Caching is enabled.");
               }
           }
       }
   
  -    public void streamContent(
  -        CopletInstanceData coplet,
  -        ContentHandler contentHandler)
  -        throws SAXException {
  -        this.streamContent(
  -            coplet,
  -            (String) coplet.getCopletData().getAttribute("uri"),
  -            contentHandler);
  -    }
  -
  -    public void streamContent(
  -        final CopletInstanceData coplet,
  -        final String uri,
  -        final ContentHandler contentHandler)
  -        throws SAXException {
  -        if (isValidCache(coplet)) {
  -            toSAXFromCache(coplet, contentHandler);
  -        }
  -        else {
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.portal.coplet.adapter.impl.AbstractCopletAdapter#streamContent(org.apache.cocoon.portal.coplet.CopletInstanceData, org.xml.sax.ContentHandler)
  +     */
  +    public void streamContent(CopletInstanceData coplet, ContentHandler contentHandler)
  +    throws SAXException {
  +        this.streamContent( coplet, (String) coplet.getCopletData().getAttribute("uri"), contentHandler);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.portal.coplet.adapter.impl.URICopletAdapter#streamContent(org.apache.cocoon.portal.coplet.CopletInstanceData, java.lang.String, org.xml.sax.ContentHandler)
  +     */
  +    public void streamContent( final CopletInstanceData coplet,
  +                               final String uri,
  +                               final ContentHandler contentHandler)
  +    throws SAXException {
  +        if (this.isValidCache(coplet)) {
  +            this.toSAXFromCache(coplet, contentHandler);
  +        } else {
               XMLByteStreamCompiler bc = new XMLByteStreamCompiler();
   
               super.streamContent(coplet, uri, bc);
   
  -            toCache(coplet, bc.getSAXFragment());
  +            this.toCache(coplet, bc.getSAXFragment());
   
  -            toSAXFromCache(coplet, contentHandler);
  +            this.toSAXFromCache(coplet, contentHandler);
           }
       }
   
  @@ -155,7 +152,7 @@
       private void toCache(CopletInstanceData coplet, Object data) {
           coplet.setAttribute(CACHE, data);
   
  -        setCacheValid(coplet);
  +        this.setCacheValid(coplet);
       }
   
       /**
  @@ -164,10 +161,9 @@
        * @param contentHandler the handler, that should receive the SAX events
        * @throws SAXException
        */
  -    private void toSAXFromCache(
  -        CopletInstanceData coplet,
  -        ContentHandler contentHandler)
  -        throws SAXException {
  +    private void toSAXFromCache(CopletInstanceData coplet,
  +                                ContentHandler contentHandler)
  +    throws SAXException {
           XMLByteStreamInterpreter bi = new XMLByteStreamInterpreter();
           bi.setContentHandler(contentHandler);
   
  @@ -179,18 +175,15 @@
        * @param coplet the coplet instance data
        */
       public boolean isValidCache(CopletInstanceData coplet) {
  -        if (disableCaching)
  +        if (disableCaching) {
               return false;
  -
  +        }
           String cacheValidity = (String) coplet.getAttribute(CACHE_VALIDITY);
   
  -        if (cacheValidity == null)
  -            return false;
  -
  -        if (CACHE_VALID.equals(cacheValidity))
  -            return true;
  -        else
  +        if (cacheValidity == null) {
               return false;
  +        }
  +        return CACHE_VALID.equals(cacheValidity);
       }
   
       /**
  @@ -213,29 +206,24 @@
        * @see org.apache.cocoon.portal.event.Subscriber#inform(org.apache.cocoon.portal.event.Event)
        */
       public void inform(Event e) {
  -        if (e instanceof CopletLinkEvent) {
  -            getLogger().info(
  -                "CopletLinkEvent " + e + " caught by CachingURICopletAdapter");
  -            handleCopletLinkEvent(e);
  +        if (e instanceof CopletInstanceEvent) {
  +            if ( this.getLogger().isInfoEnabled() ) {
  +                this.getLogger().info("CopletInstanceEvent " + e + " caught by CachingURICopletAdapter");
  +            }
  +            this.handleCopletInstanceEvent(e);
           }
  +        super.inform(e);
       }
   
       /**
  -     * This adapter listens for CopletLinkEvents. Each CopletLinkEvent sets the cache invalid.
  +     * This adapter listens for CopletInstanceEvents. Each event sets the cache invalid.
        */
  -    public void handleCopletLinkEvent(Event e) {
  -        CopletLinkEvent event = (CopletLinkEvent) e;
  -
  -        CopletInstanceData coplet = (CopletInstanceData) event.getTarget();
  +    public void handleCopletInstanceEvent(Event e) {
  +        final CopletInstanceEvent event = (CopletInstanceEvent) e;
   
  -        setCacheInvalid(coplet);
  -    }
  +        final CopletInstanceData coplet = (CopletInstanceData) event.getTarget();
   
  -    /* (non-Javadoc)
  -     * @see org.apache.cocoon.portal.event.Subscriber#getEventType()
  -     */
  -    public Class getEventType() {
  -        return CopletLinkEvent.class;
  +        this.setCacheInvalid(coplet);
       }
   
   }