You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by cz...@apache.org on 2001/11/14 16:58:03 UTC
cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml Parser.java
cziegeler 01/11/14 07:58:03
Modified: src/scratchpad/org/apache/avalon/excalibur/source
Source.java SourceResolver.java
SourceResolverImpl.java URLSource.java
src/scratchpad/org/apache/avalon/excalibur/xml Parser.java
Log:
Changed lifecycle handling of source objects. Instead of calling recycle() on the source object, they should be released by the SourceHandler. A source object can implement the lifecycle interfaces like Initializable, Loggable and Composable
Revision Changes Path
1.3 +2 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/Source.java
Index: Source.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/Source.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Source.java 2001/11/13 12:48:45 1.2
+++ Source.java 2001/11/14 15:58:03 1.3
@@ -7,7 +7,6 @@
*/
package org.apache.avalon.excalibur.source;
-import org.apache.avalon.excalibur.pool.Recyclable;
import org.xml.sax.InputSource;
import java.io.IOException;
import java.io.InputStream;
@@ -21,10 +20,10 @@
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
- * @version CVS $Revision: 1.2 $ $Date: 2001/11/13 12:48:45 $
+ * @version CVS $Revision: 1.3 $ $Date: 2001/11/14 15:58:03 $
*/
-public interface Source extends Recyclable {
+public interface Source {
/**
* Get the last modification date of the source or 0 if it
* is not possible to determine the date.
1.4 +10 -5 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolver.java
Index: SourceResolver.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolver.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SourceResolver.java 2001/11/13 15:04:48 1.3
+++ SourceResolver.java 2001/11/14 15:58:03 1.4
@@ -8,6 +8,7 @@
package org.apache.avalon.excalibur.source;
import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.component.ComponentException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -16,7 +17,7 @@
* Base interface for resolving a source by system identifiers.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.3 $ $Date: 2001/11/13 15:04:48 $
+ * @version CVS $Revision: 1.4 $ $Date: 2001/11/14 15:58:03 $
*/
public interface SourceResolver
@@ -39,20 +40,20 @@
* Get a <code>Source</code> object.
*/
Source resolve(String location)
- throws MalformedURLException, IOException;
+ throws MalformedURLException, IOException, ComponentException;
/**
* Get a <code>Source</code> object.
*/
Source resolve(URL base, String location)
- throws MalformedURLException, IOException;
+ throws MalformedURLException, IOException, ComponentException;
/**
* Get a <code>Source</code> object.
*/
Source resolve(String location,
SourceParameters parameters)
- throws MalformedURLException, IOException;
+ throws MalformedURLException, IOException, ComponentException;
/**
* Get a <code>Source</code> object.
@@ -60,7 +61,11 @@
Source resolve(URL base,
String location,
SourceParameters parameters)
- throws MalformedURLException, IOException;
+ throws MalformedURLException, IOException, ComponentException;
+ /**
+ * Releases a resolved resource
+ */
+ void release( Source source );
}
1.5 +45 -14 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolverImpl.java
Index: SourceResolverImpl.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolverImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SourceResolverImpl.java 2001/11/14 07:46:52 1.4
+++ SourceResolverImpl.java 2001/11/14 15:58:03 1.5
@@ -7,6 +7,7 @@
*/
package org.apache.avalon.excalibur.source;
+import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
@@ -32,7 +33,7 @@
/**
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version $Id: SourceResolverImpl.java,v 1.4 2001/11/14 07:46:52 cziegeler Exp $
+ * @version $Id: SourceResolverImpl.java,v 1.5 2001/11/14 15:58:03 cziegeler Exp $
*/
public class SourceResolverImpl
extends AbstractLoggable
@@ -145,7 +146,7 @@
* Get a <code>Source</code> object.
*/
public Source resolve(String location)
- throws MalformedURLException, IOException {
+ throws MalformedURLException, IOException, ComponentException {
return this.resolve(this.baseURL, location, null);
}
@@ -154,7 +155,7 @@
*/
public Source resolve(String location,
SourceParameters parameters)
- throws MalformedURLException, IOException {
+ throws MalformedURLException, IOException, ComponentException {
return this.resolve(this.baseURL, location, parameters);
}
@@ -162,7 +163,7 @@
* Get a <code>Source</code> object.
*/
public Source resolve(URL base, String location)
- throws MalformedURLException, IOException {
+ throws MalformedURLException, IOException, ComponentException {
return this.resolve(base, location, null);
}
@@ -173,7 +174,7 @@
public Source resolve(URL base,
String location,
SourceParameters parameters)
- throws MalformedURLException, IOException {
+ throws MalformedURLException, IOException, ComponentException {
this.getLogger().debug("Resolving '"+location+"' in context '" + base + "'");
if (location == null) throw new MalformedURLException("Invalid System ID");
@@ -208,25 +209,55 @@
}
this.getLogger().debug("Resolved to systemID '"+systemID+"'");
+ Source source = null;
// search for a SourceFactory implementing the protocol
final int protocolPos = systemID.indexOf(':');
if ( protocolPos != -1 ) {
final String protocol = systemID.substring(0, protocolPos);
final SourceFactory factory = ( SourceFactory )this.sourceFactories.get( protocol );
if (factory != null) {
- return factory.getSource( systemID, parameters );
+ source = factory.getSource( systemID, parameters );
}
}
-
- // no factory found, so usual url handling stuff...
+ if ( source == null ) {
+ // no factory found, so usual url handling stuff...
+ try {
+ getLogger().debug("Making URL from " + systemID);
+ source = new URLSource(new URL(systemID), parameters);
+ } catch (MalformedURLException mue) {
+ getLogger().debug("Making URL - MalformedURLException in getURL:" , mue);
+ getLogger().debug("Making URL a File (assuming that it is full path):" + systemID);
+ source = new URLSource((new File(systemID)).toURL(), parameters);
+ }
+ }
+ if (source instanceof Loggable) {
+ ((Loggable) source).setLogger(getLogger());
+ }
try {
- getLogger().debug("Making URL from " + systemID);
- return new URLSource(new URL(systemID), parameters, this.manager);
- } catch (MalformedURLException mue) {
- getLogger().debug("Making URL - MalformedURLException in getURL:" , mue);
- getLogger().debug("Making URL a File (assuming that it is full path):" + systemID);
- return new URLSource((new File(systemID)).toURL(), parameters, this.manager);
+ if (source instanceof Contextualizable) {
+ ((Contextualizable) source).contextualize (this.context);
+ }
+ } catch (ContextException ce) {
+ throw new ComponentException("ContextException occured during source resolving.", ce);
+ }
+
+ if (source instanceof Composable) {
+ ((Composable) source).compose(this.manager);
+ }
+ return source;
+ }
+
+ /**
+ * Releases a resolved resource
+ */
+ public void release( Source source ) {
+ if ( source == null) return;
+ if ( source instanceof Recyclable ) {
+ ((Recyclable)source).recycle();
+ }
+ if ( source instanceof Disposable ) {
+ ((Disposable) source).dispose();
}
}
1.5 +8 -7 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java
Index: URLSource.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- URLSource.java 2001/11/14 07:46:52 1.4
+++ URLSource.java 2001/11/14 15:58:03 1.5
@@ -7,6 +7,7 @@
*/
package org.apache.avalon.excalibur.source;
+import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.excalibur.xml.Parser;
import org.apache.avalon.excalibur.xml.XMLConsumer;
@@ -25,7 +26,7 @@
* Description of a source which is described by an URL.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.4 $ $Date: 2001/11/14 07:46:52 $
+ * @version CVS $Revision: 1.5 $ $Date: 2001/11/14 15:58:03 $
*/
public final class URLSource implements ModifiableSource, XMLizable {
@@ -62,16 +63,19 @@
* @param parameters This is optional
*/
public URLSource(URL url,
- SourceParameters parameters,
- ComponentManager manager)
+ SourceParameters parameters)
throws IOException {
- this.manager = manager;
this.systemId = url.toExternalForm();
this.isFile = systemId.startsWith(FILE);
this.url = url;
this.gotInfos = false;
}
+ public void compose(ComponentManager manager )
+ {
+ this.manager = manager;
+ }
+
/**
* Get the last modification date and content length of the source.
* Any exceptions are ignored.
@@ -321,7 +325,4 @@
}
}
- public void recycle()
- {
- }
}
1.4 +17 -1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/Parser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Parser.java 2001/11/13 12:48:45 1.3
+++ Parser.java 2001/11/14 15:58:03 1.4
@@ -18,16 +18,32 @@
/**
*
+ * The parser can be used to parse any XML document given
+ * by a <code>InputSource</code> object.
+ * It can either send XML events or create a DOM from
+ * the parsed document.
+ *
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.3 $ $Date: 2001/11/13 12:48:45 $
+ * @version CVS $Revision: 1.4 $ $Date: 2001/11/14 15:58:03 $
*/
public interface Parser extends Component {
String ROLE = "org.apache.avalon.excalibur.xml.Parser";
+ /**
+ * Parse the <code>InputSource</code> and send
+ * SAX events to the consumer.
+ * Attention: the consumer can either be an XMLConsumer
+ * or implement the <code>LexicalHandler</code> as well.
+ * The parse should take care of this.
+ */
void parse(InputSource in, ContentHandler consumer)
throws SAXException, IOException;
+ /**
+ * Parse the <code>InputSource</code> and create
+ * a DOM out of it.
+ */
Document parseDocument(InputSource in)
throws SAXException, IOException;
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>