Skip to Content.
Sympa Menu

notify-dpml - r1292 - in trunk/main/depot/library: etc/test/samples src/main/net/dpml/library/impl src/test/net/dpml/library/impl

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: r1292 - in trunk/main/depot/library: etc/test/samples src/main/net/dpml/library/impl src/test/net/dpml/library/impl
  • Date: Thu, 30 Mar 2006 05:36:04 +0200

Author: mcconnell
Date: 2006-03-30 05:36:02 +0200 (Thu, 30 Mar 2006)
New Revision: 1292

Added:
trunk/main/depot/library/etc/test/samples/duplicates.xml

trunk/main/depot/library/src/test/net/dpml/library/impl/DuplicatesTestCase.java
Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultLibrary.java
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultModule.java
Log:
add possibility for independent sub-modules

Added: trunk/main/depot/library/etc/test/samples/duplicates.xml
===================================================================
--- trunk/main/depot/library/etc/test/samples/duplicates.xml 2006-03-29
05:53:25 UTC (rev 1291)
+++ trunk/main/depot/library/etc/test/samples/duplicates.xml 2006-03-30
03:36:02 UTC (rev 1292)
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+ xmlns:part="artifact:xsd:dpml/lang/dpml-part#1.0">
+
+ <imports>
+ <import uri="link:module:junit"/>
+ <import uri="link:module:ant"/>
+ </imports>
+
+ <modules>
+ <module name="acme">
+ <resource name="widget">
+ <types>
+ <type id="foo">
+ <property name="pink" value="floyd"/>
+ <property name="alice" value="cooper"/>
+ </type>
+ <part:plugin class="Widget"/>
+ </types>
+ </resource>
+ </module>
+ <module name="acme">
+ <resource name="gizmo">
+ <types>
+ <part:plugin class="gizmo"/>
+ </types>
+ </resource>
+ </module>
+ </modules>
+
+</library>

Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultLibrary.java
===================================================================
---
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultLibrary.java
2006-03-29 05:53:25 UTC (rev 1291)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultLibrary.java
2006-03-30 03:36:02 UTC (rev 1292)
@@ -39,7 +39,9 @@
import net.dpml.library.ResourceNotFoundException;

import net.dpml.transit.Artifact;
+
import net.dpml.lang.Logger;
+import net.dpml.lang.DuplicateKeyException;

