r1870 - trunk/main/metro/part/src/main/net/dpml/runtime

mcconnell at BerliOS mcconnell at mail.berlios.de
Sat Feb 10 21:47:07 EST 2007


Author: mcconnell
Date: 2007-02-11 03:47:05 +0100 (Sun, 11 Feb 2007)
New Revision: 1870

Modified:
   trunk/main/metro/part/src/main/net/dpml/runtime/ContextModel.java
Log:
update to ensure that a nested context solution is only created if the context entry either required, or - an optional entry with at least one sub-entry

Modified: trunk/main/metro/part/src/main/net/dpml/runtime/ContextModel.java
===================================================================
--- trunk/main/metro/part/src/main/net/dpml/runtime/ContextModel.java	2007-02-11 02:45:38 UTC (rev 1869)
+++ trunk/main/metro/part/src/main/net/dpml/runtime/ContextModel.java	2007-02-11 02:47:05 UTC (rev 1870)
@@ -68,7 +68,31 @@
                 {
                     ContextDirective parent = getContextDirective( bundled, key );
                     ContextDirective nested = getContextDirective( directive, key );
-                    value = new ContextModel( clazz, path, c, policy, key, parent, nested, query );
+                    try
+                    {
+                        ContextModel model = new ContextModel( clazz, path, c, policy, key, parent, nested, query );
+                        if( !optional || ( model.size() > 0 ) )
+                        {
+                            value = model;
+                        }
+                    }
+                    catch( MissingContextEntryException mcee )
+                    {
+                        if( !optional )
+                        {
+                            final String error = 
+                              "Nested context entry ["
+                              + key
+                              + "] within the context definition ["
+                              + c.getName()
+                              + "] as a constructor argument to the component class ["
+                              + clazz.getName()
+                              + "] within the component model ["
+                              + path
+                              + "] could not be created.";
+                            throw new ComponentException( error );
+                        }
+                    }
                 }
                 else
                 {
@@ -102,12 +126,17 @@
                       + "] within the component model ["
                       + path
                       + "].";
-                    throw new ComponentException( error );
+                    throw new MissingContextEntryException( error );
                 }
             }
         }
     }
     
+    int size()
+    {
+        return m_map.size();
+    }
+    
     private String getScopedKey( String base, String key )
     {
         if( null == base )




More information about the notify-dpml mailing list