notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r1537 - in trunk/main: lang/component/etc metro/model/src/main/net/dpml/metro/data metro/model/src/test/net/dpml/metro/data/test metro/runtime/src/main/net/dpml/metro/builder
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r1537 - in trunk/main: lang/component/etc metro/model/src/main/net/dpml/metro/data metro/model/src/test/net/dpml/metro/data/test metro/runtime/src/main/net/dpml/metro/builder
- Date: Wed, 5 Jul 2006 09:25:33 +0200
Author: mcconnell
Date: 2006-07-05 09:25:28 +0200 (Wed, 05 Jul 2006)
New Revision: 1537
Removed:
trunk/main/metro/model/src/main/net/dpml/metro/data/DeploymentDirective.java
Modified:
trunk/main/lang/component/etc/component.xsd
trunk/main/metro/model/src/main/net/dpml/metro/data/ComponentDirective.java
trunk/main/metro/model/src/test/net/dpml/metro/data/test/ComponentDirectiveTestCase.java
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentDecoder.java
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentEncoder.java
Log:
add data-structures supporting the creation of a component directive via
extension of an existing component directive
Modified: trunk/main/lang/component/etc/component.xsd
===================================================================
--- trunk/main/lang/component/etc/component.xsd 2006-07-04 07:42:22 UTC (rev
1536)
+++ trunk/main/lang/component/etc/component.xsd 2006-07-05 07:25:28 UTC (rev
1537)
@@ -23,11 +23,12 @@
<element name="parts" type="this:PartsType" minOccurs="0"
maxOccurs="1"/>
</sequence>
<attribute name="name" type="string"/>
- <attribute name="type" type="string" use="required"/>
+ <attribute name="type" type="string"/>
<attribute name="lifestyle" type="this:lifestyle"/>
<attribute name="collection" type="this:collection"/>
<attribute name="activation" type="this:activation"/>
<attribute name="handler" type="part:URI"
default="link:part:dpml/metro/dpml-metro-runtime"/>
+ <attribute name="extends" type="anyURI"/>
</extension>
</complexContent>
</complexType>
Modified:
trunk/main/metro/model/src/main/net/dpml/metro/data/ComponentDirective.java
===================================================================
---
trunk/main/metro/model/src/main/net/dpml/metro/data/ComponentDirective.java
2006-07-04 07:42:22 UTC (rev 1536)
+++
trunk/main/metro/model/src/main/net/dpml/metro/data/ComponentDirective.java
2006-07-05 07:25:28 UTC (rev 1537)
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 Stephen J. McConnell.
+ * 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.
@@ -18,11 +18,15 @@
package net.dpml.metro.data;
+import java.net.URI;
+
+import net.dpml.component.ActivationPolicy;
+import net.dpml.component.Directive;
+
+import net.dpml.metro.info.Composite;
import net.dpml.metro.info.PartReference;
import net.dpml.metro.info.LifestylePolicy;
import net.dpml.metro.info.CollectionPolicy;
-import net.dpml.component.ActivationPolicy;
-import net.dpml.component.Directive;
/**
* Definition of the criteria for an explicit component profile. A profile,
when
@@ -80,7 +84,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public class ComponentDirective extends DeploymentDirective implements
Directive
+public class ComponentDirective extends Composite implements Comparable,
Directive
{
//--------------------------------------------------------------------------
// static
@@ -91,6 +95,9 @@
*/
static final long serialVersionUID = 1L;
+ private static final CategoriesDirective EMPTY_CATEGORIES =
+ new CategoriesDirective();
+
//--------------------------------------------------------------------------
// state
//--------------------------------------------------------------------------
@@ -115,6 +122,27 @@
*/
private final ContextDirective m_context;
+ /**
+ * The name of the component profile. This is an
+ * abstract name used during assembly.
+ */
+ private final String m_name;
+
+ /**
+ * The activation policy.
+ */
+ private final ActivationPolicy m_activation;
+
+ /**
+ * Logging category directives.
+ */
+ private final CategoriesDirective m_categories;
+
+ /**
+ * Base directive.
+ */
+ private final URI m_base;
+
//--------------------------------------------------------------------------
// constructors
//--------------------------------------------------------------------------
@@ -131,30 +159,12 @@
name,
ActivationPolicy.SYSTEM,
CollectionPolicy.SYSTEM,
- LifestylePolicy.TRANSIENT,
+ LifestylePolicy.SYSTEM,
classname,
- null, null, null );
+ null, null, null, null );
}
/**
- * Creation of a new deployment profile using a supplied template profile.
- * @param name the name to assign to the created profile
- * @param template the template deployment profile
- */
- public ComponentDirective( String name, ComponentDirective template )
- {
- this(
- name,
- template.getActivationPolicy(),
- template.getCollectionPolicy(),
- template.getLifestylePolicy(),
- template.getClassname(),
- template.getCategoriesDirective(),
- template.getContextDirective(),
- template.getPartReferences() );
- }
-
- /**
* Creation of a new deployment profile.
* @param name the name to assign to the created profile
* @param activation the component activation policy
@@ -164,6 +174,8 @@
* @param categories logging categories
* @param context context directive
* @param parts the component internal parts
+ * @param base URI of the component super-definition
+ * @exception NullPointerException if the supplied name if null
*/
public ComponentDirective(
final String name,
@@ -173,10 +185,29 @@
final String classname,
final CategoriesDirective categories,
final ContextDirective context,
- final PartReference[] parts )
+ final PartReference[] parts,
+ final URI base )
{
- super( name, activation, categories, parts );
-
+ super( parts );
+
+ if( null == activation )
+ {
+ m_activation = ActivationPolicy.SYSTEM;
+ }
+ else
+ {
+ m_activation = activation;
+ }
+
+ if( null == categories )
+ {
+ m_categories = EMPTY_CATEGORIES;
+ }
+ else
+ {
+ m_categories = categories;
+ }
+
if( null == classname )
{
m_classname = Object.class.getName();
@@ -197,13 +228,74 @@
m_lifestyle = lifestyle;
m_collection = collection;
+ m_base = base;
+
+ if( null != name )
+ {
+ if( name.indexOf( " " ) > 0 || name.indexOf( "." ) > 0 ||
name.indexOf( "," ) > 0
+ || name.indexOf( "/" ) > 0 )
+ {
+ final String error =
+ "Directive name ["
+ + name
+ + "] contains an illegal character (' ', ',', '/', or
'.')";
+ throw new IllegalArgumentException( error );
+ }
+ else if( name.length() == 0 )
+ {
+ final String error =
+ "Directive name [] is insufficient.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ m_name = name;
+ }
+ }
+ else
+ {
+ throw new NullPointerException( "name" );
+ }
}
//--------------------------------------------------------------------------
// implementation
//--------------------------------------------------------------------------
+ /**
+ * Return the profile name.
+ *
+ * @return the name of the component.
+ */
+ public String getName()
+ {
+ return m_name;
+ }
+
+ /**
+ * Return the logging categories for the profile.
+ *
+ * @return the categories
+ */
+ public CategoriesDirective getCategoriesDirective()
+ {
+ return m_categories;
+ }
+
/**
+ * Get the activation policy for the profile.
+ *
+ * @return the declared activation policy
+ * @see ActivationPolicy#SYSTEM
+ * @see ActivationPolicy#STARTUP
+ * @see ActivationPolicy#DEMAND
+ */
+ public ActivationPolicy getActivationPolicy()
+ {
+ return m_activation;
+ }
+
+ /**
* Return the component type classname.
*
* @return classname of the component type
@@ -245,6 +337,16 @@
}
/**
+ * Return the base directive uri.
+ *
+ * @return the uri of the base directive
+ */
+ public URI getBaseDirective()
+ {
+ return m_base;
+ }
+
+ /**
* Returns a string representation of the profile.
* @return a string representation
*/
@@ -254,6 +356,18 @@
}
/**
+ * Compare this object with the supplied object.
+ * @param object the obvject to compare with
+ * @return the result
+ */
+ public int compareTo( Object object )
+ {
+ String name = this.toString();
+ String other = object.toString();
+ return name.compareTo( other );
+ }
+
+ /**
* Test if the supplied object is equal to this object.
* @param other the object to compare with this instance
* @return TRUE if the supplied object is equal to this object
@@ -273,19 +387,38 @@
return false;
}
ComponentDirective profile = (ComponentDirective) other;
- if( !m_classname.equals( profile.getClassname() ) )
+ if( !m_name.equals( profile.getName() ) )
{
return false;
}
- if( !m_context.equals( profile.getContextDirective() ) )
+ else if( !m_activation.equals( profile.getActivationPolicy() ) )
{
return false;
}
- if( !equals( m_collection, profile.getCollectionPolicy() ) )
+ else if( !m_categories.equals( profile.getCategoriesDirective() ) )
{
return false;
}
- return equals( m_lifestyle, profile.getLifestylePolicy() );
+ else if( !m_classname.equals( profile.getClassname() ) )
+ {
+ return false;
+ }
+ else if( !m_context.equals( profile.getContextDirective() ) )
+ {
+ return false;
+ }
+ else if( !equals( m_collection, profile.getCollectionPolicy() ) )
+ {
+ return false;
+ }
+ else if( !equals( m_lifestyle, profile.getLifestylePolicy() ) )
+ {
+ return false;
+ }
+ else
+ {
+ return equals( m_base, profile.getBaseDirective() );
+ }
}
/**
@@ -295,6 +428,9 @@
public int hashCode()
{
int hash = super.hashCode();
+ hash ^= m_name.hashCode();
+ hash ^= m_activation.hashCode();
+ hash ^= m_categories.hashCode();
hash ^= m_classname.hashCode();
hash ^= m_context.hashCode();
if( null != m_collection )
@@ -305,6 +441,10 @@
{
hash ^= m_lifestyle.hashCode();
}
+ if( null != m_base )
+ {
+ hash ^= m_base.hashCode();
+ }
return hash;
}
}
Deleted:
trunk/main/metro/model/src/main/net/dpml/metro/data/DeploymentDirective.java
===================================================================
---
trunk/main/metro/model/src/main/net/dpml/metro/data/DeploymentDirective.java
2006-07-04 07:42:22 UTC (rev 1536)
+++
trunk/main/metro/model/src/main/net/dpml/metro/data/DeploymentDirective.java
2006-07-05 07:25:28 UTC (rev 1537)
@@ -1,227 +0,0 @@
-/*
- * 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.metro.data;
-
-import net.dpml.component.ActivationPolicy;
-
-import net.dpml.metro.info.Composite;
-import net.dpml.metro.info.PartReference;
-
-/**
- * Abstract base class for the ComponentDirective.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public abstract class DeploymentDirective extends Composite implements
Comparable
-{
-
//--------------------------------------------------------------------------
- // static
-
//--------------------------------------------------------------------------
-
- /**
- * Serial version identifier.
- */
- static final long serialVersionUID = 1L;
-
- private static final CategoriesDirective EMPTY_CATEGORIES =
- new CategoriesDirective();
-
-
//--------------------------------------------------------------------------
- // state
-
//--------------------------------------------------------------------------
-
- /**
- * The name of the component profile. This is an
- * abstract name used during assembly.
- */
- private final String m_name;
-
- /**
- * The activation policy.
- */
- private final ActivationPolicy m_activation;
-
- /**
- * Logging category directives.
- */
- private final CategoriesDirective m_categories;
-
-
//--------------------------------------------------------------------------
- // constructor
-
//--------------------------------------------------------------------------
-
- /**
- * Creation of a new deployment profile instance.
- * @param name the profile name
- * @param activation the activation policy
- * @param categories logging category directives
- * @param parts the internal component parts
- */
- public DeploymentDirective(
- final String name, ActivationPolicy activation, CategoriesDirective
categories, PartReference[] parts )
- {
- super( parts );
-
- m_activation = activation;
-
- if( null == categories )
- {
- m_categories = EMPTY_CATEGORIES;
- }
- else
- {
- m_categories = categories;
- }
-
- if( null != name )
- {
- if( name.indexOf( " " ) > 0 || name.indexOf( "." ) > 0 ||
name.indexOf( "," ) > 0
- || name.indexOf( "/" ) > 0 )
- {
- final String error =
- "Directive name ["
- + name
- + "] contains an illegal character (' ', ',', or '.')";
- throw new IllegalArgumentException( error );
- }
- else if( name.length() == 0 )
- {
- final String error =
- "Directive name [] is not sufficiently descriptor.";
- throw new IllegalArgumentException( error );
- }
- else
- {
- m_name = name;
- }
- }
- else
- {
- throw new NullPointerException( "name" );
- }
- }
-
-
//--------------------------------------------------------------------------
- // implementation
-
//--------------------------------------------------------------------------
-
- /**
- * Return the profile name.
- *
- * @return the name of the component.
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * Return the logging categories for the profile.
- *
- * @return the categories
- */
- public CategoriesDirective getCategoriesDirective()
- {
- return m_categories;
- }
-
- /**
- * Get the activation policy for the profile.
- *
- * @return the declared activation policy
- * @see ActivationPolicy#SYSTEM
- * @see ActivationPolicy#STARTUP
- * @see ActivationPolicy#DEMAND
- */
- public ActivationPolicy getActivationPolicy()
- {
- return m_activation;
- }
-
- /**
- * Returns a string representation of the profile.
- * @return a string representation
- */
- public String toString()
- {
- return "[" + getName() + "]";
- }
-
- /**
- * Compare this object with the supplied object.
- * @param object the obvject to compare with
- * @return the result
- */
- public int compareTo( Object object )
- {
- String name = this.toString();
- String other = object.toString();
- return name.compareTo( other );
- }
-
- /**
- * Test if the supplied object is equal to this object.
- * @param other the object to compare with this instance
- * @return TRUE if the supplied object is equal to this object
- */
- public boolean equals( Object other )
- {
- if( !super.equals( other ) )
- {
- return false;
- }
- else
- {
- if( other instanceof DeploymentDirective )
- {
- DeploymentDirective profile = (DeploymentDirective) other;
- if( !m_name.equals( profile.getName() ) )
- {
- return false;
- }
- else if( !m_activation.equals( profile.getActivationPolicy()
) )
- {
- return false;
- }
- else
- {
- return m_categories.equals(
profile.getCategoriesDirective() );
- }
- }
- else
- {
- return false;
- }
- }
- }
-
- /**
- * Return the hashcode for the instance.
- * @return the instance hashcode
- */
- public int hashCode()
- {
- int hash = super.hashCode();
- hash ^= m_name.hashCode();
- hash ^= m_activation.hashCode();
- hash ^= m_categories.hashCode();
- return hash;
- }
-}
Modified:
trunk/main/metro/model/src/test/net/dpml/metro/data/test/ComponentDirectiveTestCase.java
===================================================================
---
trunk/main/metro/model/src/test/net/dpml/metro/data/test/ComponentDirectiveTestCase.java
2006-07-04 07:42:22 UTC (rev 1536)
+++
trunk/main/metro/model/src/test/net/dpml/metro/data/test/ComponentDirectiveTestCase.java
2006-07-05 07:25:28 UTC (rev 1537)
@@ -18,6 +18,8 @@
package net.dpml.metro.data.test;
+import java.net.URI;
+
import net.dpml.metro.data.ComponentDirective;
import net.dpml.metro.data.CategoriesDirective;
import net.dpml.metro.data.CategoryDirective;
@@ -46,6 +48,7 @@
private ContextDirective m_context;
private ComponentDirective m_directive;
private PartReference[] m_parts;
+ private URI m_base;
/**
* Setup the test case.
@@ -68,10 +71,11 @@
}
);
m_parts = new PartReference[0];
+ m_base = new URI( "local:part:org/acme/widget" );
m_directive =
new ComponentDirective(
m_name, m_activation, m_collection, m_lifestyle, m_classname,
- m_categories, m_context, m_parts );
+ m_categories, m_context, m_parts, m_base );
}
/**
@@ -102,7 +106,7 @@
{
new ComponentDirective(
"", m_activation, m_collection, m_lifestyle, m_classname,
- m_categories, m_context, null );
+ m_categories, m_context, null, null );
fail( "Did not throw an IllegalArgumentException for a '' name."
);
}
catch( IllegalArgumentException e )
@@ -120,7 +124,7 @@
{
new ComponentDirective(
"fred.blogs", m_activation, m_collection, m_lifestyle,
m_classname,
- m_categories, m_context, null );
+ m_categories, m_context, null, null );
fail( "Did not throw an IllegalArgumentException for a name with
a period." );
}
catch( IllegalArgumentException e )
@@ -138,7 +142,7 @@
{
new ComponentDirective(
"fred,blogs", m_activation, m_collection, m_lifestyle,
m_classname,
- m_categories, m_context, null );
+ m_categories, m_context, null, null );
fail( "Did not throw an IllegalArgumentException for a name with
a comma." );
}
catch( IllegalArgumentException e )
@@ -156,7 +160,7 @@
{
new ComponentDirective(
"fred/blogs", m_activation, m_collection, m_lifestyle,
m_classname,
- m_categories, m_context, null );
+ m_categories, m_context, null, null );
fail( "Did not throw an IllegalArgumentException for a name with
a '/'." );
}
catch( IllegalArgumentException e )
@@ -196,7 +200,7 @@
{
ComponentDirective directive = new ComponentDirective(
m_name, m_activation, m_collection, null, m_classname,
- m_categories, m_context, m_parts );
+ m_categories, m_context, m_parts, null );
LifestylePolicy lifestyle = directive.getLifestylePolicy();
assertEquals( "null-lifestyle", null, lifestyle );
}
@@ -210,6 +214,14 @@
}
/**
+ * Test base accessor.
+ */
+ public void testBase()
+ {
+ assertEquals( "base", m_base, m_directive.getBaseDirective() );
+ }
+
+ /**
* Test categories accessor.
*/
public void testCategories()
@@ -241,11 +253,11 @@
ComponentDirective a = new ComponentDirective(
m_name, m_activation, m_collection, m_lifestyle, m_classname,
- m_categories, m_context, m_parts );
+ m_categories, m_context, m_parts, m_base );
ComponentDirective b = new ComponentDirective(
m_name, m_activation, m_collection, m_lifestyle, m_classname,
- m_categories, context, m_parts );
+ m_categories, context, m_parts, m_base );
if( a.equals( b ) )
{
Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentDecoder.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentDecoder.java
2006-07-04 07:42:22 UTC (rev 1536)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentDecoder.java
2006-07-05 07:25:28 UTC (rev 1537)
@@ -127,12 +127,36 @@
CategoriesDirective categories = getNestedCategoriesDirective(
element );
ContextDirective context = getNestedContextDirective( element );
PartReference[] parts = getNestedParts( element );
+ URI base = getBaseURI( element );
return new ComponentDirective(
name, activation, collection, lifestyle, classname,
- categories, context, parts );
+ categories, context, parts, base );
}
+ private URI getBaseURI( Element element ) throws DecodingException
+ {
+ String base = ElementHelper.getAttribute( element, "extends" );
+ if( null == base )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return new URI( base );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to resolve the URI declared as under the 'extends'
attribute."
+ + "\n URI: " + base;
+ throw new DecodingException( element, error );
+ }
+ }
+ }
+
private String buildComponentClassname( Element element ) throws
DecodingException
{
String classname = ElementHelper.getAttribute( element, "type" );
Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentEncoder.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentEncoder.java
2006-07-04 07:42:22 UTC (rev 1536)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentEncoder.java
2006-07-05 07:25:28 UTC (rev 1537)
@@ -198,6 +198,11 @@
{
writer.write( "\n" + pad + " activation=\"" +
activation.getName() + "\"" );
}
+ URI base = directive.getBaseDirective();
+ if( null != base )
+ {
+ writer.write( "\n" + pad + " extends=\"" + base.toASCIIString()
+ "\"" );
+ }
writer.write( ">" );
}
- r1537 - in trunk/main: lang/component/etc metro/model/src/main/net/dpml/metro/data metro/model/src/test/net/dpml/metro/data/test metro/runtime/src/main/net/dpml/metro/builder, mcconnell at BerliOS, 07/05/2006
Archive powered by MHonArc 2.6.24.