Skip to Content.
Sympa Menu

notify-dpml - r1131 - in trunk/main: 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/info transit/core/src/main/net/dpml/transit

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: r1131 - in trunk/main: 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/info transit/core/src/main/net/dpml/transit
  • Date: Thu, 23 Feb 2006 22:40:15 +0100

Author: mcconnell
Date: 2006-02-23 22:40:13 +0100 (Thu, 23 Feb 2006)
New Revision: 1131

Added:

trunk/main/depot/library/common/src/test/net/dpml/library/info/BuilderTestCase.java
Modified:

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

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

trunk/main/depot/library/common/src/main/net/dpml/library/info/ResourceDirective.java
trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
Log:
commence module externalization into DTD based XML format

Modified:
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 19:18:03 UTC (rev 1130)
+++
trunk/main/depot/library/common/src/main/net/dpml/library/impl/ModuleBuilder.java
2006-02-23 21:40:13 UTC (rev 1131)
@@ -24,6 +24,9 @@
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.net.URLConnection;
import java.net.URI;
import java.net.URL;
@@ -38,6 +41,7 @@
import net.dpml.library.info.LibraryDirective;
import net.dpml.library.info.ImportDirective;
import net.dpml.library.info.IncludeDirective;
+import net.dpml.library.info.IncludeDirective.Mode;
import net.dpml.library.info.ModuleDirective;
import net.dpml.library.info.ResourceDirective;
import net.dpml.library.info.ResourceDirective.Classifier;
@@ -140,6 +144,188 @@
return build( root );
}

