donaldp 2002/06/22 21:30:37
Modified: containerkit build.xml
Added:
containerkit/src/java/org/apache/excalibur/containerkit/configuration
ConfigurationBuilder.java DTDInfo.java
DTDResolver.java componentinfo.dtd package.html
Log:
Add in utility classes to help build Configurations that conform to DTDs of
ComponentInfo.
Revision Changes Path
1.3 +15 -14 jakarta-avalon-excalibur/containerkit/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/build.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- build.xml 22 Jun 2002 14:39:05 -0000 1.2
+++ build.xml 23 Jun 2002 04:30:37 -0000 1.3
@@ -15,6 +15,7 @@
<pathelement location="${avalon-framework.jar}"/>
<pathelement location="${excalibur-i18n.jar}"/>
<pathelement location="${checkstyle.jar}"/>
+ <pathelement location="${xml-apis.jar}"/>
<pathelement path="${java.class.path}"/>
</path>
@@ -308,8 +309,8 @@
<fileset dir="${build.lib}">
<include name="*.jar"/>
</fileset>
- </copy>
- </target>
+ </copy>
+ </target>
<!-- Creates a minimal distribution -->
<target name="dist.lite"
@@ -347,8 +348,8 @@
<filter token="LOGKIT_BASE" value="${logkit.base}"/>
<filter token="TESTLET_BASE" value="${testlet.base}"/>
</target>
-
-
+
+
<!-- Prepares the documentation directory -->
<target name="docs" depends="setup-filters"> <!-- depends="javadocs"
description="Generates the Docs" -->
<mkdir dir="${docs.dir}"/>
@@ -357,7 +358,7 @@
<mkdir dir="${build.xdocs}"/>
<mkdir dir="${build.docs}"/>
<mkdir dir="${build.dir}/work"/>
-
+
<!-- Base pointers for non-xdocs documentation. Override these in
.ant.properties to link to local docs -->
<copy todir="${build.context}" filtering="on">
<fileset dir="${context.dir}">
@@ -366,7 +367,7 @@
<exclude name="xdocs"/>
</fileset>
</copy>
-
+
<copy todir="${build.context}/xdocs" filtering="on" overwrite="yes">
<fileset dir="${xdocs.dir}"/>
</copy>
@@ -395,22 +396,22 @@
<fileset dir="${build.docs}">
<include name="**"/>
</fileset>
- </copy>
+ </copy>
<!-- hack for stupid transport on api link -->
<replace file="${docs.dir}/index.html" token="index.html.xml"
value="index.html"/>
-
+
</target>
-
- <target name="site" depends="javadocs, docs" description=" Places Docs
ready for hosting on website">
-
- <mkdir dir="../site/dist/docs/${dir-name}"/>
+
+ <target name="site" depends="javadocs, docs" description=" Places Docs
ready for hosting on website">
+
+ <mkdir dir="../site/dist/docs/${dir-name}"/>
<copy todir="../site/dist/docs/${dir-name}">
<fileset dir="${docs.dir}">
<include name="**"/>
</fileset>
- </copy>
-
+ </copy>
+
</target>
<!-- Cleans up build and distribution directories -->
1.1
jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/configuration/ConfigurationBuilder.java
Index: ConfigurationBuilder.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.containerkit.configuration;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
* Utility class used to load Configuration trees from XML files.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/06/23 04:30:37 $
*/
public class ConfigurationBuilder
{
private static final DTDInfo[] c_dtdInfo = new DTDInfo[]
{
new DTDInfo( "-//AVALON/Component Info DTD Version 1.0//EN",
"http://jakarta.apache.org/avalon/componentinfo_1_0.dtd",
"org/apache/excalibur/containerkit/configuration/componentinfo.dtd" ),
};
private static final DTDResolver c_resolver =
new DTDResolver( c_dtdInfo,
ConfigurationBuilder.class.getClassLoader() );
/**
* Private constructor to block instantiation.
*/
private ConfigurationBuilder()
{
}
/**
* Utility method to create a new XML reader.
*/
private static XMLReader createXMLReader()
throws SAXException, ParserConfigurationException
{
final SAXParserFactory saxParserFactory =
SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware( false );
final SAXParser saxParser = saxParserFactory.newSAXParser();
return saxParser.getXMLReader();
}
/**
* Internally sets up the XMLReader
*/
private static void setupXMLReader( final XMLReader reader,
final SAXConfigurationHandler handler
)
{
reader.setEntityResolver( c_resolver );
reader.setContentHandler( handler );
reader.setErrorHandler( handler );
}
/**
* Build a configuration object using an URI
*/
public static Configuration build( final String uri )
throws SAXException, ParserConfigurationException, IOException,
ConfigurationException
{
return build( new InputSource( uri ) );
}
/**
* Build a configuration object using an XML InputSource object
*/
public static Configuration build( final InputSource input )
throws SAXException, ParserConfigurationException, IOException,
ConfigurationException
{
final XMLReader reader = createXMLReader();
final SAXConfigurationHandler handler = new SAXConfigurationHandler();
setupXMLReader( reader, handler );
reader.parse( input );
return handler.getConfiguration();
}
}
1.1
jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/configuration/DTDInfo.java
Index: DTDInfo.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.containerkit.configuration;
/**
* Holds information about a given DTD.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/06/23 04:30:37 $
*/
class DTDInfo
{
/**
* The public identifier. Null if unknown.
*/
private final String m_publicId;
/**
* The system identifier. Null if unknown.
*/
private final String m_systemId;
/**
* The resource name, if a copy of the document is available.
*/
private final String m_resource;
public DTDInfo( final String publicId,
final String systemId,
final String resource )
{
m_publicId = publicId;
m_systemId = systemId;
m_resource = resource;
}
public String getPublicId()
{
return m_publicId;
}
public String getSystemId()
{
return m_systemId;
}
public String getResource()
{
return m_resource;
}
}
1.1
jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/configuration/DTDResolver.java
Index: DTDResolver.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.containerkit.configuration;
import java.io.IOException;
import java.io.InputStream;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* A Class to help to resolve Entitys for items such as DTDs or
* Schemas.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/06/23 04:30:37 $
*/
class DTDResolver
implements EntityResolver
{
/**
* The list of DTDs that can be resolved by this class.
*/
private final DTDInfo[] m_dtdInfos;
/**
* The ClassLoader to use when loading resources for DTDs.
*/
private final ClassLoader m_classLoader;
/**
* Construct a resolver using specified DTDInfos where resources are
loaded
* from specified ClassLoader.
*/
public DTDResolver( final DTDInfo[] dtdInfos, final ClassLoader
classLoader )
{
m_dtdInfos = dtdInfos;
m_classLoader = classLoader;
}
/**
* Resolve an entity in the XML file.
* Called by parser to resolve DTDs.
*/
public InputSource resolveEntity( final String publicId, final String
systemId )
throws IOException, SAXException
{
for( int i = 0; i < m_dtdInfos.length; i++ )
{
final DTDInfo info = m_dtdInfos[ i ];
if( ( publicId != null && publicId.equals( info.getPublicId() ) )
||
( systemId != null && systemId.equals( info.getSystemId() ) )
)
{
final ClassLoader classLoader = getClassLoader();
final InputStream inputStream =
classLoader.getResourceAsStream( info.getResource() );
return new InputSource( inputStream );
}
}
return null;
}
/**
* Return CLassLoader to load resource from.
* If a ClassLoader is specified in the constructor use that,
* else use ContextClassLoader unless that is null in which case
* use the current classes ClassLoader.
*/
private ClassLoader getClassLoader()
{
ClassLoader classLoader = m_classLoader;
if( null == classLoader )
{
classLoader = Thread.currentThread().getContextClassLoader();
}
if( null == classLoader )
{
classLoader = getClass().getClassLoader();
}
return classLoader;
}
}
1.1
jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/configuration/componentinfo.dtd
Index: componentinfo.dtd
===================================================================
<!--
This is the DTD defining the Avalon ComponentInfo 1.0
descriptor (XML) file format/syntax.
Author: Peter Donald <[EMAIL PROTECTED]>
A BlockInfo is an XML file used to describe Components and located
side-by-side with
the Component .class file. It describes the services the Component
requires to operate,
the services the Component is capable of offerring other Component, the
context entrys
that Component requires and other support meta data.
Copyright (C) The Apache Software Foundation. All rights reserved.
This software is published under the terms of the Apache Software License
version 1.1, a copy of which has been included with this distribution in
the LICENSE.txt file.
-->
<!--
The component-info is the document root, it defines:
component the specifc details about this component
context the context required by this component
services the services offered by this component
dependencies the services that this component require to operate
-->
<!ELEMENT component-info (component, context?, services?, dependencies?)>
<!ATTLIST component-info id ID #IMPLIED
xmlns CDATA #FIXED
"http://jakarta.apache.org/avalon/componentinfo_1_0.dtd" >
<!--
The component element describes the component, it defines:
name the human readable name of component type. Must be a string
containing alphanumeric characters, '.', '_' and starting
with a letter.
version the version of the component in (in the format #.#.#, #.#
or # where
# is a integer
-->
<!ELEMENT component (name?,version,attributes?)>
<!ELEMENT name (#PCDATA) >
<!ELEMENT version (#PCDATA) >
<!--
The context element defines what values and type of context
is available to component.
It contains:
entrys Key value pairs that component uses
attributes Optional attributes about service
-->
<!ELEMENT context (entry*,attributes?) >
<!ATTLIST context type CDATA #IMPLIED >
<!--
The service element defines a service that the component
can provide to other component.
It contains:
service-ref the reference to service.
attributes Optional attributes about service
-->
<!ELEMENT service (service-ref,attributes?) >
<!--
The service element defines a reference to a service that the component
can provide to other component, or this component depends upon.
It defines:
type the name of the service. This must be equal to the class name of
the
interface that defines the service.
version the version of the block in (in the format #.#.#, #.# or #
where
# is a integer
-->
<!ELEMENT service-ref EMPTY >
<!ATTLIST service-ref
type CDATA #REQUIRED
version CDATA #IMPLIED >
<!--
The service dependency describes a service that the component
requires. It defines:
role the role of the service. This is the value that is used to
lookup the
service in the ComponentManager. If not provided it defaults to
the
value specified in the name attribute of service element
service-ref the service that is required
-->
<!ELEMENT dependency (role?,service-ref,attributes?) >
<!ATTLIST dependency optional CDATA #IMPLIED >
<!ELEMENT role (#PCDATA) >
<!--
The services element contains a list of services that this component supports.
It contains service elements.
-->
<!ELEMENT services (service*)>
<!--
The dependencies element contains a list of services that this component
requires.
It contains dependency elements.
-->
<!ELEMENT dependencies (dependency*)>
<!--
The attributes element contains a list of attributes for feature.
-->
<!ELEMENT attributes (attribute*)>
<!--
The attribute element defines an attribute (an opaque key-value pair for a
feature).
It defines:
key the key for attribute.
value the value of attribute.
-->
<!ELEMENT attribute EMPTY >
<!ATTLIST attribute
key CDATA #REQUIRED
value CDATA #REQUIRED
>
<!--
The entry element defines entry in context.
It defines:
key the key for entry.
value the value of entry.
optional is entry optional
-->
<!ELEMENT entry EMPTY >
<!ATTLIST entry
key CDATA #REQUIRED
type CDATA #REQUIRED
optional CDATA #IMPLIED
>
1.1
jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/configuration/package.html
Index: package.html
===================================================================
<html><body>
Dynamic configuration builder.
</body></html>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>