cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl RepositorySourceFactory.java RepositorySource.java
Date Tue, 17 Feb 2004 17:19:26 GMT
unico       2004/02/17 09:19:26

  Modified:    src/blocks/repository/java/org/apache/cocoon/components/source/impl
                        RepositorySourceFactory.java RepositorySource.java
  Log:
  support eventcaching; 
  undo previous change in getScheme():
  unfortunately getScheme() *must* always return the factory name. 
  This is because the source resolver selects the SourceFactory to release the
  source to based on that value...
  
  Revision  Changes    Path
  1.4       +44 -4     cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl/RepositorySourceFactory.java
  
  Index: RepositorySourceFactory.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl/RepositorySourceFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RepositorySourceFactory.java	16 Feb 2004 16:03:09 -0000	1.3
  +++ RepositorySourceFactory.java	17 Feb 2004 17:19:26 -0000	1.4
  @@ -61,6 +61,7 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.cocoon.components.source.SourceDescriptor;
   import org.apache.excalibur.source.ModifiableTraversableSource;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
  @@ -77,24 +78,56 @@
       
       private ServiceManager m_manager;
       private SourceResolver m_resolver;
  +    private SourceDescriptor m_descriptor;
       private String m_name;
  +    private boolean m_useEventCaching;
       
       /**
  -     * Read the <code>name</code> attribute.
  +     * Read the <code>name</code> attribute and the <code>use-event-caching</code>
  +     * configuration element.
        */
       public void configure(final Configuration configuration) 
           throws ConfigurationException {
           
           m_name = configuration.getAttribute("name");
  +        m_useEventCaching = configuration.getChild("use-event-caching",true).
  +            getValueAsBoolean(false);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Event caching is turned " + (m_useEventCaching ? "ON" :
"OFF")
  +            + " for " + m_name + ": protocol.");
  +        }
       }
       
  -    public void service(final ServiceManager manager) throws ServiceException {
  +    /**
  +     * Lookup the SourceDescriptorManager service.
  +     */
  +    public void service(final ServiceManager manager) {
           m_manager = manager;
  +        if (manager.hasService(SourceDescriptorManager.ROLE)) {
  +            try {
  +                m_descriptor = (SourceDescriptor) manager.lookup(SourceDescriptorManager.ROLE);
  +            }
  +            catch (ServiceException e) {
  +                // impossible
  +            }
  +        }
  +        else {
  +            m_descriptor = null;
  +            if (getLogger().isInfoEnabled()) {
  +                final String message =
  +                    "SourceDescriptor is not available. " +
  +                    "RepositorySource will not support " +
  +                    "source properties.";
  +                getLogger().info(message);
  +            }
  +        }
       }
       
       public Source getSource(String location, Map parameters)
           throws IOException, MalformedURLException {
           
  +        // lazy initialization of resolver in order to avoid 
  +        // problems due to circular dependency
           if (m_resolver == null) {
               try {
                   m_resolver = (SourceResolver) m_manager.lookup(SourceResolver.ROLE);
  @@ -111,11 +144,18 @@
               final String message = "Delegate should be a ModifiableTraversableSource";
               throw new SourceException(message);
           }
  +        
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Creating RepositorySource for " + location);
  +        }
  +        
           return new RepositorySource(
               m_name,    
               (ModifiableTraversableSource) source, 
  -            m_manager,
  -            getLogger());
  +            m_descriptor,
  +            getLogger(),
  +            m_useEventCaching
  +        );
       }
       
       public void release(final Source source) {
  
  
  
  1.5       +74 -38    cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl/RepositorySource.java
  
  Index: RepositorySource.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl/RepositorySource.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RepositorySource.java	16 Feb 2004 16:03:09 -0000	1.4
  +++ RepositorySource.java	17 Feb 2004 17:19:26 -0000	1.5
  @@ -60,8 +60,8 @@
   
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.avalon.framework.service.ServiceException;
  -import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.cocoon.caching.validity.EventValidity;
  +import org.apache.cocoon.caching.validity.NamedEvent;
   import org.apache.cocoon.components.source.InspectableSource;
   import org.apache.cocoon.components.source.SourceDescriptor;
   import org.apache.cocoon.components.source.helpers.SourceProperty;
  @@ -76,14 +76,13 @@
    * Source wrapper that enhances the wrapped sources with additional capabilities.
    * 
    * <p>
  - *  Currently the extra functionality this Source adds is
  - *  inspectability through the InspectableSource interface.
  - *  The implementation accomplishes this by delegating the
  - *  inspectable calls to the SourceDescriptor service.
  + * Currently this Source optionally adds inspectability
  + * through the InspectableSource interface and event caching
  + * by handing out EventValidities based on the Source uri.
    * </p>
    * 
    * <p>
  - *  Wrapped sources must implement ModifiableTraversableSource.
  + * Wrapped sources must implement ModifiableTraversableSource.
    * </p>
    * 
    * @author <a href="mailto:unico@apache.org">Unico Hommes</a>
  @@ -95,29 +94,25 @@
       final String m_prefix;
       // the wrapped source
       final ModifiableTraversableSource m_delegate;
  -    private final ServiceManager m_manager;
       private final SourceDescriptor m_descriptor;
  +    private final boolean m_useEventCaching;
       
       // ---------------------------------------------------- Lifecycle
       
       public RepositorySource(
           final String prefix,
           final ModifiableTraversableSource delegate, 
  -        final ServiceManager manager, 
  -        final Logger logger) throws SourceException {
  +        final SourceDescriptor descriptor,
  +        final Logger logger,
  +        final boolean useEventCaching) throws SourceException {
           
           m_prefix = prefix;
           m_delegate = delegate;
  -        m_manager = manager;
  +        m_descriptor = descriptor;
           enableLogging(logger);
  -        try {
  -            m_descriptor = (SourceDescriptor) 
  -                manager.lookup(SourceDescriptorManager.ROLE);
  -        } catch (ServiceException e) {
  -            throw new SourceException("Missing service",e);
  -        }
  +        m_useEventCaching = useEventCaching;
       }
  -        
  +    
       // ---------------------------------------------------- InspectableSource implementation
       
       /**
  @@ -133,7 +128,9 @@
           if (m_delegate instanceof InspectableSource) {
               properties.addAll(Arrays.asList(((InspectableSource) m_delegate).getSourceProperties()));
           }
  -        properties.addAll(Arrays.asList(m_descriptor.getSourceProperties(m_delegate)));
  +        if (m_descriptor != null) {
  +            properties.addAll(Arrays.asList(m_descriptor.getSourceProperties(m_delegate)));
  +        }
           return (SourceProperty[]) properties.toArray(new SourceProperty[properties.size()]);
       }
       
  @@ -147,7 +144,7 @@
           if (m_delegate instanceof InspectableSource) {
               property = ((InspectableSource) m_delegate).getSourceProperty(uri,name);
           }
  -        if (property == null) {
  +        if (property == null && m_descriptor != null) {
               property = m_descriptor.getSourceProperty(m_delegate,uri,name);
           }
           return property;
  @@ -159,12 +156,12 @@
        * the wrapped source directly and on the source descriptor.
        */
       public void removeSourceProperty(String uri, String name) throws SourceException {
  -        
           if (m_delegate instanceof InspectableSource) {
               ((InspectableSource) m_delegate).removeSourceProperty(uri,name);
           }
  -        m_descriptor.removeSourceProperty(m_delegate,uri,name);
  -        
  +        if (m_descriptor != null) {
  +            m_descriptor.removeSourceProperty(m_delegate,uri,name);
  +        }
       }
       
       /**
  @@ -175,7 +172,7 @@
       public void setSourceProperty(SourceProperty property) throws SourceException {
           if (m_delegate instanceof InspectableSource) {
               ((InspectableSource) m_delegate).setSourceProperty(property);
  -        } else {
  +        } else if (m_descriptor != null) {
               m_descriptor.setSourceProperty(m_delegate, property);
           }
       }
  @@ -205,16 +202,36 @@
       }
       
       public String getScheme() {
  -        return m_prefix + ":" + m_delegate.getScheme();
  +        return m_prefix;
       }
       
       public String getURI() {
           return m_prefix + ":" + m_delegate.getURI();
       }
       
  +    /**
  +     * Return a SourceValidity object describing
  +     * the validity of this Source.
  +     * <p>
  +     * If the SourceDescriptor service is present, the resulting
  +     * validity is an aggregated validity object containing both
  +     * the validity describing the source itself _and_ one describing
  +     * the validity of the SourceProperties managed by the SourceDescriptor.
  +     * </p>
  +     * When using event caching the SourceValidity describing the Source itself
  +     * is an EventValidity that contains a NamedEvent which name is the wrapped 
  +     * Source URI.
  +     */
       public SourceValidity getValidity() {
  -        SourceValidity val1 = m_delegate.getValidity();
  -        if (val1 != null) {
  +        SourceValidity val1;
  +        if (m_useEventCaching) {
  +            val1 = new EventValidity(new NamedEvent(getURI()));
  +        }
  +        else {
  +            val1 = m_delegate.getValidity();
  +        }
  +        
  +        if (val1 != null && m_descriptor != null) {
               SourceValidity val2 = m_descriptor.getValidity(m_delegate);
               if (val2 != null) {
                   AggregatedValidity result = new AggregatedValidity();
  @@ -223,7 +240,7 @@
                   return result;
               }
           }
  -        return null;
  +        return val1;
       }
       
       public void refresh() {
  @@ -234,21 +251,35 @@
       // ---------------------------------------------------- ModifiableTraversableSource
       
       public Source getChild(String name) throws SourceException {
  +        if (!m_delegate.isCollection()) return null;
  +        ModifiableTraversableSource child = (ModifiableTraversableSource) m_delegate.getChild(name);
  +        if (child == null) return null;
  +        
           return new RepositorySource(
  -            m_prefix,  
  -            (ModifiableTraversableSource) m_delegate.getChild(name),
  -            m_manager,getLogger());
  +            m_prefix,
  +            child,
  +            m_descriptor,
  +            getLogger(),
  +            m_useEventCaching
  +        );
       }
   
       public Collection getChildren() throws SourceException {
  +        if (!m_delegate.isCollection()) return null;
       	Collection result = new ArrayList();
   		Iterator iter = m_delegate.getChildren().iterator();
       	while(iter.hasNext()) {
  -    		result.add(new RepositorySource(
  -            m_prefix,
  -    		    (ModifiableTraversableSource) iter.next(),
  -    		    m_manager,
  -    		    getLogger()));
  +            ModifiableTraversableSource child = (ModifiableTraversableSource) iter.next();
  +            
  +    		result.add(
  +                new RepositorySource(
  +                    m_prefix,
  +                    child,
  +                    m_descriptor,
  +    		        getLogger(),
  +                    m_useEventCaching
  +                )
  +            );
       	}
           return result;
       }
  @@ -258,10 +289,15 @@
       }
   
       public Source getParent() throws SourceException {
  +        String eventName = null;
  +        
           return new RepositorySource(
               m_prefix,
  -            (ModifiableTraversableSource) m_delegate.getParent(), 
  -        	  m_manager, getLogger());
  +            (ModifiableTraversableSource) m_delegate.getParent(),
  +        	m_descriptor, 
  +            getLogger(),
  +            m_useEventCaching
  +        );
       }
   
       public boolean isCollection() {
  
  
  

Mime
View raw message