knut        2005/01/31 02:10:54

  Modified:    src/documentation/content/xdocs configurations.xml
                        descriptor.xml
               framework/src/java/org/apache/hivemind/impl
                        SchemaProcessorImpl.java
               framework/src/test/org/apache/hivemind/impl
                        TestSchemaProcessor.java
  Log:
  Use the translated attribute value as the key for mapped configurations.
  
  Revision  Changes    Path
  1.13      +3 -2      
jakarta-hivemind/src/documentation/content/xdocs/configurations.xml
  
  Index: configurations.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-hivemind/src/documentation/content/xdocs/configurations.xml,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- configurations.xml        5 Jan 2005 21:53:31 -0000       1.12
  +++ configurations.xml        31 Jan 2005 10:10:54 -0000      1.13
  @@ -158,10 +158,11 @@
   
                        <p>As mentioned it is also possible to have the 
configuration contributions 
                                injected as a Map.  This requires the schema to 
define the attribute of 
  -                             the top-level elements which should be used as 
the key for the elements 
  +                             the top-level elements which should be used as 
the key for the objects 
                                in the map.  This is specified using 
&_element;'s <code>key-attribute</code> 
                                attribute. The identified key attribute is 
implicitly marked as 
  -                             <em>required</em> and <em>unique</em>.</p>
  +                             <em>required</em> and <em>unique</em>.  Further 
it is the <em>translated</em>
  +                             attribute value which is used as the key in the 
map.</p>
                        <p>The list / map of elements is always injected as an 
<em>unmodifiable</em> 
                                collection. An empty list / map may be 
injected, but never 
                                <code>null</code>.</p>
  
  
  
  1.19      +4 -4      
jakarta-hivemind/src/documentation/content/xdocs/descriptor.xml
  
  Index: descriptor.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-hivemind/src/documentation/content/xdocs/descriptor.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- descriptor.xml    5 Jan 2005 21:53:31 -0000       1.18
  +++ descriptor.xml    31 Jan 2005 10:10:54 -0000      1.19
  @@ -292,10 +292,10 @@
                                        <td>key-attribute</td>
                                        <td>string</td>
                                        <td>no</td>
  -                                     <td>The name of this element's 
&_attribute; which will be used as a unique key
  -                                             for configuration contributions 
corresponding to this element.  The 
  -                                             contributions can then be 
accessed in a Map using this key.  The specified
  -                        &_attribute; is implicitly marked as 
<em>required</em> and 
  +                                     <td>The name of this element's 
&_attribute; whose <em>translated</em> value will 
  +                                         be used as a unique key for 
configuration contributions corresponding to this 
  +                                         element.  The contributions can 
then be accessed in a Map using this key.  The 
  +                                         specified &_attribute; is 
implicitly marked as <em>required</em> and 
                           <em>unique</em>.</td>
                                </tr>
                        </table>
  
  
  
  1.13      +10 -2     
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java
  
  Index: SchemaProcessorImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SchemaProcessorImpl.java  6 Jan 2005 01:45:12 -0000       1.12
  +++ SchemaProcessorImpl.java  31 Jan 2005 10:10:54 -0000      1.13
  @@ -26,6 +26,7 @@
   import org.apache.hivemind.schema.Schema;
   import org.apache.hivemind.schema.SchemaProcessor;
   import org.apache.hivemind.schema.Translator;
  +import org.apache.hivemind.util.PropertyUtils;
   
   /**
    * Used to assemble all the [EMAIL PROTECTED] 
org.apache.hivemind.Contribution}s contributed to an
  @@ -93,9 +94,16 @@
   
           if (_canElementsBeMapped)
           {
  -            String key = 
peekElement().getAttributeValue(_activeElement.getKeyAttribute());
  +            Element currentElement = peekElement();
   
  -            _mappedElements.put(key, element);
  +            String keyAttribute = _activeElement.getKeyAttribute();
  +
  +            Translator t = getAttributeTranslator(keyAttribute);
  +
  +            Object finalValue = t.translate(getContributingModule(), 
Object.class, currentElement
  +                    .getAttributeValue(keyAttribute), 
currentElement.getLocation());
  +
  +            _mappedElements.put(finalValue, element);
           }
       }
   
  
  
  
  1.10      +13 -1     
jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
  
  Index: TestSchemaProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestSchemaProcessor.java  6 Jan 2005 01:45:16 -0000       1.9
  +++ TestSchemaProcessor.java  31 Jan 2005 10:10:54 -0000      1.10
  @@ -23,6 +23,7 @@
   
   import org.apache.hivemind.internal.Module;
   import org.apache.hivemind.schema.SchemaProcessor;
  +import org.apache.hivemind.schema.Translator;
   import org.apache.hivemind.schema.impl.AttributeModelImpl;
   import org.apache.hivemind.schema.impl.ElementModelImpl;
   import org.apache.hivemind.schema.impl.SchemaImpl;
  @@ -245,6 +246,7 @@
   
           AttributeModelImpl am = new AttributeModelImpl();
           am.setName("name");
  +        am.setTranslator("cartoon");
   
           em.addAttributeModel(am);
   
  @@ -278,6 +280,16 @@
           m.expandSymbols("fred", null);
           control.setReturnValue("fred");
   
  +        MockControl tControl = newControl(Translator.class);
  +        Translator t = (Translator) tControl.getMock();
  +
  +        m.getTranslator("cartoon");
  +        control.setReturnValue(t);
  +
  +        Object flintstoneKey = new Object();
  +        t.translate(m, Object.class, "flintstone", element.getLocation());
  +        tControl.setReturnValue(flintstoneKey);
  +
           replayControls();
   
           p.process(elements, m);
  @@ -285,7 +297,7 @@
           Map map = p.getMappedElements();
   
           assertEquals(1, map.size());
  -        StringHolder h = (StringHolder) map.get("flintstone");
  +        StringHolder h = (StringHolder) map.get(flintstoneKey);
   
           assertEquals("fred", h.getValue());
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to