cziegeler 2003/03/11 23:38:42
Modified: src/java/org/apache/cocoon/environment
AbstractEnvironment.java
Added: src/java/org/apache/cocoon/environment Source.java
Removed: src/deprecated/java/org/apache/cocoon/environment
Source.java
Log:
Next step in removing dependencies to the deprecated stuff
Revision Changes Path
1.2 +27 -2
cocoon-2.1/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
Index: AbstractEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractEnvironment.java 9 Mar 2003 00:09:28 -0000 1.1
+++ AbstractEnvironment.java 12 Mar 2003 07:38:42 -0000 1.2
@@ -62,6 +62,7 @@
import org.apache.cocoon.components.CocoonComponentManager;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.util.BufferedOutputStream;
+import org.apache.cocoon.util.ClassUtils;
import org.apache.excalibur.source.SourceException;
import org.apache.excalibur.xml.sax.XMLizable;
@@ -73,6 +74,8 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
@@ -127,6 +130,9 @@
/** The real output stream */
protected OutputStream outputStream;
+ /** The AvalonToCocoonSourceWrapper (this is for the deprecated support) */
+ static protected Constructor avalonToCocoonSourceWrapper;
+
/**
* Constructs the abstract environment
*/
@@ -348,11 +354,30 @@
}
if (systemId == null) throw new SAXException("Invalid System ID");
+ // get the wrapper class - we don't want to import the wrapper directly
+ // to avoid a direct dependency from the core to the deprecation package
+ if ( null == avalonToCocoonSourceWrapper ) {
+ synchronized (avalonToCocoonSourceWrapper) {
+ try {
+ Class clazz =
ClassUtils.loadClass("org.apache.cocoon.components.source.impl.AvalonToCocoonSource");
+ avalonToCocoonSourceWrapper = clazz.getConstructor(new Class[]
{ClassUtils.loadClass("org.apache.excalibur.source.Source"),
+
ClassUtils.loadClass("org.apache.excalibur.source.SourceResolver"),
+
ClassUtils.loadClass("org.apache.cocoon.environment.Environment")});
+ } catch (Exception e) {
+ throw new ProcessingException("The deprecated resolve() method
of the environment was called."
+ +"Please either update your code
to use the new resolveURI() method or"
+" install the deprecation
support.", e);
+ }
+ }
+ }
try {
org.apache.excalibur.source.Source source = this.resolveURI( systemId );
- return new
org.apache.cocoon.components.source.impl.AvalonToCocoonSource(source,
this.sourceResolver, this);
+ Source wrappedSource;
+ wrappedSource = (Source)avalonToCocoonSourceWrapper.newInstance(new
Object[] {source, this.sourceResolver, this});
+ return wrappedSource;
} catch (SourceException se) {
throw SourceUtil.handle(se);
+ } catch (Exception e) {
+ throw new ProcessingException("Unable to create source wrapper.", e);
}
}
1.1 cocoon-2.1/src/java/org/apache/cocoon/environment/Source.java
Index: Source.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.environment;
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.cocoon.ProcessingException;
import org.apache.excalibur.xml.sax.XMLizable;
import org.xml.sax.InputSource;
import java.io.IOException;
import java.io.InputStream;
/**
* Description of a source. This interface provides a simple interface
* for accessing a source of data. The source of data is assumed to
* <b>not change</b> during the lifetime of the Source object. If you
* have a data source that can change its content and you want it to
* reflect in Cocoon, use a [EMAIL PROTECTED] ModifiableSource} object instead.
*
* @deprecated Use the [EMAIL PROTECTED] org.apache.excalibur.source.Source}
interface instead
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
* @version CVS $Id: Source.java,v 1.1 2003/03/12 07:38:42 cziegeler Exp $
*/
public interface Source extends Recyclable, XMLizable {
/**
* Get the last modification date of the source or 0 if it
* is not possible to determine the date.
*/
long getLastModified();
/**
* Get the content length of the source or -1 if it
* is not possible to determine the length.
*/
long getContentLength();
/**
* Return an <code>InputStream</code> object to read from the source.
*/
InputStream getInputStream()
throws ProcessingException, IOException;
/**
* Return an <code>InputSource</code> object to read the XML
* content.
*
* @return an <code>InputSource</code> value
* @exception ProcessingException if an error occurs
* @exception IOException if an error occurs
*/
InputSource getInputSource()
throws ProcessingException, IOException;
/**
* Return the unique identifer for this source
*/
String getSystemId();
}