Skip to Content.
Sympa Menu

notify-dpml - r1130 - in trunk/main: . depot depot/library/common/etc/main/net/dpml/library depot/library/common/etc/test depot/library/common/etc/test/ant depot/library/common/etc/test/commons-cli depot/library/common/etc/test/dpml depot/library/common/etc/test/jgoodies depot/library/common/etc/test/junit depot/library/common/etc/test/xstream depot/library/common/src/main/net/dpml/library/impl depot/library/common/src/main/net/dpml/library/info depot/library/common/src/test/net/dpml/library/impl external metro planet planet/http transit transit/core/src/main/net/dpml/lang util

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1130 - in trunk/main: . depot depot/library/common/etc/main/net/dpml/library depot/library/common/etc/test depot/library/common/etc/test/ant depot/library/common/etc/test/commons-cli depot/library/common/etc/test/dpml depot/library/common/etc/test/jgoodies depot/library/common/etc/test/junit depot/library/common/etc/test/xstream depot/library/common/src/main/net/dpml/library/impl depot/library/common/src/main/net/dpml/library/info depot/library/common/src/test/net/dpml/library/impl external metro planet planet/http transit transit/core/src/main/net/dpml/lang util
  • Date: Thu, 23 Feb 2006 20:18:14 +0100

Author: mcconnell
Date: 2006-02-23 20:18:03 +0100 (Thu, 23 Feb 2006)
New Revision: 1130

Added:

trunk/main/depot/library/common/src/main/net/dpml/library/impl/ModuleBuilder.java
Modified:
trunk/main/depot/library/common/etc/main/net/dpml/library/library_1_0.dtd
trunk/main/depot/library/common/etc/test/ant/module.xml
trunk/main/depot/library/common/etc/test/commons-cli/module.xml
trunk/main/depot/library/common/etc/test/dpml/module.xml
trunk/main/depot/library/common/etc/test/jgoodies/module.xml
trunk/main/depot/library/common/etc/test/junit/module.xml
trunk/main/depot/library/common/etc/test/library.xml
trunk/main/depot/library/common/etc/test/test.xml
trunk/main/depot/library/common/etc/test/xstream/module.xml

trunk/main/depot/library/common/src/main/net/dpml/library/impl/LibraryDirectiveBuilder.java

trunk/main/depot/library/common/src/main/net/dpml/library/info/ModuleDirective.java

trunk/main/depot/library/common/src/test/net/dpml/library/impl/DefaultResourceTestCase.java
trunk/main/depot/module.xml
trunk/main/external/library.xml
trunk/main/library.xml
trunk/main/metro/module.xml
trunk/main/planet/http/module.xml
trunk/main/planet/module.xml
trunk/main/transit/bootstrap.xml
trunk/main/transit/core/src/main/net/dpml/lang/DTDResolver.java
trunk/main/transit/module.xml
trunk/main/util/module.xml
Log:
add DTD for library and module files

Modified:
trunk/main/depot/library/common/etc/main/net/dpml/library/library_1_0.dtd
===================================================================
--- trunk/main/depot/library/common/etc/main/net/dpml/library/library_1_0.dtd
2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/main/net/dpml/library/library_1_0.dtd
2006-02-23 19:18:03 UTC (rev 1130)
@@ -15,7 +15,7 @@
limitations under the License.
-->

-<!ELEMENT library ( imports?, modules? ) >
+<!ELEMENT library ( imports?, properties?, modules? ) >

<!ELEMENT imports ( import* ) >

@@ -24,10 +24,11 @@
<!ELEMENT import EMPTY >
<!ATTLIST import uri CDATA #REQUIRED >

-<!ELEMENT module ( types?, properties?, resource*, project*, module* ) >
+<!ELEMENT module ( properties?, types?, dependencies*, module*, project*,
resource* ) >
<!ATTLIST module name CDATA #IMPLIED >
<!ATTLIST module basedir CDATA #IMPLIED >
-<!ATTLIST module base CDATA #IMPLIED >
+<!ATTLIST module file CDATA #IMPLIED >
+<!ATTLIST module version CDATA #IMPLIED >

<!ELEMENT types ( type* ) >

@@ -41,18 +42,21 @@
<!ATTLIST property name CDATA #REQUIRED >
<!ATTLIST property value CDATA #REQUIRED >

-<!ELEMENT resource ( types?, dependencies* ) >
+<!ELEMENT resource ( properties?, types?, dependencies* ) >
<!ATTLIST resource name CDATA #REQUIRED >
<!ATTLIST resource basedir CDATA #IMPLIED >
+<!ATTLIST resource version CDATA #IMPLIED >

-<!ELEMENT project ( types?, dependencies* ) >
+<!ELEMENT project ( properties?, types?, dependencies* ) >
<!ATTLIST project name CDATA #REQUIRED >
<!ATTLIST project basedir CDATA #IMPLIED >
+<!ATTLIST module version CDATA #IMPLIED >

<!ELEMENT dependencies ( include* ) >
-<!ATTLIST dependencies scope ( build | runtime | test ) "runtime" >
+<!ATTLIST dependencies scope ( build | runtime | test | BUILD | RUNTIME |
TEST ) "runtime" >

