cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@apache.org>
Subject Re: question on getLogger()
Date Tue, 03 Apr 2001 20:07:44 GMT
Donald Ball wrote:
> 
> i thought i'd try my hand at a little LoggingEntityResolver so that we can
> try to track file/uri dependencies for the various sitemap components.
> unfortunately, i'm having trouble getting access to the Logger -
> getLogger() returns null. here's my sample code:

How is this being instantiated?  All components in Cocoon are created by a
ComponentFactory that takes care of alot of implementation details for you.
If you are creating the EntityResolver like this:

EntityResolver resolver = new LoggingEntityResolver(realResolver);

then you can't forget to do the lifecycle management functions:

resolver.setLogger(this.getLogger());
resolver.configure(conf);

> package org.apache.cocoon.xml;
> 
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import java.io.IOException;
> import org.apache.log.Logger;
> import org.apache.avalon.AbstractLoggable;
> import org.apache.avalon.configuration.Configurable;
> import org.apache.avalon.configuration.Configuration;
> import org.apache.avalon.configuration.ConfigurationException;
> 
> public class LoggingEntityResolver extends AbstractLoggable implements
> EntityResolver,Configurable {
> 
>   protected EntityResolver resolver;
> 
>   public LoggingEntityResolver(EntityResolver resolver) {
>     this.resolver = resolver;
>   }
> 
>   public void configure(Configuration conf) throws ConfigurationException
> {}
> 
>   public InputSource resolveEntity(String public_id, String system_id)
> throws SAXException,IOException {
>     InputSource input_source =
> resolver.resolveEntity(public_id,system_id);
>     StringBuffer sb = new StringBuffer();
>     sb.append("Resolving entity: ");
>     if (public_id != null) {
>       sb.append("public_id: "+public_id);
>     }
>     if (system_id != null) {
>       sb.append("system_id: "+system_id);
>     }
>     if (input_source != null) {
>       sb.append("input_source: "+input_source.toString());
>     }
>     getLogger().debug(sb.toString());
>     return input_source;
>   }
> 
> }
> 
> what's the most succinct way of configuring the class so that getLogger()
> is valid and doesn't return null?
> 
> - donald
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message