You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by hl...@apache.org on 2004/05/17 21:44:10 UTC

cvs commit: jakarta-hivemind/framework/src/test/hivemind/test TestMisc.java

hlship      2004/05/17 12:44:10

  Modified:    framework/src/java/org/apache/hivemind
                        HiveMindMessages.properties HiveMind.java
                        SymbolSourceContribution.java Orderable.java
               framework/src/descriptor/META-INF hivemodule.sdl
               framework/src/test-data/TestRegistryBuilder/META-INF
                        hivemodule.xml
               framework/src/java/org/apache/hivemind/impl
                        RegistryImpl.java
               framework/src/test/hivemind/test/config Symbols.xml
               framework/src/test/hivemind/test TestMisc.java
  Log:
  Change the Orderable interface (and some related configuration points) to use dependency ordering (as with interceptors).
  
  Revision  Changes    Path
  1.11      +3 -2      jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMindMessages.properties
  
  Index: HiveMindMessages.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMindMessages.properties,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HiveMindMessages.properties	17 May 2004 16:57:46 -0000	1.10
  +++ HiveMindMessages.properties	17 May 2004 19:44:09 -0000	1.11
  @@ -33,12 +33,13 @@
   
   wrong-factory-parameter-count=Service implementation factory {0} expects {1,choice,0#no parameters|1#one parameter|1<{1,number,integer} parameters} but received {2,choice,0#none|1#one|1<{2,number,integer}}.
   
  -HiveMind.elements-not-orderable=Elements of list {0} do not implement the Orderable interface and can not be sorted.
   HiveMind.registry-has-shutdown=The HiveMind Registry has been shutdown.
   
   exception-at-location=Exception at {0}: {1}
   
   unimplemented-method=Class {0} must provide an overridden implementation of method {1}().
  +
  +hivemind.symbol-source-contribution=symbol source
   
   # impl package
   
  
  
  
  1.6       +2 -42     jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMind.java
  
  Index: HiveMind.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMind.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HiveMind.java	13 May 2004 11:04:45 -0000	1.5
  +++ HiveMind.java	17 May 2004 19:44:09 -0000	1.6
  @@ -26,6 +26,7 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.hivemind.internal.Module;
  +import org.apache.hivemind.order.Orderer;
   
   /**
    * Static utility class for HiveMind.
  @@ -130,49 +131,8 @@
           return new ApplicationRuntimeException(getMessage("HiveMind.registry-has-shutdown"));
       }
   
  -    /**
  -     * Used to sort elements of a list that implement the
  -     * {@link Orderable} interface.
  -     */
  -    private static class OrderableSorter implements Comparator
  -    {
  -
  -        public int compare(Object o1, Object o2)
  -        {
  -            Orderable left = (Orderable) o1;
  -            Orderable right = (Orderable) o2;
  -
  -            return left.getOrder() - right.getOrder();
  -        }
  -
  -    }
  -
  -    /**
  -     * Sorts a list of elements implementing the {@link Orderable} interface.
  -     * A copy of the input list is returned, with the elements sorted
  -     * into ascending order.  The returned list is unmodifiable.
  -     * 
  -     */
  -    public static List sortOrderables(List list)
  -    {
  -        if (list == null || list.isEmpty())
  -            return Collections.EMPTY_LIST;
   
  -        List sorted = new ArrayList(list);
   
  -        try
  -        {
  -            Collections.sort(sorted, new OrderableSorter());
  -        }
  -        catch (ClassCastException ex)
  -        {
  -            throw new ApplicationRuntimeException(
  -                format("HiveMind.elements-not-orderable", list),
  -                ex);
  -        }
  -
  -        return Collections.unmodifiableList(sorted);
  -    }
   
       /**
        * Returns a fully qualfied id.  If the id contains a '.', then it
  
  
  
  1.2       +34 -10    jakarta-hivemind/framework/src/java/org/apache/hivemind/SymbolSourceContribution.java
  
  Index: SymbolSourceContribution.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/SymbolSourceContribution.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SymbolSourceContribution.java	26 Feb 2004 23:07:56 -0000	1.1
  +++ SymbolSourceContribution.java	17 May 2004 19:44:09 -0000	1.2
  @@ -26,26 +26,50 @@
    */
   public class SymbolSourceContribution implements Orderable
   {
  -    private int _order;
  +    private String _name;
  +    private String _precedingNames;
  +    private String _followingNames;
  +
       private SymbolSource _source;
   
  -    public int getOrder()
  +    public SymbolSource getSource()
       {
  -        return _order;
  +        return _source;
       }
   
  -    public SymbolSource getSource()
  +    public void setSource(SymbolSource source)
       {
  -        return _source;
  +        _source = source;
       }
   
  -    public void setOrder(int i)
  +    public String getFollowingNames()
       {
  -        _order = i;
  +        return _followingNames;
       }
   
  -    public void setSource(SymbolSource source)
  +    public String getName()
       {
  -        _source = source;
  +        return _name;
  +    }
  +
  +    public String getPrecedingNames()
  +    {
  +        return _precedingNames;
  +    }
  +
  +    public void setFollowingNames(String string)
  +    {
  +        _followingNames = string;
       }
  +
  +    public void setName(String string)
  +    {
  +        _name = string;
  +    }
  +
  +    public void setPrecedingNames(String string)
  +    {
  +        _precedingNames = string;
  +    }
  +
   }
  
  
  
  1.2       +22 -7     jakarta-hivemind/framework/src/java/org/apache/hivemind/Orderable.java
  
  Index: Orderable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/Orderable.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Orderable.java	26 Feb 2004 23:07:56 -0000	1.1
  +++ Orderable.java	17 May 2004 19:44:09 -0000	1.2
  @@ -15,9 +15,9 @@
   package org.apache.hivemind;
   
   /**
  - * Interface typically used by configuration elements that wish to be ordered.
  - * Implements an <code>order</code> property that is used to sort elements into
  - * a particular order.
  + * Interface typically used by configuration items that wish to be ordered.
  + * Each item must provide a name, and lists: names of items which should precede
  + * the item, and names of items to follow.
    * 
    * @author Howard M. Lewis Ship
    * @version $Id$
  @@ -25,8 +25,23 @@
   public interface Orderable
   {
       /**
  -     * Returns the sort order for this element.  Lower numbers are sorted first,
  -     * higher numbers are sorted last.
  +     * Returns the name of the item, which is used to establish sort order.
        */
  -    public int getOrder();
  +    public String getName();
  +
  +    /**
  +     * Returns a comma-seperated list of the names of other items. This item will precede
  +     * all such items. The special
  +     * value <code>*</code> indicates that the item should precede all items.
  +     * 
  +     * @return the list, the value <code>*</code>, or null
  +     */
  +
  +    public String getFollowingNames();
  +
  +    /**
  +     * As {@link #getFollowingNames()}, but the identified items will precede this item.
  +     */
  +
  +    public String getPrecedingNames();
   }
  
  
  
  1.4       +17 -5     jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.sdl
  
  Index: hivemodule.sdl
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.sdl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- hivemodule.sdl	17 May 2004 16:57:48 -0000	1.3
  +++ hivemodule.sdl	17 May 2004 19:44:09 -0000	1.4
  @@ -28,9 +28,9 @@
     			{
     				description { "Describes a single source of symbol values." }
     		
  -  				attribute (name=order)
  +  				attribute (name=name required=true)
     				{
  -  					description { "A number used to set the order in which sources are checked." }
  +  					description { "A unique name used to identify the source, used when ordering the sources." }
     				}
     		
     				attribute (name=class)
  @@ -43,10 +43,22 @@
   					description { "Service configuration id for a service which implements the SymbolSource interface." }
   				}
   		
  +				attribute (name=before)
  +				{
  +					description { "A list of the names of other sources this source should precede." }
  +				}
  +				
  +				attribute (name=after)
  +				{
  +					description { "A list of the names of other sources this source should follow." }
  +				}
  +		
   				conversion (class=org.apache.hivemind.SymbolSourceContribution)
   				{
   					map (attribute=class property=source translator=object)
   					map (attribute=service-id property=source translator=service)
  +					map (attribute=before property=followingNames)
  +					map (attribute=after property=precedingNames)
   				}
   			}
   		}
  @@ -54,8 +66,8 @@
   
   	contribution (configuration-id=SymbolSources)
   	{
  -		source (order= 900000 service-id=ApplicationDefaultsSymbolSource)
  -		source (order=1000000 service-id=FactoryDefaultsSymbolSource)
  +		source (name=hivemind.ApplicationDefaults service-id=ApplicationDefaultsSymbolSource)
  +		source (name=hivemind.FactoryDefaults after="*" service-id=FactoryDefaultsSymbolSource)
   	}
   	
   	schema (id=Defaults)
  
  
  
  1.5       +3 -8      jakarta-hivemind/framework/src/test-data/TestRegistryBuilder/META-INF/hivemodule.xml
  
  Index: hivemodule.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test-data/TestRegistryBuilder/META-INF/hivemodule.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- hivemodule.xml	17 May 2004 16:57:47 -0000	1.4
  +++ hivemodule.xml	17 May 2004 19:44:10 -0000	1.5
  @@ -6,18 +6,13 @@
   		<element name="datum">
   			<attribute name="key" required="true"/>
   			<attribute name="value" required="true"/>
  -			<rules>
  -				<create-object class="hivemind.test.config.impl.Datum"/>
  -				<read-attribute property="key" attribute="key"/>
  -				<read-attribute property="value" attribute="value"/>
  -				<invoke-parent method="addElement"/>
  -			</rules>
  +			<conversion class="hivemind.test.config.impl.Datum"/>
   		</element>
   	</schema>
   	<contribution configuration-id="Symbols">
   		<datum key="wife" value="${wife}"/>
   	</contribution>
   	<contribution configuration-id="hivemind.SymbolSources">
  -		<source class="hivemind.test.config.impl.MockSymbolSource"/>
  +		<source name="test" before="*" class="hivemind.test.config.impl.MockSymbolSource"/>
   	</contribution>
   </module>
  
  
  
  1.4       +23 -6     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java
  
  Index: RegistryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RegistryImpl.java	17 May 2004 16:57:47 -0000	1.3
  +++ RegistryImpl.java	17 May 2004 19:44:10 -0000	1.4
  @@ -31,6 +31,7 @@
   import org.apache.hivemind.internal.Module;
   import org.apache.hivemind.internal.RegistryInternal;
   import org.apache.hivemind.internal.ServiceModelFactory;
  +import org.apache.hivemind.order.Orderer;
   import org.apache.hivemind.schema.Translator;
   import org.apache.hivemind.schema.rules.ClassTranslator;
   import org.apache.hivemind.util.ToStringBuilder;
  @@ -43,6 +44,7 @@
    */
   public final class RegistryImpl implements RegistryInternal
   {
  +    private static final String SYMBOL_SOURCES = "hivemind.SymbolSources";
       private static final Log LOG = LogFactory.getLog(RegistryImpl.class);
   
       private static final String TRANSLATORS_CONFIGURATION_ID = "hivemind.Translators";
  @@ -317,16 +319,31 @@
           if (_variableSources != null)
               return _variableSources;
   
  -        List contributions = HiveMind.sortOrderables(getConfiguration("hivemind.SymbolSources"));
  +        List contributions = getConfiguration(SYMBOL_SOURCES);
   
  -        int count = contributions.size();
  +        Orderer o =
  +            new Orderer(
  +                LogFactory.getLog(SYMBOL_SOURCES),
  +                HiveMind.getMessage("hivemind.symbol-source-contribution"));
  +
  +        Iterator i = contributions.iterator();
  +        while (i.hasNext())
  +        {
  +            SymbolSourceContribution c = (SymbolSourceContribution) i.next();
  +
  +            o.add(c, c.getName(), c.getPrecedingNames(), c.getFollowingNames());
  +        }
  +
  +        List sources = o.getOrderedObjects();
  +
  +        int count = sources.size();
   
           _variableSources = new SymbolSource[count];
   
  -        for (int i = 0; i < count; i++)
  +        for (int j = 0; j < count; j++)
           {
  -            SymbolSourceContribution c = (SymbolSourceContribution) contributions.get(i);
  -            _variableSources[i] = c.getSource();
  +            SymbolSourceContribution c = (SymbolSourceContribution) sources.get(j);
  +            _variableSources[j] = c.getSource();
           }
   
           return _variableSources;
  
  
  
  1.5       +3 -8      jakarta-hivemind/framework/src/test/hivemind/test/config/Symbols.xml
  
  Index: Symbols.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/config/Symbols.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Symbols.xml	17 May 2004 16:57:48 -0000	1.4
  +++ Symbols.xml	17 May 2004 19:44:10 -0000	1.5
  @@ -6,12 +6,7 @@
   		<element name="datum">
   			<attribute name="key" required="true"/>
   			<attribute name="value" required="true"/>
  -			<rules>
  -				<create-object class="hivemind.test.config.impl.Datum"/>
  -				<read-attribute property="key" attribute="key"/>
  -				<read-attribute property="value" attribute="value"/>
  -				<invoke-parent method="addElement"/>
  -			</rules>
  +			<conversion class="hivemind.test.config.impl.Datum"/>
   		</element>
   	</schema>
   	<contribution configuration-id="Symbols">
  @@ -20,7 +15,7 @@
   		<datum key="work" value="${work}"/>
   	</contribution>
   	<contribution configuration-id="hivemind.SymbolSources">
  -		<source class="hivemind.test.config.impl.MockSymbolSource"/>
  +		<source name="test" before="*" class="hivemind.test.config.impl.MockSymbolSource"/>
   	</contribution>
   	<contribution configuration-id="hivemind.FactoryDefaults">
   		<default symbol="dog" value="dino"/>
  
  
  
  1.13      +1 -28     jakarta-hivemind/framework/src/test/hivemind/test/TestMisc.java
  
  Index: TestMisc.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/TestMisc.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestMisc.java	13 May 2004 11:04:47 -0000	1.12
  +++ TestMisc.java	17 May 2004 19:44:10 -0000	1.13
  @@ -58,33 +58,6 @@
           }
       }
   
  -    public void testSortOrderablesFailure()
  -    {
  -        List l = new ArrayList();
  -        l.add("alpha");
  -        l.add("beta");
  -
  -        try
  -        {
  -            HiveMind.sortOrderables(l);
  -            unreachable();
  -        }
  -        catch (ApplicationRuntimeException ex)
  -        {
  -            assertExceptionSubstring(
  -                ex,
  -                "Elements of list [alpha, beta] do not implement the Orderable interface and can not be sorted.");
  -        }
  -    }
  -
  -    public void testSortOrderablesEmpty()
  -    {
  -        List l = new ArrayList();
  -        List o = HiveMind.sortOrderables(l);
  -
  -        assertSame(Collections.EMPTY_LIST, o);
  -    }
  -
       public void testGetMessage()
       {
           assertEquals(
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org