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 2003/04/03 16:36:45 UTC
cvs commit: avalon-sandbox/merlin/merlin-smp/xdocs/starting/hello config.xml
mcconnell 2003/04/03 06:36:45
Modified: merlin/merlin-smp/xdocs/starting/hello config.xml
Log:
Updating to provide information about configuration of a component and the related configuration handling mechanisms used within Merlin.
Revision Changes Path
1.2 +116 -1 avalon-sandbox/merlin/merlin-smp/xdocs/starting/hello/config.xml
Index: config.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/merlin-smp/xdocs/starting/hello/config.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- config.xml 2 Apr 2003 15:52:17 -0000 1.1
+++ config.xml 3 Apr 2003 14:36:44 -0000 1.2
@@ -10,7 +10,122 @@
<body>
<section name="Using Merlin">
<subsection name="Managing Configurations">
- <p>In preparation.</p>
+ <p>
+ This tutorial presents information about the configuration
+ of components and how you can use Merlin to simplify the
+ the end-user experience in handling the declaration and
+ of configuration information to your component.
+ </p>
+ <p>
+ Resource supporting this tutorial are contained in the
+ turorial/002 package.
+ </p>
+ </subsection>
+
+ <subsection name="Adding configuration support to the component">
+ <p>
+ To be supplied with a configuration, our component must implement
+ the Avalon Framework Configurable interface. The following code
+ is the HelloComponent extended to include implementation of
+ Configurable, and updates to the inialize method to log the source
+ of the configuration based on runtime information.
+ </p>
+<source>
+package tutorial;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+
+public class HelloComponent extends AbstractLogEnabled
+ implements Configurable, Initializable
+{
+ private String m_source = "undefined";
+
+ /**
+ * Configuration of the component by the container. The
+ * implementation get a child element named 'source' and
+ * assigns the value of the element to a local variable.
+ *
+ * @param config the component configuration
+ * @exception ConfigurationException if a configuration error occurs
+ */
+ <strong>public void configure( Configuration config ) throws ConfigurationException
+ {
+ getLogger().info( "configuration stage" );
+ m_source = config.getChild( "source" ).getValue( "unknown" );
+ }</strong>
+
+ /**
+ * Initialization of the component by the container.
+ * @exception Exception if an initialization error occurs
+ */
+ public void initialize() throws Exception
+ {
+ getLogger().info( "initialization stage" );
+ final String message =
+ "source: " + m_source;
+ getLogger().info( message );
+ }
+}
+</source>
+ <p>
+ Build and run the tutorial without declaring any configuration.
+ </p>
+ <source>
+$ ant jar
+$ merlin build\classes
+ </source>
+ <p>
+ In the logging output we see that Merlin has created and
+ supplied an empty configuration to the component.
+ </p>
+ <source>
+$ ant jar
+$ merlin build\classes
+[INFO ] (tutorial.hello): configuration stage
+[INFO ] (tutorial.hello): initialization stage
+[INFO ] (tutorial.hello): source: unknown
+ </source>
+
+ </subsection>
+ <subsection name="Updating the block">
+ <p>
+ We can modify the above behaviour at a more general level
+ by including a configuration within the block.xml directive.
+ </p>
+<source><![CDATA[
+<block name="tutorial">
+ <container>
+ <component name="hello" class="tutorial.HelloComponent" activation="startup">
+ <configuration>
+ <source>explicit configuration within block</source>
+ </configuration>
+ </component>
+ </container>
+</block>
+]]></source>
+ <p>
+ Build and run the tutorial again.
+ </p>
+ <source>
+$ ant jar
+$ merlin build\classes
+ </source>
+ <p>
+ In the logging output we see that the configuration
+ supplied to the component has been overrided by the
+ information we supplied inside the <component>
+ directive.
+ </p>
+ <source>
+[INFO ] (tutorial.hello): configuration stage
+[INFO ] (tutorial.hello): initialization stage
+[INFO ] (tutorial.hello): source: explicit configuration within block
+ </source>
+
</subsection>
</section>
</body>
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org