cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r490550 - in /cocoon/trunk/core: cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/ cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ cocoon-spring/src/main/java/org/apache/c...
Date Wed, 27 Dec 2006 18:48:44 GMT
Author: cziegeler
Date: Wed Dec 27 10:48:42 2006
New Revision: 490550

URL: http://svn.apache.org/viewvc?view=rev&rev=490550
Log:
Provide information about deployed blocks through own component

Added:
    cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/BlockResourcesHolder.java
  (with props)
    cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/DefaultBlockResourcesHolder.java
  (with props)
Modified:
    cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlockContextSourceFactory.java
    cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsBeanFactoryPostProcessor.java
    cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsElementParser.java

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java?view=diff&rev=490550&r1=490549&r2=490550
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java
(original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java
Wed Dec 27 10:48:42 2006
@@ -45,8 +45,6 @@
 
     protected static final String BLOCK_RESOURCES_PATH = "COB-INF";
 
-    protected static final Map blockContexts = new HashMap(); 
-
     /**
      * Deploy all files with a given prefix from a jar file to a directory
      * in the file system.
@@ -75,7 +73,8 @@
     }
 
     protected static void deployBlockResources(String relativeDirectory,
-                                               String destinationDirectory)
+                                               String destinationDirectory,
+                                               Map    blockContexts)
     throws IOException {
         final Enumeration jarUrls = DeploymentUtil.class.getClassLoader().getResources(BLOCK_RESOURCES_PATH);
         while ( jarUrls.hasMoreElements() ) {
@@ -92,7 +91,7 @@
                     String blockName = url.substring(0, pos);
                     blockName = blockName.substring(blockName.lastIndexOf('/') + 1);
                     // register the root URL for the block resources
-                    DeploymentUtil.blockContexts.put(blockName, url);
+                    blockContexts.put(blockName, url);
                 }
             } else if ( "jar".equals(resourceUrl.getProtocol()) ) {
                 // if this is a jar url, it has this form: "jar:{url-to-jar}!/{resource-path}"
@@ -119,20 +118,22 @@
                 String destination = buffer.toString();
                 deploy(jarFile, BLOCK_RESOURCES_PATH, destination);
                 // register the root URL for the block resources
-                DeploymentUtil.blockContexts.put(blockName, destination);
+                blockContexts.put(blockName, destination);
             }
             // we only handle jar files and ordinary files
             // TODO - Should we throw an exception if it's some other protocol type? (or
log?)
         }        
     }
 
-    public static void deployBlockArtifacts(String destinationDirectory)
+    public static Map deployBlockArtifacts(String destinationDirectory)
     throws IOException {
         if ( destinationDirectory == null ) {
             throw new IllegalArgumentException("Destination must not be null.");
         }
+        final Map blockContexts = new HashMap();
         // deploy all artifacts containing block resources
-        deployBlockResources("blocks", destinationDirectory);
+        deployBlockResources("blocks", destinationDirectory, blockContexts);
+        return blockContexts;
     }
 
     public static void deployJarResources(String pattern, String destinationDirectory)
@@ -155,15 +156,4 @@
             }
         }
     }
-
-    /**
-     * Get a map that associates a block name with the root URL of the blocks resources
-     *  
-     * @return the blockContexts
-     */
-    // FIXME: It would be better to make the block contexts mapping available as a
-    // component instead of as a static method
-    public static Map getBlockContexts() {
-        return blockContexts;
-    }    
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlockContextSourceFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlockContextSourceFactory.java?view=diff&rev=490550&r1=490549&r2=490550
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlockContextSourceFactory.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlockContextSourceFactory.java
Wed Dec 27 10:48:42 2006
@@ -25,7 +25,7 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.configuration.impl.DeploymentUtil;
+import org.apache.cocoon.spring.BlockResourcesHolder;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
 import org.apache.excalibur.source.SourceFactory;
@@ -42,11 +42,14 @@
     
     private ServiceManager serviceManager;
 
-    /* (non-Javadoc)
+    private BlockResourcesHolder blockResourcesHolder;
+
+    /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
-    public void service(ServiceManager serviceManager) throws ServiceException {
-        this.serviceManager = serviceManager;
+    public void service(ServiceManager aServiceManager) throws ServiceException {
+        this.serviceManager = aServiceManager;
+        this.blockResourcesHolder = (BlockResourcesHolder) this.serviceManager.lookup(BlockResourcesHolder.class.getName());
     }
 
     /* (non-Javadoc)
@@ -55,7 +58,7 @@
     public Source getSource(String location, Map parameters) throws IOException,
             MalformedURLException {
 
-        Map blockContexts = DeploymentUtil.getBlockContexts();
+        Map blockContexts = this.blockResourcesHolder.getBlockContexts();
 
         // the root "directory" of the blocks
         if (location.endsWith(":/"))
@@ -95,10 +98,11 @@
         }
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
      */
     public void release(Source source) {
+        // nothing to do
     }
 
 }

