hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r514579 - in /hivemind/hivemind2/trunk/annotations/src: java/org/apache/hivemind/annotations/ java/org/apache/hivemind/annotations/definition/processors/ java/org/apache/hivemind/annotations/internal/ test/org/apache/hivemind/annotations/
Date Mon, 05 Mar 2007 07:01:04 GMT
Author: ahuegen
Date: Sun Mar  4 23:01:03 2007
New Revision: 514579

URL: http://svn.apache.org/viewvc?view=rev&rev=514579
Log:
More annotation processors

Added:
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ConfigurationProcessor.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ContributionProcessor.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/SubmoduleProcessor.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationExtensionLoader.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java
Modified:
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedModuleReader.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessingContext.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessor.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessingContextImpl.java
    hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/AnnotationTestCase.java
    hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedModuleReader.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedModuleReader.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedModuleReader.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedModuleReader.java
Sun Mar  4 23:01:03 2007
@@ -18,15 +18,13 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.ClassResolver;
-import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.HiveMind;
 import org.apache.hivemind.annotations.internal.AnnotatedModuleProcessor;
+import org.apache.hivemind.annotations.internal.AnnotationProcessorRegistryFactory;
 import org.apache.hivemind.definition.RegistryDefinition;
 import org.apache.hivemind.impl.DefaultClassResolver;
-import org.apache.hivemind.impl.DefaultErrorHandler;
 
 /**
- * Reads a annotated hivemind module into a {@link RegistryDefinition}. Thus
+ * Reads an annotated hivemind module into a {@link RegistryDefinition}. Thus
  * the defined services configurations and contributions are added to the
  * registry.
  * The class delegates the work to {@link AnnotatedModuleProcessor}
@@ -39,10 +37,6 @@
 
     private RegistryDefinition _registryDefinition;
 
-    private AnnotatedModuleProcessor _processor;
-
-    private ErrorHandler _errorHandler;
-
     private ClassResolver _classResolver;
 
     /**
@@ -50,22 +44,18 @@
      */
     public AnnotatedModuleReader(RegistryDefinition registryDefinition)
     {
-        this(registryDefinition, new DefaultClassResolver(), new DefaultErrorHandler());
+        this(registryDefinition, new DefaultClassResolver());
     }
 
     /**
      * @param registryDefinition  the registry definition to which the modules are added.
      * @param classResolver  the {@link ClassResolver} used to resolve all classes referenced
from 
      *          elements inside this module.
-     * @param errorHandler  errorHandler used for handling recoverable errors
      */
-    public AnnotatedModuleReader(RegistryDefinition registryDefinition, ClassResolver classResolver,
-            ErrorHandler errorHandler)
+    public AnnotatedModuleReader(RegistryDefinition registryDefinition, ClassResolver classResolver)
     {
         _registryDefinition = registryDefinition;
         _classResolver = classResolver;
-        _errorHandler = errorHandler;
-        _processor = new AnnotatedModuleProcessor(_registryDefinition, _classResolver, _errorHandler);
     }
 
     /**
@@ -87,13 +77,18 @@
      */
     public void readModule(Class moduleClass)
     {
+        AnnotatedModuleProcessor _processor = new AnnotatedModuleProcessor(
+                _registryDefinition, _classResolver, 
+                AnnotationProcessorRegistryFactory.createDefaultRegistry());
         try
         {
             _processor.processModule(moduleClass);
         }
         catch (RuntimeException ex)
         {
-            _errorHandler.error(LOG, ex.getMessage(), HiveMind.getLocation(ex), ex);
+            // TODO: Improve exception handling
+            throw ex;
+//            _errorHandler.error(LOG, ex.getMessage(), HiveMind.getLocation(ex), ex);
         }
     }
     

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java
Sun Mar  4 23:01:03 2007
@@ -91,7 +91,7 @@
         for (int i = 0; i < moduleClassNames.length; i++)
         {
             AnnotatedModuleReader reader = new AnnotatedModuleReader(definition,
-                    _classResolver, _errorHandler);
+                    _classResolver);
             reader.readModule(moduleClassNames[i]);
         }
 
@@ -105,7 +105,7 @@
         for (int i = 0; i < moduleClasses.length; i++)
         {
             AnnotatedModuleReader reader = new AnnotatedModuleReader(definition,
-                    _classResolver, _errorHandler);
+                    _classResolver);
             reader.readModule(moduleClasses[i]);
         }
 

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessingContext.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessingContext.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessingContext.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessingContext.java
Sun Mar  4 23:01:03 2007
@@ -3,8 +3,10 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
 
