Skip to Content.
Sympa Menu

notify-dpml - r1899 - in trunk/main/metro/part/src: main/net/dpml/runtime test/net/dpml/runtime/lifestyle

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: r1899 - in trunk/main/metro/part/src: main/net/dpml/runtime test/net/dpml/runtime/lifestyle
  • Date: Mon, 12 Mar 2007 20:33:57 +0100

Author: mcconnell
Date: 2007-03-12 20:33:56 +0100 (Mon, 12 Mar 2007)
New Revision: 1899

Modified:
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategy.java

trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategyHandler.java
trunk/main/metro/part/src/main/net/dpml/runtime/Profile.java

trunk/main/metro/part/src/test/net/dpml/runtime/lifestyle/TransientTestCase.java
Log:
updating the component model to properly support overriding of lifestyle and
collection policies

Modified:
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategy.java
===================================================================
--- trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategy.java
2007-03-12 04:57:06 UTC (rev 1898)
+++ trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategy.java
2007-03-12 19:33:56 UTC (rev 1899)
@@ -106,27 +106,30 @@
* @param priority the component priority
* @param type the component class
* @param activation the activation policy
+ * @param lifestyle the lifestyle policy
* @param context the context model
* @param parts the internal part structure
* @exception IOException if an IO error occurs
*/
ComponentStrategy(
final String partition, final String name, int priority, final Class
type,
- ActivationPolicy activation, ContextModel context, PartsDirective
parts )
+ ActivationPolicy activation, LifestylePolicy lifestyle,
CollectionPolicy collection,
+ ContextModel context, PartsDirective parts )
throws IOException
{
super( type.getClassLoader() );

m_class = type;
m_priority = priority;
+ m_activation = activation;
+ m_lifestyle = lifestyle;
+ m_collection = collection;
+ m_context = context;
+
m_name = getComponentName( name, m_class );
- m_collection = getCollectionPolicy( m_class );
- m_lifestyle = getLifestylePolicy( m_class );
m_path = getComponentPath( partition, m_name, m_class );
- m_context = context;
m_logger = getComponentLogger( m_path );
m_graph = getLifecycleGraph( m_class );
- m_activation = activation;
m_parts = getPartsDirective( parts );

m_parts.initialize( this );
@@ -392,17 +395,29 @@
return m_logger;
}

- CollectionPolicy getCollectionPolicy()
+ /**
+ * Return the assigned collection policy.
+ * @return the collection policy
+ */
+ public CollectionPolicy getCollectionPolicy()
{
return m_collection;
}

- LifestylePolicy getLifestylePolicy()
+ /**
+ * Return the assigned lifestyle policy.
+ * @return the lifestyle policy
+ */
+ public LifestylePolicy getLifestylePolicy()
{
return m_lifestyle;
}

- ActivationPolicy getActivationPolicy()
+ /**
+ * Return the assigned activation policy.
+ * @return the activation policy
+ */
+ public ActivationPolicy getActivationPolicy()
{
return m_activation;
}
@@ -444,7 +459,7 @@
return c.cast( provider );
}
}
- else if( ( c == Component.class ) || ( c == Strategy.class ) )
+ else if( c.isAssignableFrom( getClass() ) )
{
return c.cast( this );
}
@@ -773,30 +788,6 @@
return CollectionPolicy.HARD;
}

- private static LifestylePolicy getLifestylePolicy( Class<?> c )
- {
- if( c.isAnnotationPresent( net.dpml.annotation.Component.class ) )
- {
- net.dpml.annotation.Component annotation =
- c.getAnnotation( net.dpml.annotation.Component.class );
- return annotation.lifestyle();
- }
- return LifestylePolicy.THREAD;
- }
-
- /*
- private static ActivationPolicy getActivationPolicy( Class<?> c )
- {
- if( c.isAnnotationPresent( Activation.class ) )
- {
- Activation annotation =
- c.getAnnotation( Activation.class );
- return annotation.value();
- }
- return ActivationPolicy.SYSTEM;
- }
- */
-
private static State getLifecycleGraph( Class<?> c ) throws IOException
{
String name = getComponentNameFromClass( c );
@@ -860,6 +851,10 @@

private static final String NAMESPACE =
ComponentStrategyHandler.NAMESPACE;

+ /**
+ * Returns the string representing of the component.
+ * @return the component as a string
+ */
public String toString()
{
return getComponentPath();

Modified:
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategyHandler.java
===================================================================
---
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategyHandler.java
2007-03-12 04:57:06 UTC (rev 1898)
+++
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategyHandler.java
2007-03-12 19:33:56 UTC (rev 1899)
@@ -39,6 +39,8 @@

import net.dpml.annotation.Activation;
import net.dpml.annotation.ActivationPolicy;
+import net.dpml.annotation.LifestylePolicy;
+import net.dpml.annotation.CollectionPolicy;

import net.dpml.util.Resolver;
import net.dpml.util.Logger;
@@ -69,7 +71,9 @@
Profile profile = new Profile( c, spec, null );
ContextModel context = getContextModel( null, c, spec, profile,
null, null, null );
PartsDirective parts = profile.getPartsDirective();
- return new ComponentStrategy( null, spec, 0, c,
ActivationPolicy.SYSTEM, context, parts );
+ return new ComponentStrategy(
+ null, spec, 0, c, ActivationPolicy.SYSTEM, LifestylePolicy.THREAD,
+ CollectionPolicy.HARD, context, parts );
}

public Component newComponent( Class<?> c, String name ) throws
IOException
@@ -100,6 +104,8 @@
Element contextElement = ElementHelper.getChild( element, "context"
);
ContextModel context = getContextModel( classloader, c, path,
profile, contextElement, resolver, q );
ActivationPolicy activation = getActivationPolicy( element, profile,
c );
+ LifestylePolicy lifestyle = getLifestylePolicy( element, profile, c
);
+ CollectionPolicy collection = getCollectionPolicy( element, profile,
c );

try
{
@@ -119,6 +125,8 @@
priority,
c,
activation,
+ lifestyle,
+ collection,
context,
parts );

@@ -170,6 +178,62 @@
return ActivationPolicy.SYSTEM;
}