/**
* Utility class used for construction of a module model from an XML source.
@@ -92,6 +94,7 @@
m_logger = logger;
m_directive = (LibraryDirective) super.getAbstractDirective();
m_root = source.getParentFile().getCanonicalFile();
+ m_module = new DefaultModule( this, m_directive );

getLogger().debug( "loaded root module: " + m_root );
System.setProperty( "dpml.library.basedir", m_root.toString() );
@@ -129,13 +132,12 @@
}
}
}
- //DefaultModule[] importModules = new DefaultModule[
importModuleDirectives.length ];
+
m_imports = new DefaultModule( this, m_directive );
for( int i=0; i<importModuleDirectives.length; i++ )
{
ModuleDirective importModuleDirective =
importModuleDirectives[i];
m_imports.addResource( importModuleDirective );
- //importModules[i] = new DefaultModule( this, m_imports,
importModuleDirective );
}

// create the top-level modules
@@ -157,16 +159,11 @@
throw new IllegalArgumentException( error );
}
}
-
ModuleDirective[] values = (ModuleDirective[])
moduleDirectives.toArray( new ModuleDirective[0] );
- //DefaultModule[] modules = new DefaultModule[ values.length ];
- //m_module = new DefaultModule( this, m_directive, modules );
- m_module = new DefaultModule( this, m_directive );
for( int i=0; i<values.length; i++ )
{
ModuleDirective md = values[i];
m_module.addResource( md );
- //modules[i] = new DefaultModule( this, m_module, md );
}
}

@@ -426,8 +423,6 @@
}
try
{
- //DefaultModule module = new DefaultModule( this, m_module,
enclosing );
- //DefaultModule root = new DefaultModule( this, m_directive, new
DefaultModule[]{module} );
DefaultModule root = new DefaultModule( this, m_directive );
root.addResource( enclosing );
DefaultResource resource = root.getDefaultResource( group + "/"
+ name );

Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultModule.java
===================================================================
---
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultModule.java
2006-03-29 05:53:25 UTC (rev 1291)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultModule.java
2006-03-30 03:36:02 UTC (rev 1292)
@@ -55,7 +55,6 @@
public final class DefaultModule extends DefaultResource implements Module
{
private final boolean m_root;
- //private final DefaultResource[] m_resources;
private final ModuleDirective m_directive;
private final Map m_map = new Hashtable();

@@ -69,7 +68,7 @@
DefaultModule( DefaultLibrary library, AbstractDirective directive )
{
super( library, directive );
- //m_resources = resources;
+
m_root = true;
m_directive = null;
}
@@ -96,26 +95,57 @@
throw new NullPointerException( "directive" );
}

- String key = directive.getName();
- if( m_map.containsKey( key ) )
+ synchronized( m_map )
{
- throw new DuplicateKeyException( key );
- }
- else
- {
- DefaultLibrary library = getDefaultLibrary();
- if( directive instanceof ModuleDirective )
+ String key = directive.getName();
+ if( m_map.containsKey( key ) )
{
- ModuleDirective d = (ModuleDirective) directive;
- DefaultModule module = new DefaultModule( library, this, d );
- m_map.put( key, module );
- return module;
+ if( directive instanceof ModuleDirective )
+ {
+ DefaultModule module = (DefaultModule) m_map.get( key );
+
+ // update properties?
+
+ // update basedir?
+
+ // update version?
+
+ // update types?
+
+ // update dependencies?
+
+ // add additional resources
+
+ ModuleDirective d = (ModuleDirective) directive;
+ ResourceDirective[] resources =
d.getResourceDirectives();
+ for( int i=0; i<resources.length; i++ )
+ {
+ ResourceDirective r = resources[i];
+ module.addResource( r );
+ }
+ return module;
+ }
+ else
+ {
+ throw new DuplicateKeyException( key );
+ }
}
else
{
- DefaultResource resource = new DefaultResource( library,
this, directive );
- m_map.put( key, resource );
- return resource;
+ DefaultLibrary library = getDefaultLibrary();
+ if( directive instanceof ModuleDirective )
+ {
+ ModuleDirective d = (ModuleDirective) directive;
+ DefaultModule module = new DefaultModule( library, this,
d );
+ m_map.put( key, module );
+ return module;
+ }
+ else
+ {
+ DefaultResource resource = new DefaultResource( library,
this, directive );
+ m_map.put( key, resource );
+ return resource;
+ }
}
}
}
@@ -430,7 +460,6 @@
DefaultResource[] getDefaultResources()
{
return (DefaultResource[]) m_map.values().toArray( new
DefaultResource[0] );
- //return m_resources;
}

DefaultResource getDefaultResource( String ref )

Added:
trunk/main/depot/library/src/test/net/dpml/library/impl/DuplicatesTestCase.java
===================================================================
---
trunk/main/depot/library/src/test/net/dpml/library/impl/DuplicatesTestCase.java
2006-03-29 05:53:25 UTC (rev 1291)
+++
trunk/main/depot/library/src/test/net/dpml/library/impl/DuplicatesTestCase.java
2006-03-30 03:36:02 UTC (rev 1292)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2004-2006 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 net.dpml.library.info.LibraryDirective;
+import net.dpml.library.info.ModuleDirective;
+import net.dpml.library.info.ResourceDirective;
+import net.dpml.library.info.TypeDirective;
+import net.dpml.library.impl.DefaultLibrary;
+
+import net.dpml.lang.Logger;
+
+import net.dpml.transit.monitor.LoggingAdapter;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Library XML test case.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class DuplicatesTestCase extends TestCase
+{
+ static
+ {
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ }
+
+ private LibraryDecoder m_decoder;
+
+ /**
+ * Setup the library directive builder.
+ * @exception Exception if an error occurs during test execution
+ */
+ public void setUp() throws Exception
+ {
+ m_decoder = new LibraryDecoder();
+ }
+
+ /**
+ * Test an library definition containing duplicate modules.
+ * @exception Exception if an error occurs during test execution
+ */
+ public void testLibrary() throws Exception
+ {
+ String base = System.getProperty( "project.test.dir" );
+ File test = new File( base );
+ File file = new File( test, "samples/duplicates.xml" );
+ Logger logger = new LoggingAdapter( "test" );
+ DefaultLibrary library = new DefaultLibrary( logger, file );
+ }
+
+}




  • r1292 - in trunk/main/depot/library: etc/test/samples src/main/net/dpml/library/impl src/test/net/dpml/library/impl, mcconnell at BerliOS, 03/29/2006

Archive powered by MHonArc 2.6.24.

Top of Page