+import org.apache.hivemind.ClassResolver;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.annotations.definition.impl.AnnotatedModuleDefinitionImpl;
+import org.apache.hivemind.annotations.internal.AnnotatedModuleProcessor;
 import org.apache.hivemind.annotations.internal.ModuleInstanceProvider;
 
 public interface AnnotationProcessingContext
@@ -15,4 +17,6 @@
     public Location getLocation();
     public AnnotatedModuleDefinitionImpl getModule(); 
     public ModuleInstanceProvider getModuleInstanceProvider();
+    public ClassResolver getClassResolver();
+    public AnnotatedModuleProcessor createSubmoduleProcessor();
 }

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessor.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessor.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/AnnotationProcessor.java
Sun Mar  4 23:01:03 2007
@@ -2,6 +2,12 @@
 
 import org.apache.hivemind.ApplicationRuntimeException;
 
+/**
+ * The same instance is used for all annotations of one kind which are loaded
+ * by the same AnnotatedModuleProcessor or AnnotatedModuleReader.
+ * 
+ * @author Achim Huegen
+ */
 public interface AnnotationProcessor
 {
     /**

Added: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ConfigurationProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ConfigurationProcessor.java?view=auto&rev=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ConfigurationProcessor.java
(added)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ConfigurationProcessor.java
Sun Mar  4 23:01:03 2007
@@ -0,0 +1,57 @@
+package org.apache.hivemind.annotations.definition.processors;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.annotations.definition.Configuration;
+import org.apache.hivemind.annotations.definition.impl.AnnotatedModuleDefinitionImpl;
+import org.apache.hivemind.annotations.internal.CheckTools;
+import org.apache.hivemind.annotations.internal.MethodCallContributionConstructor;
+import org.apache.hivemind.definition.Contribution;
+import org.apache.hivemind.definition.Occurances;
+import org.apache.hivemind.definition.Visibility;
+import org.apache.hivemind.definition.impl.ConfigurationPointDefinitionImpl;
+import org.apache.hivemind.definition.impl.ContributionDefinitionImpl;
+
+public class ConfigurationProcessor implements AnnotationProcessor
+{
+    private static final Log _log = LogFactory.getLog(ConfigurationProcessor.class);
+
+    /**
+     * @see org.apache.hivemind.annotations.definition.processors.AnnotationProcessor#processAnnotation(org.apache.hivemind.annotations.definition.processors.AnnotationProcessingContext)
+     */
+    public boolean processAnnotation(AnnotationProcessingContext context)
+    {
+        Method method = (Method) context.getAnnotatedElement();
+        AnnotatedModuleDefinitionImpl module = context.getModule();
+        Configuration configurationAnnotation = (Configuration) context.getTargetAnnotation();

+        
+        CheckTools.checkMethodModifiers(method, 0, "configuration point");
+        
+        if (_log.isDebugEnabled())
+        {
+            _log.debug("Method " + method.getName() + "classified as configuration point.");
+        }
+        
+        Visibility visibility = Visibility.PUBLIC;
+        if (Modifier.isProtected(method.getModifiers())) {
+            visibility = Visibility.PRIVATE;
+        }
+        
+        ConfigurationPointDefinitionImpl cpd = new ConfigurationPointDefinitionImpl(module,
configurationAnnotation.id(), 
+                context.getLocation(), visibility, method.getReturnType().getName(), Occurances.UNBOUNDED,
+                false);
+        module.addConfigurationPoint(cpd);
+        
+        // Add method implementation as initial contribution
+        Contribution contribution = new MethodCallContributionConstructor(
+                context.getLocation(), method, context.getModuleInstanceProvider());
+        ContributionDefinitionImpl cd = new ContributionDefinitionImpl(module, context.getLocation(),
contribution, true);
+        cpd.addContribution(cd);
+
+        return true;
+    }
+
+}

