You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2005/04/04 14:56:50 UTC
svn commit: r160036 - in cocoon/whiteboard/block-deployer:
src/api/org/apache/cocoon/blockdeployer/block/
src/api/org/apache/cocoon/blockdeployer/repository/
src/impl/org/apache/cocoon/blockdeployer/
src/impl/org/apache/cocoon/blockdeployer/block/
src/impl/org/apache/cocoon/blockdeployer/repository/
src/impl/org/apache/cocoon/blockdeployer/utils/
test/junit/org/apache/cocoon/blockdeployer/
test/junit/org/apache/cocoon/blockdeployer/repository/
test/sample-repositories/application-server/WEB-INF/blocks/
Author: reinhard
Date: Mon Apr 4 05:56:46 2005
New Revision: 160036
URL: http://svn.apache.org/viewcvs?view=rev&rev=160036
Log:
introduce interface 'transactional' for locators that support transactions; rename 'RemoteBlock' to 'Block' as the distinction isn't useful anymore; work on exception handling
Added:
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java
- copied, changed from r159025, cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/DeploymentException.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/TransactionException.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Transactional.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnsupportedBlockException.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java
- copied, changed from r159025, cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java
Removed:
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java
Modified:
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RecursiveBlockHierarchyException.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Browsable.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Searchable.java
cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Writeable.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10Resolver.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.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/DependencyBuilder.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/CommonsTransactionLogger.java
cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/LocatorUtils.java
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java
cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java
cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml
Copied: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java (from r159025, cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java)
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java?view=diff&rev=160036&p1=cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java&r1=159025&p2=cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RemoteBlock.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/Block.java Mon Apr 4 05:56:46 2005
@@ -23,11 +23,11 @@
/**
- * The RemoteBlock points to a block that can be reached by a locator. This
+ * The Block points to a block that can be reached by a locator. This
* object gives access to this locator, to its meta information and has a method
* to get the complete block as stream.
*/
-public interface RemoteBlock {
+public interface Block {
/**
* @return returns the Block uri
@@ -52,5 +52,11 @@
* @return the meta information to a block
*/
public BlockDescriptor getBlockDescriptor();
+
+ /**
+ *
+ * @return meta information how a block is intalled (mount directory, properties)
+ */
+ public BlockDeploymentData getBlockDeploymentData();
}
Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java?view=auto&rev=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java (added)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/BlockDeploymentData.java Mon Apr 4 05:56:46 2005
@@ -0,0 +1,49 @@
+/*
+ * 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.blockdeployer.block;
+
+import java.util.Iterator;
+
+import org.apache.cocoon.blockdeployer.block.descriptor.BlockProperty;
+
+public interface BlockDeploymentData {
+
+ /**
+ * @return the path where the block is installed
+ */
+ public String getLocation();
+
+ /**
+ * @return the mount path in sitemap processing
+ */
+ public String getMountPath();
+
+ /**
+ * Get the names of all parameters that have to be set when the block is deployed
+ *
+ * @return Iterator with all parameter names
+ */
+ public Iterator getPropertyNames();
+
+ /**
+ * Get a property by its name
+ *
+ * @param name of the property
+ * @return returns a BlockProperty object containing the property information
+ */
+ public BlockProperty getProperty(String name);
+
+}
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RecursiveBlockHierarchyException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RecursiveBlockHierarchyException.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RecursiveBlockHierarchyException.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RecursiveBlockHierarchyException.java Mon Apr 4 05:56:46 2005
@@ -21,13 +21,13 @@
*/
public class RecursiveBlockHierarchyException extends Exception {
- public RecursiveBlockHierarchyException(RemoteBlock errorBlock) {
+ public RecursiveBlockHierarchyException(Block errorBlock) {
this.errorBlock = errorBlock;
}
- private RemoteBlock errorBlock;
+ private Block errorBlock;
- public RemoteBlock getErrorRoot() {
+ public Block getErrorRoot() {
return this.errorBlock;
}
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Browsable.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Browsable.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Browsable.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Browsable.java Mon Apr 4 05:56:46 2005
@@ -15,7 +15,7 @@
*/
package org.apache.cocoon.blockdeployer.repository;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
/**
* Locator inferface
@@ -29,6 +29,6 @@
*
* @return returns an array of RemoteBlocks.
*/
- public RemoteBlock[] browse();
+ public Block[] browse();
}
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java Mon Apr 4 05:56:46 2005
@@ -15,9 +15,7 @@
*/
package org.apache.cocoon.blockdeployer.repository;
-import java.io.IOException;
-
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
/**
* This interface marks a locator that is able to deploy a block into
@@ -28,18 +26,18 @@
public interface Deployable {
/**
- * Deploy an array of blocks. The implementation has to make sure
+ * <p>Deploy an array of blocks. The implementation has to make sure
* that either all or any block is deployed.
+ * </p>
*
- * @param an array of blocks
- * @return true if deployment was successfull, false if not
+ * @param block - the Block to be deployed
* @throws @link UnsupportedBlockException if the block version is not supported
- * @throws @link IOException if the block can't be deployed in the target filesystem
+ * @throws @link DeploymentException if the block can't be deployed for any reason
*/
- /*
- * FIXME remove return value - throw Exceptions instead
- */
- public boolean deploy(RemoteBlock[] blocks)
- throws UnsupportedBlockException, IOException;
+
+ public void deploy(Block block)
+ throws UnsupportedBlockException, DeploymentException;
+
+
}
Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/DeploymentException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/DeploymentException.java?view=auto&rev=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/DeploymentException.java (added)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/DeploymentException.java Mon Apr 4 05:56:46 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2004 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.blockdeployer.repository;
+
+/**
+ * Checked exception during deployment.
+ */
+public class DeploymentException extends Exception {
+
+ public DeploymentException() {
+ super();
+ }
+
+ public DeploymentException(String arg0) {
+ super(arg0);
+ }
+
+ public DeploymentException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public DeploymentException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+}
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Locator.java Mon Apr 4 05:56:46 2005
@@ -18,7 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
/**
@@ -35,12 +35,12 @@
* implementation "knows" where to look for this block.
*
* @param Get a block by its id.
- * @return A @link RemoteBlock object representing a block
+ * @return A @link Block object representing a block
* @throws BlockNotFoundException if the locator can't find the requested block
* @throws IOException in the case that the block can be found but there are problems
* when accessing its meta data
*/
- public RemoteBlock getRemoteBlock(String blockId) throws BlockNotFoundException, IOException;
+ public Block getRemoteBlock(String blockId) throws BlockNotFoundException, IOException;
/**
* @return returns the unique identifier of this locator
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Searchable.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Searchable.java?view=diff&r1=160035&r2=160036
==============================================================================
--- 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 Mon Apr 4 05:56:46 2005
@@ -15,7 +15,7 @@
*/
package org.apache.cocoon.blockdeployer.repository;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
/**
@@ -26,13 +26,13 @@
public interface Searchable {
/**
- * Search for a block by its ID. A locator can only return a single RemoteBlock,
+ * Search for a block by its ID. A locator can only return a single Block,
* a repository can return an array with RemoteBlocks available in several locators.
* Note that the order is important.
*
* @return a sorted array of all locators that contain the named block
*/
- public RemoteBlock[] lookupBlock(String blockId) throws BlockNotFoundException;
+ public Block[] lookupBlock(String blockId) throws BlockNotFoundException;
/**
* Query the repositry whether it has a certain block or not.
Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/TransactionException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/TransactionException.java?view=auto&rev=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/TransactionException.java (added)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/TransactionException.java Mon Apr 4 05:56:46 2005
@@ -0,0 +1,31 @@
+/* Copyright 2004 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.blockdeployer.repository;
+
+public class TransactionException extends Exception {
+
+ public TransactionException() {
+ super();
+ }
+
+ public TransactionException(String s) {
+ super(s);
+ }
+
+ public TransactionException(String s, Exception ex) {
+ super(s, ex);
+ }
+
+}
Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Transactional.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Transactional.java?view=auto&rev=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Transactional.java (added)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Transactional.java Mon Apr 4 05:56:46 2005
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2004 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.blockdeployer.repository;
+
+public interface Transactional {
+
+ public void startTransaction() throws TransactionException;
+
+ public void commitTransaction() throws TransactionException;
+
+ public void rollbackTransaction() throws TransactionException;
+
+}
Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnsupportedBlockException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnsupportedBlockException.java?view=auto&rev=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnsupportedBlockException.java (added)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/UnsupportedBlockException.java Mon Apr 4 05:56:46 2005
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004 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.blockdeployer.repository;
+
+/**
+ * Exception if a block implementation is not supported e.g. by a deployable locator
+ *
+ * @since 0.1
+ */
+public class UnsupportedBlockException extends Exception {
+
+ public UnsupportedBlockException() {
+ super();
+ }
+
+ public UnsupportedBlockException(String message) {
+ super(message);
+ }
+
+}
Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Writeable.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Writeable.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Writeable.java (original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Writeable.java Mon Apr 4 05:56:46 2005
@@ -15,7 +15,7 @@
*/
package org.apache.cocoon.blockdeployer.repository;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
/**
* This interface marks a locator which a block can be added to.
@@ -24,6 +24,6 @@
*/
public interface Writeable {
- public void addBlock(final RemoteBlock block, final Credentials credentials);
+ public void addBlock(final Block block, final Credentials credentials);
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java Mon Apr 4 05:56:46 2005
@@ -42,6 +42,8 @@
// get the blocks from the repository
+ // enrich blocks with deployment meta information block.getBlockDeploymentData()
+
// deploy the blocks to the Cocoon server
// deploy the blocks to locators that have the attribute 'add-unavailable-blocks' set
Copied: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java (from r159025, cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java)
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java?view=diff&rev=160036&p1=cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/RemoteBlockFactory.java&r1=159025&p2=cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockFactory.java&r2=160036
==============================================================================
--- 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/BlockFactory.java Mon Apr 4 05:56:46 2005
@@ -38,37 +38,34 @@
*
* @since 0.1
*/
-public class RemoteBlockFactory {
+public class BlockFactory {
/**
- * Creates a RemoteBlock based on the descriptor and is called from
- * a locator which wants to provide a RemoteBlock. (It's not the job of
+ * Creates a Block based on the descriptor and is called from
+ * a locator which wants to provide a Block. (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
+ * @return the Block
*/
/*
- * FIXME the factory should analyse the doctype of the descriptor (not the namespace)
* FIXME the descriptor should be analyzed whether it is correct - otherwise raise an exception
*/
- public static RemoteBlock getRemoteBlock(InputStream descriptor, Locator locator) {
+ public static Block getRemoteBlock(InputStream descriptor, Locator locator) {
if(descriptor == null) {
throw new NullPointerException("The descriptor mustn't be null.");
}
- RemoteBlock block = null;
+ Block block = null;
- // analyse the descriptor and decide which RemoteBlock implementation should be used
+ // analyse the descriptor and decide which Block implementation should be used
// by finding out the namespace of the root element
DOMParser parser = new DOMParser();
try {
parser.parse(new InputSource(descriptor));
- } catch (SAXException e) {
-
- } catch (IOException e) {
-
- }
+ } catch (Exception e) {
+ throw new RuntimeException("Block descriptor can't be read.");
+ }
Document descriptorDocument = parser.getDocument();
NodeList rootNodeList = descriptorDocument.getChildNodes();
String namespace = null;
@@ -82,21 +79,21 @@
if(Cob10.NAMESPACE.equals(namespace)) {
// it's a Cob10 ...
- Cob10 realRemoteBlock = new Cob10();
- realRemoteBlock.setBlockDescriptor(createCOB10Descriptor(descriptorDocument));
- realRemoteBlock.setBlockId(realRemoteBlock.getBlockDescriptor().getBlockId());
+ Cob10 cob10 = new Cob10();
+ cob10.setBlockDescriptor(createCOB10Descriptor(descriptorDocument));
+ cob10.setBlockId(cob10.getBlockDescriptor().getBlockId());
if(locator == null) {
throw new NullPointerException("The locator mustn't be null.");
}
- realRemoteBlock.setLocator(locator);
- block = realRemoteBlock;
+ cob10.setLocator(locator);
+ block = cob10;
}
return block;
}
private static Cob10Descriptor createCOB10Descriptor(Node descriptor) {
- Cob10Descriptor realBlockDescriptor = null;
+ Cob10Descriptor cob10Descriptor = null;
try {
Mapping mapping = new Mapping();
mapping.loadMapping(Cob10Descriptor.class.getClassLoader().
@@ -107,11 +104,11 @@
unmarshaller.setIgnoreExtraAttributes(true);
unmarshaller.setIgnoreExtraElements(true);
// unmarshaller.setDebug(true);
- realBlockDescriptor = (Cob10Descriptor)unmarshaller.unmarshal(descriptor);
+ cob10Descriptor = (Cob10Descriptor)unmarshaller.unmarshal(descriptor);
} catch(Exception e) {
throw new RuntimeException(e);
}
- return realBlockDescriptor;
+ return cob10Descriptor;
}
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10.java Mon Apr 4 05:56:46 2005
@@ -18,14 +18,14 @@
import java.io.IOException;
import java.io.InputStream;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
import org.apache.cocoon.blockdeployer.block.descriptor.BlockDescriptor;
import org.apache.cocoon.blockdeployer.repository.Locator;
/**
* @since 0.1
*/
-public class Cob10 implements RemoteBlock {
+public class Cob10 implements Block {
public final static String NAMESPACE = "http://apache.org/cocoon/blocks/cob/1.0";
@@ -65,6 +65,10 @@
StringBuffer sb = new StringBuffer();
sb.append("id: " + this.blockId + ", locator: " + this.locator.toString());
return sb.toString();
+ }
+
+ public BlockDeploymentData getBlockDeploymentData() {
+ return null;
}
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10Resolver.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10Resolver.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10Resolver.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/Cob10Resolver.java Mon Apr 4 05:56:46 2005
@@ -15,7 +15,7 @@
*/
package org.apache.cocoon.blockdeployer.block;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
/**
* These services help to find required blocks and to resolve dependencies.
@@ -31,8 +31,8 @@
* @param blocks - the know blocks to be deployed
* @return all blocks that are necessary to make the passed blocks run
*/
- public static RemoteBlock[] resolve(RemoteBlock[] blocks, RemoteBlock[] installedBlocks) {
- return new RemoteBlock[0];
+ public static Block[] resolve(Block[] blocks, Block[] installedBlocks) {
+ return new Block[0];
}
/**
@@ -41,8 +41,8 @@
* @param block
* @return
*/
- public static RemoteBlock[] getRequiredBlocks(RemoteBlock block) throws RecursiveBlockHierarchyException {
- return new RemoteBlock[0];
+ public static Block[] getRequiredBlocks(Block block) throws RecursiveBlockHierarchyException {
+ return new Block[0];
}
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java Mon Apr 4 05:56:46 2005
@@ -15,16 +15,14 @@
*/
package org.apache.cocoon.blockdeployer.repository;
-import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.net.MalformedURLException;
-import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
import org.apache.cocoon.blockdeployer.locking.Lock;
import org.apache.cocoon.blockdeployer.locking.LockingException;
import org.apache.cocoon.blockdeployer.logging.LoggerFacade;
@@ -35,6 +33,8 @@
import org.apache.commons.transaction.file.ResourceManagerException;
import org.apache.commons.transaction.file.ResourceManagerSystemException;
import org.apache.commons.transaction.util.FileHelper;
+import org.exolab.castor.xml.MarshalException;
+import org.exolab.castor.xml.ValidationException;
/**
* The <code>ApplicationServer22Locator</code> points to a Cocoon server that
@@ -42,8 +42,11 @@
*
* @since 0.1
*/
-public class ApplicationServer22Locator implements Locator, Deployable, Lockable {
+public class ApplicationServer22Locator implements Locator, Deployable, Lockable, Transactional {
+ protected final static String WIRING_XML = "wiring.xml";
+ protected final static String WORK_DIR = "work";
+
private File basedir;
private LoggerFacade logger;
@@ -53,8 +56,6 @@
* @param basedir
* is a <code>File</code> object pointing to the directory
* where blocks can be deployed
- * @param wiring
- * is the {@link Wiring} (representing wiring.xml) of a Cocoon server
*/
public ApplicationServer22Locator(File basedir, LoggerFacade logger ) {
if(logger == null) {
@@ -65,126 +66,53 @@
this.logger = logger;
}
- public RemoteBlock getRemoteBlock(String blockUri) {
+ public Block getRemoteBlock(String blockUri) {
return null;
}
- public RemoteBlock[] browse() {
+ public Block[] browse() {
return null;
}
- /**
- * Deploy an array of blocks. It makes sure that either any or all blocks
- * are deployed.
- */
- public boolean deploy(RemoteBlock[] blocks) throws UnsupportedBlockException, IOException {
- // create the workdir
- // FIXME workdir has to be configurable
- String workDir = "WORK";
- FileHelper.removeRec(new File(workDir));
- new File(workDir).mkdirs();
-
- // initialize the logger by using a implementation delegating all logging infos of
- // Commons transactions to BlockDeployer LoggingFacade
- org.apache.commons.transaction.util.LoggerFacade ctLogger = new CommonsTransactionLogger(this.logger);
+
+ public synchronized void deploy(Block block) throws DeploymentException, UnsupportedBlockException {
+ // check whether transaction is available
+ if(frm == null) {
+ throw new IllegalStateException("A transaction has to be started before a block can be deployed!");
+ }
- // start the file resource manager
- if(this.logger.isDebugEnabled()) {
- this.logger.debug(this.getClass(), "Initializing FileResourceManager - workdir:"
- + workDir + ", store:" + this.basedir.getAbsolutePath());
+ // check if the block can be deployed
+ if(false) {
+ throw new UnsupportedBlockException("Deploying a block of this type is not supported!");
}
- FileResourceManager frm = new FileResourceManager(this.basedir
- .getAbsolutePath(), workDir, false, ctLogger, true);
- String txId = "deploy";
- boolean success = false;
- long startDeployment = System.currentTimeMillis();
- try {
- // start resource manager
- frm.start();
- // start file system transaction
- frm.startTransaction(txId);
- this.logger.info(this.getClass(), "Started FileResourceManager transaction \"" + txId + "\"");
-
- // loop over all blocks and deploy them using the file resource
- // manager
- for (int i = 0; i < blocks.length; i++) {
- // check if the block can be deployed
- if(false) {
- throw new UnsupportedBlockException("Deploying a block of this type is not supported!");
- }
- // create random string as base directory for the block to be deployer
+ // deploy block into next available directory and update wiring.xml accordingly
+ try {
+ if(!this.blockExists(this.wiring10, block.getBlockId())) {
String nextDir = LocatorUtils.getNextDirectory(this.basedir);
- this.logger.info(this.getClass(), "Block to be deployed in " + nextDir);
- // write block
- ZipInputStream zis = new ZipInputStream(blocks[i].getStream());
- ZipEntry document = null;
- try {
- do {
- document = zis.getNextEntry();
- if (document != null) {
- // skip directories (only files have to be written)
- if (document.isDirectory()) {
- zis.closeEntry();
- continue;
- }
- // open output stream with the file/directory-name
- // saved in the ZIP file
- OutputStream out = frm.writeResource(txId, nextDir + File.separator + document
- .getName());
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- // loop over ZIP entry stream
- byte[] buffer = new byte[8192];
- int length = -1;
- while (zis.available() > 0) {
- length = zis.read(buffer, 0, 8192);
- if (length > 0) {
- baos.write(buffer, 0, length);
- }
- }
- // write it to the output stream provided by the
- // file resource manager
- out.write(baos.toByteArray());
- // go to next entry
- zis.closeEntry();
- }
- } while (document != null);
- } finally {
- zis.close();
- }
- // add new block to wiring object
-
+ this.logger.debug(this.getClass(), "Block to be deployed in " + nextDir);
+ LocatorUtils.writeZip(new ZipInputStream(block.getStream()), this.frm, this.txId, nextDir);
}
+ this.updateWiring(block);
+ } catch(Exception ex) {
+ throw new DeploymentException("Block " + block.getBlockId() + " couldn't be deployed.", ex);
+ }
+ }
+
+ protected void updateWiring(Block block) {
- // write wiring
- // commit transaction
- frm.commitTransaction(txId);
- success = true;
- this.logger.debug(this.getClass(), "Deployment took " + (System.currentTimeMillis() - startDeployment) + "ms");
- this.logger.info(this.getClass(), "Transaction \"" + txId + "\" has been committed");
- } catch (Exception rme) {
- try {
- frm.rollbackTransaction(txId);
- this.logger.error(this.getClass(), "Transaction \"" + txId + "\" has been roled back: " + rme.getStackTrace());
- return false;
- } catch (ResourceManagerException rme1) {
- this.logger.error(this.getClass(), "While rolling back transaction \"" + txId + "\" an error occurred: " + rme1.getStackTrace());
- }
- throw new IOException(this.getClass().getName() + ": While deploying the passed blocks an error occurred. Check the logs for details. " + rme.getClass());
- } finally {
- try {
- frm.stop(FileResourceManager.SHUTDOWN_MODE_NORMAL);
- } catch (ResourceManagerSystemException e) {
- String msg = "the filesystem transaction that extracts all blocks was NOT successful.";
- if(success) {
- msg = "the filesystem transaction that extracts all blocks WAS successful.";
- }
- throw new RuntimeException("FileResourceManager wasn't shut down normally - " + msg);
+ }
+
+ protected boolean blockExists(Wiring wiring10, String blockId) {
+ for(int i = 0; i < wiring10.getBlockCount(); i++) {
+ if(wiring10.getBlock(i).getId().equals(blockId)) {
+ return true;
}
}
- return true;
- }
+ return false;
+ }
+
public String getIdentifier() {
try {
@@ -194,9 +122,14 @@
}
}
-
+ public InputStream getBlockAsStream(String blockId) throws IOException, BlockNotFoundException {
+ return null;
+ }
+
+
+ // ------- locking --------------------------------------------------------------
+
public void setLock(Lock lock) throws LockingException {
-
}
public Lock getLockingStatus() throws LockingException {
@@ -207,8 +140,122 @@
return false;
}
- public InputStream getBlockAsStream(String blockId) throws IOException, BlockNotFoundException {
- return null;
+ // ------- transaction handling -------------------------------------------------
+
+ protected FileResourceManager frm = null;
+ protected String txId = "deploy";
+ protected Wiring wiring10 = null;
+
+ public synchronized void startTransaction() throws TransactionException {
+ // check if a transaction has already been started, if so, throw an exception
+ if(frm != null) {
+ throw new TransactionException("Transaction has already been started!");
+ }
+
+ // read in wiring.xml
+ try {
+ readWiring();
+ } catch (Exception ex) {
+ String msg = "Transaction couldn't be started because problems when reading application server's wiring.xml";
+ logger.error(ApplicationServer22Locator.class, msg);
+ throw new TransactionException(msg);
+ }
+
+ // create and reset the workdir
+ // FIXME workdir has to be a temporary directory
+ String workDir = "WORK";
+ FileHelper.removeRec(new File(workDir));
+ new File(workDir).mkdirs();
+
+ // start the file resource manager
+ if(this.logger.isDebugEnabled()) {
+ this.logger.debug(this.getClass(), "Initializing FileResourceManager - workdir:"
+ + workDir + ", store:" + this.basedir.getAbsolutePath());
+ }
+
+ // initialize and start file resource manager and start transaction
+ try {
+ this.frm = new FileResourceManager(this.basedir.getAbsolutePath(),
+ workDir, false, new CommonsTransactionLogger(this.logger), true);
+ this.frm.start();
+ this.frm.startTransaction(txId);
+ this.logger.debug(this.getClass(), "Started FileResourceManager transaction \"" + txId + "\"");
+ } catch(ResourceManagerException rme) {
+ throw new TransactionException("Can't start transaction.", rme);
+ }
+ }
+
+ public void commitTransaction() throws TransactionException {
+ if(frm == null) {
+ throw new TransactionException("You have to start a transaction before it can be committed!");
+ }
+
+ try {
+ writeWiring();
+ frm.commitTransaction(txId);
+ this.logger.debug(ApplicationServer22Locator.class, "Filesystem transaction has been committed successfully.");
+ } catch (ResourceManagerException ex) {
+ throw new TransactionException("Transaction couldn't be committed!", ex);
+ } catch (Exception ex) {
+ String msg = "Transaction couldn't be written because of problems when writing the wiring information.";
+ logger.error(ApplicationServer22Locator.class, msg);
+ throw new TransactionException(msg);
+ } finally {
+ stopResourceManager();
+ }
+ }
+
+
+ public void rollbackTransaction() throws TransactionException {
+ if(frm == null) {
+ throw new TransactionException("You have to start a transaction before it can be rolled back!");
+ }
+ try {
+ frm.rollbackTransaction(txId);
+ this.logger.debug(ApplicationServer22Locator.class, "Filesystem transaction has been rolled back successfully.");
+ } catch (ResourceManagerException ex) {
+ this.logger.error(this.getClass(), "Transaction \"" + txId + "\" has been roled back: " + ex.getStackTrace());
+ throw new TransactionException("Transaction couldn't be committed!", ex);
+ } finally {
+ stopResourceManager();
+ }
+ }
+
+ private void readWiring() throws MarshalException, ValidationException, IOException {
+ // read the wiring information (currently we have to support only
+ // http://apache.org/cocoon/blocks/wiring/1.0)
+ File wiringDescriptor = new File(this.basedir, WIRING_XML);
+ if(wiringDescriptor.exists()) {
+ wiring10 = (Wiring) Wiring.unmarshal(new FileReader(wiringDescriptor));
+ logger.info("Using wiring descriptor at " + wiringDescriptor.getCanonicalPath().toString());
+
+ // log already deployed blocks
+ if(logger.isDebugEnabled()) {
+ StringBuffer logInformation = new StringBuffer("Following blocks are already installed: ");
+ for(int i = 0; i < wiring10.getBlockCount(); i++) {
+ logInformation.append(wiring10.getBlock(i).getId() + "; ");
+ }
+ logger.debug(ApplicationServer22Locator.class, logInformation.toString());
+ }
+ } else {
+ wiring10 = new Wiring();
+ }
+ }
+
+ private void writeWiring() throws MarshalException, ValidationException, IOException {
+
}
+
+ private void stopResourceManager() {
+ try {
+ frm.stop(FileResourceManager.SHUTDOWN_MODE_NORMAL);
+ } catch (ResourceManagerSystemException e) {
+ String msg = "The filesystem transaction that extracts all blocks was NOT successful.";
+ throw new RuntimeException("FileResourceManager wasn't shut down normally - " + msg);
+ } finally {
+ // null out FileResourceManager so that another transaction can start
+ frm = null;
+ }
+ }
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java?view=diff&r1=160035&r2=160036
==============================================================================
--- 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 Mon Apr 4 05:56:46 2005
@@ -20,7 +20,7 @@
import java.util.Iterator;
import java.util.List;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
import org.apache.cocoon.blockdeployer.repository.Locator;
import org.apache.cocoon.blockdeployer.repository.Repository;
@@ -45,7 +45,7 @@
this.locators.remove(locator);
}
- public RemoteBlock[] browse() {
+ public Block[] browse() {
return null;
}
@@ -56,13 +56,13 @@
* @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 {
+ public Block[] lookupBlock(String blockId) throws BlockNotFoundException {
ArrayList tempLocators = new ArrayList();
// if the locator has the requested block it is added
Iterator locatorsIterator = this.locators.iterator();
while(locatorsIterator.hasNext()) {
Locator locator = (Locator) locatorsIterator.next();
- RemoteBlock remoteBlock = null;
+ Block remoteBlock = null;
try {
remoteBlock = locator.getRemoteBlock(blockId);
tempLocators.add(remoteBlock);
@@ -73,12 +73,13 @@
}
}
if(tempLocators.size() == 0) {
- throw new BlockNotFoundException("The block " + blockId + " can't be found in any of the provided locators.");
+ 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()];
+ Block[] resultRemoteBlock = new Block[tempLocators.size()];
for(int i = 0; i < tempLocators.size(); i++) {
- resultRemoteBlock[i] = (RemoteBlock) array[i];
+ resultRemoteBlock[i] = (Block) array[i];
}
return resultRemoteBlock;
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DependencyBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DependencyBuilder.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DependencyBuilder.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DependencyBuilder.java Mon Apr 4 05:56:46 2005
@@ -15,14 +15,14 @@
*/
package org.apache.cocoon.blockdeployer.repository;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
/**
* @since 0.1
*/
public class DependencyBuilder {
- public static RemoteBlock[] getDependingBlocks(RemoteBlock repositoryBlock) {
+ public static Block[] getDependingBlocks(Block repositoryBlock) {
return null;
}
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java?view=diff&r1=160035&r2=160036
==============================================================================
--- 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 Mon Apr 4 05:56:46 2005
@@ -23,8 +23,8 @@
import java.net.MalformedURLException;
import java.util.zip.ZipInputStream;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
-import org.apache.cocoon.blockdeployer.block.RemoteBlockFactory;
+import org.apache.cocoon.blockdeployer.block.Block;
+import org.apache.cocoon.blockdeployer.block.BlockFactory;
import org.apache.cocoon.blockdeployer.logging.LoggerFacade;
import org.apache.cocoon.blockdeployer.utils.LocatorUtils;
@@ -73,8 +73,8 @@
this.logger.info(this.getClass(), infoMsg);
throw new BlockNotFoundException(infoMsg);
}
- InputStream descriptorInputStream = null;
- return LocatorUtils.getDescriptorInputStream(new ZipInputStream(new FileInputStream(cobFile)), this.logger);
+ ZipInputStream descriptorInputStream = new ZipInputStream(new FileInputStream(cobFile));
+ return LocatorUtils.getDescriptorInputStream(descriptorInputStream, this.logger);
}
protected File getBlockAsFile(String blockUri) throws FileNotFoundException {
@@ -83,20 +83,19 @@
throw new IllegalArgumentException("Can't find the requested block " + blockUri +
". Wrong schema, only http:// block uris are allowed.");
}
-
return LocatorUtils.getBlockAsFile(this.basedir, blockUri.substring("http:/".length()));
}
- public RemoteBlock getRemoteBlock(String blockUri) throws IOException, BlockNotFoundException {
+ public Block getRemoteBlock(String blockUri) throws IOException, BlockNotFoundException {
InputStream descriptorInputStream = this.getBlockDescriptorAsStream(blockUri);
if(descriptorInputStream == null) {
throw new BlockNotFoundException("Block " + blockUri + " not found.");
}
- return RemoteBlockFactory.getRemoteBlock(descriptorInputStream, this);
+ return BlockFactory.getRemoteBlock(descriptorInputStream, this);
}
- public RemoteBlock[] browse() {
- return null;
+ public Block[] browse() {
+ throw new UnsupportedOperationException("Not supported yet");
}
public String toString() {
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/CommonsTransactionLogger.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/CommonsTransactionLogger.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/CommonsTransactionLogger.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/CommonsTransactionLogger.java Mon Apr 4 05:56:46 2005
@@ -35,7 +35,7 @@
}
public void logInfo(String msg) {
- this.logger.info(PREFIX + msg);
+ this.logger.debug(PREFIX + msg);
}
public void logFine(String msg) {
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/LocatorUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/LocatorUtils.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/LocatorUtils.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/LocatorUtils.java Mon Apr 4 05:56:46 2005
@@ -21,6 +21,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -29,6 +30,8 @@
import org.apache.cocoon.blockdeployer.logging.LoggerFacade;
import org.apache.cocoon.blockdeployer.repository.Locator;
+import org.apache.commons.transaction.file.FileResourceManager;
+import org.apache.commons.transaction.file.ResourceManagerException;
/**
* @since 0.1
@@ -161,6 +164,7 @@
}
} catch(NumberFormatException nfe) {
// ignore it because directories with alpha characters are no problem
+ // as they don't conflict with the namespace
}
}
@@ -196,5 +200,52 @@
logger.error(errorMsg);
throw new IllegalArgumentException(errorMsg);
}
+ }
+
+ /**
+ * Write (extract) a zip file using the jakarta-commons-transaction FileResourceManager
+ *
+ * @param blockStream
+ * @param frm
+ * @param txId
+ * @param targetDir
+ * @throws IOException
+ * @throws ResourceManagerException
+ */
+ public static void writeZip(ZipInputStream blockStream, FileResourceManager frm, String txId, String targetDir)
+ throws IOException, ResourceManagerException {
+ ZipEntry document = null;
+ try {
+ do {
+ document = blockStream.getNextEntry();
+ if (document != null) {
+ // skip directories (only files have to be written)
+ if (document.isDirectory()) {
+ blockStream.closeEntry();
+ continue;
+ }
+ // open output stream with the file/directory-name
+ // saved in the ZIP file
+ OutputStream out = frm.writeResource(
+ txId, targetDir + File.separator + document.getName());
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ // loop over ZIP entry stream
+ byte[] buffer = new byte[8192];
+ int length = -1;
+ while (blockStream.available() > 0) {
+ length = blockStream.read(buffer, 0, 8192);
+ if (length > 0) {
+ baos.write(buffer, 0, length);
+ }
+ }
+ // write it to the output stream provided by the file resource manager
+ out.write(baos.toByteArray());
+ // go to next entry
+ blockStream.closeEntry();
+ }
+ } while (document != null);
+ } finally {
+ blockStream.close();
+ }
}
}
Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java (original)
+++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java Mon Apr 4 05:56:46 2005
@@ -26,8 +26,7 @@
// basedirs for locators
public static final String VALID_LOCATION_1 = "test/sample-repositories/rep1";
public static final String VALID_ASL_1 = "test/sample-repositories/application-server/WEB-INF/blocks";
- public static final String VALID_ASL21_1 = "test/sample-repositories/application-server-21";
- public static final String TMP_VALID_ASL_1 = TMP_JUNIT + "/asf1";
+ public static final String TMP_VALID_ASL_1 = TMP_JUNIT + "/asf1/WEB-INF/blocks";
public static final String INVALID_LOCATION = "bla";
// available and valid block
Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java (original)
+++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java Mon Apr 4 05:56:46 2005
@@ -23,7 +23,9 @@
import org.apache.cocoon.blockdeployer.Constants;
import org.apache.cocoon.blockdeployer.LogEnabledTestCase;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
+import org.apache.cocoon.blockdeployer.block.BlockDeploymentData;
+import org.apache.cocoon.blockdeployer.block.descriptor.BlockDescriptor;
import org.easymock.MockControl;
/**
@@ -31,51 +33,133 @@
*/
public class ApplicationServer22LocatorTest extends LogEnabledTestCase {
+ private final static String ASL = Constants.TMP_VALID_ASL_1;
+
private void setupExamples() {
- FileUtil.mkdir(Constants.TMP_VALID_ASL_1);
- FileUtil.copyDir(Constants.VALID_ASL_1, Constants.TMP_VALID_ASL_1);
+ FileUtil.deleteDir(ASL);
+ FileUtil.mkdirs(ASL);
+ FileUtil.copyDir(ASL, Constants.TMP_VALID_ASL_1);
}
- private void removeExamples() {
- FileUtil.deleteDir(Constants.TMP_VALID_ASL_1);
+ public void testTransactionManagement() {
+ ApplicationServer22Locator asl = new ApplicationServer22Locator(new File(ASL), this.logger);
+ try {
+ asl.commitTransaction();
+ fail("Calling commitTransaction() before calling start ransaction mustn't work.");
+ } catch (TransactionException ex) {
+ // expected behaviour
+ }
+
+ try {
+ asl.rollbackTransaction();
+ fail("Calling rollbackTransaction() before calling start ransaction mustn't work.");
+ } catch (TransactionException ex) {
+ // expected behaviour
+ }
+
+ try {
+ asl.startTransaction();
+ assertNotNull(asl.frm);
+ assertNotNull(asl.wiring10);
+ } catch (TransactionException ex) {
+ fail("startTransaction() on a new ApplicationServer22Locator should work.");
+ }
+
+ try {
+ asl.startTransaction();
+ fail("Calling startTransaction() twice should not work.");
+ } catch (TransactionException ex) {
+ // expected behaviour
+ }
+ assertNotNull(asl.frm);
+ assertNotNull(asl.wiring10);
+
}
public void testDeploy() throws Exception {
// copy examples into tmp location
setupExamples();
- // first hack to run the deploy method
- ApplicationServer22Locator asl = new ApplicationServer22Locator(new File(Constants.TMP_VALID_ASL_1), this.logger);
- RemoteBlock b[] = new RemoteBlock[1];
- b[0] = createBlockMock(null);
+ // deploy method
+ ApplicationServer22Locator asl = new ApplicationServer22Locator(new File(ASL), this.logger);
+
+ asl.startTransaction();
+
+ Block b = createBlockMock("http://bla", null);
asl.deploy(b);
+
+ asl.commitTransaction();
+
+ // test that the block is extracted correctly by checking whether the
+ // COB_INF and the block.xml are available
+
// clean up
- // removeExamples();
+ // FileUtil.deleteDir(ASL);
}
- private RemoteBlock createBlockMock(String file) throws Exception {
+ /*
+ public void testAddBlockToWiring() throws Exception {
+ ApplicationServer22Locator asl = new ApplicationServer22Locator(
+ new File(ASL), this.logger);
+ String blockId = "http://bla";
+ Block block = createBlockMock(blockId, null);
+ Wiring wiring = new Wiring();
+ asl.addBlockToWiring(wiring, block);
+
+ // check that only one block is set
+ int blockCount = wiring.getBlockCount();
+ // assertEquals(blockCount, 1);
+
+ // check that the right number of connections is set
+ Connections connections = wiring.getBlock(0).getConnections();
+ int connectionsCount = connections.getConnectionCount();
+ // assertEquals(connectionsCount, 1);
+
+ // check that the right connection is set
+ Connection connection = connections.getConnection(0);
+ // assertEquals(connection.getBlock(), blockId);
+ }
+ */
+
+ private Block createBlockMock(String id, BlockDeploymentData deployData) throws Exception {
// create the Block
- MockControl blockControl = MockControl.createControl(RemoteBlock.class);
- RemoteBlock block = (RemoteBlock) blockControl.getMock();
+ MockControl blockControl = MockControl.createControl(Block.class);
+ Block block = (Block) blockControl.getMock();
// create the block descriptor information
+ block.getBlockDescriptor();
+ blockControl.setReturnValue(createBlockDescriptorMock(id));
- // create the Inputstream containing block as binary
- try {
- block.getStream();
- InputStream is = new FileInputStream(
- Constants.VALID_LOCATION_1 + File.separator +
- Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKPATH +
- File.separator + Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKFILE) ;
- blockControl.setReturnValue(is);
- } catch (Exception e) {
- throw e;
- }
+ // set the id
+ block.getBlockId();
+ blockControl.setReturnValue(id);
+
+ // create the deployment meta information
+ block.getBlockDeploymentData();
+ blockControl.setReturnValue(deployData);
+ // create the Inputstream containing block as binary
+ block.getStream();
+ InputStream is = new FileInputStream(
+ Constants.VALID_LOCATION_1 + File.separator +
+ Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKPATH +
+ File.separator + Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKFILE) ;
+ blockControl.setReturnValue(is);
+
blockControl.replay();
-
return block;
+ }
+
+
+ private BlockDescriptor createBlockDescriptorMock(String id) {
+ MockControl descriptorControl = MockControl.createControl(BlockDescriptor.class);
+ BlockDescriptor descriptor = (BlockDescriptor) descriptorControl.getMock();
+
+ descriptor.getBlockId();
+ descriptorControl.setReturnValue(id);
+ descriptorControl.replay();
+ return descriptor;
}
}
Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java?view=diff&r1=160035&r2=160036
==============================================================================
--- 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 Mon Apr 4 05:56:46 2005
@@ -19,7 +19,7 @@
import junit.framework.TestCase;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
import org.easymock.MockControl;
/**
@@ -46,7 +46,7 @@
defaultRepository.addLocator(createMockLocator(locator3Name, allAvailableBlocks, new String[0], new String[] {"myBlock"}));
// test that all locators return the block
- RemoteBlock[] resultRemoteBlock = defaultRepository.lookupBlock("myBlock");
+ Block[] resultRemoteBlock = defaultRepository.lookupBlock("myBlock");
assertEquals(resultRemoteBlock[0].getLocator().getIdentifier(), locator1Name);
assertEquals(resultRemoteBlock[1].getLocator().getIdentifier(), locator2Name);
assertEquals(resultRemoteBlock[2].getLocator().getIdentifier(), locator3Name);
@@ -95,7 +95,7 @@
createMockLocator(locator3Name, allAvailableBlocks, new String[0], new String[] {"myBlock1", "myBlock4", "myBlock3"}));
// test that myBlock3 is returned twice, having the locators locator2 and locator3
- RemoteBlock[] resultRemoteBlock = defaultRepository.lookupBlock("myBlock3");
+ Block[] resultRemoteBlock = defaultRepository.lookupBlock("myBlock3");
assertEquals(resultRemoteBlock[0].getLocator().getIdentifier(), locator2Name);
assertEquals(resultRemoteBlock[1].getLocator().getIdentifier(), locator3Name);
assertEquals(resultRemoteBlock.length, 2);
@@ -119,7 +119,7 @@
defaultRepository.addLocator(
createMockLocator(locator1Name, new String[0], allUnavailableBlocks, new String[0]));
try {
- RemoteBlock[] resultRemoteBlock = defaultRepository.lookupBlock("myBlock1");
+ Block[] resultRemoteBlock = defaultRepository.lookupBlock("myBlock1");
fail("This block shouldn't be available in the repository and therefore throw an BlockNotFoundException");
} catch(BlockNotFoundException bnfe) {
// correct behaviour
@@ -127,7 +127,7 @@
}
/**
- * Create a mock locator containg all <code>locatorBlocks</code> and returning a RemoteBlock object for them.
+ * Create a mock locator containg all <code>locatorBlocks</code> and returning a Block object for them.
* If they don't contain a certain block, the locator returns null.
*
* @param name
@@ -137,9 +137,9 @@
*/
private Locator createMockLocator(String name, String[] allAvailableBlocks, String[] allUnavailableBlocks, String[] locatorBlocks) throws Exception {
- // create a mock for a RemoteBlock
- MockControl blockControl = MockControl.createControl(RemoteBlock.class);
- RemoteBlock remoteBlock = (RemoteBlock) blockControl.getMock();
+ // create a mock for a Block
+ MockControl blockControl = MockControl.createControl(Block.class);
+ Block remoteBlock = (Block) blockControl.getMock();
// create a mock for the locator
MockControl control1 = MockControl.createControl(Locator.class);
Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java (original)
+++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java Mon Apr 4 05:56:46 2005
@@ -24,7 +24,7 @@
import org.apache.cocoon.blockdeployer.Constants;
import org.apache.cocoon.blockdeployer.LogEnabledTestCase;
-import org.apache.cocoon.blockdeployer.block.RemoteBlock;
+import org.apache.cocoon.blockdeployer.block.Block;
import org.apache.cocoon.blockdeployer.utils.LocatorUtils;
/**
@@ -55,7 +55,7 @@
assertNotNull(filesystemLocator);
// get the block that should be available and test its data
- RemoteBlock remoteBlock = null;
+ Block remoteBlock = null;
try {
remoteBlock = filesystemLocator.getRemoteBlock(Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKID);
} catch(Exception e) {
@@ -87,7 +87,7 @@
}
// try to get an unavailable block
- RemoteBlock remoteBlock = null;
+ Block remoteBlock = null;
try {
remoteBlock = filesystemLocator.getRemoteBlock(Constants.AVAILABLE_INVALID_SAMPLE_BLOCKID);
fail("The block URI is valid but at this place there is no block. An exception should be raised.");
Modified: cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml?view=diff&r1=160035&r2=160036
==============================================================================
--- cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml (original)
+++ cocoon/whiteboard/block-deployer/test/sample-repositories/application-server/WEB-INF/blocks/wiring.xml Mon Apr 4 05:56:46 2005
@@ -1,28 +1,51 @@
-<!-- in Stefan's example "blocks" instead of "wiring" is used -->
-<wiring xmlns="http://apache.org/cocoon/blocks/wiring/1.0">
+<!--
+ Copyright 1999-2004 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.
+-->
+<wiring xmlns="http://apache.org/cocoon/blocks/wiring/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://apache.org/cocoon/blocks/wiring/1.0 wiring-schema-1.0.xsd"
+>
<block id="http://mycompany.com/webmail/1.3.43"
location="WEB-INF/blocks/384938958499">
- <mount>/mail/</mount>
+ <mount path="/mail/"/>
<connections>
- <connection
- name="external-skin">http://yetanothercompany.com/skins/fancy/1.2.2</connection>
- <connection
- name="internal-skin">http://mycompany.com/skins/corporate/34.3.345</connection>
- <connection
- name="repository">http://mycompany.com/repositories/email/exchange/3.2.1</connection>
+ <connection name="external-skin"
+ block="http://yetanothercompany.com/skins/fancy/1.2.2"/>
+ <connection name="internal-skin"
+ block="http://mycompany.com/skins/corporate/34.3.345"/>
+ <connection name="repository"
+ block="http://mycompany.com/repositories/email/exchange/3.2.1"/>
</connections>
<properties>
- <property name="user">guest</property>
- <property name="password">sj3u493</property>
+ <property name="user" value="guest"/>
+ <property name="password" value="sj3u493"/>
</properties>
</block>
<block id="http://mycompany.com/repositories/email/exchange/3.2.1"
location="WEB-INF/blocks/394781274834">
<properties>
- <property name="host">mail.blah.org</property>
+ <property name="host" value="mail.blah.org"/>
</properties>
</block>
+
+ <block id="http://yetanothercompany.com/skins/fancy/1.2.2"
+ location="WEB-INF/blocks/947384127832"/>
+
+ <block id="http://mycompany.com/skins/corporate/34.3.345"
+ location="WEB-INF/blocks/746394782637"/>
</wiring>