+ /**
+ * Return the lifestyle policy.
+ *
+ * @return the resolved lifestyle policy
+ */
+ private static LifestylePolicy getLifestylePolicy( Element element,
Profile profile, Class<?> c )
+ {
+ if( null != element )
+ {
+ String value = ElementHelper.getAttribute( element, "lifestyle"
);
+ if( null != value )
+ {
+ return LifestylePolicy.valueOf( value.toUpperCase() );
+ }
+ }
+ if( null != profile )
+ {
+ return profile.getLifestylePolicy();
+ }
+ if( c.isAnnotationPresent( net.dpml.annotation.Component.class ) )
+ {
+ net.dpml.annotation.Component annotation =
+ c.getAnnotation( net.dpml.annotation.Component.class );
+ return annotation.lifestyle();
+ }
+ return LifestylePolicy.THREAD;
+ }
+
+ /**
+ * Return the collection policy.
+ *
+ * @return the resolved collection policy
+ */
+ private static CollectionPolicy getCollectionPolicy( Element element,
Profile profile, Class<?> c )
+ {
+ if( null != element )
+ {
+ String value = ElementHelper.getAttribute( element, "collection"
);
+ if( null != value )
+ {
+ return CollectionPolicy.valueOf( value.toUpperCase() );
+ }
+ }
+ if( null != profile )
+ {
+ return profile.getCollectionPolicy();
+ }
+ if( c.isAnnotationPresent( net.dpml.annotation.Component.class ) )
+ {
+ net.dpml.annotation.Component annotation =
+ c.getAnnotation( net.dpml.annotation.Component.class );
+ return annotation.collection();
+ }
+ return CollectionPolicy.HARD;
+ }
+
private int getPriority( Element element, Resolver resolver )
{
String value = ElementHelper.getAttribute( element, "priority",
null, resolver );

Modified: trunk/main/metro/part/src/main/net/dpml/runtime/Profile.java
===================================================================
--- trunk/main/metro/part/src/main/net/dpml/runtime/Profile.java
2007-03-12 04:57:06 UTC (rev 1898)
+++ trunk/main/metro/part/src/main/net/dpml/runtime/Profile.java
2007-03-12 19:33:56 UTC (rev 1899)
@@ -26,6 +26,8 @@

import net.dpml.annotation.Activation;
import net.dpml.annotation.ActivationPolicy;
+import net.dpml.annotation.LifestylePolicy;
+import net.dpml.annotation.CollectionPolicy;

import net.dpml.util.Resolver;

@@ -50,6 +52,8 @@
private ContextDirective m_context;
private PartsDirective m_parts;
private ActivationPolicy m_activation;
+ private LifestylePolicy m_lifestyle;
+ private CollectionPolicy m_collection;

/**
* Creation of a new profile using a supplied class, path and property
resolver.
@@ -65,6 +69,8 @@
m_context = getContextProfile( classloader, m_element, resolver );
m_parts = getPartsProfile( classloader, m_element, resolver, path );
m_activation = getActivationPolicy( m_element, c );
+ m_lifestyle = getLifestylePolicy( m_element, c );
+ m_collection = getCollectionPolicy( m_element, c );
}

ContextDirective getContextDirective()
@@ -82,6 +88,16 @@
return m_activation;
}

+ LifestylePolicy getLifestylePolicy()
+ {
+ return m_lifestyle;
+ }
+
+ CollectionPolicy getCollectionPolicy()
+ {
+ return m_collection;
+ }
+
private static Element getProfileElement( Class<?> c ) throws IOException
{
ClassLoader classloader = c.getClassLoader();
@@ -119,29 +135,79 @@
*
* @return the resolved activation policy
*/
- private static ActivationPolicy getActivationPolicy( Element element,
Class<?> c )
+ private static ActivationPolicy getActivationPolicy( final Element
element, final Class<?> c )
{
if( null == element )
{
- return ActivationPolicy.SYSTEM;
+ String value = ElementHelper.getAttribute( element, "activation"
);
+ if( null != value )
+ {
+ return ActivationPolicy.valueOf( value.toUpperCase() );
+ }
}
- String value = ElementHelper.getAttribute( element, "activation" );
- if( null == value )
+ if( c.isAnnotationPresent( Activation.class ) )
{
- if( c.isAnnotationPresent( Activation.class ) )
+ Activation annotation =
+ c.getAnnotation( Activation.class );
+ return annotation.value();
+ }
+ return ActivationPolicy.SYSTEM;
+ }
+
+ /**
+ * Return the lifestyle policy. If the element declares the lifestyle
attribute
+ * that value (resolved to the policy enum) is returned, otherwise the
class is checked for
+ * the declaration of an explicit lifestyle policy and if present the
value is returned,
+ * otherwise the default THREAD policy is returned.
+ *
+ * @return the resolved lifestyle policy
+ */
+ private static LifestylePolicy getLifestylePolicy( final Element
element, final Class<?> c )
+ {
+ if( null != element )
+ {
+ String value = ElementHelper.getAttribute( element, "lifestyle"
);
+ if( null != value )
{
- Activation annotation =
- c.getAnnotation( Activation.class );
- return annotation.value();
+ return LifestylePolicy.valueOf( value.toUpperCase() );
}
- return ActivationPolicy.SYSTEM;
}
- else
+ if( c.isAnnotationPresent( net.dpml.annotation.Component.class ) )
{
- return ActivationPolicy.valueOf( value.toUpperCase() );
+ net.dpml.annotation.Component annotation =
+ c.getAnnotation( net.dpml.annotation.Component.class );
+ return annotation.lifestyle();
}
+ return LifestylePolicy.THREAD;
}

+ /**
+ * Return the collection policy. If the element declares the collection
attribute
+ * that value (resolved to the policy enum) is returned, otherwise the
class is checked for
+ * the declaration of an explicit collection policy and if present the
value is returned,
+ * otherwise the default HARD policy is returned.
+ *
+ * @return the resolved lifestyle policy
+ */
+ private static CollectionPolicy getCollectionPolicy( final Element
element, final Class<?> c )
+ {
+ if( null != element )
+ {
+ String value = ElementHelper.getAttribute( element, "collection"
);
+ if( null != value )
+ {
+ return CollectionPolicy.valueOf( value.toUpperCase() );
+ }
+ }
+ if( c.isAnnotationPresent( net.dpml.annotation.Component.class ) )
+ {
+ net.dpml.annotation.Component annotation =
+ c.getAnnotation( net.dpml.annotation.Component.class );
+ return annotation.collection();
+ }
+ return CollectionPolicy.HARD;
+ }
+
private static ContextDirective getContextProfile(
ClassLoader classloader, Element profile, Resolver resolver ) throws
IOException
{

Modified:
trunk/main/metro/part/src/test/net/dpml/runtime/lifestyle/TransientTestCase.java
===================================================================
---
trunk/main/metro/part/src/test/net/dpml/runtime/lifestyle/TransientTestCase.java
2007-03-12 04:57:06 UTC (rev 1898)
+++
trunk/main/metro/part/src/test/net/dpml/runtime/lifestyle/TransientTestCase.java
2007-03-12 19:33:56 UTC (rev 1899)
@@ -18,9 +18,11 @@

package net.dpml.runtime.lifestyle;

+import net.dpml.annotation.LifestylePolicy;
import net.dpml.runtime.AbstractTestCase;

import net.dpml.runtime.Component;
+import net.dpml.runtime.ComponentStrategy;

import org.acme.DefaultWidget;
import org.acme.Widget;
@@ -34,7 +36,8 @@
{
public void testEquality() throws Exception
{
- Component component = load( Component.class, "transient.xml",
"transient" );
+ ComponentStrategy component = load( ComponentStrategy.class,
"transient.xml", "transient" );
+ assertEquals( "lifestyle", component.getLifestylePolicy(),
LifestylePolicy.TRANSIENT );
Widget w1 = component.getProvider().getInstance( DefaultWidget.class
);
Widget w2 = component.getProvider().getInstance( DefaultWidget.class
);
if( w1 == w2 )




  • r1899 - in trunk/main/metro/part/src: main/net/dpml/runtime test/net/dpml/runtime/lifestyle, mcconnell at BerliOS, 03/12/2007

Archive powered by MHonArc 2.6.24.

Top of Page