Added: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ContributionProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ContributionProcessor.java?view=auto&rev=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ContributionProcessor.java
(added)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ContributionProcessor.java
Sun Mar  4 23:01:03 2007
@@ -0,0 +1,46 @@
+package org.apache.hivemind.annotations.definition.processors;
+
+import java.lang.reflect.Method;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.annotations.definition.Contribution;
+import org.apache.hivemind.annotations.definition.impl.AnnotatedModuleDefinitionImpl;
+import org.apache.hivemind.annotations.internal.CheckTools;
+import org.apache.hivemind.annotations.internal.MethodCallContributionConstructor;
+import org.apache.hivemind.definition.impl.ContributionDefinitionImpl;
+import org.apache.hivemind.util.IdUtils;
+
+public class ContributionProcessor implements AnnotationProcessor
+{
+    private static final Log _log = LogFactory.getLog(ContributionProcessor.class);
+
+    /**
+     * @see org.apache.hivemind.annotations.definition.processors.AnnotationProcessor#processAnnotation(org.apache.hivemind.annotations.definition.processors.AnnotationProcessingContext)
+     */
+    public boolean processAnnotation(AnnotationProcessingContext context)
+    {
+        Method method = (Method) context.getAnnotatedElement();
+        AnnotatedModuleDefinitionImpl module = context.getModule();
+        Contribution contributionAnnotation = (Contribution) context.getTargetAnnotation();

+        
+        CheckTools.checkMethodModifiers(method, 0, "contribution");
+        
+        if (_log.isDebugEnabled())
+        {
+            _log.debug("Method " + method.getName() + "classified as contribution.");
+        }
+        
+        org.apache.hivemind.definition.Contribution constructor = new MethodCallContributionConstructor(
+                context.getLocation(), method, context.getModuleInstanceProvider());
+
+        ContributionDefinitionImpl cd = new ContributionDefinitionImpl(module, context.getLocation(),
constructor, false);
+        String qualifiedConfigurationId = IdUtils.qualify(
+                module.getId(),
+                contributionAnnotation.configurationId());
+        module.addContribution(qualifiedConfigurationId, cd);
+
+        return true;
+    }
+
+}

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java
Sun Mar  4 23:01:03 2007
@@ -5,10 +5,8 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hivemind.Location;
 import org.apache.hivemind.annotations.definition.Service;
 import org.apache.hivemind.annotations.definition.impl.AnnotatedModuleDefinitionImpl;
-import org.apache.hivemind.annotations.internal.AnnotatedModuleLocation;
 import org.apache.hivemind.annotations.internal.CheckTools;
 import org.apache.hivemind.annotations.internal.MethodCallImplementationConstructor;
 import org.apache.hivemind.definition.ImplementationConstructor;

Added: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/SubmoduleProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/SubmoduleProcessor.java?view=auto&rev=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/SubmoduleProcessor.java
(added)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/SubmoduleProcessor.java
Sun Mar  4 23:01:03 2007
@@ -0,0 +1,43 @@
+package org.apache.hivemind.annotations.definition.processors;
+
+import java.lang.reflect.Method;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.annotations.definition.Submodule;
+import org.apache.hivemind.annotations.definition.impl.AnnotatedModuleDefinitionImpl;
+import org.apache.hivemind.annotations.internal.AnnotatedModuleProcessor;
+import org.apache.hivemind.annotations.internal.CheckTools;
+import org.apache.hivemind.util.IdUtils;
+
+public class SubmoduleProcessor implements AnnotationProcessor
+{
+    private static final Log _log = LogFactory.getLog(SubmoduleProcessor.class);
+
+    /**
+     * @see org.apache.hivemind.annotations.definition.processors.AnnotationProcessor#processAnnotation(org.apache.hivemind.annotations.definition.processors.AnnotationProcessingContext)
+     */
+    public boolean processAnnotation(AnnotationProcessingContext context)
+    {
+        Method method = (Method) context.getAnnotatedElement();
+        AnnotatedModuleDefinitionImpl module = context.getModule();
+        Submodule submoduleAnnotation = (Submodule) context.getTargetAnnotation(); 
+        
+        CheckTools.checkMethodModifiers(method, 0, "submodule");
+        
+        if (_log.isDebugEnabled())
+        {
+            _log.debug("Method " + method.getName() + "classified as submodule.");
+        }
+        
+        String fullModuleId = IdUtils.qualify(
+                module.getId(),
+                submoduleAnnotation.id());
+        // TODO: Check if return type is defined
+        AnnotatedModuleProcessor submoduleProcessor = context.createSubmoduleProcessor();
+        submoduleProcessor.processModule(method.getReturnType(), fullModuleId);
+
+        return true;
+    }
+
+}

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
Sun Mar  4 23:01:03 2007
@@ -23,35 +23,27 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.ClassResolver;
-import org.apache.hivemind.ErrorHandler;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.Resource;
 import org.apache.hivemind.annotations.AnnotationsMessages;
