mcconnell 2004/04/20 09:53:19
Modified: composition/impl/src/java/org/apache/avalon/composition/model/impl
DefaultSystemContextFactory.java
composition/impl/src/test/conf/system kernel.xml logging.xml
composition/impl/src/test/org/apache/avalon/composition/model/test
AbstractTestCase.java
Log:
Updates to support logging manager creation.
Revision Changes Path
1.10 +81 -22
avalon/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultSystemContextFactory.java
Index: DefaultSystemContextFactory.java
===================================================================
RCS file:
/home/cvs/avalon/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultSystemContextFactory.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DefaultSystemContextFactory.java 1 Apr 2004 04:06:52 -0000 1.9
+++ DefaultSystemContextFactory.java 20 Apr 2004 16:53:19 -0000 1.10
@@ -18,6 +18,7 @@
package org.apache.avalon.composition.model.impl;
import java.io.File;
+import java.net.URL;
import java.util.Hashtable;
import java.util.Map;
@@ -446,30 +447,11 @@
*/
private LoggingManager createLoggingManager()
{
- Artifact[] artifacts =
- m_context.getRepository().getCandidates(
- LoggingManager.class );
- if( artifacts.length < 1 )
- {
- final String error =
- "No factory registered for the class ["
- + LoggingManager.class.getName() + "].";
- throw new IllegalStateException( error );
- }
-
- Artifact artifact = artifacts[0];
+ boolean trace = isTraceEnabled();
try
{
- File dir = getBaseDirectory();
- ClassLoader classloader =
- DefaultSystemContextFactory.class.getClassLoader();
- Builder builder = m_context.newBuilder( classloader, artifact );
- LoggingFactory factory = (LoggingFactory) builder.getFactory();
- LoggingCriteria params = factory.createDefaultLoggingCriteria();
- params.setDebugEnabled( isTraceEnabled() );
- params.setBaseDirectory( dir );
- return factory.createLoggingManager( params );
+ return createLoggingManager( m_context, null, null, null, trace );
}
catch( Throwable e )
{
@@ -478,4 +460,81 @@
throw new ModelRuntimeException( error, e );
}
}
+
+ /**
+ * Utility method to create the LoggingManager.
+ * @param context the initial context reference
+ * @param artifact the logging implementation factory artifact
+ * @param dir the logging system base directory
+ * @param path the logging system configuration path
+ * @param trace the trace enabled flag
+ * @return the logging manager
+ * @exception NullPointerException if the supplied context is null
+ */
+ public static LoggingManager createLoggingManager(
+ final InitialContext context, final Artifact artifact,
+ final File dir, final URL path, boolean trace ) throws Exception
+ {
+ assertNotNull( context, "context" );
+
+ Artifact implementation =
+ locateArtifact( context, LoggingManager.class, artifact );
+ File basedir = getBaseDirectory( context, dir );
+
+ ClassLoader classloader =
+ DefaultSystemContextFactory.class.getClassLoader();
+ Builder builder = context.newBuilder( classloader, implementation );
+ LoggingFactory factory = (LoggingFactory) builder.getFactory();
+ LoggingCriteria params = factory.createDefaultLoggingCriteria();
+ params.setBaseDirectory( basedir );
+ params.setLoggingConfiguration( path );
+ params.setDebugEnabled( trace );
+ return factory.createLoggingManager( params );
+ }
+
+ private static Artifact locateArtifact(
+ InitialContext context, Class clazz, Artifact artifact )
+ {
+ if( null != artifact ) return artifact;
+ return locateArtifact( context, clazz );
+ }
+
+ private static Artifact locateArtifact( InitialContext context, Class clazz )
+ throws IllegalStateException
+ {
+ assertNotNull( context, "context" );
+ assertNotNull( clazz, "clazz" );
+
+ Artifact[] artifacts =
+ context.getRepository().getCandidates( clazz );
+ if( artifacts.length < 1 )
+ {
+ final String error =
+ "No factory registered for the class ["
+ + clazz.getName() + "].";
+ throw new IllegalStateException( error );
+ }
+
+ return artifacts[0];
+ }
+
+ private static void assertNotNull( Object object, String key )
+ throws NullPointerException
+ {
+ if( null == object )
+ throw new NullPointerException( key );
+ }
+
+ /**
+ * Return the base directory from which relative classloader
+ * references may be resolved.
+ *
+ * @return the base directory
+ */
+ private static File getBaseDirectory( InitialContext context, File dir )
+ {
+ if( null != dir ) return dir;
+ return context.getInitialWorkingDirectory();
+ }
+
}
1.4 +2 -0 avalon/composition/impl/src/test/conf/system/kernel.xml
Index: kernel.xml
===================================================================
RCS file: /home/cvs/avalon/composition/impl/src/test/conf/system/kernel.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- kernel.xml 9 Apr 2004 12:11:49 -0000 1.3
+++ kernel.xml 20 Apr 2004 16:53:19 -0000 1.4
@@ -9,6 +9,8 @@
<artifact spec="@AVALON-LOGGING-LOGKIT-SPEC@"/>
</system>
+ <logging path="conf/system/logging.xml"/>
+
<security>
<profile name="default">
<permissions>
1.2 +1 -1 avalon/composition/impl/src/test/conf/system/logging.xml
Index: logging.xml
===================================================================
RCS file: /home/cvs/avalon/composition/impl/src/test/conf/system/logging.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- logging.xml 27 Feb 2004 22:39:36 -0000 1.1
+++ logging.xml 20 Apr 2004 16:53:19 -0000 1.2
@@ -19,7 +19,7 @@
</file>
</targets>
- <categories priority="info" target="simple"/>
+ <categories priority="debug" target="simple"/>
<logger name="kernel.logger"/>
1.10 +15 -1
avalon/composition/impl/src/test/org/apache/avalon/composition/model/test/AbstractTestCase.java
Index: AbstractTestCase.java
===================================================================
RCS file:
/home/cvs/avalon/composition/impl/src/test/org/apache/avalon/composition/model/test/AbstractTestCase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AbstractTestCase.java 9 Apr 2004 12:11:49 -0000 1.9
+++ AbstractTestCase.java 20 Apr 2004 16:53:19 -0000 1.10
@@ -19,7 +19,7 @@
package org.apache.avalon.composition.model.test;
import java.io.File;
-
+import java.net.URL;
import org.apache.avalon.composition.data.SecurityProfile;
import org.apache.avalon.composition.data.builder.XMLSecurityProfileBuilder;
@@ -31,6 +31,8 @@
import org.apache.avalon.composition.provider.ModelFactory;
import org.apache.avalon.composition.provider.SystemContextFactory;
+import org.apache.avalon.logging.provider.LoggingManager;
+
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.repository.Repository;
import org.apache.avalon.repository.provider.InitialContext;
@@ -106,6 +108,18 @@
SystemContextFactory factory =
new DefaultSystemContextFactory( context );
+
+ //
+ // setup the logging manager
+ //
+
+ String logConfigPath = config.getChild( "logging" ).getAttribute( "path" );
+ File file = new File( test, logConfigPath );
+ URL url = file.toURL();
+ LoggingManager logging =
+ DefaultSystemContextFactory.createLoggingManager(
+ context, null, null, url, false );
+ factory.setLoggingManager( logging );
//
// setup the security profiles
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]