hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r414278 - in /jakarta/hivemind/trunk: ./ 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 14:50:15 GMT
Author: jcarman
Date: Wed Jun 14 07:50:14 2006
New Revision: 414278

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

Added:
    jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DateLoggingStrategy.java
    jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DefaultLoggingStrategy.java
    jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/LoggingStrategy.java
    jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/ParameterIndexTest.xml
Modified:
    jakarta/hivemind/trunk/library/src/descriptor/META-INF/hivemodule.xml
    jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java
    jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java
    jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java
    jakarta/hivemind/trunk/status.xml

Modified: jakarta/hivemind/trunk/library/src/descriptor/META-INF/hivemodule.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/library/src/descriptor/META-INF/hivemodule.xml?rev=414278&r1=414277&r2=414278&view=diff
==============================================================================
--- jakarta/hivemind/trunk/library/src/descriptor/META-INF/hivemodule.xml (original)
+++ jakarta/hivemind/trunk/library/src/descriptor/META-INF/hivemodule.xml Wed Jun 14 07:50:14
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/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java?rev=414278&r1=414277&r2=414278&view=diff
==============================================================================
--- jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java
(original)
+++ jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyFactory.java
Wed Jun 14 07:50:14 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/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java?rev=414278&r1=414277&r2=414278&view=diff
==============================================================================
--- jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java
(original)
+++ jakarta/hivemind/trunk/library/src/java/org/apache/hivemind/lib/strategy/StrategyParameter.java
Wed Jun 14 07:50:14 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;
+	}
+    
+    
 }

Added: jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DateLoggingStrategy.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DateLoggingStrategy.java?rev=414278&view=auto
==============================================================================
--- jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DateLoggingStrategy.java
(added)
+++ jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DateLoggingStrategy.java
Wed Jun 14 07:50:14 2006
@@ -0,0 +1,15 @@
+package org.apache.hivemind.lib.strategy;
+
+import java.text.MessageFormat;
+
+import org.apache.commons.logging.Log;
+
+public class DateLoggingStrategy implements LoggingStrategy 
+{
+
+	public void log(Log log, Object message) 
+	{
+		log.debug( MessageFormat.format( "{0,date,MM/dd/yyyy}", new Object[] { message } ) );
+	}
+	
+}

Added: jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DefaultLoggingStrategy.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DefaultLoggingStrategy.java?rev=414278&view=auto
==============================================================================
--- jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DefaultLoggingStrategy.java
(added)
+++ jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/DefaultLoggingStrategy.java
Wed Jun 14 07:50:14 2006
@@ -0,0 +1,13 @@
+package org.apache.hivemind.lib.strategy;
+
+import org.apache.commons.logging.Log;
+
+public class DefaultLoggingStrategy implements LoggingStrategy
+{
+
+	public void log(Log log, Object message) 
+	{
+		log.debug( String.valueOf( message ) );
+	}
+	
+}

Added: jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/LoggingStrategy.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/LoggingStrategy.java?rev=414278&view=auto
==============================================================================
--- jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/LoggingStrategy.java
(added)
+++ jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/LoggingStrategy.java
Wed Jun 14 07:50:14 2006
@@ -0,0 +1,8 @@
+package org.apache.hivemind.lib.strategy;
+
+import org.apache.commons.logging.Log;
+
+public interface LoggingStrategy {
+
+	public void log( Log log, Object message );
+}

Added: jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/ParameterIndexTest.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/ParameterIndexTest.xml?rev=414278&view=auto
==============================================================================
--- jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/ParameterIndexTest.xml
(added)
+++ jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/ParameterIndexTest.xml
Wed Jun 14 07:50:14 2006
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!-- 
+   Copyright 2004, 2005 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.
+-->
+
+<module id="hivemind.lib.test" version="1.0.0" package="org.apache.hivemind.lib.strategy">
+  
+  <configuration-point id="LoggingStrategies" schema-id="hivemind.lib.StrategyRegistry"/>
+  
+  <contribution configuration-id="LoggingStrategies">
+    
+    <strategy class="java.lang.Object" object="instance:DefaultLoggingStrategy"/>
+    <strategy class="java.util.Date" object="instance:DateLoggingStrategy" />
+    
+  </contribution>
+  
+  <service-point id="LoggingStrategy" interface="LoggingStrategy">
+    <invoke-factory service-id="hivemind.lib.StrategyFactory">
+      <construct configuration-id="LoggingStrategies" parameterIndex="1"/>
+    </invoke-factory>
+  </service-point>
+</module>
\ No newline at end of file

Modified: jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java?rev=414278&r1=414277&r2=414278&view=diff
==============================================================================
--- jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java
(original)
+++ jakarta/hivemind/trunk/library/src/test/org/apache/hivemind/lib/strategy/TestStrategyFactory.java
Wed Jun 14 07:50:14 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/trunk/status.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/status.xml?rev=414278&r1=414277&r2=414278&view=diff
==============================================================================
--- jakarta/hivemind/trunk/status.xml (original)
+++ jakarta/hivemind/trunk/status.xml Wed Jun 14 07:50:14 2006
@@ -38,6 +38,7 @@
       <action type="fix" dev="JC" fixes-bug="HIVEMIND-169">Using JDK proxied service
in 
       ServicePropertyFactory doesn't work</action>
       <action type="add" dev="KW" fixes-bug="HIVEMIND-137">New &quot;default&quot;
attribute for &lt;attribute&gt; element.</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



---------------------------------------------------------------------
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