-import org.apache.hivemind.annotations.definition.Configuration;
 import org.apache.hivemind.annotations.definition.Module;
-import org.apache.hivemind.annotations.definition.Service;
-import org.apache.hivemind.annotations.definition.Submodule;
 import org.apache.hivemind.annotations.definition.impl.AnnotatedModuleDefinitionImpl;
 import org.apache.hivemind.annotations.definition.processors.AnnotationProcessingContext;
 import org.apache.hivemind.annotations.definition.processors.AnnotationProcessor;
-import org.apache.hivemind.annotations.definition.processors.ServiceProcessor;
-import org.apache.hivemind.definition.Contribution;
-import org.apache.hivemind.definition.ImplementationConstructor;
-import org.apache.hivemind.definition.ImplementationDefinition;
-import org.apache.hivemind.definition.Occurances;
 import org.apache.hivemind.definition.RegistryDefinition;
-import org.apache.hivemind.definition.Visibility;
-import org.apache.hivemind.definition.impl.ConfigurationPointDefinitionImpl;
-import org.apache.hivemind.definition.impl.ContributionDefinitionImpl;
-import org.apache.hivemind.definition.impl.ImplementationDefinitionImpl;
-import org.apache.hivemind.definition.impl.ServicePointDefinitionImpl;
 import org.apache.hivemind.util.ClasspathResource;
