hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r453279 - in /hivemind/branches/branch-2-0-annot: ./ annotations/src/java/org/apache/hivemind/annotations/ annotations/src/java/org/apache/hivemind/annotations/internal/ annotations/src/test/org/apache/hivemind/annotations/
Date Thu, 05 Oct 2006 16:09:45 GMT
Author: ahuegen
Date: Thu Oct  5 09:09:44 2006
New Revision: 453279

URL: http://svn.apache.org/viewvc?view=rev&rev=453279
Log:
support for contributions

Added:
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/Contribution.java
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/TemplateMethodContributionConstructor.java
Modified:
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
    hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
    hivemind/branches/branch-2-0-annot/status.xml

Added: hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/Contribution.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/Contribution.java?view=auto&rev=453279
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/Contribution.java
(added)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/Contribution.java
Thu Oct  5 09:09:44 2006
@@ -0,0 +1,20 @@
+package org.apache.hivemind.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a method in an annotated module as contribution to a configuration point.
+ * The single parameter of the method must be compatible with the type of the configuration.

+ *  
+ * @author Achim Huegen
+ */
+@Documented
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value = ElementType.METHOD)
+public @interface Contribution {
+    String configurationId();
+}

Modified: hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java?view=diff&rev=453279&r1=453278&r2=453279
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
(original)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
Thu Oct  5 09:09:44 2006
@@ -11,17 +11,21 @@
 import org.apache.hivemind.Occurances;
 import org.apache.hivemind.Resource;
 import org.apache.hivemind.annotations.Configuration;
+import org.apache.hivemind.annotations.Contribution;
 import org.apache.hivemind.annotations.Service;
 import org.apache.hivemind.definition.ConfigurationPointDefinition;
+import org.apache.hivemind.definition.ContributionDefinition;
 import org.apache.hivemind.definition.ModuleDefinition;
 import org.apache.hivemind.definition.RegistryDefinition;
 import org.apache.hivemind.definition.ServiceImplementationDefinition;
 import org.apache.hivemind.definition.ServicePointDefinition;
 import org.apache.hivemind.definition.construction.ConfigurationConstructor;
+import org.apache.hivemind.definition.construction.ContributionConstructor;
 import org.apache.hivemind.definition.construction.ImplementationConstructor;
 import org.apache.hivemind.impl.LocationImpl;
 import org.apache.hivemind.internal.Visibility;
 import org.apache.hivemind.util.ClasspathResource;
+import org.apache.hivemind.util.IdUtils;
 
 /**
  * Does the work for {@link org.apache.hivemind.annotations.AnnotatedModuleReader}. Processes
an
@@ -121,6 +125,14 @@
                         module,
                         instanceProvider);
             }
+            else if (Contribution.class.isAssignableFrom(annotation.annotationType()))
+            {
+                processAnnotatedContributionMethod(
+                        method,
+                        (Contribution) annotation,
+                        module,
+                        instanceProvider);
+            }
         }
 
     }
@@ -163,6 +175,26 @@
 
     }
 
+
+    private void processAnnotatedContributionMethod(Method method, Contribution contribution,
ModuleDefinition module, ModuleInstanceProvider instanceProvider)
+    {
+        if (_log.isDebugEnabled())
+        {
+            _log.debug("Method " + method.getName() + "classified as contribution.");
+        }
+        
+        ContributionConstructor constructor = new TemplateMethodContributionConstructor(module
+                .getLocation(), method, instanceProvider);
+
+        ContributionDefinition cd = new ContributionDefinition(module, module
+                .getLocation(), constructor);
+        String qualifiedConfigurationId = IdUtils.qualify(
+                module.getId(),
+                contribution.configurationId());
+        module.addContribution(qualifiedConfigurationId, cd);
+
+    }
+    
     /**
      * Creates a location pointing at the module class. The location contains a fixed line
number 1.
      * 

Added: hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/TemplateMethodContributionConstructor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/TemplateMethodContributionConstructor.java?view=auto&rev=453279
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/TemplateMethodContributionConstructor.java
(added)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/TemplateMethodContributionConstructor.java
Thu Oct  5 09:09:44 2006
@@ -0,0 +1,53 @@
+package org.apache.hivemind.annotations.internal;
+
+import java.lang.reflect.Method;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.annotations.Contribution;
+import org.apache.hivemind.definition.construction.ContributionConstructionContext;
+import org.apache.hivemind.definition.construction.ContributionConstructor;
+
+/**
+ * Contributes to a configuration point by passing the configuration container
+ * to a method defined in an annotated module by use of the {@link Contribution} annotation.

+ * 
+ * @author Achim Huegen
+ */
+public class TemplateMethodContributionConstructor implements
+        ContributionConstructor
+{
+    private Method _templateMethod;
+
+    private ModuleInstanceProvider _moduleInstanceProvider;
+
+    private Location _location;
+
+    public TemplateMethodContributionConstructor(Location location, Method factoryMethod,
+            ModuleInstanceProvider moduleInstanceProvider)
+    {
+        _location = location;
+        _templateMethod = factoryMethod;
+        _moduleInstanceProvider = moduleInstanceProvider;
+    }
+
+    public Location getLocation()
+    {
+        return _location;
+    }
+
+    public void contribute(ContributionConstructionContext context, Object container)
+    {
+        try
+        {
+            Object[] params = new Object[] {container}; 
+            _templateMethod.invoke(_moduleInstanceProvider.getModuleInstance(), params);
+        }
+        catch (Exception ex)
+        {
+            throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex);
+        }
+        
+    }
+
+}

Modified: hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java?view=diff&rev=453279&r1=453278&r2=453279
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
(original)
+++ hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
Thu Oct  5 09:09:44 2006
@@ -40,6 +40,12 @@
         return result;
     }
 
+    @Contribution(configurationId="Demo")
+    public void contributeData(List<String> container)
+    {
+        container.add("contributed-data");
+    }
+
     public Registry getRegistry()
     {
         return _registry;

Modified: hivemind/branches/branch-2-0-annot/status.xml
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/status.xml?view=diff&rev=453279&r1=453278&r2=453279
==============================================================================
--- hivemind/branches/branch-2-0-annot/status.xml (original)
+++ hivemind/branches/branch-2-0-annot/status.xml Thu Oct  5 09:09:44 2006
@@ -20,6 +20,7 @@
     <person name="Howard M. Lewis Ship" email="hlship@comcast.net" id="HLS" />
     <person name="Knut Wannheden" email="knut.wannheden@gmail.com" id="KW" />
     <person name="James Carman" email="james@carmanconsulting.com" id="JC" />
+    <person name="Achim Huegen" email="achim.huegen@gmx.de" id="AH" />
   </developers>
   <todo>
     <actions priority="Release 1.2">



Mime
View raw message