forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject svn commit: r232644 - in /forrest/trunk/main/java/org/apache/forrest/locationmap/lm: LocationMap.java MountNode.java
Date Sun, 14 Aug 2005 21:04:04 GMT
Author: twilliams
Date: Sun Aug 14 14:03:55 2005
New Revision: 232644

URL: http://svn.apache.org/viewcvs?rev=232644&view=rev
Log:
the first cut at a locationmap mounting capability.  

Added:
    forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MountNode.java   (with props)
Modified:
    forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java

Modified: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java?rev=232644&r1=232643&r2=232644&view=diff
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java (original)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java Sun Aug 14
14:03:55 2005
@@ -104,7 +104,10 @@
     
     /** list of LocatorNodes */
     private LocatorNode[] m_locatorNodes;
-    
+
+    /** list of MountNodes */
+    private MountNode[] m_mountNodes;
+   
     
     public LocationMap(ServiceManager manager) {
         m_manager = new LocationMapServiceManager(manager);
@@ -119,6 +122,16 @@
         // components
         final Configuration components = configuration.getChild("components");
 
+        // mount
+        final Configuration[] mountChildren = configuration.getChildren("mount");
+        m_mountNodes = new MountNode[mountChildren.length];
+
+        for (int i = 0; i < mountChildren.length; i++) {
+            m_mountNodes[i] = new MountNode(m_manager);
+            m_mountNodes[i].enableLogging(getLogger());
+            m_mountNodes[i].build(mountChildren[i]);
+        }
+
         // matchers
         Configuration child = components.getChild("matchers",false);
         if (child != null) {
@@ -223,6 +236,15 @@
         final Map anchorMap = new HashMap(2);
         anchorMap.put(HINT_KEY,hint);
         context.pushMap(ANCHOR_NAME,anchorMap);
+
+        //mounted locations first
+        for (int i = 0; i < m_mountNodes.length; i++) {
+        	location = m_mountNodes[i].locate(om,context);
+        	if (location !=null) {
+        		ContainerUtil.dispose(context);
+        		return location;
+        	}
+        }
 
         for (int i = 0; i < m_locatorNodes.length; i++) {
             location = m_locatorNodes[i].locate(om,context);

Added: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MountNode.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MountNode.java?rev=232644&view=auto
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MountNode.java (added)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MountNode.java Sun Aug 14 14:03:55
2005
@@ -0,0 +1,169 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.forrest.locationmap.lm;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.NamespacedSAXConfigurationHandler;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
+import org.apache.cocoon.sitemap.PatternException;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.SourceUtil;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.xml.sax.SAXParser;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * locationmap mount statement.
+ */
+public class MountNode extends AbstractNode {
+
+    // the resolvable location source
+    private SourceResolver m_srcResolver;
+    private VariableResolver m_varResolver;
+    private String m_src;
+    private SourceValidity m_srcVal;
+    private LocationMap m_lm;
+
+
+    public MountNode(final ServiceManager manager) {
+        super(manager);
+    }
+
+    public void build(final Configuration configuration) throws ConfigurationException {
+        try
+        {
+        	m_varResolver = VariableResolverFactory.getResolver(
+        	    configuration.getAttribute("src"), super.m_manager);
+        }
+        catch (PatternException e) {
+        	throw new ConfigurationException("unable to resolve mounts 'src' attribute");
+        }
+    }
+
+    //TODO:  Look at re-use with locationmapmodule code.
+    private LocationMap getLocationMap() throws Exception {
+        Source source = null;
+        try {
+            try {
+            	m_srcResolver = (SourceResolver) m_manager.lookup(SourceResolver.ROLE);
+            }
+            catch (ServiceException e) {
+            	throw new ConfigurationException("building mount node");
+            }
+            source = m_srcResolver.resolveURI(m_src);
+            if (m_lm == null) {
+                synchronized (this) {
+                    if (m_lm == null) {
+                        if (getLogger().isDebugEnabled()) {
+                            getLogger().debug("loading mounted location map at " + m_src);
+                        }
+                        m_srcVal = source.getValidity();
+                        m_lm = new LocationMap(m_manager);
+                        m_lm.enableLogging(getLogger());
+                        m_lm.build(loadConfiguration(source));
+                    }
+                }
+            }
+            else {
+                SourceValidity valid = source.getValidity();
+                if (m_srcVal != null && m_srcVal.isValid(valid) != 1) {
+                    synchronized (this) {
+                        if (m_srcVal != null && m_srcVal.isValid(valid) != 1) {
+                            if (getLogger().isDebugEnabled()) {
+                                getLogger().debug("reloading mounted location map at " +
m_src);
+                            }
+                            m_srcVal = valid;
+                            m_lm.dispose();
+                            m_lm = new LocationMap(m_manager);
+                            m_lm.enableLogging(getLogger());
+                            m_lm.build(loadConfiguration(source));
+                        }
+                    }
+                }
+            }
+        }
+        finally {
+            if (source != null) {
+                m_srcResolver.release(source);
+            }
+        }
+        return m_lm;
+    }
+
+    //TODO:  Look at re-use with locationmapmodule code.
+    private Configuration loadConfiguration(Source source) throws ConfigurationException
{
+        Configuration configuration = null;
+        SAXParser parser = null;
+        try {
+            parser = (SAXParser) m_manager.lookup(SAXParser.ROLE);
+            NamespacedSAXConfigurationHandler handler =
+                new NamespacedSAXConfigurationHandler();
+            parser.parse(new InputSource(source.getInputStream()),handler);
+            configuration = handler.getConfiguration();
+        }
+        catch (IOException e) {
+            throw new ConfigurationException("Unable to build LocationMap.",e);
+        }
+        catch (SAXException e) {
+            throw new ConfigurationException("Unable to build LocationMap.",e);
+        }
+        catch (ServiceException e) {
+            throw new ConfigurationException("Unable to build LocationMap.",e);
+        }
+        finally {
+            if (parser != null) {
+                m_manager.release(parser);
+            }
+        }
+        return configuration;
+    }
+
+    /**
+     * use mounted locationmap to locate hint
+     */
+    public String locate(Map om, InvokeContext context) throws Exception {
+       try {
+    	    Map anchor = context.getMapByAnchor(LocationMap.ANCHOR_NAME );
+   	    String hint = (String)anchor.get(LocationMap.HINT_KEY);
+
+            //TODO: Put this in a better place, closer to instantiation;
+            //      m_src needs to be properly set prior to getLocMap call
+            m_src = m_varResolver.resolve(context,om);
+
+            return getLocationMap().locate(hint,om);
+        }
+        catch (ConfigurationException e) {
+            throw e;
+        }
+        catch (Exception e) {
+            getLogger().error("Failure processing LocationMap.",e);
+        }
+        return null;
+
+    }
+
+}

Propchange: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MountNode.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message