-import org.apache.hivemind.util.IdUtils;
 
 /**
- * Does the work for {@link org.apache.hivemind.annotations.AnnotatedModuleReader}. Processes
an
- * annotated class and registers the defined extension and extension points in a registry
- * definition.
+ * Does the work for {@link org.apache.hivemind.annotations.AnnotatedModuleReader}. 
+ * Processes an annotated class and registers the defined extension and extension points

+ * in a registry definition. For each module class a new instance of this processor is created.
+ * 
+ * The processor iterates over the methods of the module class and their annotations.
+ * Annotations defined in ancestors are included too.
+ * For each found annotation a list of registered processors for the annotation type 
+ * is requested from the associated {@link AnnotationProcessorRegistry}. 
+ * The processors are called and can contribute to the module definition.
+ * 
  * The construction of extension points and extensions bases on reflective method calls
  * to an instance of the module class. The module instance is created by a 
  * {@link ModuleInstanceProvider} during registry construction. 
@@ -64,19 +56,16 @@
 
     private ClassResolver _classResolver;
 
-    private ErrorHandler _errorHandler;
-
     private RegistryDefinition _registryDefinition;
     
     private AnnotationProcessorRegistry _annotationProcessorRegistry;
 
     public AnnotatedModuleProcessor(RegistryDefinition registryDefinition,
-            ClassResolver classResolver, ErrorHandler errorHandler)
+            ClassResolver classResolver, AnnotationProcessorRegistry annotationProcessorRegistry)
     {
         _registryDefinition = registryDefinition;
         _classResolver = classResolver;
-        _errorHandler = errorHandler;
-        _annotationProcessorRegistry = createAnnotationProcessorRegistry();
+        _annotationProcessorRegistry = annotationProcessorRegistry;
     }
     
     public void processModule(Class moduleClass)
@@ -110,13 +99,6 @@
 
     }
     
-    private AnnotationProcessorRegistry createAnnotationProcessorRegistry()
-    {
-        AnnotationProcessorRegistry result = new AnnotationProcessorRegistry();
-        result.registerProcessor(Service.class, new ServiceProcessor());
-        return result;
-    }
-    
     /**
      * Ensures that a module class fulfills all prerequisites.
      * 
@@ -172,160 +154,22 @@
             Location location = new AnnotatedModuleLocation(module.getLocation().getResource(),

                     method.getDeclaringClass(), method);
 
-            AnnotationProcessingContext context = new AnnotationProcessingContextImpl(module,
-                    annotation, method, location, instanceProvider);
+            AnnotationProcessingContext context = new AnnotationProcessingContextImpl(
+                    _registryDefinition, module, _classResolver,
+                    annotation, method, location, instanceProvider,
+                    _annotationProcessorRegistry);
             
-            List<AnnotationProcessor> processors = _annotationProcessorRegistry.getProcessors(annotation.getClass());
+            List<AnnotationProcessor> processors = _annotationProcessorRegistry.getProcessors(annotation.annotationType());
             if (processors != null) {
                 for (AnnotationProcessor processor : processors)
                 {
-                    processor.processAnnotation(null);
+                    processor.processAnnotation(context);
                 }
             }
-            
-            if (Service.class.equals(annotation.annotationType()))
-            {
-                processAnnotatedServiceMethod(
-                        method,
-                        (Service) annotation,
-                        module,
-                        instanceProvider);
-            }
-            else if (Configuration.class.equals(annotation.annotationType()))
-            {
-                processAnnotatedConfigurationMethod(
-                        method,
-                        (Configuration) annotation,
-                        module,
-                        instanceProvider);
-            }
-            else if (org.apache.hivemind.annotations.definition.Contribution.class.equals(annotation.annotationType()))
-            {
-                processAnnotatedContributionMethod(
-                        method,
-                        (org.apache.hivemind.annotations.definition.Contribution) annotation,
-                        module,
-                        instanceProvider);
-            }
-            else if (Submodule.class.equals(annotation.annotationType()))
-            {
-                processAnnotatedSubmoduleMethod(
-                        method,
-                        (Submodule) annotation,
-                        module,
-                        instanceProvider);
-            }
-        }
-
-    }
-    
-
-    private void processAnnotatedServiceMethod(Method method, Service service,
-            AnnotatedModuleDefinitionImpl module, ModuleInstanceProvider instanceProvider)
-    {
-        CheckTools.checkMethodModifiers(method, 0, "service point");
-        
-        if (_log.isDebugEnabled())
-        {
-            _log.debug("Method " + method.getName() + "classified as service point.");
-        }
-        
-        Location location = new AnnotatedModuleLocation(module.getLocation().getResource(),

-                method.getDeclaringClass(), method);
-
-        Visibility visibility = Visibility.PUBLIC;
-        if (Modifier.isProtected(method.getModifiers())) {
-            visibility = Visibility.PRIVATE;
-        }
-        ServicePointDefinitionImpl spd = new ServicePointDefinitionImpl(module, service.id(),
location, 
-                visibility, method.getReturnType().getName());
-        module.addServicePoint(spd);
-
-        ImplementationConstructor constructor = new MethodCallImplementationConstructor(location,

-                method, instanceProvider);
-
-        ImplementationDefinition sid = new ImplementationDefinitionImpl(module, location,

-                constructor, service.serviceModel(), true);
-
-        spd.addImplementation(sid);
-
-    }
-
-    private void processAnnotatedConfigurationMethod(Method method, Configuration configuration,

-            AnnotatedModuleDefinitionImpl module, ModuleInstanceProvider instanceProvider)
-    {
-        CheckTools.checkMethodModifiers(method, 0, "configuration point");
-
-        if (_log.isDebugEnabled())
-        {
-            _log.debug("Method " + method.getName() + "classified as configuration point.");
-        }
-        
-        Location location = new AnnotatedModuleLocation(module.getLocation().getResource(),

-                method.getDeclaringClass(), method);
-        
-        Visibility visibility = Visibility.PUBLIC;
-        if (Modifier.isProtected(method.getModifiers())) {
-            visibility = Visibility.PRIVATE;
         }
-        ConfigurationPointDefinitionImpl cpd = new ConfigurationPointDefinitionImpl(module,
configuration.id(), 
-                location, visibility, method.getReturnType().getName(), Occurances.UNBOUNDED,
-                false);
-        module.addConfigurationPoint(cpd);
-        
-        // Add method implementation as initial contribution
-        Contribution contribution = new MethodCallContributionConstructor(
-                location, method, instanceProvider);
-        ContributionDefinitionImpl cd = new ContributionDefinitionImpl(module, location,
contribution, true);
-        cpd.addContribution(cd);
-    }
-
-    private void processAnnotatedContributionMethod(Method method, org.apache.hivemind.annotations.definition.Contribution
contribution, 
-            AnnotatedModuleDefinitionImpl module, ModuleInstanceProvider instanceProvider)
-    {
-        CheckTools.checkMethodModifiers(method, 0, "contribution");
-
-        if (_log.isDebugEnabled())
-        {
-            _log.debug("Method " + method.getName() + "classified as contribution.");
-        }
-        
-        Location location = new AnnotatedModuleLocation(module.getLocation().getResource(),

-                method.getDeclaringClass(), method);
-        
-        Contribution constructor = new MethodCallContributionConstructor(
-                location, method, instanceProvider);
-
-        ContributionDefinitionImpl cd = new ContributionDefinitionImpl(module, location,
constructor, false);
-        String qualifiedConfigurationId = IdUtils.qualify(
-                module.getId(),
-                contribution.configurationId());
-        module.addContribution(qualifiedConfigurationId, cd);
 
     }
-    
-    /**
-     * Processes a method that is marked as submodule definition.
-     */
-    private void processAnnotatedSubmoduleMethod(Method method, Submodule submodule, 
-            AnnotatedModuleDefinitionImpl module, ModuleInstanceProvider instanceProvider)
-    {
-        CheckTools.checkMethodModifiers(method, 0, "submodule");
 
-        if (_log.isDebugEnabled())
-        {
-            _log.debug("Method " + method.getName() + "classified as submodule.");
-        }
-        
-        String fullModuleId = IdUtils.qualify(
-                module.getId(),
-                submodule.id());
-        // TODO: Check if return type is defined
-        AnnotatedModuleProcessor submoduleProcessor = new AnnotatedModuleProcessor(_registryDefinition,
-                _classResolver, _errorHandler);
-        submoduleProcessor.processModule(method.getReturnType(), fullModuleId);
-    }
-    
     /**
      * Creates a location pointing at the module class. 
      */