-<!ELEMENT include EMPTY >
+<!ELEMENT include ( property* ) >
<!ATTLIST include key CDATA #IMPLIED >
<!ATTLIST include ref CDATA #IMPLIED >
-<!ATTLIST include uri CDATA #IMPLIED >
+<!ATTLIST include urn CDATA #IMPLIED >
+<!ATTLIST include tag CDATA #IMPLIED >

Modified: trunk/main/depot/library/common/etc/test/ant/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/ant/module.xml 2006-02-23
13:18:53 UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/test/ant/module.xml 2006-02-23
19:18:03 UTC (rev 1130)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

<module name="ant" version="1.6.5">


Modified: trunk/main/depot/library/common/etc/test/commons-cli/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/commons-cli/module.xml
2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/test/commons-cli/module.xml
2006-02-23 19:18:03 UTC (rev 1130)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

<module name="commons-cli" version="1.0">


Modified: trunk/main/depot/library/common/etc/test/dpml/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/dpml/module.xml 2006-02-23
13:18:53 UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/test/dpml/module.xml 2006-02-23
19:18:03 UTC (rev 1130)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

<module name="dpml" basedir="..">

@@ -36,12 +37,12 @@
</properties>

<project name="dpml-transit-main" basedir="transit/core/handler">
+ <properties>
+ <property name="project.template" value="${basedir}/build.xml"/>
+ </properties>
<types>
<type id="jar"/>
</types>
- <properties>
- <property name="project.template" value="${basedir}/build.xml"/>
- </properties>
<dependencies scope="TEST">
<include ref="ant/ant-junit"/>
</dependencies>

Modified: trunk/main/depot/library/common/etc/test/jgoodies/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/jgoodies/module.xml
2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/test/jgoodies/module.xml
2006-02-23 19:18:03 UTC (rev 1130)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

<module name="jgoodies">


Modified: trunk/main/depot/library/common/etc/test/junit/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/junit/module.xml 2006-02-23
13:18:53 UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/test/junit/module.xml 2006-02-23
19:18:03 UTC (rev 1130)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

<module name="junit" version="3.8.1">


Modified: trunk/main/depot/library/common/etc/test/library.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/library.xml 2006-02-23
13:18:53 UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/test/library.xml 2006-02-23
19:18:03 UTC (rev 1130)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE library PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

<library>

@@ -17,12 +18,12 @@
-->

<modules>
- <module base="junit"/>
- <module base="commons-cli"/>
- <module base="xstream"/>
- <module base="jgoodies"/>
- <module base="dpml"/>
- <module base="ant"/>
+ <module file="junit/module.xml"/>
+ <module file="commons-cli/module.xml"/>
+ <module file="xstream/module.xml"/>
+ <module file="jgoodies/module.xml"/>
+ <module file="dpml/module.xml"/>
+ <module file="ant/module.xml"/>
</modules>

</library>

Modified: trunk/main/depot/library/common/etc/test/test.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/test.xml 2006-02-23 13:18:53
UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/test/test.xml 2006-02-23 19:18:03
UTC (rev 1130)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE library PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

<library>


Modified: trunk/main/depot/library/common/etc/test/xstream/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/xstream/module.xml 2006-02-23
13:18:53 UTC (rev 1129)
+++ trunk/main/depot/library/common/etc/test/xstream/module.xml 2006-02-23
19:18:03 UTC (rev 1130)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

<module name="xstream" version="1.1">


Modified:
trunk/main/depot/library/common/src/main/net/dpml/library/impl/LibraryDirectiveBuilder.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/LibraryDirectiveBuilder.java
2006-02-23 13:18:53 UTC (rev 1129)
+++
trunk/main/depot/library/common/src/main/net/dpml/library/impl/LibraryDirectiveBuilder.java
2006-02-23 19:18:03 UTC (rev 1130)
@@ -30,6 +30,9 @@
import java.util.Properties;
import java.beans.XMLDecoder;

+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import net.dpml.library.info.LibraryDirective;
import net.dpml.library.info.ImportDirective;
import net.dpml.library.info.IncludeDirective;
@@ -40,10 +43,20 @@
import net.dpml.library.info.DependencyDirective;
import net.dpml.library.info.Scope;

+import net.dpml.lang.DTD;
+import net.dpml.lang.DTDResolver;
+
import net.dpml.transit.util.ElementHelper;
+import net.dpml.transit.util.ExceptionHelper;
import net.dpml.lang.Category;

+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;

