hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r414281 - in /jakarta/hivemind/branches/branch-1-1: ./ library/src/descriptor/META-INF/ library/src/java/org/apache/hivemind/lib/strategy/ library/src/test/org/apache/hivemind/lib/strategy/
Date Wed, 14 Jun 2006 15:04:31 GMT
Author: jcarman
Date: Wed Jun 14 08:04:30 2006
New Revision: 414281

URL: http://svn.apache.org/viewvc?rev=414281&view=rev
Log:
HIVEMIND-177: Allow for customization of "parameter index" in StrategyFactory

Added:
    jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/DateLoggingStrategy.java
      - copied unchanged from r414279, jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DateLoggingStrategy.java
    jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/DefaultLoggingStrategy.java
      - copied unchanged from r414279, jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DefaultLoggingStrategy.java
    jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/LoggingStrategy.java
      - copied unchanged from r414279, jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/LoggingStrategy.java
    jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/ParameterIndexTest.xml
      - copied unchanged from r414279, jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/ParameterIndexTest.xml
Modified:
    jakarta/hivemind/branches/branch-1-1/library/src/descriptor/META-INF/hivemodule.xml
    jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java
    jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java
    jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java
    jakarta/hivemind/branches/branch-1-1/status.xml

Modified: jakarta/hivemind/branches/branch-1-1/library/src/descriptor/META-INF/hivemodule.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/library/src/descriptor/META-INF/hivemodule.xml?rev=414281&r1=414280&r2=414281&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/library/src/descriptor/META-INF/hivemodule.xml (original)
+++ jakarta/hivemind/branches/branch-1-1/library/src/descriptor/META-INF/hivemodule.xml Wed
Jun 14 08:04:30 2006
@@ -365,7 +365,10 @@
           A configuration utilizing the hivemind.lib.StrategyRegistry schema, which
           defines the classes and matching strategies.
         </attribute>
-        
+        <attribute name="parameterIndex" required="false">
+          The index (zero-based) of the parameter to be used to determine which
+          strategy to use.
+        </attribute>
         <conversion class="strategy.StrategyParameter">
           <map attribute="configuration-id" property="contributions"/>
         </conversion>

Modified: jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java?rev=414281&r1=414280&r2=414281&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java
Wed Jun 14 08:04:30 2006
@@ -122,6 +122,7 @@
             String name)
     {
         Class serviceInterface = factoryParameters.getServiceInterface();
+        StrategyParameter p = (StrategyParameter) factoryParameters.getFirstParameter();
 
         ClassFab cf = _classFactory.newClass(name, Object.class);
 
@@ -140,14 +141,14 @@
                 + ") _registry.getStrategy($1.getClass());");
 
         MethodIterator i = new MethodIterator(serviceInterface);