Added: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationExtensionLoader.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationExtensionLoader.java?view=auto&rev=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationExtensionLoader.java
(added)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationExtensionLoader.java
Sun Mar  4 23:01:03 2007
@@ -0,0 +1,175 @@
+// Copyright 2007 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.
+
+package org.apache.hivemind.annotations.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.ClassResolver;
+import org.apache.hivemind.annotations.definition.processors.AnnotationProcessor;
+import org.apache.hivemind.util.IOUtils;
+import org.apache.hivemind.util.URLResource;
+
+/**
+ * @author Achim Huegen
+ */
+public class AnnotationExtensionLoader
+{
+    private static final Log LOG = LogFactory.getLog(AnnotationExtensionLoader.class);
+    public static final String MANIFEST = "META-INF/MANIFEST.MF";
+    public static final String HIVEMIND_SECTION_NAME = "hivemind";
+    public static final String PROCESSOR_ATTRIBUTE_NAME = "annotation-definition-processors";
+    
+    private List _providers = new ArrayList();
+    
+    public AnnotationExtensionLoader(ClassResolver resolver)
+    {
+        processManifestFiles(resolver);
+    }
+    
+    public List getProviders()
+    {
+        return _providers;
+    }
+    
+    /**
+     * Process all manifest files found in the classpath
+     * @param resolver  the ClassResolver to use for the search
+     */
+    private void processManifestFiles(ClassResolver resolver)
+    {
+        if (LOG.isDebugEnabled())
+            LOG.debug("Processing manifest files visible to " + resolver);
+
+        ClassLoader loader = resolver.getClassLoader();
+        Enumeration e = null;
+
+        try
+        {
+            e = loader.getResources(MANIFEST);
+        }
+        catch (IOException ex)
+        {
+            throw new ApplicationRuntimeException(ImplMessages.unableToFindProviders(resolver,
ex),
+                    ex);
+        }
+
+        while (e.hasMoreElements())
+        {
+            URL descriptorURL = (URL) e.nextElement();
+
+            processManifestFile(resolver, new URLResource(descriptorURL));
+        }
+
+    }
+
+
+    /**
+     * Process a single manifest file.
+     * 
+     * @param resolver
+     * @param resource  pointer to the manifest file
+     */
+    private void processManifestFile(ClassResolver resolver, URLResource resource)
+    {
+        URL url = resource.getResourceURL();
+        InputStream manifestStream = null;
+        Manifest manifest;
+        try
+        {
+            manifestStream = IOUtils.openStreamWithoutCaching(url);
+            manifest = new Manifest(manifestStream);
+        }
+        catch (IOException e)
+        {
+            throw new ApplicationRuntimeException(ImplMessages.unableToReadManifest(url,
e),
+                    e);
+        }
+        finally
+        {
+            IOUtils.close(manifestStream);
+        }
+        // Search for an entry that defines a provider class
+        Attributes attributes = manifest.getMainAttributes();
+        if (attributes != null) {
+            String providers = attributes.getValue(PROCESSOR_ATTRIBUTE_NAME);
+            if (providers != null) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Found providers '" + providers + "' defined in manifest file
'" + url.toString() + "'");
+                }
+                handleProviderAttribute(resolver, providers);
+            }
+        }
+    }
+
+    /**
+     * Parse the provider list in an attribute and load all classes.
+     */
+    private void handleProviderAttribute(ClassResolver resolver, String providers)
+    {
+        StringTokenizer tokenizer = new StringTokenizer(providers, ",");
+        while (tokenizer.hasMoreTokens())
+        {   
+            String providerClassName = tokenizer.nextToken();
+            loadProvider(resolver, providerClassName);
+        }
+    }
+    
+    /**
+     * Load a provider class and create an instance.
+     * 
+     * @param resolver
+     * @param providerClassName
+     */
+    private void loadProvider(ClassResolver resolver, String providerClassName)
+    {
+        if (LOG.isDebugEnabled())
+            LOG.debug("Loading provider " + providerClassName);
+        Object provider = null;
+        try
+        {
+            Class providerClass = resolver.findClass(providerClassName);
+            provider = providerClass.newInstance();
+        }
+        catch (Exception e)
+        {
+            Exception cause = e;
+            if (e instanceof InvocationTargetException)
+            {
+                cause = (InvocationTargetException) e;
+            }
+            throw new ApplicationRuntimeException(ImplMessages.unableToCreateProvider(providerClassName,
e),
+                    cause);
+        }
+        // Check type of provider
+        if (!(provider instanceof AnnotationProcessor)) {
+            throw new ApplicationRuntimeException(ImplMessages.providerWrongType(providerClassName,
RegistryProvider.class));
+        }
+        
+        _providers.add(provider);
+    }
+
+}

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessingContextImpl.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessingContextImpl.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessingContextImpl.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessingContextImpl.java
Sun Mar  4 23:01:03 2007
@@ -3,9 +3,11 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
 