/**
* Utility class used for construction of a module model from an XML source.
@@ -53,6 +66,17 @@
*/
public final class LibraryDirectiveBuilder
{
+ private static final DTD[] DTDS = new DTD[]
+ {
+ new DTD(
+ ModuleBuilder.PUBLIC_ID,
+ ModuleBuilder.SYSTEM_ID,
+ ModuleBuilder.RESOURCE, null )
+ };
+
+ private static final DTDResolver DTD_RESOLVER =
+ new DTDResolver( DTDS,
LibraryDirectiveBuilder.class.getClassLoader() );
+
private static final String LIBRARY_ELEMENT_NAME = "library";
private static final String IMPORTS_ELEMENT_NAME = "imports";
private static final String IMPORT_ELEMENT_NAME = "import";
@@ -94,23 +118,61 @@
+ "] references a directory.";
throw new IllegalArgumentException( error );
}
- FileInputStream input = new FileInputStream( source );
- BufferedInputStream buffer = new BufferedInputStream( input );
try
{
- final Element root = ElementHelper.getRootElement( input );
+ final Element root = getRootElement( source );
File base = source.getParentFile();
return buildLibraryDirective( base, root );
}
catch( Throwable e )
{
+ System.out.println( "# ERROR: " + e.toString() );
+ String message = ExceptionHelper.packException( e, true );
+ System.out.println( message );
+
final String error =
"An error occured while attempting to build a library
directive from the source: "
+ source;
IOException ioe = new IOException( error );
ioe.initCause( e );
throw ioe;
+
}
+ }
+
+ private static Element getRootElement( File source ) throws IOException
+ {
+ FileInputStream input = new FileInputStream( source );
+ try
+ {
+ final DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ factory.setValidating( true );
+ factory.setNamespaceAware( true );
+ factory.setExpandEntityReferences( true );
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver( DTD_RESOLVER );
+ builder.setErrorHandler( new InternalErrorHandler( source ) );
+
+ final Document document = builder.parse( input );
+ return document.getDocumentElement();
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ System.out.println( "# ERROR: " + e.toString() );
+ String message = ExceptionHelper.packException( e, true );
+ System.out.println( message );
+
+ final String error =
+ "An unexpected error occured while attempting to load library
or module source.";
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
finally
{
input.close();
@@ -187,7 +249,7 @@
* @exception IOException if an IO exception occurs
*/
public static ModuleDirective buildModuleDirective( File source, String
path ) throws IOException
- {
+ {
if( null == source )
{
throw new NullPointerException( "source" );
@@ -204,18 +266,12 @@
+ "] references a directory.";
throw new IllegalArgumentException( error );
}
- FileInputStream input = new FileInputStream( source );
- BufferedInputStream buffer = new BufferedInputStream( input );
try
{
- final Element root = ElementHelper.getRootElement( input );
+ final Element root = getRootElement( source );
final File parent = source.getParentFile();
- //String baseSpec = base.getCanonicalPath();
- //String parentSpec = parent.getCanonicalPath();
- ///String fragment = parentSpec.substring( baseSpec.length() + 1
);
- final String basedir = path;
+ final String basedir = path;
return buildModuleDirectiveFromElement( parent, root, basedir );
- //return buildModuleDirectiveFromElement( parent, root, null );
}
catch( Throwable e )
{
@@ -226,10 +282,6 @@
ioe.initCause( e );
throw ioe;
}
- finally
- {
- input.close();
- }
}

/**
@@ -281,10 +333,13 @@
throw new IllegalArgumentException( error );
}

- String spec = ElementHelper.getAttribute( element, "base", null );
- if( null != spec )
+ String path = ElementHelper.getAttribute( element, "file" );
+ if( null != path )
{
- File dir = new File( base, spec );
+ File file = new File( base, path );
+ File dir = file.getParentFile();
+ String spec = getRelativePath( base, dir );
+
if( !dir.exists() )
{
final String error =
@@ -293,7 +348,7 @@
+ "] because the directory does not exist.";
throw new FileNotFoundException( error );
}
- File source = new File( dir, "module.xml" ).getCanonicalFile();
+ File source = file.getCanonicalFile();
if( !source.exists() )
{
final String error =
@@ -356,6 +411,22 @@
return new ModuleDirective( resource, resources );
}

+ private static String getRelativePath( File base, File dir ) throws
IOException
+ {
+ String baseSpec = base.getCanonicalPath();
+ String dirSpec = dir.getCanonicalPath();
+ if( dirSpec.startsWith( baseSpec ) )
+ {
+ return dirSpec.substring( baseSpec.length() + 1 );
+ }
+ else
+ {
+ final String error =
+ "Supplied dir [" + dirSpec + "] is not with base [" + baseSpec
+ "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
/**
* Build an array of include directives contained within the supplied
enclosing element.
* @param element the enclosing element
@@ -506,7 +577,18 @@
{
final String name = ElementHelper.getAttribute( element, "name",
null );
final String version = ElementHelper.getAttribute( element,
"version", null );
- final String basedir = ElementHelper.getAttribute( element,
"basedir", path );
+ String basedir = ElementHelper.getAttribute( element, "basedir",
null );
+ if( path != null )
+ {
+ if( basedir == null )
+ {
+ basedir = path;
+ }
+ else
+ {
+ basedir = path + "/" + basedir;
+ }
+ }

if( PROJECT_ELEMENT_NAME.equals( tag ) )
{
@@ -652,4 +734,36 @@
}
}
}
+
+ private static final class InternalErrorHandler implements ErrorHandler
+ {
+ private final File m_file;
+
+ InternalErrorHandler( File file )
+ {
+ m_file = file;
+ }
+
+ public void error( SAXParseException e ) throws SAXException
+ {
+ System.out.println( "ERROR: "
+ + e.getMessage()
+ + "\nFile: " + m_file
+ + "\nLine " + e.getLineNumber() + " Column: " +
e.getColumnNumber() );
+ }
+ public void fatalError( SAXParseException e ) throws SAXException
+ {
+ System.out.println( "FATAL: "
+ + e.getMessage()
+ + "\nFile: " + m_file
+ + "\nLine " + e.getLineNumber() + " Column: " +
e.getColumnNumber() );
+ }
+ public void warning( SAXParseException e ) throws SAXException
+ {
+ System.out.println( "WARNING: "
+ + e.getMessage()
+ + "\nFile: " + m_file
+ + "\nLine " + e.getLineNumber() + " Column: " +
e.getColumnNumber() );
+ }
+ }
}

Added:
trunk/main/depot/library/common/src/main/net/dpml/library/impl/ModuleBuilder.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/ModuleBuilder.java
2006-02-23 13:18:53 UTC (rev 1129)
+++
trunk/main/depot/library/common/src/main/net/dpml/library/impl/ModuleBuilder.java
2006-02-23 19:18:03 UTC (rev 1130)
@@ -0,0 +1,435 @@
+/*
+ * Copyright 2005 Stephen J. McConnell
+ *
+ * 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 net.dpml.library.impl;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.net.URLConnection;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Properties;
+import java.beans.XMLDecoder;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import net.dpml.library.info.LibraryDirective;
+import net.dpml.library.info.ImportDirective;
+import net.dpml.library.info.IncludeDirective;
+import net.dpml.library.info.ModuleDirective;
+import net.dpml.library.info.ResourceDirective;
+import net.dpml.library.info.ResourceDirective.Classifier;
+import net.dpml.library.info.TypeDirective;
+import net.dpml.library.info.DependencyDirective;
+import net.dpml.library.info.Scope;
+
+import net.dpml.lang.DTD;
+import net.dpml.lang.DTDResolver;
+
+import net.dpml.transit.util.ElementHelper;
+import net.dpml.lang.Category;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+
+/**
+ * Utility class used for construction of a module model from an XML source.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class ModuleBuilder
+{
+ public static final String XML_HEADER =
+ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
+
+ public static final String NAME = "module";
+
+ public static final String PUBLIC_ID =
+ "-//DPML//DTD Library 1.0//EN";
+
+ public static final String SYSTEM_ID =
+ "http://www.dpml.net/dtds/library_1_0.dtd";;
+
+ public static final String RESOURCE =
+ "net/dpml/library/library_1_0.dtd";
+
+ private static final String DOCTYPE =
+ "\n<!DOCTYPE "
+ + NAME
+ + " PUBLIC \""
+ + PUBLIC_ID
+ + "\" \""
+ + SYSTEM_ID
+ + "\" >";
+
+ static final DTD[] DTDS = new DTD[]
+ {
+ new DTD(
+ PUBLIC_ID,
+ SYSTEM_ID,
+ RESOURCE, null )
+ };
+
+ static final DTDResolver DTD_RESOLVER =
+ new DTDResolver( DTDS, ModuleBuilder.class.getClassLoader() );
+
+ static final ErrorHandler ERROR_HANDLER =
+ new InternalErrorHandler();
+
+ private static final String MODULE_ELEMENT_NAME = "module";
+ private static final String MODULES_ELEMENT_NAME = "modules";
+ private static final String DEPENDENCIES_ELEMENT_NAME = "dependencies";
+ private static final String INCLUDE_ELEMENT_NAME = "include";
+ private static final String RESOURCE_ELEMENT_NAME = "resource";
+ private static final String TYPES_ELEMENT_NAME = "types";
+ private static final String TYPE_ELEMENT_NAME = "type";
+ private static final String PROJECT_ELEMENT_NAME = "project";
+ private static final String PROPERTIES_ELEMENT_NAME = "properties";
+
+ /**
+ * Construct a module from a supplied url.
+ * @param url the module url
+ * @return the module datastructure
+ * @exception Exception if an error occurs during module loading
+ */
+ public ModuleDirective load( final URL url ) throws Exception
+ {
+ URLConnection connection = url.openConnection();
+ InputStream input = connection.getInputStream();
+
+ final DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ factory.setValidating( true );
+ factory.setNamespaceAware( true );
+ factory.setExpandEntityReferences( true );
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver( DTD_RESOLVER );
+ builder.setErrorHandler( ERROR_HANDLER );
+
+ final Document document = builder.parse( input );
+ final DocumentType docType = document.getDoctype();
+ final Element root = document.getDocumentElement();
+ return build( root );
+ }
+
+ private ModuleDirective build( Element element )
+ {
+ final String elementName = element.getTagName();
+ if( !MODULE_ELEMENT_NAME.equals( elementName ) )
+ {
+ final String error =
+ "Element ["
+ + elementName
+ + "] is not a module.";
+ throw new IllegalArgumentException( error );
+ }
+
+ ResourceDirective resource = buildResourceDirective( element );
+ ArrayList list = new ArrayList();
+ Element[] children = ElementHelper.getChildren( element );
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ final String tag = child.getTagName();
+ if( PROPERTIES_ELEMENT_NAME.equals( tag ) )
+ {
+ boolean ok = true; // already processed
+ }
+ else if( DEPENDENCIES_ELEMENT_NAME.equals( tag ) )
+ {
+ boolean ok = true; // already processed
+ }
+ else if( TYPES_ELEMENT_NAME.equals( tag ) )
+ {
+ boolean ok = true; // already processed
+ }
+ else if( MODULE_ELEMENT_NAME.equals( tag ) )
+ {
+ ModuleDirective directive = build( child );
+ list.add( directive );
+ }
+ else if( PROJECT_ELEMENT_NAME.equals( tag ) )
+ {
+ ResourceDirective directive = buildResourceDirective( child
);
+ list.add( directive );
+ }
+ else if( RESOURCE_ELEMENT_NAME.equals( tag ) )
+ {
+ ResourceDirective directive = buildResourceDirective( child
);
+ list.add( directive );
+ }
+ else
+ {
+ final String error =
+ "Illegal element name ["
+ + tag
+ + "] within 'module' element.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ ResourceDirective[] resources = (ResourceDirective[]) list.toArray(
new ResourceDirective[0] );
+ return new ModuleDirective( resource, resources );
+ }
+
+ private DependencyDirective buildDependencyDirective( Element element )
+ {
+ final String tag = element.getTagName();
+ if( DEPENDENCIES_ELEMENT_NAME.equals( tag ) )
+ {
+ final String spec = ElementHelper.getAttribute( element,
"scope", "runtime" );
+ Scope scope = Scope.parse( spec );
+ Element[] children = ElementHelper.getChildren( element );
+ IncludeDirective[] includes = new IncludeDirective[
children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ includes[i] = buildIncludeDirective( child );
+ }
+ return new DependencyDirective( scope, includes );
+ }
+ else
+ {
+ final String error =
+ "Invalid dependency element name ["
+ + tag
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Build an array of include directives contained within the supplied
enclosing element.
+ * @param element the enclosing element
+ * @return the array of includes
+ */
+ private IncludeDirective[] buildIncludeDirectives( Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element );
+ IncludeDirective[] includes = new IncludeDirective[ children.length
];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ includes[i] = buildIncludeDirective( child );
+ }
+ return includes;
+ }
+
+ private IncludeDirective buildIncludeDirective( Element element )
+ {
+ final String tag = element.getTagName();
+ final Properties properties = buildProperties( element );
+ if( INCLUDE_ELEMENT_NAME.equals( tag ) )
+ {
+
+ final String tagValue = ElementHelper.getAttribute( element,
"tag", "private" );
+ Category category = Category.parse( tagValue );
+ if( element.hasAttribute( "key" ) )
+ {
+ final String value = ElementHelper.getAttribute( element,
"key", null );
+ return new IncludeDirective( IncludeDirective.KEY, category,
value, properties );
+ }
+ else if( element.hasAttribute( "ref" ) )
+ {
+ final String value = ElementHelper.getAttribute( element,
"ref", null );
+ return new IncludeDirective( IncludeDirective.REF, category,
value, properties );
+ }
+ else if( element.hasAttribute( "urn" ) )
+ {
+ final String value = ElementHelper.getAttribute( element,
"urn", null );
+ return new IncludeDirective( IncludeDirective.URN, category,
value, properties );
+ }
+ else
+ {
+ final String error =
+ "Include directive does not declare a 'urn', 'key' or
'ref' attribute.\n"
+ + element.toString();
+ throw new IllegalArgumentException( error );
+ }
+ }
+ else
+ {
+ final String error =
+ "Invalid include element name ["
+ + tag
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private ResourceDirective buildResourceDirective( Element element )
+ {
+ Classifier classifier = null;
+ final String tag = element.getTagName();
+ if( RESOURCE_ELEMENT_NAME.equals( tag ) ||
PROJECT_ELEMENT_NAME.equals( tag )
+ || MODULE_ELEMENT_NAME.equals( tag ) )
+ {
+ final String name = ElementHelper.getAttribute( element, "name"
);
+ final String version = ElementHelper.getAttribute( element,
"version" );
+ final String basedir = ElementHelper.getAttribute( element,
"basedir" );
+
+ if( PROJECT_ELEMENT_NAME.equals( tag ) )
+ {
+ classifier = Classifier.LOCAL;
+ if( null == basedir )
+ {
+ final String error =
+ "Missing basedir attribute on project ["
+ + name
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ else if( MODULE_ELEMENT_NAME.equals( tag ) )
+ {
+ if( null != basedir )
+ {
+ classifier = Classifier.LOCAL;
+ }
+ else
+ {
+ classifier = Classifier.EXTERNAL;
+ }
+ }
+ else
+ {
+ classifier = Classifier.EXTERNAL;
+ }
+
+ ArrayList dependencies = new ArrayList();
+ TypeDirective[] types = new TypeDirective[0];
+ Element[] children = ElementHelper.getChildren( element );
+ Properties properties = null;
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ final String childTag = child.getTagName();
+ if( TYPES_ELEMENT_NAME.equals( childTag ) )
+ {
+ types = buildTypeDirectives( child );
+ }
+ else if( DEPENDENCIES_ELEMENT_NAME.equals( childTag ) )
+ {
+ DependencyDirective dependency =
buildDependencyDirective( child );
+ dependencies.add( dependency );
+ }
+ else if( PROPERTIES_ELEMENT_NAME.equals( childTag ) )
+ {
+ properties = buildProperties( child );
+ }
+ }
+ DependencyDirective[] deps = (DependencyDirective[])
dependencies.toArray( new DependencyDirective[0] );
+ return new ResourceDirective( name, version, classifier,
basedir, types, deps, properties );
+ }
+ else
+ {
+ final String error =
+ "Invalid element name ["
+ + tag
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private TypeDirective[] buildTypeDirectives( Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element );
+ TypeDirective[] types = new TypeDirective[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ types[i] = buildTypeDirective( child );
+ }
+ return types;
+ }
+
+ private TypeDirective buildTypeDirective( Element element )
+ {
+ final String tag = element.getTagName();
+ if( TYPE_ELEMENT_NAME.equals( tag ) )
+ {
+ final String name = ElementHelper.getAttribute( element, "id",
null );
+ final boolean alias = ElementHelper.getBooleanAttribute(
element, "alias", false );
+ final Properties properties = buildProperties( element );
+ return new TypeDirective( name, alias, properties );
+ }
+ else
+ {
+ final String error =
+ "Invalid resource element name ["
+ + tag
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private Properties buildProperties( Element element )
+ {
+ Properties properties = new Properties();
+ Element[] children = ElementHelper.getChildren( element );
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ String tag = child.getTagName();
+ if( "property".equals( tag ) )
+ {
+ String key = ElementHelper.getAttribute( child, "name", null
);
+ if( null == key )
+ {
+ final String error =
+ "Property declaration does not contain a 'name'
attribute.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ String value = ElementHelper.getAttribute( child,
"value", null );
+ properties.setProperty( key, value );
+ }
+ }
+ }
+ return properties;
+ }
+
+ private static final class InternalErrorHandler implements ErrorHandler
+ {
+ public void error( SAXParseException e ) throws SAXException
+ {
+ System.out.println( "ERROR: " + e.getMessage() );
+ }
+ public void fatalError( SAXParseException e ) throws SAXException
+ {
+ System.out.println( "FATAL: " + e.getMessage() );
+ }
+ public void warning( SAXParseException e ) throws SAXException
+ {
+ System.out.println( "WARN: " + e.getMessage() );
+ }
+ }
+}

Modified:
trunk/main/depot/library/common/src/main/net/dpml/library/info/ModuleDirective.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/info/ModuleDirective.java
2006-02-23 13:18:53 UTC (rev 1129)
+++
trunk/main/depot/library/common/src/main/net/dpml/library/info/ModuleDirective.java
2006-02-23 19:18:03 UTC (rev 1130)
@@ -48,7 +48,7 @@

/**
* Creation of a new module directive.
- * @param resource the abstract resource defintion
+ * @param resource the abstract resource definition
* @param resources resource contained within the module
*/
public ModuleDirective(

Modified:
trunk/main/depot/library/common/src/test/net/dpml/library/impl/DefaultResourceTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/impl/DefaultResourceTestCase.java
2006-02-23 13:18:53 UTC (rev 1129)
+++
trunk/main/depot/library/common/src/test/net/dpml/library/impl/DefaultResourceTestCase.java
2006-02-23 19:18:03 UTC (rev 1130)
@@ -102,10 +102,12 @@
String path = "dpml";
Resource resource = getLibrary().getResource( path );
File basedir = resource.getBaseDir();
+ System.out.println( "# BASEDIR: " + basedir );
assertNotNull( "basedir", basedir );
String testPath = System.getProperty( "project.test.dir" );
File test = new File( testPath );
- File base = new File( test, ".." ).getCanonicalFile();
+ File dpml = new File( test, "dpml" );
+ File base = new File( dpml, ".." ).getCanonicalFile();
assertEquals( "basedir", base, basedir );
}


Modified: trunk/main/depot/module.xml
===================================================================
--- trunk/main/depot/module.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/depot/module.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -7,18 +7,6 @@
<type id="module" alias="true"/>
</types>

- <resource name="dpml-library-main" basedir="library/common">
- <types>
- <type id="jar"/>
- </types>
- <dependencies>
- <include ref="dpml/transit/dpml-transit-main"/>
- </dependencies>
- <dependencies scope="test">
- <include ref="ant/ant-junit"/>
- </dependencies>
- </resource>
-
<project name="dpml-library-console" basedir="library/console">
<types>
<type id="jar"/>
@@ -37,24 +25,6 @@
</dependencies>
</project>

- <resource name="dpml-tools-builder" basedir="tools/builder">
- <types>
- <type id="jar"/>
- <type id="plugin" alias="true">
- <property name="project.plugin.class"
- value="net.dpml.tools.impl.StandardBuilder"/>
- </type>
- </types>
- <dependencies>
- <include key="dpml-library-main"/>
- <include ref="dpml/transit/dpml-transit-tools"/>
- <include ref="ant/ant-junit" tag="system"/>
- <include ref="ant/ant" tag="system"/>
- <include ref="ant/ant-xslp" tag="system"/>
- <include ref="ant/ant-trax" tag="system"/>
- </dependencies>
- </resource>
-
<project name="dpml-depot-checkstyle" basedir="tools/checkstyle">
<types>
<type id="jar"/>
@@ -96,12 +66,12 @@
</project>

<project name="dpml-depot-console" basedir="core/console">
+ <properties>
+ <property name="project.jar.main.class" value="net.dpml.depot.Main"/>
+ </properties>
<types>
<type id="jar"/>
</types>
- <properties>
- <property name="project.jar.main.class" value="net.dpml.depot.Main"/>
- </properties>
<dependencies>
<include ref="dpml/transit/dpml-transit-main"/>
</dependencies>
@@ -128,4 +98,34 @@
</project>
-->

+ <resource name="dpml-library-main" basedir="library/common">
+ <types>
+ <type id="jar"/>
+ </types>
+ <dependencies>
+ <include ref="dpml/transit/dpml-transit-main"/>
+ </dependencies>
+ <dependencies scope="test">
+ <include ref="ant/ant-junit"/>
+ </dependencies>
+ </resource>
+
+ <resource name="dpml-tools-builder" basedir="tools/builder">
+ <types>
+ <type id="jar"/>
+ <type id="plugin" alias="true">
+ <property name="project.plugin.class"
+ value="net.dpml.tools.impl.StandardBuilder"/>
+ </type>
+ </types>
+ <dependencies>
+ <include key="dpml-library-main"/>
+ <include ref="dpml/transit/dpml-transit-tools"/>
+ <include ref="ant/ant-junit" tag="system"/>
+ <include ref="ant/ant" tag="system"/>
+ <include ref="ant/ant-xslp" tag="system"/>
+ <include ref="ant/ant-trax" tag="system"/>
+ </dependencies>
+ </resource>
+
</module>

Modified: trunk/main/external/library.xml
===================================================================
--- trunk/main/external/library.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/external/library.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -7,10 +7,6 @@

<module name="junit" version="3.8.1" basedir="junit">

- <types>
- <type id="module" alias="true"/>
- </types>
-
<properties>
<property name="project.publisher.name" value="JUnit"/>
<property name="project.specification.vendor"
value="${project.publisher.name}"/>
@@ -21,6 +17,10 @@
<property name="project.api.host" value="http://api.dpml.net"/>
</properties>

+ <types>
+ <type id="module" alias="true"/>
+ </types>
+
<resource name="junit">
<properties>
<property name="project.api.root"
value="${project.api.host}/${group}/${version}"/>
@@ -34,10 +34,6 @@

<module name="ant" version="1.6.5" basedir="ant">

- <types>
- <type id="module" alias="true"/>
- </types>
-
<properties>
<property name="project.publisher.name" value="Apache Software
Foundation"/>
<property name="project.specification.vendor"
value="${project.publisher.name}"/>
@@ -48,6 +44,10 @@
<property name="project.api.host" value="http://api.dpml.net"/>
</properties>

+ <types>
+ <type id="module" alias="true"/>
+ </types>
+
<resource name="ant">
<properties>
<property name="project.api.root"
value="${project.api.host}/${group}/${version}"/>
@@ -100,10 +100,6 @@

<module name="jgoodies" version="M1" basedir="jgoodies">

- <types>
- <type id="module" alias="true"/>
- </types>
-
<properties>
<property name="project.publisher.name" value="JGoodies"/>
<property name="project.specification.vendor"
value="${project.publisher.name}"/>
@@ -114,6 +110,10 @@
<property name="project.api.host" value="http://api.dpml.net"/>
</properties>

+ <types>
+ <type id="module" alias="true"/>
+ </types>
+
<resource name="looks" version="1.3.1">
<types>
<type id="jar"/>

Modified: trunk/main/library.xml
===================================================================
--- trunk/main/library.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/library.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -13,10 +13,6 @@

<module name="dpml" basedir=".">

- <types>
- <type id="module" alias="true"/>
- </types>
-
<properties>
<property name="project.publisher.name" value="Digital Product Meta
Library"/>
<property name="project.specification.vendor"
value="${project.publisher.name}"/>
@@ -29,14 +25,18 @@
<property name="project.javadoc.linksource" value="true"/>
</properties>

- <module base="transit"/>
- <module base="metro"/>
- <module base="depot"/>
- <module base="util"/>
- <module base="planet"/>
+ <types>
+ <type id="module" alias="true"/>
+ </types>

+ <module file="transit/module.xml"/>
+ <module file="metro/module.xml"/>
+ <module file="depot/module.xml"/>
+ <module file="util/module.xml"/>
+ <module file="planet/module.xml"/>
+
<project name="central" basedir="central"/>
-
+
</module>

</modules>

Modified: trunk/main/metro/module.xml
===================================================================
--- trunk/main/metro/module.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/metro/module.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -60,12 +60,12 @@
</project>

<project name="dpml-part-test" basedir="part/test">
+ <properties>
+ <property name="project.test.fork" value="true"/>
+ </properties>
<types>
<type id="jar"/>
</types>
- <properties>
- <property name="project.test.fork" value="true"/>
- </properties>
<dependencies scope="build">
<include key="dpml-metro-tools"/>
</dependencies>

Modified: trunk/main/planet/http/module.xml
===================================================================
--- trunk/main/planet/http/module.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/planet/http/module.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

-<module name="http">
+<module name="http" basedir=".">

<types>
<type id="module" alias="true"/>
@@ -54,12 +54,12 @@
</project>

<project name="dpml-http-test" basedir="test">
+ <properties>
+ <property name="project.test.fork" value="true"/>
+ </properties>
<types>
<type id="jar"/>
</types>
- <properties>
- <property name="project.test.fork" value="true"/>
- </properties>
<dependencies scope="build">
<include key="dpml-http-server"/>
</dependencies>

Modified: trunk/main/planet/module.xml
===================================================================
--- trunk/main/planet/module.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/planet/module.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -7,6 +7,6 @@
<type id="module" alias="true"/>
</types>

- <module base="http"/>
+ <module file="http/module.xml"/>

</module>

Modified: trunk/main/transit/bootstrap.xml
===================================================================
--- trunk/main/transit/bootstrap.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/transit/bootstrap.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -377,7 +377,7 @@
<mkdir dir="${target.deliverables.jars.dir}"/>
<jar destfile="${target.deliverables.jars.dir}/${project.filename}"
basedir="${target.classes.dir}"
- includes="**/*.class,**/*.xml,**/*.properties"
+ includes="**/*.class,**/*.xml,**/*.properties,**/*.dtd"
excludes="**/*.html,**/*.gif,**/*.png">
<manifest>
<attribute name="Created-By" value="The Digital Product Meta
Library."/>

Modified: trunk/main/transit/core/src/main/net/dpml/lang/DTDResolver.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/DTDResolver.java
2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/transit/core/src/main/net/dpml/lang/DTDResolver.java
2006-02-23 19:18:03 UTC (rev 1130)
@@ -71,6 +71,11 @@
final ClassLoader classLoader = getClassLoader();
final InputStream inputStream =
classLoader.getResourceAsStream( info.getResource() );
+ if( null == inputStream )
+ {
+ String path = "resource:" + info.getResource();
+ throw new NullPointerException( path );
+ }
return new InputSource( inputStream );
}
}

Modified: trunk/main/transit/module.xml
===================================================================
--- trunk/main/transit/module.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/transit/module.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -3,30 +3,14 @@

<module name="transit">

- <types>
- <type id="module" alias="true"/>
- </types>
-
<properties>
<property name="project.test.fork" value="true"/>
</properties>

- <resource name="dpml-transit-main" basedir="core">
- <types>
- <type id="jar"/>
- </types>
- </resource>
+ <types>
+ <type id="module" alias="true"/>
+ </types>

- <resource name="dpml-transit-tools" basedir="tools">
- <types>
- <type id="jar"/>
- </types>
- <dependencies scope="RUNTIME">
- <include key="dpml-transit-main"/>
- <include ref="ant/ant"/>
- </dependencies>
- </resource>
-
<project name="dpml-transit-console" basedir="console">
<types>
<type id="jar"/>
@@ -44,4 +28,20 @@
</dependencies>
</project>

+ <resource name="dpml-transit-main" basedir="core">
+ <types>
+ <type id="jar"/>
+ </types>
+ </resource>
+
+ <resource name="dpml-transit-tools" basedir="tools">
+ <types>
+ <type id="jar"/>
+ </types>
+ <dependencies scope="RUNTIME">
+ <include key="dpml-transit-main"/>
+ <include ref="ant/ant"/>
+ </dependencies>
+ </resource>
+
</module>

Modified: trunk/main/util/module.xml
===================================================================
--- trunk/main/util/module.xml 2006-02-23 13:18:53 UTC (rev 1129)
+++ trunk/main/util/module.xml 2006-02-23 19:18:03 UTC (rev 1130)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://www.dpml.net/dtds/library_1_0.dtd"; >

-<module name="util">
+<module name="util" basedir=".">

<types>
<type id="module" alias="true"/>
@@ -21,16 +21,12 @@
</project>

<project name="dpml-util-cli" basedir="cli">
- <types>
- <type id="jar"/>
- </types>
<properties>
<property name="project.test.fork" value="true"/>
- <!--
- <property name="project.test.halt-on-error" value="false"/>
- <property name="project.test.halt-on-failure" value="false"/>
- -->
</properties>
+ <types>
+ <type id="jar"/>
+ </types>
<dependencies scope="test">
<include ref="ant/ant-junit"/>
</dependencies>




  • r1130 - in trunk/main: . depot depot/library/common/etc/main/net/dpml/library depot/library/common/etc/test depot/library/common/etc/test/ant depot/library/common/etc/test/commons-cli depot/library/common/etc/test/dpml depot/library/common/etc/test/jgoodies depot/library/common/etc/test/junit depot/library/common/etc/test/xstream depot/library/common/src/main/net/dpml/library/impl depot/library/common/src/main/net/dpml/library/info depot/library/common/src/test/net/dpml/library/impl external metro planet planet/http transit transit/core/src/main/net/dpml/lang util, mcconnell at BerliOS, 02/23/2006

Archive powered by MHonArc 2.6.24.

Top of Page