Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2213 - in development/main/metro/composition/testing: acme acme/src/main/net/dpml/composition/testing unit unit/src/test/net/dpml/composition/testing

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2213 - in development/main/metro/composition/testing: acme acme/src/main/net/dpml/composition/testing unit unit/src/test/net/dpml/composition/testing
  • Date: Tue, 05 Apr 2005 15:12:02 -0400

Author: mcconnell AT dpml.net
Date: Tue Apr 5 15:11:57 2005
New Revision: 2213

Added:

development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/Dimension.java

development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/MicroWidget.java

development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/MicroTestCase.java
Modified:
development/main/metro/composition/testing/acme/build.xml
development/main/metro/composition/testing/unit/build.xml
Log:
Add an example demonstrating a constructed context entry.

Modified: development/main/metro/composition/testing/acme/build.xml
==============================================================================
--- development/main/metro/composition/testing/acme/build.xml (original)
+++ development/main/metro/composition/testing/acme/build.xml Tue Apr 5
15:11:57 2005
@@ -12,6 +12,7 @@
<type class="net.dpml.composition.testing.DefaultWidget"/>
<type class="net.dpml.composition.testing.DefaultGizmo"/>
<type class="net.dpml.composition.testing.AcmeContainer"/>
+ <type class="net.dpml.composition.testing.MicroWidget"/>
</types>

<!-- simple component -->

Added:
development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/Dimension.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/Dimension.java
Tue Apr 5 15:11:57 2005
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2004 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.composition.testing;
+
+/**
+ * An example of a multi-parameter class used as a constructed context entry.
+ * The class takes two int values as constructed arguments and proves a
service
+ * of multiplying the two numbers together. The purpose of this class is
simply
+ * to demonstrate how foreign classes can be easily included into a
component
+ * context.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id: CompositionTestCase.java 1393 2005-01-06 10:27:10Z niclas $
+ */
+public class Dimension
+{
+ private int m_x;
+ private int m_y;
+
+ public Dimension( int x, int y )
+ {
+ m_x = x;
+ m_y = y;
+ }
+
+ public int getX()
+ {
+ return m_x;
+ }
+
+ public int getY()
+ {
+ return m_y;
+ }
+
+ public int getSize()
+ {
+ return multiply( m_x, m_y );
+ }
+
+ private int multiply( int x, int y )
+ {
+ int result = 0;
+ if( 1 == x )
+ {
+ return y;
+ }
+ else if( 1 == y )
+ {
+ return x;
+ }
+ else if( ( x % 2) == 0 )
+ {
+ // even number
+ int m = x/2;
+ int subtotal = multiply( m, y );
+ return subtotal + subtotal;
+ }
+ else
+ {
+ // odd number
+ return y + multiply( x-1, y );
+ }
+ }
+}

Added:
development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/MicroWidget.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/MicroWidget.java
Tue Apr 5 15:11:57 2005
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2004 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.composition.testing;
+
+import java.io.File;
+
+import net.dpml.logging.Logger;
+
+/**
+ * Component implementation that demonstrates the use of a context
inner-class.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id: CompositionTestCase.java 1393 2005-01-06 10:27:10Z niclas $
+ */
+public class MicroWidget implements Widget
+{
+ //------------------------------------------------------------------
+ // static
+ //------------------------------------------------------------------
+
+ /**
+ * Declaration to the container that this component is NOT thread-safe.
+ * As such the container will assign a default per-request lifestyle.
+ */
+ public static final boolean TYPE_THREADSAFE_CAPABLE = false;
+
+ //------------------------------------------------------------------
+ // state
+ //------------------------------------------------------------------
+
+ /**
+ * The logging channel.
+ */
+ private final Logger m_logger;
+
+ /**
+ * The component context.
+ */
+ private final Context m_context;
+
+ //------------------------------------------------------------------
+ // constructor
+ //------------------------------------------------------------------
+
+ /**
+ * Creation of a new widget component. The component is assigned
+ * a logging channel and context by the container. The context is
+ * pre-prepared by the container based on the criteria expressed in
+ * the Context inner interface.
+ *
+ * @param logger the logging channel asigned by the container
+ * @param context the assign component context
+ */
+ public MicroWidget( final Logger logger, Context context )
+ {
+ m_logger = logger;
+ m_context = context;
+ }
+
+ //------------------------------------------------------------------
+ // Widget
+ //------------------------------------------------------------------
+
+ /**
+ * Implementation of the widget service contract.
+ */
+ public void doWidgetTypeStuff()
+ {
+ Dimension dimension = m_context.getDimension();
+ int size = dimension.getSize();
+ m_logger.info( "size: " + size );
+ }
+
+ //------------------------------------------------------------------
+ // concerns
+ //------------------------------------------------------------------
+
+ public interface Context
+ {
+ Dimension getDimension();
+ }
+
+}

Modified: development/main/metro/composition/testing/unit/build.xml
==============================================================================
--- development/main/metro/composition/testing/unit/build.xml (original)
+++ development/main/metro/composition/testing/unit/build.xml Tue Apr 5
15:11:57 2005
@@ -7,7 +7,7 @@

<target name="build" depends="standard.build">

- <!-- simple component -->
+ <!-- simple component example -->
<component dest="target/test/acme-simple.part"
xmlns="plugin:dpml/composition/dpml-composition-builder"
class="net.dpml.composition.testing.DefaultWidget"
@@ -22,7 +22,7 @@
</context>
</component>

- <!-- acme container -->
+ <!-- composite component example -->
<component dest="target/test/acme-container.part"
xmlns="plugin:dpml/composition/dpml-composition-builder"
class="net.dpml.composition.testing.AcmeContainer"
@@ -46,6 +46,19 @@
</parts>
</component>

+ <!-- custom context entry example -->
+ <component dest="target/test/acme-micro.part"
+ xmlns="plugin:dpml/composition/dpml-composition-builder"
+ class="net.dpml.composition.testing.MicroWidget"
+ name="widget">
+ <context>
+ <entry key="dimension"
class="net.dpml.composition.testing.Dimension">
+ <value class="int" value="12"/>
+ <value class="int" value="100"/>
+ </entry>
+ </context>
+ </component>
+
</target>

</project>

Added:
development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/MicroTestCase.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/MicroTestCase.java
Tue Apr 5 15:11:57 2005
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * 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.composition.testing;
+
+import java.net.URI;
+import java.util.Hashtable;
+
+import junit.framework.TestCase;
+
+import net.dpml.automation.model.Model;
+import net.dpml.composition.unit.CompositionHelper;
+
+/**
+ * Test a simple component case.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id: AbstractDescriptorTestCase.java 1556 2005-01-22 12:43:42Z
niclas $
+ */
+public class MicroTestCase extends TestCase
+{
+ private static final String PATH = "acme-micro.part";
+
+ /**
+ * Test the construction of a component that contains two child components
+ * (widget and gizmo).
+ */
+ public void testResolve() throws Exception
+ {
+ CompositionHelper helper = new CompositionHelper( false );
+ URI uri = helper.toURI( PATH );
+ Model model = helper.getCompositionManager().addPart( uri );
+ Object acme = model.resolve();
+ model.release( acme );
+ helper.dispose();
+ }
+}



  • svn commit: r2213 - in development/main/metro/composition/testing: acme acme/src/main/net/dpml/composition/testing unit unit/src/test/net/dpml/composition/testing, mcconnell, 04/05/2005

Archive powered by MHonArc 2.6.24.

Top of Page