You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by ha...@apache.org on 2004/07/02 22:31:57 UTC
svn commit: rev 22491 - in excalibur/branches/fortress-experiments/bean/src: java/org/apache/avalon/fortress/testcase java/org/apache/avalon/fortress/tools test/org/apache/avalon/fortress/tools
Author: hammett
Date: Fri Jul 2 13:31:56 2004
New Revision: 22491
Modified:
excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/testcase/FortressTestCase.java
excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/tools/AvalonLogger.java
excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/tools/FortressBean.java
excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/FortressBeanTestCase.java
excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/TestImpl.java
excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/TestInterface.java
Log:
House cleaning - adapting to Excalibur's code conventions.
Modified: excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/testcase/FortressTestCase.java
==============================================================================
--- excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/testcase/FortressTestCase.java (original)
+++ excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/testcase/FortressTestCase.java Fri Jul 2 13:31:56 2004
@@ -229,13 +229,11 @@
*/
public class FortressTestCase extends TestCase
{
-
///Format of default formatter
private static final String FORMAT =
"%7.7{priority} %23.23{time:yyyy-MM-dd' 'HH:mm:ss.SSS} [%30.30{category}] " +
"(%{context}): %{message}\n%{throwable}";
-
//The default logger
private Logger m_logger;
@@ -248,10 +246,8 @@
private LoggerManager m_loggerManager;
private ServiceManager m_serviceManager;
-
private static HashMap m_tests = new HashMap();
-
public FortressTestCase( final String name )
{
super( name );
@@ -301,7 +297,6 @@
{
return m_logger;
}
-
/**
* Override <code>run</code> so that we can have code that is run once.
@@ -531,7 +526,6 @@
{
}
-
/**
* Exctract the base class name of a class.
*/
@@ -546,7 +540,6 @@
return name;
}
-
/**
* Disposes Fortress
*/
@@ -554,5 +547,4 @@
{
ContainerUtil.dispose( m_containerManager );
}
-
}
Modified: excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/tools/AvalonLogger.java
==============================================================================
--- excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/tools/AvalonLogger.java (original)
+++ excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/tools/AvalonLogger.java Fri Jul 2 13:31:56 2004
@@ -4,9 +4,10 @@
import org.apache.commons.logging.Log;
/**
- * Created by IntelliJ IDEA. User: bloritsch Date: Jun 24, 2004 Time:
- * 5:07:47 PM To change this template use File | Settings | File
- * Templates.
+ * Adapter to be used where a commons-logging Log is expected.
+ * Dispatch invocations to Avalon's Logger implementation.
+ *
+ * @author <a href="mailto:dev@excalibur.apache.org">The Excalibur Team</a>
*/
public class AvalonLogger implements Log
{
Modified: excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/tools/FortressBean.java
==============================================================================
--- excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/tools/FortressBean.java (original)
+++ excalibur/branches/fortress-experiments/bean/src/java/org/apache/avalon/fortress/tools/FortressBean.java Fri Jul 2 13:31:56 2004
@@ -39,58 +39,85 @@
* @author <a href="mailto:dev@avalon.apache.org">The Avalon Team</a>
* @version CVS $Revision: 1.7 $ $Date: 2004/05/06 11:00:44 $
*/
-public class FortressBean implements Initializable, LogEnabled, Serviceable, Disposable {
-
+public class FortressBean implements Initializable, LogEnabled, Serviceable, Disposable
+{
+ public static final String PROPERTY_CONTAINER_CLASS = "container.class";
+ public static final String PROPERTY_CONTAINER_CONFIGURATION = "container.configuration";
+ public static final String PROPERTY_CONTEXT_DIRECTORY = "context.directory";
+ public static final String PROPERTY_INSTRUMENT_MANAGER_CONFIGURATION = "instrument.manager.configuration";
+ public static final String PROPERTY_INVOKE_METHOD = "invoke.method";
+ public static final String PROPERTY_LOGGER_MANAGER_CONFIGURATION = "logger.manager.configuration";
+ public static final String PROPERTY_LOOKUP_COMPONENT_ROLE = "lookup.component.role";
+ public static final String PROPERTY_ROLE_MANAGER_CONFIGURATION = "role.manager.configuration";
+ public static final String PROPERTY_SYSTEM_EXIT_ON_DISPOSE = "system.exit.on.dispose";
+ public static final String PROPERTY_WORK_DIRECTORY = "work.directory";
private static final String COMMONS_LOG_PROPERTY = "org.apache.commons.logging.Log";
- private final FortressConfig config = new FortressConfig();
- private Logger logger = null;
- private DefaultContainerManager cm;
- private DefaultContainer container;
- private ServiceManager sm;
+ private final FortressConfig m_config = new FortressConfig();
+ private Logger m_logger = null;
+ private DefaultContainerManager m_cm;
+ private DefaultContainer m_container;
+ private ServiceManager m_sm;
- private String lookupComponentRole = null;
- private String invokeMethod = null;
+ private String m_lookupComponentRole = null;
+ private String m_invokeMethod = null;
- private boolean systemExitOnDispose = true;
+ private boolean m_systemExitOnDispose = true;
- private Properties properties = null;
+ private Properties m_properties = null;
/**
* @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
*/
- public void enableLogging(Logger logger) {
- this.logger = logger;
+ public void enableLogging(Logger logger)
+ {
+ m_logger = logger;
}
- protected final Logger getLogger() {
- if (this.logger == null) this.logger = new ConsoleLogger();
- return this.logger;
+ protected final Logger getLogger()
+ {
+ if (m_logger == null)
+ {
+ m_logger = new ConsoleLogger();
+ }
+ return m_logger;
}
/**
* @see org.apache.avalon.framework.activity.Initializable#initialize()
*/
- public void initialize() throws Exception {
+ public void initialize() throws Exception
+ {
//only initialize if we do not already have a servicemanager passed in from outside
- if (this.sm == null) {
- ClassLoader cl = null;
- if (this.properties != null) initialize(this.properties);
- if (Thread.currentThread().getContextClassLoader() == null) {
- if (this.getClass().getClassLoader() != null) {
- cl = this.getClass().getClassLoader();
- config.setContextClassLoader(cl);
- Thread.currentThread().setContextClassLoader(cl);
- } else {
+ if (m_sm == null)
+ {
+
+ if (m_properties != null)
+ {
+ initialize(m_properties);
+ }
+
+ if (Thread.currentThread().getContextClassLoader() == null)
+ {
+ if (this.getClass().getClassLoader() != null)
+ {
+ ClassLoader classClassloader = getClass().getClassLoader();
+
+ m_config.setContextClassLoader( classClassloader );
+ Thread.currentThread().setContextClassLoader( classClassloader );
+ }
+ else
+ {
getLogger().warn("context classloader not set and class classloader is null!");
}
}
+
// Get the root container initialized
- this.cm = new DefaultContainerManager(config.getContext());
- ContainerUtil.initialize(cm);
+ m_cm = new DefaultContainerManager(m_config.getContext());
+ ContainerUtil.initialize(m_cm);
initializeCommonsLogging();
- this.container = (DefaultContainer) cm.getContainer();
- this.sm = container.getServiceManager();
+ m_container = (DefaultContainer) m_cm.getContainer();
+ m_sm = m_container.getServiceManager();
}
}
@@ -99,73 +126,97 @@
* if it is not available, this section is ignored. This needs version 1.0.4 (or later) of commons
* logging, earlier versions do not have avalon support.
*/
- private void initializeCommonsLogging() {
- try {
- AvalonLogger.setDefaultLogger( cm.getLogger() );
+ private void initializeCommonsLogging()
+ {
+ try
+ {
+ AvalonLogger.setDefaultLogger(m_cm.getLogger());
System.setProperty(COMMONS_LOG_PROPERTY, AvalonLogger.class.getName());
- } catch (Exception e) {
- if (getLogger().isDebugEnabled()) getLogger().debug("error while initializing commons logging: " + e.getClass().getName() + ", " + e.getMessage());
+ }
+ catch (Exception e)
+ {
+ if (getLogger().isDebugEnabled())
+ getLogger().debug(
+ "error while initializing commons logging: " + e.getClass().getName() + ", " + e.getMessage());
}
}
- private void disposeCommonsLogging() {
+ private void disposeCommonsLogging()
+ {
System.getProperties().remove(COMMONS_LOG_PROPERTY);
}
- public static final String PROPERTY_CONTAINER_CLASS = "container.class";
- public static final String PROPERTY_CONTAINER_CONFIGURATION = "container.configuration";
- public static final String PROPERTY_CONTEXT_DIRECTORY = "context.directory";
- public static final String PROPERTY_INSTRUMENT_MANAGER_CONFIGURATION =
- "instrument.manager.configuration";
- public static final String PROPERTY_INVOKE_METHOD = "invoke.method";
- public static final String PROPERTY_LOGGER_MANAGER_CONFIGURATION = "logger.manager.configuration";
- public static final String PROPERTY_LOOKUP_COMPONENT_ROLE = "lookup.component.role";
- public static final String PROPERTY_ROLE_MANAGER_CONFIGURATION = "role.manager.configuration";
- public static final String PROPERTY_SYSTEM_EXIT_ON_DISPOSE = "system.exit.on.dispose";
- public static final String PROPERTY_WORK_DIRECTORY = "work.directory";
-
- public void initialize(Properties p) throws Exception {
+ public void initialize(Properties p) throws Exception
+ {
if (p.getProperty(PROPERTY_CONTAINER_CLASS) != null)
- this.setContainerClass(p.getProperty(PROPERTY_CONTAINER_CLASS));
+ {
+ this.setContainerClass(p.getProperty(PROPERTY_CONTAINER_CLASS));
+ }
if (p.getProperty(PROPERTY_CONTAINER_CONFIGURATION) != null)
+ {
this.setContainerConfiguration(p.getProperty(PROPERTY_CONTAINER_CONFIGURATION));
+ }
if (p.getProperty(PROPERTY_CONTEXT_DIRECTORY) != null)
+ {
this.setContextDirectory(p.getProperty(PROPERTY_CONTEXT_DIRECTORY));
+ }
if (p.getProperty(PROPERTY_INSTRUMENT_MANAGER_CONFIGURATION) != null)
+ {
this.setInstrumentManagerConfiguration(p.getProperty(PROPERTY_INSTRUMENT_MANAGER_CONFIGURATION));
+ }
if (p.getProperty(PROPERTY_INVOKE_METHOD) != null)
+ {
this.setInvokeMethod(p.getProperty(PROPERTY_INVOKE_METHOD));
+ }
if (p.getProperty(PROPERTY_LOGGER_MANAGER_CONFIGURATION) != null)
+ {
this.setLoggerManagerConfiguration(p.getProperty(PROPERTY_LOGGER_MANAGER_CONFIGURATION));
+ }
if (p.getProperty(PROPERTY_LOOKUP_COMPONENT_ROLE) != null)
+ {
this.setLookupComponentRole(p.getProperty(PROPERTY_LOOKUP_COMPONENT_ROLE));
+ }
if (p.getProperty(PROPERTY_ROLE_MANAGER_CONFIGURATION) != null)
+ {
this.setRoleManagerConfiguration(p.getProperty(PROPERTY_ROLE_MANAGER_CONFIGURATION));
+ }
if (p.getProperty(PROPERTY_SYSTEM_EXIT_ON_DISPOSE) != null)
+ {
this.setSystemExitOnDispose(Boolean.valueOf(p.getProperty(PROPERTY_SYSTEM_EXIT_ON_DISPOSE)).booleanValue());
+ }
if (p.getProperty(PROPERTY_WORK_DIRECTORY) != null)
+ {
this.setWorkDirectory(p.getProperty(PROPERTY_WORK_DIRECTORY));
+ }
}
- public void run() throws Exception {
- Object component = getServiceManager().lookup(lookupComponentRole);
- Method method = component.getClass().getMethod(invokeMethod, null);
+ public void run() throws Exception
+ {
+ Object component = getServiceManager().lookup(m_lookupComponentRole);
+ Method method = component.getClass().getMethod(m_invokeMethod, null);
method.invoke(component, null);
}
/**
* Implementation execute() method for Ant compatability.
*/
- public void execute() {
- try {
+ public void execute()
+ {
+ try
+ {
initialize();
- try {
+ try
+ {
run();
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
getLogger().error("error while running", e);
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
getLogger().error("error while initializing", e);
}
dispose();
@@ -174,32 +225,43 @@
/**
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
- public void service(ServiceManager sm) throws ServiceException {
- if (this.sm == null) this.sm = sm;
+ public void service(ServiceManager sm) throws ServiceException
+ {
+ if (m_sm == null)
+ {
+ m_sm = sm;
+ }
}
/**
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
- public void dispose() {
+ public void dispose()
+ {
// Properly clean up when we are done
- org.apache.avalon.framework.container.ContainerUtil.dispose( cm );
+ ContainerUtil.dispose(m_cm);
disposeCommonsLogging();
+
//system exit, in case we were running some GUI and some thread is still active
- if (this.systemExitOnDispose) {
+ if (m_systemExitOnDispose)
+ {
Thread.yield();
- try {
+ try
+ {
Thread.sleep(100);
- } catch (InterruptedException e) {
+ }
+ catch (InterruptedException e)
+ {
//ignore
}
-
+
System.exit(0);
}
}
- protected ServiceManager getServiceManager() {
- return this.sm;
+ protected ServiceManager getServiceManager()
+ {
+ return m_sm;
}
/**
@@ -208,41 +270,50 @@
*
* @param containerClass fully qualified class name of the container implementation class.
*/
- public void setContainerClass(String containerClass) throws Exception {
- config.setContextClassLoader(getClass().getClassLoader());
- config.setContainerClass(containerClass);
+ public void setContainerClass(String containerClass) throws Exception
+ {
+ m_config.setContextClassLoader(getClass().getClassLoader());
+ m_config.setContainerClass(containerClass);
}
- public void setContainerConfiguration(String containerConfiguration) {
- config.setContainerConfiguration(containerConfiguration);
+ public void setContainerConfiguration(String containerConfiguration)
+ {
+ m_config.setContainerConfiguration(containerConfiguration);
}
- public void setContextDirectory(String contextDirectory) {
- config.setContextDirectory(contextDirectory);
+ public void setContextDirectory(String contextDirectory)
+ {
+ m_config.setContextDirectory(contextDirectory);
}
- public void setInstrumentManagerConfiguration(String instrumentManagerConfiguration) {
- config.setInstrumentManagerConfiguration(instrumentManagerConfiguration);
+ public void setInstrumentManagerConfiguration(String instrumentManagerConfiguration)
+ {
+ m_config.setInstrumentManagerConfiguration(instrumentManagerConfiguration);
}
- public void setLoggerManagerConfiguration(String loggerManagerConfiguration) {
- config.setLoggerManagerConfiguration(loggerManagerConfiguration);
+ public void setLoggerManagerConfiguration(String loggerManagerConfiguration)
+ {
+ m_config.setLoggerManagerConfiguration(loggerManagerConfiguration);
}
- public void setRoleManagerConfiguration(String roleManagerConfiguration) {
- config.setRoleManagerConfiguration(roleManagerConfiguration);
+ public void setRoleManagerConfiguration(String roleManagerConfiguration)
+ {
+ m_config.setRoleManagerConfiguration(roleManagerConfiguration);
}
- public void setWorkDirectory(String workDirectory) {
- config.setWorkDirectory(workDirectory);
+ public void setWorkDirectory(String workDirectory)
+ {
+ m_config.setWorkDirectory(workDirectory);
}
- public void setInvokeMethod(String invokeMethod) {
- this.invokeMethod = invokeMethod;
+ public void setInvokeMethod(String invokeMethod)
+ {
+ m_invokeMethod = invokeMethod;
}
- public void setLookupComponentRole(String lookupComponentRole) {
- this.lookupComponentRole = lookupComponentRole;
+ public void setLookupComponentRole(String lookupComponentRole)
+ {
+ m_lookupComponentRole = lookupComponentRole;
}
/**
@@ -250,20 +321,28 @@
* Useful if the components have a GUI and there are some threads running that
* do not allow the JVM to exit.
*/
- public void setSystemExitOnDispose(boolean systemExitOnDispose) {
- this.systemExitOnDispose = systemExitOnDispose;
+ public void setSystemExitOnDispose(boolean systemExitOnDispose)
+ {
+ m_systemExitOnDispose = systemExitOnDispose;
}
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
FortressBean bean = new FortressBean();
bean.setProperties(System.getProperties());
- if (args.length > 0) bean.setLookupComponentRole(args[0]);
- if (args.length > 1) bean.setInvokeMethod(args[1]);
+ if (args.length > 0)
+ {
+ bean.setLookupComponentRole(args[0]);
+ }
+ if (args.length > 1)
+ {
+ bean.setInvokeMethod(args[1]);
+ }
bean.execute();
}
- public void setProperties(Properties properties) {
- this.properties = properties;
+ public void setProperties(Properties properties)
+ {
+ m_properties = properties;
}
-
}
Modified: excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/FortressBeanTestCase.java
==============================================================================
--- excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/FortressBeanTestCase.java (original)
+++ excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/FortressBeanTestCase.java Fri Jul 2 13:31:56 2004
@@ -19,37 +19,41 @@
import junit.framework.TestCase;
-public class FortressBeanTestCase extends TestCase {
+public class FortressBeanTestCase extends TestCase
+{
+ private FortressBean m_bean;
- private FortressBean bean;
-
- public FortressBeanTestCase(String name) {
+ public FortressBeanTestCase(String name)
+ {
super(name);
}
/**
* @see junit.framework.TestCase#setUp()
*/
- protected void setUp() throws Exception {
- this.bean = new FortressBean();
- this.bean.setRoleManagerConfiguration("resource://org/apache/avalon/fortress/tools/FortressBeanTestCase.roles");
- this.bean.setContainerConfiguration("resource://org/apache/avalon/fortress/tools/FortressBeanTestCase.xconf");
- this.bean.setLoggerManagerConfiguration("resource://org/apache/avalon/fortress/tools/FortressBeanTestCase.xlog");
- this.bean.setLookupComponentRole(TestInterface.ROLE);
- this.bean.setInvokeMethod("run");
- this.bean.setSystemExitOnDispose(false);
- this.bean.initialize();
- this.bean.run();
+ protected void setUp() throws Exception
+ {
+ m_bean = new FortressBean();
+ m_bean.setRoleManagerConfiguration("resource://org/apache/avalon/fortress/tools/FortressBeanTestCase.roles");
+ m_bean.setContainerConfiguration("resource://org/apache/avalon/fortress/tools/FortressBeanTestCase.xconf");
+ m_bean.setLoggerManagerConfiguration(
+ "resource://org/apache/avalon/fortress/tools/FortressBeanTestCase.xlog");
+ m_bean.setLookupComponentRole(TestInterface.ROLE);
+ m_bean.setInvokeMethod("run");
+ m_bean.setSystemExitOnDispose(false);
+ m_bean.initialize();
+ m_bean.run();
}
- protected void tearDown() throws Exception {
- this.bean.dispose();
+ protected void tearDown() throws Exception
+ {
+ m_bean.dispose();
}
- public void test() throws Exception {
- TestInterface ti = (TestInterface) this.bean.getServiceManager().lookup(TestInterface.ROLE);
+ public void test() throws Exception
+ {
+ TestInterface ti = (TestInterface) m_bean.getServiceManager().lookup(TestInterface.ROLE);
assertNotNull(ti);
assertTrue(ti.isRunning());
}
-
}
Modified: excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/TestImpl.java
==============================================================================
--- excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/TestImpl.java (original)
+++ excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/TestImpl.java Fri Jul 2 13:31:56 2004
@@ -23,22 +23,23 @@
* @author <a href="mailto:dev@avalon.apache.org">The Avalon Team</a>
* @version CVS $Revision: 1.3 $ $Date: 2004/02/28 15:16:27 $
*/
-public class TestImpl implements TestInterface {
-
- private boolean isRunning = false;
+public class TestImpl implements TestInterface
+{
+ private boolean m_isRunning = false;
/**
* @see org.apache.avalon.fortress.tools.TestInterface#isRunning()
*/
- public boolean isRunning() {
- return this.isRunning;
+ public boolean isRunning()
+ {
+ return m_isRunning;
}
/**
* @see org.apache.avalon.fortress.tools.TestInterface#run()
*/
- public void run() {
- this.isRunning = true;
+ public void run()
+ {
+ m_isRunning = true;
}
-
}
Modified: excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/TestInterface.java
==============================================================================
--- excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/TestInterface.java (original)
+++ excalibur/branches/fortress-experiments/bean/src/test/org/apache/avalon/fortress/tools/TestInterface.java Fri Jul 2 13:31:56 2004
@@ -23,12 +23,11 @@
* @author <a href="mailto:dev@avalon.apache.org">The Avalon Team</a>
* @version CVS $Revision: 1.3 $ $Date: 2004/02/28 15:16:27 $
*/
-public interface TestInterface {
-
+public interface TestInterface
+{
static final String ROLE = TestInterface.class.getName();
void run();
boolean isRunning();
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org