Re: LoggerStore

Peter Donald <peter-4lf8KW9E9MLMqX/[email protected]>
Newsgroups gmane.comp.java.spice.devel
Message-ID <[email protected]>
On Fri, 16 May 2003 09:24 am, Mauro Talevi wrote:
> > If we did all the construction in the LoggerStoreFactory then we would
> > just need to change that rather than having to change both the
> > LoggerStore and the coresponding factory. It also makes testing the
> > LoggerStore much more easier.
>
> that's the way I started off - but there are a issues that made me go in
> this way:

I am still not entirely sure what you mean. What I mean is changing to 
something like

public class Log4JLoggerStoreFactory
    implements LoggerStoreFactory
{
    public LoggerStore createLoggerStore( final Map config )
        throws Exception
    {
        InputStream resource = (InputStream)config.get( CONFIGURATION );
        if( resource != null )
        {
            String type = (String)config.get( CONFIGURATION_TYPE );
            if( type != null )
            {
              if( type.equals( LoggerStoreFactory.PROPERTIES ) )
              {
                  return new Log4jLoggerStore( buildProperties( resource ) );
              }
              else if( type.equals( LoggerStoreFactory.XML ) )
              {
                  return new Log4jLoggerStore( buildElement( resource ) );
              }
            }
        }
        throw new Exception( "Invalid configuration" );
    }
}

public class Log4JLoggerStore
    extends AbstractLoggerStore
{
    public Log4JLoggerStore( final Element element )
        throws Exception
    {
        m_repository = LogManager.getLoggerRepository();
        final DOMConfigurator configurator = new DOMConfigurator();
        configurator.doConfigure( element, repository );
        setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) );
    }

    public Log4JLoggerStore( final Properties properties )
        throws Exception
    {
        m_repository = LogManager.getLoggerRepository();
        final PropertyConfigurator configurator = new PropertyConfigurator();
        configurator.doConfigure( properties, repository );
        setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) );
    }
...
}

AFAIK this is just moving code around and should not make things any harder?

> 4. The InputStream on the other hand is a general input object that can
> be tranformed input all types - XML, Properties, etc ...
> What is the problems with InputStream?  It can be loaded from any
> classloader, can it not?

See above to see what I mean because I think we are talking about different 
things?

-- 
Cheers,

Peter Donald
Einstein argued that there must be simplified explanations of nature, because
God is not capricious or arbitrary.  No such faith comforts the software
engineer.
- Fred Brooks, Jr.



-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.