mcconnell 2003/10/19 03:31:01
Modified:
merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl
DefaultAppliance.java
merlin/activation/impl/src/java/org/apache/avalon/activation/lifestyle/impl
AbstractLifestyleHandler.java
merlin/composition/api/src/java/org/apache/avalon/composition/data
DeploymentProfile.java
merlin/composition/api/src/java/org/apache/avalon/composition/model
DeploymentModel.java
merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder
XMLDeploymentProfileCreator.java
merlin/composition/impl/src/java/org/apache/avalon/composition/data/writer
XMLDeploymentProfileWriter.java
merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
DefaultDeploymentModel.java
merlin/composition/impl/src/test/org/apache/avalon/composition/data/test
DeploymentProfileTestCase.java
Log:
Update to handle ranked policy.
Revision Changes Path
1.6 +8 -3
avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/DefaultAppliance.java
Index: DefaultAppliance.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/DefaultAppliance.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultAppliance.java 19 Oct 2003 06:12:58 -0000 1.5
+++ DefaultAppliance.java 19 Oct 2003 10:31:00 -0000 1.6
@@ -636,7 +636,6 @@
{
getLogger().warn( "ignoring release stage error", e );
}
- getLogger().debug( "destroyed instance: " + id );
}
//-------------------------------------------------------------------
@@ -1229,7 +1228,13 @@
if( !m_disposed )
{
final String message =
- "Releasing finalized component in [" + m_model.getQualifiedName()
+ "].";
+ "Releasing component ["
+ + System.identityHashCode( m_instance ) + "] ("
+ + m_model.getType().getInfo().getLifestyle()
+ + "/"
+ + InfoDescriptor.getCollectionPolicyKey(
+ m_model.getCollectionPolicy() )
+ + ").";
getLogger().debug( message );
release( m_instance, true );
}
1.5 +4 -4
avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/lifestyle/impl/AbstractLifestyleHandler.java
Index: AbstractLifestyleHandler.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/lifestyle/impl/AbstractLifestyleHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractLifestyleHandler.java 19 Oct 2003 06:12:58 -0000 1.4
+++ AbstractLifestyleHandler.java 19 Oct 2003 10:31:00 -0000 1.5
@@ -98,12 +98,12 @@
Reference getReference( Object instance )
{
- final String policy =
getFactory().getDeploymentModel().getCollectionPolicy();
- if( policy.equals( InfoDescriptor.LIBERAL ) )
+ final int policy = getFactory().getDeploymentModel().getCollectionPolicy();
+ if( policy == InfoDescriptor.LIBERAL )
{
return new WeakReference( instance, m_liberals );
}
- else if( policy.equals( InfoDescriptor.DEMOCRAT ) )
+ else if( policy == InfoDescriptor.DEMOCRAT )
{
return new SoftReference( instance );
}
1.4 +6 -6
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/data/DeploymentProfile.java
Index: DeploymentProfile.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/data/DeploymentProfile.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DeploymentProfile.java 19 Oct 2003 06:12:58 -0000 1.3
+++ DeploymentProfile.java 19 Oct 2003 10:31:01 -0000 1.4
@@ -148,7 +148,7 @@
/**
* The collection policy override.
*/
- private String m_collection;
+ private int m_collection;
/**
* The component classname.
@@ -201,7 +201,7 @@
final String classname )
{
this(
- name, false, InfoDescriptor.LIBERAL, classname, null, null, null, null,
+ name, false, InfoDescriptor.UNDEFINED, classname, null, null, null, null,
null, null, Mode.IMPLICIT );
}
@@ -229,7 +229,7 @@
public DeploymentProfile(
final String name,
final boolean activation,
- final String collection,
+ final int collection,
final String classname,
final CategoriesDirective categories,
final ContextDirective context,
@@ -285,9 +285,9 @@
* Return the component collection policy. If null, the component
* type collection policy will apply.
*
- * @return a LIBERAL, DEMOCRAT, CONSERVATIVE or null
+ * @return a LIBERAL, DEMOCRAT, CONSERVATIVE or UNDEFINED
*/
- public String getCollectionPolicy()
+ public int getCollectionPolicy()
{
return m_collection;
}
1.4 +13 -2
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/DeploymentModel.java
Index: DeploymentModel.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/DeploymentModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DeploymentModel.java 19 Oct 2003 06:12:58 -0000 1.3
+++ DeploymentModel.java 19 Oct 2003 10:31:01 -0000 1.4
@@ -89,7 +89,18 @@
* @see org.apache.avalon.meta.info.InfoDescriptor#DEMOCRAT
* @see org.apache.avalon.meta.info.InfoDescriptor#CONSERVATIVE
*/
- String getCollectionPolicy();
+ int getCollectionPolicy();
+
+ /**
+ * Set the collection policy to a supplied value.
+ *
+ * @param the collection policy
+ * @see org.apache.avalon.meta.info.InfoDescriptor#LIBERAL
+ * @see org.apache.avalon.meta.info.InfoDescriptor#DEMOCRAT
+ * @see org.apache.avalon.meta.info.InfoDescriptor#CONSERVATIVE
+ * @see org.apache.avalon.meta.info.InfoDescriptor#UNDEFINED
+ */
+ void setCollectionPolicy( int policy );
/**
* Return the logging categories.
1.4 +6 -5
avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLDeploymentProfileCreator.java
Index: XMLDeploymentProfileCreator.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLDeploymentProfileCreator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLDeploymentProfileCreator.java 19 Oct 2003 06:12:58 -0000 1.3
+++ XMLDeploymentProfileCreator.java 19 Oct 2003 10:31:01 -0000 1.4
@@ -59,6 +59,7 @@
import org.apache.avalon.composition.data.DependencyDirective;
import org.apache.avalon.composition.data.SelectionDirective;
import org.apache.avalon.composition.data.*;
+import org.apache.avalon.meta.info.InfoDescriptor;
import org.apache.excalibur.configuration.ConfigurationUtil;
/**
@@ -108,7 +109,7 @@
throws Exception
{
final boolean activation = getActivationPolicy( config, true );
- final String collection = getCollectionPolicy( config );
+ final int collection = getCollectionPolicy( config );
final CategoriesDirective categories =
getCategoriesDirective( config.getChild( "categories", false ), name );
@@ -134,11 +135,11 @@
* policy shall default to the component type collection policy.
*
* @param config a configuration fragment holding a collection attribute
- * @return collection policy or null if not declared
+ * @return collection policy
*/
- protected String getCollectionPolicy( Configuration config )
+ protected int getCollectionPolicy( Configuration config )
{
- return config.getAttribute( "collection", null );
+ return InfoDescriptor.getCollectionPolicy( config.getAttribute(
"collection", null ) );
}
protected DependencyDirective[] getDependencyDirectives( Configuration config )
1.3 +7 -3
avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/writer/XMLDeploymentProfileWriter.java
Index: XMLDeploymentProfileWriter.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/writer/XMLDeploymentProfileWriter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLDeploymentProfileWriter.java 19 Oct 2003 06:12:58 -0000 1.2
+++ XMLDeploymentProfileWriter.java 19 Oct 2003 10:31:01 -0000 1.3
@@ -70,6 +70,7 @@
import org.apache.avalon.composition.data.ConstructorDirective;
import org.apache.avalon.composition.data.StageDirective;
import org.apache.avalon.composition.data.Parameter;
+import org.apache.avalon.meta.info.InfoDescriptor;
import org.apache.excalibur.configuration.ConfigurationUtil;
/**
@@ -98,18 +99,21 @@
writer.write( pad + "<component name=\"" + profile.getName() + "\"");
writer.write( "\n" + pad + " class=\"" + profile.getClassname() + "\"");
+
if( !profile.getActivationPolicy() )
{
writer.write(
"\n" + pad
+ " activation=\"false\"" );
}
- if( profile.getCollectionPolicy() != null )
+
+ final int collection = profile.getCollectionPolicy();
+ if( collection > InfoDescriptor.UNDEFINED )
{
writer.write(
"\n" + pad
+ " collection=\""
- + profile.getCollectionPolicy()
+ + InfoDescriptor.getCollectionPolicyKey( collection )
+ "\"" );
}
1.4 +43 -40
avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java
Index: DefaultDeploymentModel.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultDeploymentModel.java 19 Oct 2003 06:12:58 -0000 1.3
+++ DefaultDeploymentModel.java 19 Oct 2003 10:31:01 -0000 1.4
@@ -139,6 +139,8 @@
private boolean m_activation;
+ private int m_collection;
+
//==============================================================
// constructor
//==============================================================
@@ -161,6 +163,8 @@
m_activation = m_context.getProfile().getActivationPolicy();
m_categories = m_context.getProfile().getCategories();
+ setCollectionPolicy( m_context.getProfile().getCollectionPolicy() );
+
ClassLoader classLoader = m_context.getClassLoader();
if( isConfigurable() )
@@ -312,7 +316,7 @@
/**
* Return the collection policy for the model. If a profile
* does not declare a collection policy, then the collection
- * policy declareed by the underrlying component type
+ * policy declared by the underlying component type
* will be used.
*
* @return the collection policy
@@ -320,55 +324,54 @@
* @see InfoDescriptor#DEMOCRAT
* @see InfoDescriptor#CONSERVATIVE
*/
- public String getCollectionPolicy()
+ public int getCollectionPolicy()
{
- final String policy = m_context.getProfile().getCollectionPolicy();
- if( policy != null )
+ if( m_collection == InfoDescriptor.UNDEFINED )
{
- if( policy.equalsIgnoreCase( InfoDescriptor.LIBERAL ) )
- {
- return InfoDescriptor.LIBERAL;
- }
- else if( policy.equalsIgnoreCase( InfoDescriptor.DEMOCRAT ) )
- {
- return InfoDescriptor.DEMOCRAT;
- }
- else if( policy.equalsIgnoreCase( InfoDescriptor.CONSERVATIVE ) )
- {
- return InfoDescriptor.CONSERVATIVE;
- }
- else
- {
- final String warning =
- "Overriding collection policy argument [" + policy + "] is not
recognized. "
- + "Reverting to CONSERVATIVE policy.";
- return InfoDescriptor.CONSERVATIVE;
- }
+ return getTypeCollectionPolicy();
}
else
{
- //if( isStartable() )
- //{
- // return InfoDescriptor.CONSERVATIVE;
- //}
- //else
- //{
- return m_context.getType().getInfo().getCollectionPolicy();
- //}
+ return m_collection;
}
}
/**
- * Rest if the component type backing the model is
- * startable.
+ * Set the collection policy for the model.
*
- * @return TRUE if the component type is startable
- * otherwise FALSE
+ * @param the collection policy
+ * @see InfoDescriptor#LIBERAL
+ * @see InfoDescriptor#DEMOCRAT
+ * @see InfoDescriptor#CONSERVATIVE
*/
- //public boolean isStartable()
- //{
- // return Startable.class.isAssignableFrom( getDeploymentClass() );
- //}
+ public void setCollectionPolicy( int policy )
+ {
+ if( policy == InfoDescriptor.UNDEFINED )
+ {
+ m_collection = InfoDescriptor.UNDEFINED;
+ }
+ else
+ {
+ int minimum = getTypeCollectionPolicy();
+ if( policy >= minimum )
+ {
+ m_collection = policy;
+ }
+ else
+ {
+ final String warning =
+ "Ignoring collection policy override [" + policy
+ + "] because the value is higher that type threshhold [" +
minimum + "].";
+ getLogger().warn( warning );
+ }
+ }
+ }
+
+ private int getTypeCollectionPolicy()
+ {
+ return m_context.getType().getInfo().getCollectionPolicy();
+ }
+
/**
* Set categories.
1.3 +2 -2
avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/data/test/DeploymentProfileTestCase.java
Index: DeploymentProfileTestCase.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/data/test/DeploymentProfileTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DeploymentProfileTestCase.java 19 Oct 2003 06:12:58 -0000 1.2
+++ DeploymentProfileTestCase.java 19 Oct 2003 10:31:01 -0000 1.3
@@ -81,7 +81,7 @@
private StageDirective[] m_stages;
private String m_name;
private String m_classname;
- private String m_collection;
+ private int m_collection;
public DeploymentProfileTestCase( String name )
{
@@ -101,7 +101,7 @@
m_activation = true;
m_mode = Mode.IMPLICIT;
m_categories = new CategoriesDirective( new CategoryDirective[0] );
- m_collection = InfoDescriptor.CONSERVATIVE;
+ m_collection = InfoDescriptor.DEMOCRAT;
}
public void testProfile() throws ContextException
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]