Author: thorsten Date: Thu Aug 21 02:47:18 2008 New Revision: 687674 URL: http://svn.apache.org/viewvc?rev=687674&view=rev Log: Refactoring code to release all sources that we have resolved. Further making sure we use the correct resolver FOR-955
Modified: forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/ContractBeanDOMImpl.java forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/RecursiveDirectoryTraversalAction.java forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/util/SourceUtil.java Modified: forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/ContractBeanDOMImpl.java URL: http://svn.apache.org/viewvc/forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/ContractBeanDOMImpl.java?rev=687674&r1=687673&r2=687674&view=diff ============================================================================== --- forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/ContractBeanDOMImpl.java (original) +++ forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/ContractBeanDOMImpl.java Thu Aug 21 02:47:18 2008 @@ -32,6 +32,7 @@ import javax.xml.transform.dom.DOMSource; import org.apache.avalon.framework.service.ServiceManager; +import org.apache.excalibur.source.SourceResolver; import org.apache.forrest.dispatcher.lenya.xml.NamespaceHelper; import org.apache.forrest.dispatcher.transformation.DispatcherTransformer; import org.w3c.dom.Document; @@ -107,7 +108,6 @@ protected DispatcherHelper dispatcherHelper; - protected ServiceManager manager; private HashMap parameterHelper; @@ -117,6 +117,8 @@ private Object defaultVariables; + private SourceResolver resolver; + /** * The ContractBean contains all fields to work with contracts. It is a * helper bean. @@ -131,11 +133,11 @@ * @param defaultProperties * @throws ParserConfigurationException */ - public ContractBeanDOMImpl(ServiceManager manager, HashMap parameterHelper,Document defaultProperties, URIResolver uriResolver) + public ContractBeanDOMImpl(SourceResolver resolver, HashMap parameterHelper,Document defaultProperties, URIResolver uriResolver) throws ParserConfigurationException { m_uriResolver=uriResolver; - this.manager = manager; - dispatcherHelper = new DispatcherHelper(manager); + this.resolver = resolver; + dispatcherHelper = new DispatcherHelper(resolver); this.parameterHelper = parameterHelper; this.defaultVariables=defaultProperties; } @@ -167,7 +169,7 @@ * @see org.apache.forrest.dispatcher.ContractBeanInterface#initialize() */ public void initialize() throws ParserConfigurationException { - dispatcherHelper = new DispatcherHelper(this.manager); + dispatcherHelper = new DispatcherHelper(resolver); } /* Modified: forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java URL: http://svn.apache.org/viewvc/forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java?rev=687674&r1=687673&r2=687674&view=diff ============================================================================== --- forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java (original) +++ forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java Thu Aug 21 02:47:18 2008 @@ -27,10 +27,10 @@ import javax.xml.transform.TransformerFactory; import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; import org.apache.cocoon.xml.XMLUtils; import org.apache.cocoon.xml.dom.DOMBuilder; import org.apache.excalibur.source.SourceNotFoundException; +import org.apache.excalibur.source.SourceResolver; import org.apache.forrest.dispatcher.lenya.xml.NamespaceHelper; import org.w3c.dom.DOMException; import org.w3c.dom.Document; @@ -53,7 +53,7 @@ private NamespaceHelper namespaceHelper; - private ServiceManager manager; + private SourceResolver resolver; /** * Create a DOM representation of this dispatcher. @@ -72,7 +72,7 @@ */ public Document getDocument(String uri) throws Exception { Document doc = org.apache.forrest.dispatcher.util.SourceUtil.readDOM( - uri, this.manager); + uri, this.resolver); if (doc != null) { this.namespaceHelper = new NamespaceHelper( DISPATCHER_NAMESPACE_URI, DISPATCHER_PREFIX, doc); @@ -184,9 +184,9 @@ } - public DispatcherHelper(ServiceManager manager) + public DispatcherHelper(SourceResolver resolver) throws ParserConfigurationException { - this.manager = manager; + this.resolver = resolver; this.namespaceHelper = new NamespaceHelper(DISPATCHER_NAMESPACE_URI, DISPATCHER_PREFIX, "foo"); } Modified: forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/RecursiveDirectoryTraversalAction.java URL: http://svn.apache.org/viewvc/forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/RecursiveDirectoryTraversalAction.java?rev=687674&r1=687673&r2=687674&view=diff ============================================================================== --- forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/RecursiveDirectoryTraversalAction.java (original) +++ forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/RecursiveDirectoryTraversalAction.java Thu Aug 21 02:47:18 2008 @@ -30,6 +30,7 @@ import org.apache.cocoon.environment.Redirector; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceResolver; +import org.apache.forrest.dispatcher.DispatcherException; /** * Selects the first of a set of Sources that exists in the context. @@ -121,17 +122,13 @@ } else { return null; } - } catch (MalformedURLException e) { - getLogger().warn( - "Selector URL '" + uri + "' is not a valid Source URL"); - return null; - } catch (IOException e) { + } catch (DispatcherException e) { getLogger().warn( "Error reading from source '" + uri + "': " + e.getMessage()); return null; } finally { - resolver.release(src); + release(src); } } @@ -159,14 +156,13 @@ * is overriding this view. This override can be used for directories * (default.fv) and/or files (*.fv). That means that the root view is the * default view as long no other view can be found in the requested child. - * @throws IOException - * @throws MalformedURLException + * @throws DispatcherException * */ - private void computeResponseURI(String uri, Source src) - throws MalformedURLException, IOException { - src = resolver.resolveURI(uri); - if (src.exists()) { + private void computeResponseURI(String uri, Source src) throws DispatcherException{ + try { + src = resolver.resolveURI(uri); + if (src.exists()) { this.map.put("uri", uri); } else { if (this.getRest().lastIndexOf("/") > -1) { @@ -185,8 +181,23 @@ } } } + } catch (MalformedURLException e) { + throw new DispatcherException(e); + } catch (IOException e) { + throw new DispatcherException(e); + }finally{ + release(src); + } + + } + /** + * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source) + */ + public void release(Source source) { + if(source!=null){ + resolver.release(source); + } } - public void prepare(Parameters parameters, String src) { this.setRequest(parameters.getParameter("request", src)); this.setProjectFallback(parameters.getParameter("projectFallback", Modified: forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java URL: http://svn.apache.org/viewvc/forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java?rev=687674&r1=687673&r2=687674&view=diff ============================================================================== --- forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java (original) +++ forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java Thu Aug 21 02:47:18 2008 @@ -49,6 +49,7 @@ import org.apache.cocoon.environment.Redirector; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceResolver; +import org.apache.forrest.dispatcher.DispatcherException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; @@ -106,31 +107,23 @@ } else { return null; } - } catch (MalformedURLException e) { - getLogger().warn( - "Selector URL '" + uri + "' is not a valid Source URL"); - return null; - } catch (IOException e) { - getLogger().warn( - "Error reading from source '" + uri + "': " - + e.getMessage()); - return null; - } catch (Exception e) { + } catch (Exception e) { getLogger().warn( "Error reading from source '" + uri + "': " + e.getMessage()); return null; }finally { - resolver.release(src); + release(src); } } private void computeResponseURI(String uri, Source src) - throws Exception { - src = resolver.resolveURI(uri); - if (src.exists()) { + throws DispatcherException { + try { + src = resolver.resolveURI(uri); + if (src.exists()) { Document rawData = org.apache.forrest.dispatcher.util.SourceUtil.readDOM( - uri, this.manager); + uri, resolver); NodeList type = rawData.getElementsByTagNameNS(getResourceTypeElementNS(),getResourceTypeElement()); String typeString = type.item(0).getFirstChild().getNodeValue(); Source typeSource = resolver.resolveURI(resourceTypeBase+typeString); @@ -138,8 +131,21 @@ this.map.put("uri", typeSource.getURI()); } } + } catch (Exception e) { + throw new DispatcherException(e); + }finally{ + release(src); + } + } - + /** + * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source) + */ + public void release(Source source) { + if(source!=null){ + resolver.release(source); + } + } public void prepare(Parameters parameters, String src) { this.setRequest(parameters.getParameter("request", src)); this.setMetaExtension(parameters.getParameter("metaExtension", Modified: forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java URL: http://svn.apache.org/viewvc/forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java?rev=687674&r1=687673&r2=687674&view=diff ============================================================================== --- forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java (original) +++ forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java Thu Aug 21 02:47:18 2008 @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.Map; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.URIResolver; @@ -44,6 +45,7 @@ import org.apache.cocoon.xml.dom.DOMUtil; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; +import org.apache.excalibur.source.SourceNotFoundException; import org.apache.excalibur.source.SourceValidity; import org.apache.excalibur.source.impl.validity.AggregatedValidity; import org.apache.excalibur.xml.xpath.XPathProcessor; @@ -51,6 +53,7 @@ import org.apache.forrest.dispatcher.ContractBeanDOMImpl; import org.apache.forrest.dispatcher.DispatcherException; import org.apache.forrest.dispatcher.DispatcherHelper; +import org.apache.forrest.dispatcher.lenya.xml.DocumentHelper; import org.apache.forrest.dispatcher.lenya.xml.NamespaceHelper; import org.w3c.dom.DOMException; import org.w3c.dom.Document; @@ -190,7 +193,7 @@ private HashMap parameterHelper; - private SourceResolver m_resolver; + private org.apache.excalibur.source.SourceResolver m_resolver; private String requestId; @@ -245,10 +248,14 @@ // to force a SourceValidity.INVALID if (null != validityFile & !(validityOverride.equals(CACHING_OFF))) { this.validity = new AggregatedValidity(); + Source resolveSource=null; try { - this.validity.add(m_resolver.resolveURI(validityFile).getValidity()); + resolveSource= m_resolver.resolveURI(validityFile); + this.validity.add(resolveSource.getValidity()); } catch (Exception e) { getLogger().error(e.getMessage()); + }finally{ + release(resolveSource); } } else this.validity = null; @@ -256,6 +263,15 @@ } /** + * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source) + */ + public void release(Source source) { + if(source!=null){ + m_resolver.release(source); + } + } + + /** * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) */ public void service(ServiceManager manager) throws ServiceException { @@ -282,7 +298,7 @@ public void recycle() { localRecycle(); this.validity = null; - super.recycle(); + //super.recycle(); } @@ -332,7 +348,7 @@ parameterHelper.put(HOOKS_TRANSFORMER_PARAMETER, hooksXSL); if (null == m_resolver) try { - m_resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE); + m_resolver = (org.apache.excalibur.source.SourceResolver) manager.lookup(SourceResolver.ROLE); } catch (ServiceException e) { throw new ProcessingException(e); } @@ -520,7 +536,7 @@ localRecycle(); try { if (null == this.dispatcherHelper) - this.dispatcherHelper = new DispatcherHelper(manager); + this.dispatcherHelper = new DispatcherHelper(m_resolver); if (null == this.processor) this.processor = (XPathProcessor) this.manager .lookup(XPathProcessor.ROLE); @@ -533,7 +549,7 @@ String propertyURI = "cocoon://" + requestId + ".props"; try { this.defaultProperties = org.apache.forrest.dispatcher.util.SourceUtil - .readDOM(propertyURI, this.manager); + .readDOM(propertyURI, m_resolver); } catch (Exception e1) { String error = "dispatcherError:\n" + "Could not get the properties for " + propertyURI + "\n DispatcherStack: " + e1; @@ -640,7 +656,7 @@ private void contractProcessingStart(Attributes attr) throws SAXException { try { if (contract == null) - contract = new ContractBeanDOMImpl(this.manager, parameterHelper, + contract = new ContractBeanDOMImpl(m_resolver, parameterHelper, defaultProperties, (URIResolver) this); } catch (Exception e) { String error = DispatcherException.ERROR_500 + "\n" @@ -658,19 +674,21 @@ contract.setContractName(value); String contractUri = ContractBean.CONTRACT_RESOLVE_PREFIX + "." + currentFormat + "." + value; + Source contractSource = null; try { // Adding the contract to the validity object. // As soon the contract changes we want a rebuild of // the page and not the cached object. if (!validityOverride.equals(CACHING_OFF) & null != this.validity) { - SourceValidity contractValidityId = m_resolver.resolveURI(contractUri) + contractSource = m_resolver.resolveURI(contractUri); + SourceValidity contractValidityId = contractSource .getValidity(); // we cannot allow null in an AggregatedValidity if (null != contractValidityId) this.validity.add(contractValidityId); } Document doc = org.apache.forrest.dispatcher.util.SourceUtil.readDOM( - contractUri, this.manager); + contractUri, m_resolver); contract.setContractImpl(doc, contractUri); // contract.setContractImpl(contractUri); } catch (Exception e) { @@ -683,6 +701,8 @@ + contractUri + "\".\n\n" + "dispatcherErrorStack:\n" + e; getLogger().error(error); throw new SAXException(error); + }finally{ + release(contractSource); } if (getLogger().isDebugEnabled()) { getLogger().debug( @@ -692,19 +712,21 @@ } else if (ContractBean.CONTRACT_NUGGET_ATTRIBUTE.equals(localName)) { // contract is a nugget-contract contract.setNugget(true); + Source contractRawSource =null; try { // Adding the raw data to the validity object. // As soon the raw data changes we want a rebuild of // the page and not the cached object. if (!validityOverride.equals(CACHING_OFF) & null != this.validity) { - SourceValidity contractValidityRaw = m_resolver.resolveURI(value) + contractRawSource = m_resolver.resolveURI(value); + SourceValidity contractValidityRaw = contractRawSource .getValidity(); // we cannot allow null in an AggregatedValidity if (null != contractValidityRaw) this.validity.add(contractValidityRaw); } Document doc = org.apache.forrest.dispatcher.util.SourceUtil.readDOM( - value, this.manager); + value, m_resolver); contract.setContractRawData(doc); // contract.setNuggetUri(value); } catch (Exception e) { @@ -714,6 +736,8 @@ + value + "\".\n\n" + "dispatcherErrorStack:\n " + e; getLogger().error(error); throw new SAXException(error); + } finally{ + release(contractRawSource); } if (getLogger().isDebugEnabled()) { getLogger().debug( @@ -1039,7 +1063,7 @@ return null; } finally { - m_resolver.release(xslSource); + release(xslSource); } } @@ -1057,5 +1081,5 @@ newObject.setSystemId(source.getURI()); return newObject; } - + } Modified: forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/util/SourceUtil.java URL: http://svn.apache.org/viewvc/forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/util/SourceUtil.java?rev=687674&r1=687673&r2=687674&view=diff ============================================================================== --- forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/util/SourceUtil.java (original) +++ forrest/branches/update_cocoon_2.1.12-dev/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/util/SourceUtil.java Thu Aug 21 02:47:18 2008 @@ -21,10 +21,9 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.cocoon.environment.SourceResolver; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceNotFoundException; +import org.apache.excalibur.source.SourceResolver; import org.apache.forrest.dispatcher.lenya.xml.DocumentHelper; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -41,27 +40,20 @@ * @throws SAXException if an error occurs. * @throws IOException if an error occurs. */ - public static Document readDOM(String sourceUri, ServiceManager manager) + public static Document readDOM(String sourceUri, SourceResolver resolver) throws ServiceException, SourceNotFoundException, ParserConfigurationException, SAXException, IOException { - SourceResolver resolver = null; Source source = null; Document document = null; try { - - resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE); source = resolver.resolveURI(sourceUri); - if (source.exists()) { document = DocumentHelper.readDocument(source.getInputStream()); } } finally { - if (resolver != null) { if (source != null) { resolver.release(source); } - manager.release(resolver); - } } return document; }