Author: reinhard
Date: Tue Oct 12 01:49:48 2004
New Revision: 54663

Modified:
   
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Searchable.java
   
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RealRemoteBlock.java
   
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java
   
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java
   
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java
   
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java
Log:
- work on exceptions
- some Javadocs

Modified: 
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Searchable.java
==============================================================================
--- 
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Searchable.java
 (original)
+++ 
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Searchable.java
 Tue Oct 12 01:49:48 2004
@@ -32,6 +32,13 @@
      * 
      * @return a sorted array of all locators that contain the named block
      */
-    public RemoteBlock[] lookupBlock(String blockId);
+    public RemoteBlock[] lookupBlock(String blockId) throws 
BlockNotFoundException;
 
+    /**
+     * Query the repositry whether it has a certain block or not.
+     * @param block URI
+     * @return true if the block can be provided by the repository, false if 
not
+     */
+    public boolean hasBlock(String blockId);
+    
 }

Modified: 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RealRemoteBlock.java
==============================================================================
--- 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RealRemoteBlock.java
        (original)
+++ 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RealRemoteBlock.java
        Tue Oct 12 01:49:48 2004
@@ -59,4 +59,10 @@
         return this.blockId;
     }
     
+    public String toString() {
+       StringBuffer sb = new StringBuffer();
+       sb.append("id: " + this.blockId + ", locator: " + 
this.locator.toString());
+       return sb.toString();
+    }
+    
 }

Modified: 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java
==============================================================================
--- 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java
     (original)
+++ 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java
     Tue Oct 12 01:49:48 2004
@@ -36,7 +36,8 @@
 
     /**
      * Creates a RemoteBlock based on the descriptor and is called from
-     * a locator which wants to provide a RemoteBlock.
+     * a locator which wants to provide a RemoteBlock. (It's not the job of
+     * the locator to know where to find and how to read the descriptor file.)
      * 
      * @param descriptorString is a string containing the BlockDescription 
(block.xml)
      * @return the RemoteBlock

Modified: 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java
==============================================================================
--- 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java
 (original)
+++ 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java
 Tue Oct 12 01:49:48 2004
@@ -15,6 +15,7 @@
  */
 package org.apache.cocoon.blockdeployer.repository;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -48,7 +49,14 @@
         return null;
     }
 
-    public RemoteBlock[] lookupBlock(String blockId) {
+    /**
+     * Query all available locators in the order they are set whether they
+     * can provide a block.
+     * 
+     * @param blockId is the URI of the block
+     * @throws BlockNotFoundException if the block can't be found in any 
locator.
+     */
+    public RemoteBlock[] lookupBlock(String blockId) throws 
BlockNotFoundException {
         ArrayList tempLocators = new ArrayList();
         // if the locator has the requested block it is added
         Iterator locatorsIterator = this.locators.iterator();
@@ -57,14 +65,16 @@
             RemoteBlock remoteBlock = null;
             try {
                 remoteBlock = locator.getRemoteBlock(blockId);
-               if(remoteBlock != null) {
-                   tempLocators.add(remoteBlock);
-               }                
-            } catch(Exception ex) { 
-                // don't add this RemoteBlock to the list
+                tempLocators.add(remoteBlock);   
+            } catch (BlockNotFoundException e) {
+                // block not added to the list to be returned
+            } catch (IOException e) {
+                // don't tell client that block is there but can't be read ...
             }
         }
-        
+        if(tempLocators.size() == 0) {
+            throw new BlockNotFoundException("The block " + blockId + " can't 
be found in any of the provided locators.");
+        }
         Object[] array = tempLocators.toArray();
         RemoteBlock[] resultRemoteBlock = new RemoteBlock[tempLocators.size()];
         for(int i = 0; i < tempLocators.size(); i++) {
@@ -81,6 +91,10 @@
             sb.append(" " + i + ". " + locator.getIdentifier() );            
         }
         return sb.toString();
+    }
+
+    public boolean hasBlock(String blockId) {
+        return false;
     }
 
 }

Modified: 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java
==============================================================================
--- 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java
 (original)
+++ 
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java
 Tue Oct 12 01:49:48 2004
@@ -78,7 +78,6 @@
     }
     
     public RemoteBlock getRemoteBlock(String blockUri) throws IOException, 
BlockNotFoundException {
-        // get the RemoteBlock from the factory
         InputStream descriptorInputStream = 
this.getBlockDescriptorAsStream(blockUri);
         if(descriptorInputStream == null) {
             throw new BlockNotFoundException("Block " + blockUri + " not 
found.");

Modified: 
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java
==============================================================================
--- 
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java
   (original)
+++ 
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java
   Tue Oct 12 01:49:48 2004
@@ -96,6 +96,7 @@
         
         // test that myBlock3 is returned twice, having the locators locator2 
and locator3
         RemoteBlock[] resultRemoteBlock = 
defaultRepository.lookupBlock("myBlock3");
+        System.out.println("test: " + resultRemoteBlock.toString());
         assertEquals(resultRemoteBlock[0].getLocator().getIdentifier(), 
locator2Name);
         assertEquals(resultRemoteBlock[1].getLocator().getIdentifier(), 
locator3Name);   
         assertEquals(resultRemoteBlock.length, 2);
@@ -117,7 +118,13 @@
         String[] allUnavailableBlocks = {"myBlock1"};   
         String locator1Name = "locator1";
         defaultRepository.addLocator(
-                createMockLocator(locator1Name, new String[0], 
allUnavailableBlocks, new String[] {"myBlock4"}));        
+                createMockLocator(locator1Name, new String[0], 
allUnavailableBlocks, new String[0]));    
+        try {
+            RemoteBlock[] resultRemoteBlock = 
defaultRepository.lookupBlock("myBlock1");
+            fail("This block shouldn't be available in the repository and 
therefore throw an BlockNotFoundException");
+        } catch(BlockNotFoundException bnfe) {
+            // correct behaviour
+        }
     }
     
     /**
@@ -148,7 +155,7 @@
                 control1.setReturnValue(remoteBlock, 
MockControl.ZERO_OR_MORE);                       
             }
             else {
-                control1.setReturnValue(null, MockControl.ZERO_OR_MORE);
+                control1.setThrowable(new BlockNotFoundException());
             }
         }
         

Reply via email to