Author: reinhard Date: Fri Nov 12 01:30:47 2004 New Revision: 57510 Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RecursiveBlockHierarchyException.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockResolver.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/SimpleBlock.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/configuration/ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/configuration/DeploymentConfiguration.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/configuration/DeploymentConfigurationException.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer21Locator.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/SingleBlockLocator.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer21LocatorTest.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/SingeBlockLocatorTest.java cocoon/whiteboard/block-deployer/test/sample-repositories/application-server-21/ Modified: cocoon/whiteboard/block-deployer/.classpath cocoon/whiteboard/block-deployer/mapping/sample-deploy.xml cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/logging/LoggerFacade.java cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.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/ApplicationServerLocator.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/LocatorUtils.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocatorTest.java Log: refactoring to support reference deployments (for developers) and provide support for clients via a service
Modified: cocoon/whiteboard/block-deployer/.classpath ============================================================================== --- cocoon/whiteboard/block-deployer/.classpath (original) +++ cocoon/whiteboard/block-deployer/.classpath Fri Nov 12 01:30:47 2004 @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src/api"/> + <classpathentry kind="src" path="src/client"/> <classpathentry kind="src" path="test/junit"/> <classpathentry kind="src" path="src/impl"/> <classpathentry kind="lib" path="lib/castor-0.9.5.3-xml.jar"/> @@ -17,5 +18,6 @@ <classpathentry kind="lib" path="lib/commons-transaction-0.1pre-20041008.jar"/> <classpathentry kind="lib" path="lib/geronimo-spec-j2ee-1.0-M1.jar"/> <classpathentry kind="lib" path="tools/lib/jodd-fileutils-0.29.jar"/> + <classpathentry kind="lib" path="lib/commons-cli-1.0.jar"/> <classpathentry kind="output" path="build/eclipse"/> </classpath> Modified: cocoon/whiteboard/block-deployer/mapping/sample-deploy.xml ============================================================================== --- cocoon/whiteboard/block-deployer/mapping/sample-deploy.xml (original) +++ cocoon/whiteboard/block-deployer/mapping/sample-deploy.xml Fri Nov 12 01:30:47 2004 @@ -19,7 +19,9 @@ <locator>C:\myDirectory</locator> <locator>F:\anotherDirectory</locator> </locators> - <cocoon-root version="2.2">E:\blblb</cocoon-root> + <servers> + <server version="2.2">E:\blblb</server> + </servers> <install> <block id="http://mycompany.com/webmail/1.3.43" auto-resolve="true"/> <block id="http://mycompany.com/myblock/1.3.43" auto-resolve="false"/> Added: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RecursiveBlockHierarchyException.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/block/RecursiveBlockHierarchyException.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,34 @@ +/* + * 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.block; + + +/** + * @since 0.1 + */ +public class RecursiveBlockHierarchyException extends Exception { + + public RecursiveBlockHierarchyException(RemoteBlock errorBlock) { + this.errorBlock = errorBlock; + } + + private RemoteBlock errorBlock; + + public RemoteBlock getErrorRoot() { + return this.errorBlock; + } + +} Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/logging/LoggerFacade.java ============================================================================== --- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/logging/LoggerFacade.java (original) +++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/logging/LoggerFacade.java Fri Nov 12 01:30:47 2004 @@ -34,6 +34,7 @@ public boolean isWarnEnabled(); public void error(String error); public void error(Class clazz, String msg); + public void error(Class clazz, String msg, Exception ex); public boolean isErrorEnabled(); } Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java ============================================================================== --- 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 Fri Nov 12 01:30:47 2004 @@ -36,6 +36,9 @@ * @throws @link UnsupportedBlockException if the block version is not supported * @throws @link IOException if the block can't be deployed in the target filesystem */ + /* + * FIXME remove return value - throw Exceptions instead + */ public boolean deploy(RemoteBlock[] blocks) throws UnsupportedBlockException, IOException; Added: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,44 @@ +/* + * 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; + +import org.apache.cocoon.blockdeployer.configuration.DeploymentConfiguration; +import org.apache.cocoon.blockdeployer.configuration.DeploymentConfigurationException; +import org.apache.cocoon.blockdeployer.logging.LoggerFacade; + +/** + * @since 0.1 + */ +public class DeploymentService { + + /** + * Deploy blocks using the information in the [EMAIL PROTECTED] DeploymentConfiguration}. + * @param conf + * @param logger + */ + public static void deploy(DeploymentConfiguration conf, LoggerFacade logger) throws DeploymentConfigurationException { + if(logger == null) { + throw new NullPointerException("The logger mustn't be null."); + } + checkDeploymentConfiguration(conf, logger); + } + + protected static void checkDeploymentConfiguration(DeploymentConfiguration conf, LoggerFacade logger) + throws DeploymentConfigurationException { + + } + +} Added: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockResolver.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/BlockResolver.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,48 @@ +/* + * 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.block; + +import org.apache.cocoon.blockdeployer.block.RemoteBlock; + +/** + * These services help to find required blocks and to resolve dependencies. + * + * @since 0.1 + */ +public class BlockResolver { + + /** + * Find all blocks, the passed blocks depend on. It checks + * for version incompatiblities and recursive dependencies. + * + * @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]; + } + + /** + * Get all blocks this block requires. + * + * @param block + * @return + */ + public static RemoteBlock[] getRequiredBlocks(RemoteBlock block) throws RecursiveBlockHierarchyException { + return new RemoteBlock[0]; + } + +} 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 Fri Nov 12 01:30:47 2004 @@ -26,6 +26,8 @@ * @since 0.1 */ public class RealRemoteBlock implements RemoteBlock { + + public final static String NAMESPACE = "http://apache.org/cocoon/blocks/cob/1.0"; private Locator locator; private BlockDescriptor blockDescriptor; 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 Fri Nov 12 01:30:47 2004 @@ -15,13 +15,19 @@ */ package org.apache.cocoon.blockdeployer.block; +import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import org.apache.cocoon.blockdeployer.block.descriptor.RealBlockDescriptor; import org.apache.cocoon.blockdeployer.repository.Locator; +import org.apache.xerces.parsers.DOMParser; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.xml.Unmarshaller; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; /** * This factory class creates RemoteBlocks based on the descriptor @@ -51,21 +57,46 @@ if(descriptor == null) { throw new NullPointerException("The descriptor mustn't be null."); } - if(locator == null) { - throw new NullPointerException("The locator mustn't be null."); - } + + RemoteBlock block = null; + // analyse the descriptor and decide which RemoteBlock 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) { + + } + Document descriptorDocument = parser.getDocument(); + NodeList rootNodeList = descriptorDocument.getChildNodes(); + String namespace = null; + for(int i = 0; i <= rootNodeList.getLength() && i <= 1; i++ ) { + Node rootChildNode = rootNodeList.item(i); + if(rootChildNode.getNodeType() == Node.ELEMENT_NODE) { + namespace = rootChildNode.getNamespaceURI(); + System.out.println("namespace: " + namespace); + } + } - // it's a RealRemoteBlock ... - RealRemoteBlock realRemoteBlock = new RealRemoteBlock(); - realRemoteBlock.setBlockDescriptor(createCOB10Descriptor(descriptor)); - realRemoteBlock.setBlockId(realRemoteBlock.getBlockDescriptor().getBlockId()); - realRemoteBlock.setLocator(locator); + if(RealRemoteBlock.NAMESPACE.equals(namespace)) { + // it's a RealRemoteBlock ... + RealRemoteBlock realRemoteBlock = new RealRemoteBlock(); + realRemoteBlock.setBlockDescriptor(createCOB10Descriptor(descriptorDocument)); + realRemoteBlock.setBlockId(realRemoteBlock.getBlockDescriptor().getBlockId()); + if(locator == null) { + throw new NullPointerException("The locator mustn't be null."); + } + realRemoteBlock.setLocator(locator); + block = realRemoteBlock; + } - return realRemoteBlock; + return block; } - private static RealBlockDescriptor createCOB10Descriptor(InputStream descriptor) { + private static RealBlockDescriptor createCOB10Descriptor(Node descriptor) { RealBlockDescriptor realBlockDescriptor = null; try { Mapping mapping = new Mapping(); @@ -76,7 +107,7 @@ unmarshaller.setIgnoreExtraAttributes(true); unmarshaller.setIgnoreExtraElements(true); // unmarshaller.setDebug(true); - realBlockDescriptor = (RealBlockDescriptor)unmarshaller.unmarshal(new InputStreamReader(descriptor)); + realBlockDescriptor = (RealBlockDescriptor)unmarshaller.unmarshal(descriptor); } catch(Exception e) { throw new RuntimeException(e); } Added: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/SimpleBlock.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/block/SimpleBlock.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,47 @@ +/* + * 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.block; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.cocoon.blockdeployer.block.descriptor.BlockDescriptor; +import org.apache.cocoon.blockdeployer.repository.Locator; + +/** + * This block implementation represents Blocks prior Real Cocoon Blocks. + * + * @since 0.1 + */ +public class SimpleBlock implements RemoteBlock { + + public String getBlockId() { + return null; + } + + public Locator getLocator() { + return null; + } + + public InputStream getStream() throws IOException { + return null; + } + + public BlockDescriptor getBlockDescriptor() { + return null; + } + +} Added: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/configuration/DeploymentConfiguration.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/configuration/DeploymentConfiguration.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,101 @@ +/* + * 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.configuration; + +import java.util.ArrayList; +import java.util.List; + +/** + * <p> + * This configuration contains all information that are collected by the client + * to deploy one ore more blocks, into one or more Cocoon servers by using + * one or more locators. + * </p> + * <p> + * It doesn't perform any validity checks on the data. This is done by the service this + * object is passed to. + * </p> + * @since 0.1 + */ +public class DeploymentConfiguration { + + protected List servers = new ArrayList(); + protected List blocks = new ArrayList(); + protected List locators = new ArrayList(); + + public void addBlock(Block block) { + this.blocks.add(block); + } + + public void addServer(Server server) { + this.servers.add(server); + } + + public void addLocator(Locator locator) { + this.locators.add(locator); + } + + public List getLocators() { + return this.locators; + } + + public List getServers() { + return this.servers; + } + + public List getBlocks() { + return this.blocks; + } + + static class Block { + String uri; + boolean autoResolve = true; + public boolean isAutoResolve() { + return autoResolve; + } + public void setAutoResolve(boolean autoResolve) { + this.autoResolve = autoResolve; + } + public String getUri() { + return uri; + } + public void setUri(String uri) { + this.uri = uri; + } + } + + static class Server { + String uri; + public void setUri(String uri) { + this.uri = uri; + } + public String getUri() { + return this.uri; + } + } + + static class Locator { + String uri; + boolean local = false; + public void setUri(String uri) { + this.uri = uri; + } + public String getUri() { + return this.uri; + } + } + +} Added: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/configuration/DeploymentConfigurationException.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/configuration/DeploymentConfigurationException.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,25 @@ +/* + * 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.configuration; + +/** + * A checked exception indicating that a [EMAIL PROTECTED] DeploymentConfiguration} is not valid. + * + * @since 0.1 + */ +public class DeploymentConfigurationException extends Exception { + +} Added: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer21Locator.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer21Locator.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,63 @@ +/* + * 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; + +import java.io.File; +import java.io.IOException; + +import org.apache.cocoon.blockdeployer.block.RemoteBlock; +import org.apache.cocoon.blockdeployer.logging.LoggerFacade; +import org.apache.cocoon.blockdeployer.utils.LocatorUtils; + +/** + * @since 0.1 + */ +public class ApplicationServer21Locator implements Deployable { + + private LoggerFacade logger; + private File basedir; + + public ApplicationServer21Locator(File basedir, LoggerFacade logger) { + if( logger == null) { + throw new NullPointerException("You have to set a logger."); + } + this.logger = logger; + LocatorUtils.checkBasedir(basedir, logger, ApplicationServer21Locator.class); + this.basedir = basedir; + try { + this.logger.info(ApplicationServer21Locator.class, "Set basedir to " + + this.basedir.getCanonicalPath()); + } catch (IOException e) { + this.logger.error(ApplicationServer21Locator.class, "Error resolving basedir"); + } + } + + /** + * Deploy a block only by adding references (mount-table, cocoon.xconf, logkit.xconf, + * ParanoidCocoonServlet configuration) to the Cocoon server. + */ + // protected void devDeploy(File[] blockBasedirs) throws UnsupportedBlockException, IOException { + + // } + + public boolean deploy(RemoteBlock[] blocks) throws UnsupportedBlockException, IOException { + if(blocks.length == 0) { + throw new IllegalArgumentException("Passing an empty array is now allowed."); + } + return false; + } + +} Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocator.java ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocator.java (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocator.java Fri Nov 12 01:30:47 2004 @@ -60,27 +60,15 @@ * 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 + * is the [EMAIL PROTECTED] Wiring} (representing wiring.xml) of a Cocoon server */ public ApplicationServerLocator(File basedir, Wiring wiring, LoggerFacade logger ) { - if( logger == null) { + if(logger == null) { throw new NullPointerException("You have to set a logger!"); } - if (!basedir.exists()) { - throw new IllegalArgumentException( - "The specified directory is not available!"); - } - if (!basedir.isDirectory()) { - throw new IllegalArgumentException( - "The specified base dir (usually [appserv]/WEB-INF/blocks) " - + "for this locator is not a directory!"); - } - if (!basedir.canWrite()) { - throw new IllegalArgumentException( - "The specified base dir is not writeable!"); - } - if (wiring == null) { + LocatorUtils.checkBasedir(basedir, logger, ApplicationServerLocator.class); + // FIXME shouldn't be the wiring encapsulated by this locator? currently its a mix ... :-/ + if(wiring == null) { throw new NullPointerException("The wiring mustn't be null!"); } this.basedir = basedir; @@ -207,14 +195,12 @@ } } return true; - } - + } + public String getIdentifier() { try { return this.basedir.toURL().toString(); } catch (MalformedURLException e) { - // if a MalformedURLException occurs this indicates a problem (maybe in the - // BlockFactory throw new IllegalStateException(this.getClass().getName() + ": The block doesn't have a valid ID."); } } @@ -223,7 +209,6 @@ * Create a wiring descriptor out of the block descriptor * * @param Block - * object * @return returns a WiredRealBlockDescriptor object containing */ protected static WiredRealBlockDescriptor createBlockWiringDescriptor( 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 Fri Nov 12 01:30:47 2004 @@ -37,17 +37,13 @@ private LoggerFacade logger; public FilesystemLocator(File basedir, LoggerFacade logger) { - if(!basedir.exists()) { - throw new IllegalArgumentException("The specified directory is not available!"); - } - if(!basedir.isDirectory()) { - throw new IllegalArgumentException("The specified base for this locator is not a directory!"); - } if(logger == null) { - throw new NullPointerException("Please set a Logger implementing the interface " + LoggerFacade.class.getClass().getName() + "."); - } - this.basedir = basedir; + throw new NullPointerException("Please set a Logger implementing the interface " + LoggerFacade.class.getClass().getName() + "."); + } this.logger = logger; + + LocatorUtils.checkBasedir(basedir, logger, FilesystemLocator.class); + this.basedir = basedir; this.logger.debug(this.getClass(), "Created FileSystemLocator, basedir: " + this.basedir.getAbsolutePath()); } @@ -55,6 +51,7 @@ try { return this.basedir.toURL().toString(); } catch (MalformedURLException e) { + this.logger.error(FilesystemLocator.class, "The locator's basedir can't be resolved", e); } return null; } Added: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/SingleBlockLocator.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/SingleBlockLocator.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,70 @@ +/* + * 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; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.cocoon.blockdeployer.block.RemoteBlock; +import org.apache.cocoon.blockdeployer.logging.LoggerFacade; +import org.apache.cocoon.blockdeployer.utils.LocatorUtils; + +/** + * This locator provides access to a single block. The basedir of this + * locator is identical to the block's basedir. + * + * @since 0.1 + */ +public class SingleBlockLocator implements Locator { + + private LoggerFacade logger; + private File basedir; + + public SingleBlockLocator(File basedir, LoggerFacade logger) { + if(logger == null) { + throw new NullPointerException("The logger mustn't be null."); + } + this.logger = logger; + LocatorUtils.checkBasedir(basedir, logger, SingleBlockLocator.class); + this.basedir = basedir; + } + + public RemoteBlock getRemoteBlock(String blockId) throws BlockNotFoundException, IOException { + // read the block descriptor file of the only available block + + // compare whethr this available block and the blockId are the same + + // if yes, return the block + + // if no, throw Exception + + return null; + } + + public String getIdentifier() { + return null; + } + + public InputStream getBlockAsStream(String blockId) throws IOException, BlockNotFoundException { + return null; + } + + public RemoteBlock[] browse() { + return null; + } + +} Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/utils/LocatorUtils.java ============================================================================== --- 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 Fri Nov 12 01:30:47 2004 @@ -175,4 +175,26 @@ } return nextDirSB.append(nextDir).toString(); } + + public static void checkBasedir(File basedir, LoggerFacade logger, Class clazz) { + if(basedir == null) { + String errorMsg = "The basedir mustn't be null."; + logger.error(errorMsg); + throw new NullPointerException(errorMsg); + } + if(!basedir.exists()) { + String errorMsg = "The specified basedir [" + basedir.getAbsolutePath() + "] is not available."; + logger.error(errorMsg); + throw new IllegalArgumentException(errorMsg); + } + if(!basedir.canRead()) { + String errorMsg = "The basedir [" + basedir.getAbsolutePath() + "] must be readable."; + throw new IllegalArgumentException(errorMsg); + } + if(!basedir.isDirectory()) { + String errorMsg = "The specified basedir [" + basedir.getAbsolutePath() + "] for this locator is not a directory!"; + logger.error(errorMsg); + throw new IllegalArgumentException(errorMsg); + } + } } Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java ============================================================================== --- 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 Fri Nov 12 01:30:47 2004 @@ -26,6 +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 INVALID_LOCATION = "bla"; Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java ============================================================================== --- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java (original) +++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java Fri Nov 12 01:30:47 2004 @@ -21,7 +21,7 @@ public class ConsoleLogger implements LoggerFacade { public void debug(String msg) { - System.out.println(" DEBUG: " + msg); + System.out.println(" DEBUG: " + msg); } public void debug(Class clazz, String msg) { @@ -57,11 +57,20 @@ } public void error(String msg) { - System.out.println(" ERROR: " + msg); + System.out.println(" ERROR: " + msg); } public void error(Class clazz, String msg) { this.error(clazz.getName() + ": " + msg); + } + // FIXME code never tested! + public void error(Class clazz, String msg, Exception e) { + StringBuffer stacktrace = new StringBuffer(msg + "\n"); + StackTraceElement[] ste = e.getStackTrace(); + for(int i = 0; i < ste.length; i++) { + stacktrace.append(ste[i]).append('\n'); + } + this.error(clazz, stacktrace.toString()); } public boolean isErrorEnabled() { Added: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer21LocatorTest.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer21LocatorTest.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,56 @@ +/* + * 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; + +import java.io.File; + +import org.apache.cocoon.blockdeployer.Constants; +import org.apache.cocoon.blockdeployer.LogEnabledTestCase; + + +/** + * @since 0.1 + */ +public class ApplicationServer21LocatorTest extends LogEnabledTestCase { + + + public void testDeployInitialization() { + ApplicationServer21Locator asl = new ApplicationServer21Locator(new File(Constants.VALID_ASL21_1), this.logger); + + } + + public void testCreation() { + try { + ApplicationServer21Locator asl = new ApplicationServer21Locator(new File(Constants.VALID_ASL21_1), null); + fail("The logger is null and no exception has been thrown."); + } catch(NullPointerException npe) { + // should throw Exception -> expected behaviour + } + try { + ApplicationServer21Locator asl = new ApplicationServer21Locator(null, this.logger); + fail("The basedir is null and no exception has been thrown."); + } catch(NullPointerException npe) { + // should throw Exception -> expected behaviour + } + try { + ApplicationServer21Locator asl = new ApplicationServer21Locator(new File(Constants.VALID_ASL21_1 + "/blblblb.txt"), this.logger); + fail("The basedir is not a directory and no exception has been thrown."); + } catch(IllegalArgumentException iae) { + // should throw Exception -> expected behaviour + } + } + +} Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocatorTest.java ============================================================================== --- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocatorTest.java (original) +++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServerLocatorTest.java Fri Nov 12 01:30:47 2004 @@ -33,7 +33,7 @@ public class ApplicationServerLocatorTest extends LogEnabledTestCase { private void setupExamples() { - new File(Constants.TMP_VALID_ASL_1).mkdirs(); + FileUtil.mkdir(Constants.TMP_VALID_ASL_1); FileUtil.copyDir(Constants.VALID_ASL_1, Constants.TMP_VALID_ASL_1); } Added: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/SingeBlockLocatorTest.java ============================================================================== --- (empty file) +++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/SingeBlockLocatorTest.java Fri Nov 12 01:30:47 2004 @@ -0,0 +1,32 @@ +/* + * 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; + +import org.apache.cocoon.blockdeployer.LogEnabledTestCase; + +/** + * @since 0.1 + */ +public class SingeBlockLocatorTest extends LogEnabledTestCase { + + public void testGetRemoteBlock() { + + } + + public void testGetIdentifier() { + } + +}