oalexeev 02/01/22 10:44:34
Modified: services/src/java/org/apache/commons/services
EventModule.java Module.java QueueModule.java
ServiceManager.java ServiceModule.java
Added: services/src/java/org/apache/commons/services
ConfigObject.java ConfigObjectCreateRule.java
InitConfigRule.java
Log:
Add ability to register Digester rules at phase of config parsing.
Revision Changes Path
1.4 +25 -2
jakarta-commons-sandbox/services/src/java/org/apache/commons/services/EventModule.java
Index: EventModule.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/EventModule.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EventModule.java 19 Dec 2001 16:58:24 -0000 1.3
+++ EventModule.java 22 Jan 2002 18:44:34 -0000 1.4
@@ -11,10 +11,11 @@
import java.util.Map;
import java.util.HashMap;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.apache.commons.digester.Digester;
/** Event module. Generate events.
*
- * @version $Id: EventModule.java,v 1.3 2001/12/19 16:58:24 oalexeev Exp $
+ * @version $Id: EventModule.java,v 1.4 2002/01/22 18:44:34 oalexeev Exp $
* @author Oleg V Alexeev
*/
public class EventModule extends Module {
@@ -75,4 +76,26 @@
return (Event)pool.borrowObject( defaultEventRegistration.getName()
);
}
-}
\ No newline at end of file
+ public Digester initDigester( Digester digester, String path ) {
+
+ if( path!=null )
+ path += "/";
+ else
+ path = "";
+
+ String serviceManagerPath =
+ path + "service-manager";
+
+ String eventsRegistrationPath =
+ serviceManagerPath + "/event-module";
+
+ String servicesRegistrationPath =
+ serviceManagerPath + "/service-module";
+
+ String queuesRegistrationPath =
+ serviceManagerPath + "/queue-module";
+
+ return digester;
+ }
+
+}
1.2 +2 -2
jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Module.java
Index: Module.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Module.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Module.java 17 Dec 2001 16:38:18 -0000 1.1
+++ Module.java 22 Jan 2002 18:44:34 -0000 1.2
@@ -12,10 +12,10 @@
/** Base class for modules.
*
- * @version $Id: Module.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
+ * @version $Id: Module.java,v 1.2 2002/01/22 18:44:34 oalexeev Exp $
* @author Oleg V Alexeev
*/
-public class Module implements Serializable {
+public abstract class Module implements Serializable, ConfigObject {
protected boolean strongCheck = false;
1.2 +6 -1
jakarta-commons-sandbox/services/src/java/org/apache/commons/services/QueueModule.java
Index: QueueModule.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/QueueModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QueueModule.java 17 Dec 2001 16:38:18 -0000 1.1
+++ QueueModule.java 22 Jan 2002 18:44:34 -0000 1.2
@@ -11,10 +11,11 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
+import org.apache.commons.digester.Digester;
/** QueueModule - manages queues.
*
- * @version $Id: QueueModule.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
+ * @version $Id: QueueModule.java,v 1.2 2002/01/22 18:44:34 oalexeev Exp $
* @author Oleg V Alexeev
*/
public class QueueModule extends Module {
@@ -82,6 +83,10 @@
public Queue getDefaultQueue() {
return defaultQueue;
+ }
+
+ public Digester initDigester( Digester digester, String path ) {
+ return digester;
}
}
1.5 +66 -2
jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceManager.java
Index: ServiceManager.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServiceManager.java 21 Jan 2002 21:26:28 -0000 1.4
+++ ServiceManager.java 22 Jan 2002 18:44:34 -0000 1.5
@@ -12,11 +12,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogSource;
import org.apache.commons.logging.SimpleLog;
+import org.apache.commons.digester.Digester;
/**
* Core class in package.
*
- * @version $Id: ServiceManager.java,v 1.4 2002/01/21 21:26:28 craigmcc Exp $
+ * @version $Id: ServiceManager.java,v 1.5 2002/01/22 18:44:34 oalexeev Exp $
* @author Oleg V Alexeev
*/
public class ServiceManager implements Serializable {
@@ -78,8 +79,71 @@
this.queueModule.setServiceManager( this );
}
+ public String getConfigURI() {
+ return "";
+ }
+
+ public Digester initDigester( Digester digester, String path ) {
+
+ if( path!=null )
+ path += "/";
+ else
+ path = "";
+
+ String serviceManagerPath =
+ path + "service-manager";
+
+ String eventsRegistrationPath =
+ serviceManagerPath + "/event-module";
+
+ String servicesRegistrationPath =
+ serviceManagerPath + "/service-module";
+
+ String queuesRegistrationPath =
+ serviceManagerPath + "/queue-module";
+
+ // Init wrapper rule
+ digester.addRule( serviceManagerPath,
+ new InitConfigRule( digester, this ) );
+ digester.addSetProperties( serviceManagerPath );
+
+ //----------------------------
+ // Init events
+ digester.addRule( eventsRegistrationPath,
+ new ConfigObjectCreateRule( digester,
+ "org.apache.commons.services.EventModule", "type",
+ eventsRegistrationPath ) );
+ digester.addSetNext( eventsRegistrationPath, "setEventModule",
+ "org.apache.commons.services.EventModule" );
+
+ // Init services
+ digester.addRule( servicesRegistrationPath,
+ new ConfigObjectCreateRule( digester,
+ "org.apache.commons.services.ServiceModule", "type",
+ servicesRegistrationPath ) );
+ digester.addSetNext( eventsRegistrationPath, "setServiceModule",
+ "org.apache.commons.services.ServiceModule" );
+
+ // Init queues
+ digester.addRule( queuesRegistrationPath,
+ new ConfigObjectCreateRule( digester,
+ "org.apache.commons.services.QueueModule", "type",
+ queuesRegistrationPath ) );
+ digester.addSetNext( eventsRegistrationPath, "setQueueModule",
+ "org.apache.commons.services.QueueModule" );
+
+ //----------------------------
+
+ return digester;
+
+ }
+
public void init() {
- ;
+ Digester digester = initDigester( new Digester(), null );
+ try {
+ digester.parse( getConfigURI() );
+ } catch ( Exception e ) {
+ }
}
public void destroy() {
1.2 +6 -1
jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceModule.java
Index: ServiceModule.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceModule.java 17 Dec 2001 16:38:18 -0000 1.1
+++ ServiceModule.java 22 Jan 2002 18:44:34 -0000 1.2
@@ -11,10 +11,11 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
+import org.apache.commons.digester.Digester;
/** ServiceModule manages services.
*
- * @version $Id: ServiceModule.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
+ * @version $Id: ServiceModule.java,v 1.2 2002/01/22 18:44:34 oalexeev Exp $
* @author Oleg V Alexeev
*/
public class ServiceModule extends Module {
@@ -68,6 +69,10 @@
public Iterator getServices() {
return services.values().iterator();
+ }
+
+ public Digester initDigester( Digester digester, String path ) {
+ return digester;
}
}
1.1
jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ConfigObject.java
Index: ConfigObject.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.commons.services;
import org.apache.commons.digester.Digester;
/**
*
* @version $Id: ConfigObject.java,v 1.1 2002/01/22 18:44:34 oalexeev Exp $
* @author Oleg V Alexeev
*/
public interface ConfigObject {
public Digester initDigester( Digester digester, String path );
}
1.1
jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ConfigObjectCreateRule.java
Index: ConfigObjectCreateRule.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.commons.services;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.Rule;
import org.apache.commons.digester.ObjectCreateRule;
import org.xml.sax.Attributes;
/**
* @author Oleg V Alexeev
* @version $Revision: 1.1 $ $Date: 2002/01/22 18:44:34 $
*/
public class ConfigObjectCreateRule extends ObjectCreateRule {
String initialPath = null;
public void setInitialPath( String initialPath ) {
this.initialPath = initialPath;
}
public String getInitialPath() {
return initialPath;
}
public ConfigObjectCreateRule( Digester digester, String className,
String attributeName, String initialPath ) {
super( digester, className, attributeName );
setInitialPath( initialPath );
}
public void begin( Attributes attributes ) throws Exception {
super.begin( attributes );
Object configObject = digester.peek();
if( configObject instanceof ConfigObject ) {
((ConfigObject)configObject).initDigester(
digester, initialPath );
if (digester.getLogger().isDebugEnabled()) {
digester.getLogger().debug("Call to the
initDigester() for "
+ configObject.getClass().getName());
}
}
}
}
1.1
jakarta-commons-sandbox/services/src/java/org/apache/commons/services/InitConfigRule.java
Index: InitConfigRule.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.commons.services;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.Rule;
import org.xml.sax.Attributes;
/**
* @author Oleg V Alexeev
* @version $Revision: 1.1 $ $Date: 2002/01/22 18:44:34 $
*/
public class InitConfigRule extends Rule {
protected ServiceManager serviceManager = null;
public InitConfigRule( Digester digester, ServiceManager serviceManager ) {
super( digester );
this.serviceManager = serviceManager;
}
public void begin( Attributes attributes ) throws Exception {
digester.push( serviceManager );
}
public void end() throws Exception {
digester.pop();
}
public void finish() throws Exception {
serviceManager = null;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>