cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r351990 - in /cocoon/trunk/src/java/org/apache/cocoon/blocks: BlockDispatcherProcessor.java BlockManager.java Blocks.java BlocksManager.java InterBlockServiceManager.java
Date Sat, 03 Dec 2005 17:19:05 GMT
Author: danielf
Date: Sat Dec  3 09:18:50 2005
New Revision: 351990

URL: http://svn.apache.org/viewcvs?rev=351990&view=rev
Log:
Interface for requesting blocks.

Added:
    cocoon/trunk/src/java/org/apache/cocoon/blocks/Blocks.java   (with props)
Modified:
    cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockDispatcherProcessor.java
    cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockManager.java
    cocoon/trunk/src/java/org/apache/cocoon/blocks/BlocksManager.java
    cocoon/trunk/src/java/org/apache/cocoon/blocks/InterBlockServiceManager.java   (contents,
props changed)

Modified: cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockDispatcherProcessor.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockDispatcherProcessor.java?rev=351990&r1=351989&r2=351990&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockDispatcherProcessor.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockDispatcherProcessor.java Sat Dec 
3 09:18:50 2005
@@ -31,16 +31,16 @@
  */
 public class BlockDispatcherProcessor extends AbstractLogEnabled implements Processor {
 
-    private BlocksManager blocksManager;
+    private Blocks blocks;
 
     /** Processor attributes */
     private Map processorAttributes = new HashMap();
    
     /**
-     * @param blocksManager
+     * @param blocks
      */
-    public BlockDispatcherProcessor(BlocksManager blocksManager) {
-        this.blocksManager = blocksManager;
+    public BlockDispatcherProcessor(Blocks blocks) {
+        this.blocks = blocks;
     }
 
     /* (non-Javadoc)
@@ -55,7 +55,7 @@
         if (uri.length() == 0 || uri.charAt(0) != '/') {
             uri = "/" + uri;
         }
-        Block block = this.blocksManager.getMountedBlock(uri);
+        Block block = this.blocks.getMountedBlock(uri);
         if (block == null) {
             return false;
         } else {

Modified: cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockManager.java?rev=351990&r1=351989&r2=351990&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/blocks/BlockManager.java Sat Dec  3 09:18:50 2005
@@ -60,7 +60,7 @@
     private Processor blockProcessor;
     private BlockWiring blockWiring;
     private BlockContext blockContext;
-    private BlocksManager blocksManager;
+    private Blocks blocks;
 
     // Life cycle
 
@@ -96,7 +96,7 @@
             this.serviceManager = this.parentServiceManager;
        } else {
             // Create a service manager for getting components from other blocks
-            ServiceManager topServiceManager = new InterBlockServiceManager(this.blockWiring,
this.blocksManager);
+            ServiceManager topServiceManager = new InterBlockServiceManager(this.blockWiring,
this.blocks);
             ((InterBlockServiceManager)topServiceManager).enableLogging(this.getLogger());
 
             this.serviceManager =
@@ -187,8 +187,8 @@
     // didn't want to make it part of the parent manager. But this is
     // a little bit clumsy. Question is what components, if any, the
     // blocks should have in common.
-    public void setBlocksManager(BlocksManager blocksManager) {
-    	this.blocksManager = blocksManager;
+    public void setBlocks(Blocks blocks) {
+    	this.blocks = blocks;
     }
 
     /**
@@ -207,7 +207,7 @@
 		    // Ask the super block for the property
 		    String superId = this.blockWiring.getBlockId(Block.SUPER);
 		    this.getLogger().debug("Try super property=" + name + " block=" + superId);
-		    Block block = this.blocksManager.getBlock(superId);
+		    Block block = this.blocks.getBlock(superId);
 		    if (block != null) {
 		        value =  block.getProperty(name);
 		    }
@@ -246,7 +246,7 @@
         } else {
             // another block
         	String blockId = this.blockWiring.getBlockId(blockName);
-            block = this.blocksManager.getBlock(blockId);
+            block = this.blocks.getBlock(blockId);
         }
         if (block == null)
             throw new URISyntaxException(uriToResolve.toString(), "Unknown block name");
@@ -311,7 +311,7 @@
             	}
         		superCall = true;
             }
-            Block block = this.blocksManager.getBlock(blockId);
+            Block block = this.blocks.getBlock(blockId);
     		if (block == null) {
     			return false;
     		}

Added: cocoon/trunk/src/java/org/apache/cocoon/blocks/Blocks.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/blocks/Blocks.java?rev=351990&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/blocks/Blocks.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/blocks/Blocks.java Sat Dec  3 09:18:50 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blocks;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.Processor;
+
+/**
+ * @version SVN $Id$
+ */
+public interface Blocks { 
+
+    /**
+     * Returns the block with the specified identity
+     * @param blockId
+     * @return
+     */
+    Block getBlock(String blockId);
+    
+    /**
+     * The block with the largest mount point that is a prefix of the URI is
+     * chosen.
+     * @param uri
+     * @return
+     */
+    Block getMountedBlock(String uri);
+}

Propchange: cocoon/trunk/src/java/org/apache/cocoon/blocks/Blocks.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cocoon/trunk/src/java/org/apache/cocoon/blocks/BlocksManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/blocks/BlocksManager.java?rev=351990&r1=351989&r2=351990&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/blocks/BlocksManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/blocks/BlocksManager.java Sat Dec  3 09:18:50
2005
@@ -54,7 +54,9 @@
  */
 public class BlocksManager
     extends AbstractLogEnabled
-    implements Configurable,
+    implements
+	Blocks,
+	Configurable,
         Contextualizable,
         Disposable,
         Initializable,
@@ -119,7 +121,7 @@
                               " id=" + blockConf.getAttribute("id") +
                               " location=" + blockConf.getAttribute("location"));
             BlockManager blockManager = new BlockManager();
-            blockManager.setBlocksManager(this);
+            blockManager.setBlocks(this);
             LifecycleHelper.setupComponent(blockManager,
                                            this.getLogger(),
                                            this.context,

Modified: cocoon/trunk/src/java/org/apache/cocoon/blocks/InterBlockServiceManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/blocks/InterBlockServiceManager.java?rev=351990&r1=351989&r2=351990&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/blocks/InterBlockServiceManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/blocks/InterBlockServiceManager.java Sat Dec 
3 09:18:50 2005
@@ -1,136 +1,136 @@
-/*
- * Copyright 2005 The Apache Software Foundation
- * Licensed  under the  Apache License,  Version 2.0  (the "License");
- * you may not use  this file  except in  compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed  under the  License is distributed on an "AS IS" BASIS,
- * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cocoon.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;
-
-/**
- * Look for a component in blocks that are connected to the current block.
- * 
- * @version SVN $Id$
- */
-public class InterBlockServiceManager extends AbstractLogEnabled implements ServiceManager
{
-    
-    private BlockWiring blockWiring;
-    private BlocksManager blocksManager;
-    private Map managers = new HashMap();
-    private boolean called;
-
-    /**
-     * @param blockWiring
-     * @param blocksManager
-     */
-    public InterBlockServiceManager(BlockWiring blockWiring, BlocksManager blocksManager)
{
-        this.blockWiring = blockWiring;
-        this.blocksManager = blocksManager;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String)
-     */
-    public Object lookup(String role) throws ServiceException {
-        ServiceManager manager = this.findServiceManager(role);
-        if (manager == null) {
-            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 component
-        this.managers.put(component, manager);
-        return component;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String)
-     */
-    public boolean hasService(String role) {
-        ServiceManager manager = this.findServiceManager(role);
-        return manager != null;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object)
-     */
-    public void release(Object component) {
-        if (component == null)
-            return;
-        ServiceManager manager = (ServiceManager)this.managers.get(component);
-        if (manager != null) {
-            manager.release(component);
-        }
-    }
-
-    
-    /**
-     * Find a service manager that contains a given role from one of the connected blocks.
The component
-     * managers of the connected blocks are searched in the order they are declared in the
block configuration.
-     * The super block, if there is one, is tried after the connected blocks. This is to
make certain that
-     * a blocks connections is searched before its super blocks connections. 
-     * 
-     * @param role the role to find a service manager for
-     * @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) {
-            return null;
-        } else {
-            this.called = true;
-        }
-        ServiceManager manager = null;
-        try {
-            Enumeration connectionNames = this.blockWiring.getConnectionNames();
-            while (connectionNames.hasMoreElements()) {
-                String blockName = (String)connectionNames.nextElement();
-                String blockId = this.blockWiring.getBlockId(blockName);
-                Block block = this.blocksManager.getBlock(blockId);
-                // Don't access blocks that isn't setup yet
-                if (block != null) {
-                    manager = block.getServiceManager();
-                    if (manager != null && manager.hasService(role)) {
-                        return manager;
-                    }
-                } else {
-                    this.getLogger().debug("Serching for role=" + role + " in blockId=" +
blockId + " that isn't setup.");
-                }
-            }
-            String superId = this.blockWiring.getBlockId(Block.SUPER);
-            if (superId != null) {
-                Block superBlock = this.blocksManager.getBlock(superId);
-                // Don't access blocks that isn't setup yet
-                if (superBlock != null) {
-                    manager = superBlock.getServiceManager();
-                    if (manager.hasService(role)) {
-                        return manager;
-                    }
-                } else {
-                    this.getLogger().debug("Serching for role=" + role + " in blockId=" +
superId + " that isn't setup.");
-                }
-            }
-        } finally {
-            this.called = false;
-        }
-        return null;
-    }
-}
+/*
+ * Copyright 2005 The Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.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;
+
+/**
+ * Look for a component in blocks that are connected to the current block.
+ * 
+ * @version SVN $Id$
+ */
+public class InterBlockServiceManager extends AbstractLogEnabled implements ServiceManager
{
+    
+    private BlockWiring blockWiring;
+    private Blocks blocks;
+    private Map managers = new HashMap();
+    private boolean called;
+
+    /**
+     * @param blockWiring
+     * @param blocks
+     */
+    public InterBlockServiceManager(BlockWiring blockWiring, Blocks blocks) {
+        this.blockWiring = blockWiring;
+        this.blocks = blocks;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String)
+     */
+    public Object lookup(String role) throws ServiceException {
+        ServiceManager manager = this.findServiceManager(role);
+        if (manager == null) {
+            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 component
+        this.managers.put(component, manager);
+        return component;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String)
+     */
+    public boolean hasService(String role) {
+        ServiceManager manager = this.findServiceManager(role);
+        return manager != null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object)
+     */
+    public void release(Object component) {
+        if (component == null)
+            return;
+        ServiceManager manager = (ServiceManager)this.managers.get(component);
+        if (manager != null) {
+            manager.release(component);
+        }
+    }
+
+    
+    /**
+     * Find a service manager that contains a given role from one of the connected blocks.
The component
+     * managers of the connected blocks are searched in the order they are declared in the
block configuration.
+     * The super block, if there is one, is tried after the connected blocks. This is to
make certain that
+     * a blocks connections is searched before its super blocks connections. 
+     * 
+     * @param role the role to find a service manager for
+     * @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) {
+            return null;
+        } else {
+            this.called = true;
+        }
+        ServiceManager manager = null;
+        try {
+            Enumeration connectionNames = this.blockWiring.getConnectionNames();
+            while (connectionNames.hasMoreElements()) {
+                String blockName = (String)connectionNames.nextElement();
+                String blockId = this.blockWiring.getBlockId(blockName);
+                Block block = this.blocks.getBlock(blockId);
+                // Don't access blocks that isn't setup yet
+                if (block != null) {
+                    manager = block.getServiceManager();
+                    if (manager != null && manager.hasService(role)) {
+                        return manager;
+                    }
+                } else {
+                    this.getLogger().debug("Serching for role=" + role + " in blockId=" +
blockId + " that isn't setup.");
+                }
+            }
+            String superId = this.blockWiring.getBlockId(Block.SUPER);
+            if (superId != null) {
+                Block superBlock = this.blocks.getBlock(superId);
+                // Don't access blocks that isn't setup yet
+                if (superBlock != null) {
+                    manager = superBlock.getServiceManager();
+                    if (manager.hasService(role)) {
+                        return manager;
+                    }
+                } else {
+                    this.getLogger().debug("Serching for role=" + role + " in blockId=" +
superId + " that isn't setup.");
+                }
+            }
+        } finally {
+            this.called = false;
+        }
+        return null;
+    }
+}

Propchange: cocoon/trunk/src/java/org/apache/cocoon/blocks/InterBlockServiceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message