Added: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/BlockResourcesHolder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/BlockResourcesHolder.java?view=auto&rev=490550
==============================================================================
--- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/BlockResourcesHolder.java
(added)
+++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/BlockResourcesHolder.java
Wed Dec 27 10:48:42 2006
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.spring;
+
+import java.util.Map;
+
+/**
+ * FIXME: Perhaps someone has a better name?!?
+ * @version $Id$
+ *
+ */
+public interface BlockResourcesHolder {
+
+    /**
+     * Return a map with deployed block names as keys and the url of the deployed
+     * resources as value.
+     */
+    Map getBlockContexts();
+}

Propchange: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/BlockResourcesHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/BlockResourcesHolder.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/DefaultBlockResourcesHolder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/DefaultBlockResourcesHolder.java?view=auto&rev=490550
==============================================================================
--- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/DefaultBlockResourcesHolder.java
(added)
+++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/DefaultBlockResourcesHolder.java
Wed Dec 27 10:48:42 2006
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.spring.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.configuration.impl.DeploymentUtil;
+import org.apache.cocoon.spring.BlockResourcesHolder;
+
+/**
+ * FIXME: Perhaps someone has a better name?!?
+ * @version $Id$
+ *
+ */
+public class DefaultBlockResourcesHolder
+    implements BlockResourcesHolder {
+
+    protected Settings settings;
+
+    protected Map blockContexts = new HashMap();
+
+    public void setSettings(Settings settings) {
+        this.settings = settings;
+    }
+
+    public void init()
+    throws Exception {
+        this.blockContexts = DeploymentUtil.deployBlockArtifacts(this.settings.getWorkDirectory());
+    }
+
+    /**
+     * Return a map with deployed block names as keys and the url of the deployed
+     * resources as value.
+     */
+    public Map getBlockContexts() {
+        return this.blockContexts;
+    }
+}

Propchange: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/DefaultBlockResourcesHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/DefaultBlockResourcesHolder.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsBeanFactoryPostProcessor.java?view=diff&rev=490550&r1=490549&r2=490550
==============================================================================
--- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsBeanFactoryPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsBeanFactoryPostProcessor.java
Wed Dec 27 10:48:42 2006
@@ -28,7 +28,6 @@
 import org.apache.cocoon.configuration.PropertyProvider;
 import org.apache.cocoon.configuration.Settings;
 import org.apache.cocoon.configuration.SettingsDefaults;
-import org.apache.cocoon.configuration.impl.DeploymentUtil;
 import org.apache.cocoon.configuration.impl.MutableSettings;
 import org.apache.cocoon.configuration.impl.PropertyHelper;
 import org.apache.cocoon.spring.ResourceUtils;
@@ -69,9 +68,6 @@
         this.dumpSystemProperties();
         this.dumpSettings();
         this.forceLoad();
-
-        // finally deploy block artifacts!
-        DeploymentUtil.deployBlockArtifacts(this.settings.getWorkDirectory());
     }
 
     /**

Modified: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsElementParser.java?view=diff&rev=490550&r1=490549&r2=490550
==============================================================================
--- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/impl/SettingsElementParser.java
Wed Dec 27 10:48:42 2006
@@ -21,6 +21,7 @@
 import javax.servlet.ServletContext;
 
 import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.spring.BlockResourcesHolder;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -71,8 +72,14 @@
         this.registerPropertyOverrideConfigurer(parserContext, springConfigLocation);
 
         // add the servlet context as a bean
-        this.addComponent(ServletContextFactoryBean.class.getName(), ServletContext.class.getName(),
null, false,
-                parserContext.getRegistry());
+        this.addComponent(ServletContextFactoryBean.class.getName(),
+                          ServletContext.class.getName(),
+                          null, false, parserContext.getRegistry());
+
+        // deploy blocks and add a bean holding the information
+        this.addComponent(DefaultBlockResourcesHolder.class.getName(), 
+                          BlockResourcesHolder.class.getName(),
+                          "init", true, parserContext.getRegistry());
 
         // handle includes
         try {
@@ -81,6 +88,7 @@
         } catch (Exception e) {
             throw new BeanDefinitionStoreException("Unable to read spring configurations
from " + Constants.DEFAULT_SPRING_CONFIGURATION_LOCATION, e);
         }
+
         return null;
     }
 }



Mime
View raw message