+import org.apache.hivemind.ClassResolver;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.annotations.definition.impl.AnnotatedModuleDefinitionImpl;
 import org.apache.hivemind.annotations.definition.processors.AnnotationProcessingContext;
+import org.apache.hivemind.definition.RegistryDefinition;
 
 public class AnnotationProcessingContextImpl implements AnnotationProcessingContext
 {
@@ -14,15 +16,26 @@
     private AnnotatedModuleDefinitionImpl _module;
     private ModuleInstanceProvider _moduleInstanceProvider;
     private Annotation _targetAnnotation;
-
-    public AnnotationProcessingContextImpl(AnnotatedModuleDefinitionImpl module, Annotation
targetAnnotation, AnnotatedElement annotatedElement, Location location, ModuleInstanceProvider
moduleInstanceProvider)
+    private RegistryDefinition _registryDefinition;
+    private ClassResolver _classResolver;
+    private AnnotationProcessorRegistry _annotationProcessorRegistry;
+    
+    public AnnotationProcessingContextImpl(
+            RegistryDefinition registryDefinition, AnnotatedModuleDefinitionImpl module,
+            ClassResolver classResolver,
+            Annotation targetAnnotation, AnnotatedElement annotatedElement, 
+            Location location, ModuleInstanceProvider moduleInstanceProvider,
+            AnnotationProcessorRegistry annotationProcessorRegistry)
     {
         super();
+        _registryDefinition = registryDefinition;
         _module = module;
+        _classResolver = classResolver;
         _targetAnnotation = targetAnnotation;
         _annotatedElement = annotatedElement;
         _location = location;
         _moduleInstanceProvider = moduleInstanceProvider;
+        _annotationProcessorRegistry = annotationProcessorRegistry;
     }
 
     public Annotation[] getAllAnnotations()
@@ -53,6 +66,17 @@
     public Annotation getTargetAnnotation()
     {
         return _targetAnnotation;
+    }
+
+    public ClassResolver getClassResolver()
+    {
+        return _classResolver;
+    }
+
+    public AnnotatedModuleProcessor createSubmoduleProcessor()
+    {
+        return new AnnotatedModuleProcessor(_registryDefinition,
+                _classResolver, _annotationProcessorRegistry);
     }
 
 }

