You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2004/02/22 18:28:30 UTC
cvs commit: avalon/merlin/platform/tutorials/dynamics/src/java/tutorial DefaultGizmo.java HelloFacility.java
mcconnell 2004/02/22 09:28:30
Modified: merlin/composition/api/src/java/org/apache/avalon/composition/model
ContextModel.java
merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
DefaultContextModel.java
merlin/platform/tutorials/dynamics/src/java/tutorial
DefaultGizmo.java HelloFacility.java
Log:
Add additional content to the dynamcis tutorial.
Revision Changes Path
1.5 +9 -1 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContextModel.java
Index: ContextModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContextModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ContextModel.java 22 Feb 2004 16:12:58 -0000 1.4
+++ ContextModel.java 22 Feb 2004 17:28:29 -0000 1.5
@@ -72,4 +72,12 @@
*/
void setEntryModel( String key, EntryModel model );
+ /**
+ * Set the entry to a suplied value.
+ *
+ * @param key the entry key
+ * @param value the entry value
+ */
+ void setEntry( String key, Object value );
+
}
1.12 +15 -1 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContextModel.java
Index: DefaultContextModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContextModel.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DefaultContextModel.java 22 Feb 2004 16:22:17 -0000 1.11
+++ DefaultContextModel.java 22 Feb 2004 17:28:30 -0000 1.12
@@ -257,6 +257,20 @@
}
/**
+ * Set the entry to a suplied value.
+ *
+ * @param key the entry key
+ * @param value the entry value
+ */
+ public void setEntry( String key, Object value )
+ {
+ EntryDescriptor descriptor = m_descriptor.getEntry( key );
+ OverrideEntryModel model =
+ new OverrideEntryModel( descriptor, value );
+ setEntryModel( key, model );
+ }
+
+ /**
* Return the class representing the contextualization stage interface.
*
* @return the class representing the contextualization interface
1.3 +13 -10 avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/DefaultGizmo.java
Index: DefaultGizmo.java
===================================================================
RCS file: /home/cvs/avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/DefaultGizmo.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultGizmo.java 22 Feb 2004 16:12:58 -0000 1.2
+++ DefaultGizmo.java 22 Feb 2004 17:28:30 -0000 1.3
@@ -1,9 +1,11 @@
package tutorial;
+import java.io.File;
+
import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
/**
* A component that implements the Gizmo service.
@@ -11,7 +13,7 @@
* @avalon.component name="gizmo" lifestyle="singleton"
* @avalon.service type="tutorial.Gizmo"
*/
-public class DefaultGizmo implements Gizmo, Configurable
+public class DefaultGizmo implements Gizmo, Contextualizable
{
//---------------------------------------------------------
// immutable state
@@ -37,16 +39,17 @@
}
//---------------------------------------------------------
- // configurable
+ // Contextualizable
//---------------------------------------------------------
/**
- * Configuration of the gizmo by the container.
- * @param config the supplied configuration
+ * Contextualization of the gizmo by the container.
+ * @param context the supplied runtime context
+ * @avalon.entry key="urn:avalon:home"
*/
- public void configure( Configuration config ) throws ConfigurationException
+ public void contextualize( Context context ) throws ContextException
{
- final String message = config.getChild( "message" ).getValue( "" );
- m_logger.info( "I've been configured with the message: [" + message + "]" );
+ File home = (File) context.get( "urn:avalon:home" );
+ m_logger.info( "home: " + home );
}
}
1.3 +27 -6 avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/HelloFacility.java
Index: HelloFacility.java
===================================================================
RCS file: /home/cvs/avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/HelloFacility.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HelloFacility.java 22 Feb 2004 16:12:58 -0000 1.2
+++ HelloFacility.java 22 Feb 2004 17:28:30 -0000 1.3
@@ -1,5 +1,7 @@
package tutorial;
+import java.io.File;
+
import org.apache.avalon.composition.model.ContainmentModel;
import org.apache.avalon.composition.model.DeploymentModel;
import org.apache.avalon.composition.model.ComponentModel;
@@ -96,15 +98,11 @@
getLogger().info( "looking for a widget" );
//
- // create a reference to the widget service
+ // create a reference to the widget service and resolve a reference
+ // to a component model using the service reference
//
ReferenceDescriptor reference = new ReferenceDescriptor( Widget.class.getName() );
-
- //
- // get hold of a model representing a widget deployment scenario
- //
-
ComponentModel model = (ComponentModel) m_model.getModel( reference );
getLogger().info( "got a widget model: " + model );
@@ -147,6 +145,29 @@
model.release( widget );
model.decommission();
+ //
+ // that's enought playing around with configurations - lets
+ // grab a gizmo model and fiddle with its context
+ //
+
+ getLogger().info( "lets play with the gizmo" );
+ reference = new ReferenceDescriptor( Gizmo.class.getName() );
+ model = (ComponentModel) m_model.getModel( reference );
+ getLogger().info( "got a gizmo model: " + model );
+
+ //
+ // override the standard home context entry with something
+ // we have derived
+ //
+
+ getLogger().info( "building alternative context entry" );
+ model.getContextModel().setEntry(
+ "urn:avalon:home",
+ new File( System.getProperty( "user.dir" ) ) );
+ model.commission();
+ Gizmo gizmo = (Gizmo) model.resolve();
+ getLogger().info( "got a gizmo: " + gizmo );
+
}
//---------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org