+ /**
+ * Write a module directive to an output stream as a portable XML
definition.
+ * @param module the moudle directive to externalize
+ * @param output the output stream
+ * @exception Exception if an error occurs during module externalization
+ */
+ public void write( final ModuleDirective module, final OutputStream
output ) throws Exception
+ {
+ final Writer writer = new OutputStreamWriter( output );
+ try
+ {
+ writer.write( XML_HEADER );
+ writer.write( DOCTYPE );
+ writeModule( writer, module, "" );
+ writer.write( "\n" );
+ }
+ finally
+ {
+ writer.flush();
+ writer.close();
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ // internal utilities supporting ModuleDirective to XML creation
+ //-----------------------------------------------------------------------
+
+ private void writeModule( Writer writer, ModuleDirective module, String
lead ) throws IOException
+ {
+ String name = module.getName();
+ String version = module.getVersion();
+ Properties properties = module.getProperties();
+ String basedir = module.getBasedir();
+ TypeDirective[] types = module.getTypeDirectives();
+ DependencyDirective[] dependencies = new DependencyDirective[0];
+ ResourceDirective[] resources = module.getResourceDirectives();
+
+ writer.write( "\n" + lead + "<" + NAME );
+ if( null != name )
+ {
+ writer.write( " name=\"" + name + "\"" );
+ }
+ if( null != version )
+ {
+ writer.write( " version=\"" + version + "\"" );
+ }
+ writer.write( ">" );
+ writeProperties( writer, properties, lead + " ", true );
+ writeTypes( writer, types, lead + " " );
+ writeDependencies( writer, dependencies, lead + " " );
+ writeResources( writer, resources, lead + " " );
+ writer.write( "\n" + lead + "</" + NAME + ">" );
+ }
+
+ private void writeProperties( Writer writer, Properties properties,
String lead, boolean flag ) throws IOException
+ {
+ if( properties.size() > 0 )
+ {
+ if( flag )
+ {
+ writer.write( "\n" + lead + "<properties>" );
+ }
+ String[] names = (String[]) properties.keySet().toArray( new
String[0] );
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ String value = properties.getProperty( name );
+ writer.write( "\n" + lead );
+ if( flag )
+ {
+ writer.write( " " );
+ }
+ writer.write( "<property name=\"" + name + "\" value=\"" +
value + "\"/>" );
+ }
+ if( flag )
+ {
+ writer.write( "\n" + lead + "</properties>" );
+ }
+ }
+ }
+
+ private void writeTypes( Writer writer, TypeDirective[] types, String
lead ) throws IOException
+ {
+ if( types.length > 0 )
+ {
+ writer.write( lead + "<types>" );
+ for( int i=0; i<types.length; i++ )
+ {
+ TypeDirective type = types[i];
+ String id = type.getName();
+ boolean alias = type.getAlias();
+ writer.write( lead + " <type id=\"" + id + "\"" );
+ if( alias )
+ {
+ writer.write( " alias=\"true\"" );
+ }
+ Properties properties = type.getProperties();
+ if( properties.size() > 0 )
+ {
+ writer.write( ">" );
+ writeProperties( writer, properties, lead + " ", false
);
+ }
+ }
+ writer.write( lead + "</types>" );
+ }
+ }
+
+ private void writeDependencies( Writer writer, DependencyDirective[]
dependencies, String lead ) throws IOException
+ {
+ if( dependencies.length > 0 )
+ {
+ for( int i=0; i<dependencies.length; i++ )
+ {
+ DependencyDirective dependency = dependencies[i];
+ IncludeDirective[] includes =
dependency.getIncludeDirectives();
+ if( includes.length > 0 )
+ {
+ Scope scope = dependency.getScope();
+ if( Scope.RUNTIME.equals( scope ) )
+ {
+ writer.write( lead + "<dependencies>" );
+ }
+ else
+ {
+ writer.write( lead + "<dependencies scope=\"" +
scope + "\">" );
+ }
+
+ for( int j=0; j<includes.length; j++ )
+ {
+ IncludeDirective include = includes[j];
+ Mode mode = include.getMode();
+ String value = include.getValue();
+ writer.write( lead + " <include" );
+ if( Mode.KEY.equals( mode ) )
+ {
+ writer.write( " key=\"" + value + "\"" );
+ }
+ else if( Mode.REF.equals( mode ) )
+ {
+ writer.write( " ref=\"" + value + "\"" );
+ }
+ else if( Mode.URN.equals( mode ) )
+ {
+ writer.write( " urn=\"" + value + "\"" );
+ }
+
+ if( Scope.RUNTIME.equals( scope ) )
+ {
+ Category category = include.getCategory();
+ if( !Category.PRIVATE.equals( category ) )
+ {
+ writer.write( " tag=\"" + category + "\"" );
+ }
+ }
+
+ Properties props = include.getProperties();
+ if( props.size() > 0 )
+ {
+ writer.write( ">" );
+ writeProperties( writer, props, lead + " ",
false );
+ writer.write( "\n" + lead + " </include>");
+ }
+ else
+ {
+ writer.write( "/>" );
+ }
+ }
+ writer.write( "\n" + lead + "</dependencies>" );
+ }
+ }
+ }
+ }
+
+ private void writeResources( Writer writer, ResourceDirective[]
dependencies, String lead ) throws IOException
+ {
+
+ }
+
+ //-----------------------------------------------------------------------
+ // internal utilities supporting XML to ModuleDirective creation
+ //-----------------------------------------------------------------------
+
private ModuleDirective build( Element element )
{
final String elementName = element.getTagName();

Modified:
trunk/main/depot/library/common/src/main/net/dpml/library/info/IncludeDirective.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/info/IncludeDirective.java
2006-02-23 19:18:03 UTC (rev 1130)
+++
trunk/main/depot/library/common/src/main/net/dpml/library/info/IncludeDirective.java
2006-02-23 21:40:13 UTC (rev 1131)
@@ -76,7 +76,7 @@
}
if( null == category )
{
- m_category = Category.PUBLIC;
+ m_category = Category.PRIVATE; // was PUBLIC
}
else
{

Modified:
trunk/main/depot/library/common/src/main/net/dpml/library/info/ResourceDirective.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/info/ResourceDirective.java
2006-02-23 19:18:03 UTC (rev 1130)
+++
trunk/main/depot/library/common/src/main/net/dpml/library/info/ResourceDirective.java
2006-02-23 21:40:13 UTC (rev 1131)
@@ -179,7 +179,7 @@
{
return m_types;
}
-
+
/**
* Return an named type.
* @param name the type name

Added:
trunk/main/depot/library/common/src/test/net/dpml/library/info/BuilderTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/info/BuilderTestCase.java
2006-02-23 19:18:03 UTC (rev 1130)
+++
trunk/main/depot/library/common/src/test/net/dpml/library/info/BuilderTestCase.java
2006-02-23 21:40:13 UTC (rev 1131)
@@ -0,0 +1,45 @@
+/*
+ * 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.info;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import net.dpml.library.impl.ModuleBuilder;
+
+/**
+ * The ModuleDirective class describes a module data-structure.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class BuilderTestCase extends AbstractTestCase
+{
+ public void testReadWrite() throws Exception
+ {
+ ModuleBuilder builder = new ModuleBuilder();
+ String testPath = System.getProperty( "project.test.dir" );
+ File test = new File( testPath );
+ File file = new File( test, "dpml/module.xml" );
+ ModuleDirective module = builder.load( file.toURL() );
+
+ File destination = new File( test, "externalization.xml" );
+ builder.write( module, new FileOutputStream( destination ) );
+ }
+}

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
2006-02-23 19:18:03 UTC (rev 1130)
+++ trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
2006-02-23 21:40:13 UTC (rev 1131)
@@ -124,7 +124,45 @@
return build( root );
}

-
+ /**
+ * Write a transit directive to an output stream as XML.
+ * @param directive the directive to externalize
+ * @param output the output stream to write to
+ * @exception IOException if an I/O error occurs
+ */
+ public void write( TransitDirective directive, OutputStream output )
throws IOException
+ {
+ final Writer writer = new OutputStreamWriter( output );
+ try
+ {
+ writer.write( XML_HEADER );
+ writer.write( DOCTYPE );
+
+ CacheDirective cache = directive.getCacheDirective();
+ String cachePath = cache.getCache();
+ String cacheLayout = cache.getCacheLayout();
+ writeHeader( writer, cachePath, cacheLayout );
+
+ ProxyDirective proxy = directive.getProxyDirective();
+ writeProxy( writer, proxy );
+
+ String localPath = cache.getLocal();
+ String localLayout = cache.getLocalLayout();
+ writeLocal( writer, localPath, localLayout );
+
+ HostDirective[] hosts = cache.getHostDirectives();
+ writeHosts( writer, hosts );
+
+ writeFooter( writer );
+ writer.write( "\n" );
+ }
+ finally
+ {
+ writer.flush();
+ writer.close();
+ }
+ }
+
//-------------------------------------------------------------
// internals supporting XML to directive transformation
//-------------------------------------------------------------
@@ -339,39 +377,6 @@
writer.write( "\n</" + NAME + ">" );
}

- public void write( TransitDirective directive, OutputStream output )
throws IOException
- {
- final Writer writer = new OutputStreamWriter( output );
- try
- {
- writer.write( XML_HEADER );
- writer.write( DOCTYPE );
-
- CacheDirective cache = directive.getCacheDirective();
- String cachePath = cache.getCache();
- String cacheLayout = cache.getCacheLayout();
- writeHeader( writer, cachePath, cacheLayout );
-
- ProxyDirective proxy = directive.getProxyDirective();
- writeProxy( writer, proxy );
-
- String localPath = cache.getLocal();
- String localLayout = cache.getLocalLayout();
- writeLocal( writer, localPath, localLayout );
-
- HostDirective[] hosts = cache.getHostDirectives();
- writeHosts( writer, hosts );
-
- writeFooter( writer );
- writer.write( "\n" );
- }
- finally
- {
- writer.flush();
- writer.close();
- }
- }
-
private void writeProxy( Writer writer, ProxyDirective proxy ) throws
IOException
{
if( null != proxy )




  • r1131 - in trunk/main: 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/info transit/core/src/main/net/dpml/transit, mcconnell at BerliOS, 02/23/2006

Archive powered by MHonArc 2.6.24.

Top of Page