You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by ah...@apache.org on 2008/02/13 14:54:11 UTC

svn commit: r627409 - in /hivemind/hivemind2/trunk: ./ annotations/src/java/org/apache/hivemind/annotations/internal/ annotations/src/test/org/apache/hivemind/annotations/ framework/src/java/org/apache/hivemind/ framework/src/java/org/apache/hivemind/s...

Author: ahuegen
Date: Wed Feb 13 05:54:07 2008
New Revision: 627409

URL: http://svn.apache.org/viewvc?rev=627409&view=rev
Log:
Improved Logging for wrong contributions to EagerLoad
Test for Annotated EagerLoadContribution

Added:
    hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/EagerLoadContributionModule.java   (with props)
Modified:
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/MethodCallContributionConstructor.java
    hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
    hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindMessages.java
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindStrings.properties
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/service/impl/EagerLoader.java
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/Defense.java
    hivemind/hivemind2/trunk/pom.xml
    hivemind/hivemind2/trunk/status.xml

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/MethodCallContributionConstructor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/MethodCallContributionConstructor.java?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/MethodCallContributionConstructor.java (original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/MethodCallContributionConstructor.java Wed Feb 13 05:54:07 2008
@@ -14,6 +14,7 @@
 
 package org.apache.hivemind.annotations.internal;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.apache.hivemind.ApplicationRuntimeException;
@@ -66,6 +67,10 @@
             } else {
                 // TODO: Throw Exception
             }
+        }
+        catch (InvocationTargetException ex)
+        {
+            throw new ApplicationRuntimeException(ex.getCause().getMessage(), getLocation(), ex.getCause());
         }
         catch (Exception ex)
         {

Added: hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/EagerLoadContributionModule.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/EagerLoadContributionModule.java?rev=627409&view=auto
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/EagerLoadContributionModule.java (added)
+++ hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/EagerLoadContributionModule.java Wed Feb 13 05:54:07 2008
@@ -0,0 +1,30 @@
+package org.apache.hivemind.annotations;
+
+import hivemind.test.services.StringHolder;
+import hivemind.test.services.impl.StringHolderImpl;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hivemind.annotations.definition.Contribution;
+import org.apache.hivemind.annotations.definition.Service;
+
+/**
+ * Module that eager loads a service by contributing it to "hivemind.EagerLoad"
+ */
+public class EagerLoadContributionModule extends AbstractAnnotatedModule
+{
+    @Service(id = "StringHolder")
+    public StringHolder getStringHolderService()
+    {
+        StringHolderImpl result = new StringHolderImpl();
+        result.setValue("test");
+        return result;
+    }
+   
+//    @Contribution(configurationId="hivemind.EagerLoad")
+//    public List eagerLoad() {
+//        return Collections.singletonList(service(StringHolder.class ));
+//    }
+
+}

Propchange: hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/EagerLoadContributionModule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java (original)
+++ hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java Wed Feb 13 05:54:07 2008
@@ -14,7 +14,6 @@
 
 package org.apache.hivemind.annotations;
 
-import hivemind.test.services.StringHolder;
 import hivemind.test.services.impl.StringHolderImpl;
 
 import java.util.ArrayList;

Modified: hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java (original)
+++ hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java Wed Feb 13 05:54:07 2008
@@ -42,4 +42,12 @@
         assertEquals(service.getClass(), StringHolderImpl.class);
     }
 
+    
+    public void testEagerLoadContribution()
+    {
+        TypedRegistry registry = constructRegistry(EagerLoadContributionModule.class);
+        StringHolder service = registry.getService(StringHolder.class);
+        assertNotNull(service);
+    }
+    
 }

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindMessages.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindMessages.java?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindMessages.java (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindMessages.java Wed Feb 13 05:54:07 2008
@@ -59,4 +59,12 @@
                 .getJavaClassName(parameter.getClass()), ClassFabUtils
                 .getJavaClassName(expectedType));
     }
+    
+    /** @since 2.0 */
+    public static String contributionWrongType(Object contribution, Class expectedType)
+    {
+        return _formatter.format("contribution-wrong-type", ClassFabUtils
+                .getJavaClassName(contribution.getClass()), ClassFabUtils
+                .getJavaClassName(expectedType));
+    }
 }

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindStrings.properties
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindStrings.properties?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindStrings.properties (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/HiveMindStrings.properties Wed Feb 13 05:54:07 2008
@@ -18,6 +18,7 @@
 param-not-null=Parameter {0} must not be null.
 field-not-null=Field {0} has not been assigned.
 param-wrong-type=Parameter {0} is of type {1} which is not compatible with {2}.
+contribution-wrong-type=Contribution is of type {0} which is not compatible with {1}.
 
 
 

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/service/impl/EagerLoader.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/service/impl/EagerLoader.java?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/service/impl/EagerLoader.java (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/service/impl/EagerLoader.java Wed Feb 13 05:54:07 2008
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import org.apache.hivemind.internal.ServicePoint;
+import org.apache.hivemind.util.Defense;
 
 /**
  * Implementation of the <code>hivemind.EagerLoad</code> service, which
@@ -34,7 +35,9 @@
         Iterator i = _servicePoints.iterator();
         while (i.hasNext())
         {
-            ServicePoint point = (ServicePoint) i.next();
+            Object untypedPoint = i.next();
+            Defense.isContributionAssignable(untypedPoint, ServicePoint.class);
+            ServicePoint point = (ServicePoint) untypedPoint;
 
             point.forceServiceInstantiation();
         }

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/Defense.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/Defense.java?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/Defense.java (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/Defense.java Wed Feb 13 05:54:07 2008
@@ -70,4 +70,18 @@
                     parameter,
                     expectedType));
     }
+    
+    /**
+     * Check that a contribution is assignable to a particular type.
+     * 
+     * @throws ClassCastException
+     *             if not assignable (with a useable message)
+     */
+    public static void isContributionAssignable(Object contribution, Class expectedType)
+    {
+        if (!expectedType.isAssignableFrom(contribution.getClass()))
+            throw new ClassCastException(HiveMindMessages.contributionWrongType(
+                    contribution,
+                    expectedType));
+    }    
 }

Modified: hivemind/hivemind2/trunk/pom.xml
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/pom.xml?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/pom.xml (original)
+++ hivemind/hivemind2/trunk/pom.xml Wed Feb 13 05:54:07 2008
@@ -6,7 +6,7 @@
     <groupId>org.apache.hivemind</groupId>
     <artifactId>hivemind-project</artifactId>
     <packaging>pom</packaging>
-    <version>2.0-alpha-1</version>
+    <version>2.0-alpha-2-SNAPSHOT</version>
     <name>HiveMind Project</name>
     <inceptionYear>2003</inceptionYear>
     <modules>

Modified: hivemind/hivemind2/trunk/status.xml
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/status.xml?rev=627409&r1=627408&r2=627409&view=diff
==============================================================================
--- hivemind/hivemind2/trunk/status.xml (original)
+++ hivemind/hivemind2/trunk/status.xml Wed Feb 13 05:54:07 2008
@@ -27,7 +27,7 @@
     </actions>
   </todo>
   <changes>
-    <release version="2.0-alpha-1" date="unreleased">
+    <release version="2.0-alpha-2" date="unreleased">
     </release>
   </changes>
 </status>