|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AbstractLoggerStoreFactory.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (C) The Spice Group. All rights reserved.
|
|
| 3 |
*
|
|
| 4 |
* This software is published under the terms of the Spice
|
|
| 5 |
* Software License version 1.1, a copy of which has been included
|
|
| 6 |
* with this distribution in the LICENSE.txt file.
|
|
| 7 |
*/
|
|
| 8 |
package org.codehaus.spice.loggerstore.factories;
|
|
| 9 |
|
|
| 10 |
import java.io.File;
|
|
| 11 |
import java.io.FileInputStream;
|
|
| 12 |
import java.io.InputStream;
|
|
| 13 |
import java.net.URL;
|
|
| 14 |
import java.util.Map;
|
|
| 15 |
import org.codehaus.spice.loggerstore.LoggerStore;
|
|
| 16 |
import org.codehaus.spice.loggerstore.LoggerStoreFactory;
|
|
| 17 |
import org.jcontainer.dna.AbstractLogEnabled;
|
|
| 18 |
|
|
| 19 |
/**
|
|
| 20 |
* The abstract class that makes it easy to create LoggerStoreFactory
|
|
| 21 |
* implementations.
|
|
| 22 |
*
|
|
| 23 |
* @author Peter Donald
|
|
| 24 |
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
|
|
| 25 |
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
|
|
| 26 |
*/
|
|
| 27 |
public abstract class AbstractLoggerStoreFactory |
|
| 28 |
extends AbstractLogEnabled
|
|
| 29 |
implements LoggerStoreFactory
|
|
| 30 |
{
|
|
| 31 |
/**
|
|
| 32 |
* Creates a LoggerStore from a given set of configuration parameters. The
|
|
| 33 |
* configuration map contains entrys specific to the concrete
|
|
| 34 |
* implementation.
|
|
| 35 |
*
|
|
| 36 |
* @param config the parameter map to configuration of the store
|
|
| 37 |
* @return the LoggerStore
|
|
| 38 |
* @throws Exception if unable to create the LoggerStore
|
|
| 39 |
*/
|
|
| 40 | 85 |
public LoggerStore createLoggerStore( final Map config )
|
| 41 |
throws Exception
|
|
| 42 |
{
|
|
| 43 | 85 |
final LoggerStore loggerStore = doCreateLoggerStore( config ); |
| 44 | 78 |
setupLogger( loggerStore ); |
| 45 | 78 |
return loggerStore;
|
| 46 |
} |
|
| 47 |
|
|
| 48 |
protected abstract LoggerStore doCreateLoggerStore( Map config )
|
|
| 49 |
throws Exception;
|
|
| 50 |
|
|
| 51 |
/**
|
|
| 52 |
* Utility method to throw exception indicating input data was invalid.
|
|
| 53 |
*
|
|
| 54 |
* @return never returns
|
|
| 55 |
* @throws Exception indicating input data was invalid
|
|
| 56 |
*/
|
|
| 57 | 6 |
protected LoggerStore missingConfiguration()
|
| 58 |
throws Exception
|
|
| 59 |
{
|
|
| 60 | 6 |
throw new Exception( "Invalid configuration" ); |
| 61 |
} |
|
| 62 |
|
|
| 63 |
/**
|
|
| 64 |
* A utility method to retrieve a InputStream from input map. It will
|
|
| 65 |
* systematically go through the following steps to attempt to locate the
|
|
| 66 |
* InputStream stopping at success.
|
|
| 67 |
*
|
|
| 68 |
* <ul> <li>Lookup LoggerStoreFactory.URL_LOCATION for string defining URL
|
|
| 69 |
* location of input configuration.</li> <li>Lookup java.net.URL for URL
|
|
| 70 |
* object defining URL location of input configuration.</li> <li>Lookup
|
|
| 71 |
* LoggerStoreFactory.FILE_LOCATION for string defining File location of
|
|
| 72 |
* input configuration.</li> <li>Lookup java.io.File for File object
|
|
| 73 |
* defining File location of input configuration.</li> <li>Lookup
|
|
| 74 |
* java.io.InputStream for InputStream object.</li> </ul>
|
|
| 75 |
*
|
|
| 76 |
* @param config the input map
|
|
| 77 |
* @return the InputStream or null if no stream present
|
|
| 78 |
* @throws Exception if there was a problem aquiring stream
|
|
| 79 |
*/
|
|
| 80 | 74 |
protected InputStream getInputStream( final Map config )
|
| 81 |
throws Exception
|
|
| 82 |
{
|
|
| 83 | 74 |
final String urlLocation = (String)config.get( URL_LOCATION ); |
| 84 | 74 |
URL url = null;
|
| 85 | 74 |
if( null != urlLocation ) |
| 86 |
{
|
|
| 87 | 7 |
url = new URL( urlLocation );
|
| 88 |
} |
|
| 89 | 74 |
if( null == url ) |
| 90 |
{
|
|
| 91 | 67 |
url = (URL)config.get( URL.class.getName() );
|
| 92 |
} |
|
| 93 | 74 |
if( null != url ) |
| 94 |
{
|
|
| 95 | 14 |
return url.openStream();
|
| 96 |
} |
|
| 97 |
|
|
| 98 | 60 |
final String fileLocation = (String)config.get( FILE_LOCATION ); |
| 99 | 60 |
File file = null;
|
| 100 | 60 |
if( null != fileLocation ) |
| 101 |
{
|
|
| 102 | 25 |
file = new File( fileLocation );
|
| 103 |
} |
|
| 104 | 60 |
if( null == file ) |
| 105 |
{
|
|
| 106 | 35 |
file = (File)config.get( File.class.getName() );
|
| 107 |
} |
|
| 108 | 60 |
if( null != file ) |
| 109 |
{
|
|
| 110 | 32 |
return new FileInputStream( file ); |
| 111 |
} |
|
| 112 |
|
|
| 113 | 28 |
return (InputStream)config.get( InputStream.class.getName() ); |
| 114 |
} |
|
| 115 |
} |
|
| 116 |
|
|
||||||||||