You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2005/11/14 21:48:03 UTC
svn commit: r344226 - in
/cocoon/trunk/src/java/org/apache/cocoon/components/blocks:
BlockManager.java InterBlockServiceManager.java
Author: danielf
Date: Mon Nov 14 12:47:58 2005
New Revision: 344226
URL: http://svn.apache.org/viewcvs?rev=344226&view=rev
Log:
Started to integrate the InterBlockServiceManager. Haven't
start to test it yet, but at least got the old tests running ;)
Modified:
cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java
cocoon/trunk/src/java/org/apache/cocoon/components/blocks/InterBlockServiceManager.java
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java?rev=344226&r1=344225&r2=344226&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java Mon Nov 14 12:47:58 2005
@@ -54,6 +54,7 @@
private Context context;
private Configuration config;
private ServiceManager parentServiceManager;
+ private InterBlockServiceManager interBlockSM;
private ServiceManager serviceManager;
private Processor blockProcessor;
@@ -89,12 +90,17 @@
this.blockContext = new BlockContext(this.blockWiring, this);
Context newContext = this.getAvalonContext();
+
+ // Create a service manager for getting components from other blocks
+ this.interBlockSM = new InterBlockServiceManager(this.blockWiring, this.parentServiceManager);
+ this.interBlockSM.enableLogging(this.getLogger());
+
+ String confLocation = this.blockWiring.getContextURL() + "::";
+ ServiceManager sourceResolverSM =
+ this.createLocalSourceResolverSM(newContext, this.interBlockSM, confLocation);
- // Create block a service manager with the exposed components of the block
+ // Create a service manager with the exposed components of the block
if (this.blockWiring.getComponentConfiguration() != null) {
- String confLocation = this.blockWiring.getContextURL() + "::";
- ServiceManager sourceResolverSM = this.createLocalSourceResolverSM(newContext, confLocation);
-
DefaultConfiguration componentConf =
new DefaultConfiguration("components", confLocation);
componentConf.addAll(this.blockWiring.getComponentConfiguration());
@@ -105,7 +111,7 @@
null,
componentConf);
} else {
- this.serviceManager = this.parentServiceManager;
+ this.serviceManager = sourceResolverSM;
}
// Create a processor for the block
@@ -145,7 +151,7 @@
* @return
* @throws Exception
*/
- protected ServiceManager createLocalSourceResolverSM(Context newContext, String confLocation) throws Exception {
+ protected ServiceManager createLocalSourceResolverSM(Context newContext, ServiceManager parentServiceManager, String confLocation) throws Exception {
// The source resolver must be defined in this service
// manager, otherwise the root path will be the one from the
// parent manager, we add a resolver to get it right. If the
@@ -154,11 +160,16 @@
// for resolving the include.
DefaultConfiguration sourceManagerConf =
new DefaultConfiguration("components", confLocation);
+ // FIXME: Need a local role manager as it is not inherited through the InterBlockServiceManager
+ DefaultConfiguration roleInclude =
+ new DefaultConfiguration("include");
+ roleInclude.setAttribute("src", "resource://org/apache/cocoon/cocoon.roles");
+ sourceManagerConf.addChild(roleInclude);
DefaultConfiguration resolverConf =
new DefaultConfiguration("source-resolver");
sourceManagerConf.addChild(resolverConf);
ServiceManager sourceResolverSM =
- new CoreServiceManager(this.parentServiceManager);
+ new CoreServiceManager(parentServiceManager);
LifecycleHelper.setupComponent(
sourceResolverSM,
this.getLogger(),
@@ -176,6 +187,7 @@
// blocks should have in common.
public void setBlocksManager(BlocksManager blocksManager) {
this.blocksManager = blocksManager;
+ this.interBlockSM.setBlocksManager(blocksManager);
}
/**
@@ -211,7 +223,7 @@
*/
public ServiceManager getServiceManager() {
// Check that the block have a local service manager
- if (this.serviceManager != this.parentServiceManager) {
+ if (this.serviceManager != this.interBlockSM) {
return this.serviceManager;
} else {
return null;
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/InterBlockServiceManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/InterBlockServiceManager.java?rev=344226&r1=344225&r2=344226&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/InterBlockServiceManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/InterBlockServiceManager.java Mon Nov 14 12:47:58 2005
@@ -17,8 +17,10 @@
package org.apache.cocoon.components.blocks;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Map;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
@@ -27,19 +29,30 @@
*
* @version SVN $Id$
*/
-public class InterBlockServiceManager implements ServiceManager {
+public class InterBlockServiceManager extends AbstractLogEnabled implements ServiceManager {
private BlockWiring blockWiring;
private BlocksManager blocksManager;
- private Map managers;
+ /* FIXME: Geting components from a parent manager is only a temporary solution, everything should be
+ * found from sibling blocks. There should be one core block that contains common components.
+ */
+ private ServiceManager parentManager;
+ private Map managers = new HashMap();
private boolean called;
/**
* @param blockWiring
* @param blocksManager
*/
- public InterBlockServiceManager(BlockWiring blockWiring, BlocksManager blocksManager) {
+ public InterBlockServiceManager(BlockWiring blockWiring, ServiceManager parentManager) {
this.blockWiring = blockWiring;
+ this.parentManager = parentManager;
+ }
+
+ /**
+ * @param blocksManager The blocksManager to set.
+ */
+ public void setBlocksManager(BlocksManager blocksManager) {
this.blocksManager = blocksManager;
}
@@ -52,7 +65,7 @@
throw new ServiceException(role, "Could not find any manager in connected blocks that contains the role");
}
Object component = manager.lookup(role);
- // Keep track on what manager that was used so that we can return the
+ // Keep track on what manager that was used so that we can return the component
this.managers.put(component, manager);
return component;
}
@@ -88,6 +101,7 @@
* @return the found service manager or null if not found
*/
private ServiceManager findServiceManager(String role) {
+ this.getLogger().debug("findServiceManager: blockId=" + this.blockWiring.getId() + " role=" + role);
// FIXME: Called is used for protection about infinite loops for blocks with circular dependencies.
// It must be made thread safe.
if (called) {
@@ -97,6 +111,14 @@
}
ServiceManager manager = null;
try {
+ if (this.parentManager != null) {
+ if (this.parentManager.hasService(role)) {
+ return this.parentManager;
+ }
+ }
+ // Don't try to use components from other blocks during setup
+ if (this.blocksManager == null)
+ return null;
Enumeration connectionNames = this.blockWiring.getConnectionNames();
while (connectionNames.hasMoreElements()) {
String blockName = (String)connectionNames.nextElement();