-
+        final int parameterIndex = p.getParameterIndex();
         while (i.hasNext())
         {
             MethodSignature sig = i.next();
 
             if (proper(sig))
             {
-                addAdaptedMethod(cf, sig);
+                addAdaptedMethod(cf, sig, parameterIndex);
             }
             else
             {
@@ -168,9 +169,11 @@
         return cf.createClass();
     }
 
-    private void addAdaptedMethod(ClassFab cf, MethodSignature sig)
+    private void addAdaptedMethod(ClassFab cf, MethodSignature sig, int parameterIndex)
     {
-        String body = "return ($r) _getStrategy($1)." + sig.getName() + "($$);";
+    	
+
+        String body = "return ($r) _getStrategy($" + ( parameterIndex + 1 ) + ")." + sig.getName()
+ "($$);";
 
         cf.addMethod(Modifier.PUBLIC, sig, body);
     }

Modified: jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java?rev=414281&r1=414280&r2=414281&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java
Wed Jun 14 08:04:30 2006
@@ -27,7 +27,8 @@
 public class StrategyParameter extends BaseLocatable
 {
     private List _contributions;
-
+    private int parameterIndex = 0;
+    
     /**
      * List of {@link org.apache.hivemind.lib.strategy.StrategyContribution}.
      */
@@ -40,4 +41,16 @@
     {
         _contributions = configuration;
     }
+
+	public int getParameterIndex() 
+	{
+		return parameterIndex;
+	}
+
+	public void setParameterIndex(int parameterIndex) 
+	{
+		this.parameterIndex = parameterIndex;
+	}
+    
+    
 }

Modified: jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java?rev=414281&r1=414280&r2=414281&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java
Wed Jun 14 08:04:30 2006
@@ -15,9 +15,12 @@
 package org.apache.hivemind.lib.strategy;
 
 import java.lang.reflect.Modifier;
+import java.text.MessageFormat;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
 import org.apache.hivemind.ErrorLog;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.Registry;
@@ -156,7 +159,9 @@
 
         fp.getServiceInterface();
         fpc.setReturnValue(ToStringStrategy.class);
-
+        final StrategyParameter param = new StrategyParameter();
+        fp.getFirstParameter();
+        fpc.setReturnValue(param);
         factory.newClass("NewClass", Object.class);
         factoryControl.setReturnValue(cf);
 
@@ -175,6 +180,8 @@
                         "return (org.apache.hivemind.lib.strategy.ToStringStrategy) _registry.getStrategy($1.getClass());");
         cfc.setReturnValue(mf);
 
+        
+        
         cf.addMethod(Modifier.PUBLIC, new MethodSignature(String.class, "toString", new Class[]
         { Object.class }, null), "return ($r) _getStrategy($1).toString($$);");
         cfc.setReturnValue(mf);
@@ -220,7 +227,10 @@
 
         fp.getServiceInterface();
         fpc.setReturnValue(Runnable.class);
-
+        final StrategyParameter param = new StrategyParameter();
+        fp.getFirstParameter();
+        fpc.setReturnValue(param);
+        
         factory.newClass("NewClass", Object.class);
         factoryControl.setReturnValue(cf);
 
@@ -280,5 +290,20 @@
         ToStringStrategy ts = (ToStringStrategy) r.getService(ToStringStrategy.class);
 
         assertEquals("5150", ts.toString(new Integer(5150)));
+    }
+    
+    public void testParameterIndex() throws Exception
+    {
+    	Registry r = buildFrameworkRegistry("ParameterIndexTest.xml");
+    	LoggingStrategy loggingStrategy = ( LoggingStrategy )r.getService(LoggingStrategy.class);
+    	Log log = ( Log )newMock( Log.class );
+    	final Date now = new Date();
+    	log.debug( "Hello, World!" );
+    	log.debug( MessageFormat.format( "{0,date,MM/dd/yyyy}", new Object[] { now } ) );
+    	replayControls();
+    	loggingStrategy.log( log, "Hello, World!" );
+    	loggingStrategy.log( log, now );
+    	
+    	verifyControls();
     }
 }

Modified: jakarta/hivemind/branches/branch-1-1/status.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/status.xml?rev=414281&r1=414280&r2=414281&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/status.xml (original)
+++ jakarta/hivemind/branches/branch-1-1/status.xml Wed Jun 14 08:04:30 2006
@@ -34,6 +34,7 @@
       <action type="fix" dev="JC" fixes-bug="HIVEMIND-159">documentation on &lt;filter
after=&quot;...&quot;&gt; is reverse</action>
       <action type="fix" dev="AH" fixes-bug="HIVEMIND-171">JMX Support does not work
if you use the class directly as the interface</action>
       <action type="fix" dev="AH" >Start script of example classes not working because
of wrong packages</action>
+      <action type="add" dev="JC" fixes-bug="HIVEMIND-177">Allow for customization
of &quot;parameter index&quot; in StrategyFactory.</action>
     </release> 
     <release version="1.1.1" date="Jan 28 2006">
       <action type="fix" dev="HLS" fixes-bug="HIVEMIND-162">Performance bottleneck
with threaded services</action>



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


Mime
View raw message