Added: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java?view=auto&rev=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java
(added)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java
Sun Mar  4 23:01:03 2007
@@ -0,0 +1,25 @@
+package org.apache.hivemind.annotations.internal;
+
+import org.apache.hivemind.annotations.definition.Configuration;
+import org.apache.hivemind.annotations.definition.Contribution;
+import org.apache.hivemind.annotations.definition.Service;
+import org.apache.hivemind.annotations.definition.Submodule;
+import org.apache.hivemind.annotations.definition.processors.ConfigurationProcessor;
+import org.apache.hivemind.annotations.definition.processors.ContributionProcessor;
+import org.apache.hivemind.annotations.definition.processors.ServiceProcessor;
+import org.apache.hivemind.annotations.definition.processors.SubmoduleProcessor;
+
+public class AnnotationProcessorRegistryFactory
+{
+    
+    public static AnnotationProcessorRegistry createDefaultRegistry()
+    {
+        AnnotationProcessorRegistry result = new AnnotationProcessorRegistry();
+        result.registerProcessor(Service.class, new ServiceProcessor());
+        result.registerProcessor(Configuration.class, new ConfigurationProcessor());
+        result.registerProcessor(Contribution.class, new ContributionProcessor());
+        result.registerProcessor(Submodule.class, new SubmoduleProcessor());
+        return result;
+    }
+}
+

Modified: hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/AnnotationTestCase.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/AnnotationTestCase.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/AnnotationTestCase.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/AnnotationTestCase.java
Sun Mar  4 23:01:03 2007
@@ -16,9 +16,13 @@
 
 import org.apache.hivemind.definition.RegistryDefinition;
 import org.apache.hivemind.definition.impl.RegistryDefinitionImpl;
-import org.apache.hivemind.impl.DefaultErrorHandler;
 import org.apache.hivemind.test.HiveMindTestCase;
 
+/**
+ * Ancestor for test cases that use annotated modules.
+ * 
+ * @author Achim Huegen
+ */
 public class AnnotationTestCase extends HiveMindTestCase
 {
     protected TypedRegistry constructRegistry(String ... moduleClassNames)
@@ -39,8 +43,7 @@
 
         for (int i = 0; i < moduleClasses.length; i++)
         {
-            AnnotatedModuleReader reader = new AnnotatedModuleReader(definition, getClassResolver(),
-                    new DefaultErrorHandler());
+            AnnotatedModuleReader reader = new AnnotatedModuleReader(definition, getClassResolver());
             reader.readModule(moduleClasses[i]);
         }
 

Modified: hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java?view=diff&rev=514579&r1=514578&r2=514579
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java
Sun Mar  4 23:01:03 2007
@@ -21,7 +21,6 @@
 import org.apache.hivemind.definition.ServicePointDefinition;
 import org.apache.hivemind.definition.impl.RegistryDefinitionImpl;
 import org.apache.hivemind.impl.DefaultClassResolver;
-import org.apache.hivemind.impl.DefaultErrorHandler;
 
 public class TestAnnotatedModuleReader extends AnnotationTestCase
 {
@@ -57,7 +56,7 @@
     public void testModuleClassNotFinal()
     {
         AnnotatedModuleProcessor processor = new AnnotatedModuleProcessor(new RegistryDefinitionImpl(),
-                new DefaultClassResolver(), new DefaultErrorHandler());
+                new DefaultClassResolver());
         try
         {
             processor.processModule(FinalModule.class);
@@ -71,7 +70,7 @@
     public void testModuleClassNotAbstract()
     {
         AnnotatedModuleProcessor processor = new AnnotatedModuleProcessor(new RegistryDefinitionImpl(),
-                new DefaultClassResolver(), new DefaultErrorHandler());
+                new DefaultClassResolver());
         try
         {
             processor.processModule(AbstractModule.class);
@@ -85,7 +84,7 @@
     public void testModuleClassPublic()
     {
         AnnotatedModuleProcessor processor = new AnnotatedModuleProcessor(new RegistryDefinitionImpl(),
-                new DefaultClassResolver(), new DefaultErrorHandler());
+                new DefaultClassResolver());
         try
         {
             processor.processModule(NotPublicModule.class);



Mime
View raw message