hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r470727 - in /hivemind/branches/branch-2-0-annot/xml/src: descriptor/META-INF/ java/org/apache/hivemind/ java/org/apache/hivemind/ant/ java/org/apache/hivemind/impl/ java/org/apache/hivemind/impl/natures/ java/org/apache/hivemind/schema/rul...
Date Fri, 03 Nov 2006 08:54:34 GMT
Author: ahuegen
Date: Fri Nov  3 00:54:32 2006
New Revision: 470727

URL: http://svn.apache.org/viewvc?view=rev&rev=470727
Log:
Made TranslatorManager an ordinary service. 
It is defined in the new XmlCoreServicesProvider which is autoloaded.

Added:
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/HivemoduleProvider.java
      - copied, changed from r470270, hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlCoreServicesProvider.java
Removed:
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java
Modified:
    hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/MANIFEST.MF
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/TranslatorManager.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/ant/ConstructRegistry.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryInterceptorConstructor.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlContributionImpl.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java
    hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestInvokeFactoryServiceConstructor.java
    hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
    hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestTranslatorManager.java
    hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet.java

Modified: hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/MANIFEST.MF?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/MANIFEST.MF (original)
+++ hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/MANIFEST.MF Fri Nov  3
00:54:32 2006
@@ -1,2 +1,2 @@
-hivemind-provider: org.apache.hivemind.impl.XmlRegistryProvider
+hivemind-providers: org.apache.hivemind.impl.HivemoduleProvider,org.apache.hivemind.impl.XmlCoreServicesProvider
 

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/TranslatorManager.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/TranslatorManager.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/TranslatorManager.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/TranslatorManager.java
Fri Nov  3 00:54:32 2006
@@ -2,9 +2,19 @@
 
 import org.apache.hivemind.schema.Translator;
 
+/**
+ * Manages translators for {@link org.apache.hivemind.impl.RegistryInfrastructureImpl}.
+ * Translators may be a shared, cached instance.
+ * (Translators should be stateless). Translators are identified by a constructor, which
may be
+ * the name of a translator defined in the <code>hivemind.Translators</code>
extension point
+ * (a single builtin translator, <code>class</code>, is hardcoded). Alternately,
the name may
+ * consist of a translator name, a comma, and an initializer string for the service (example:
+ * <code>int,min=5</code>).
+ * 
+ * @author Howard Lewis Ship
+ */
 public interface TranslatorManager
 {
-
     public abstract Translator getTranslator(String constructor);
 
 }

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/ant/ConstructRegistry.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/ant/ConstructRegistry.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/ant/ConstructRegistry.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/ant/ConstructRegistry.java
Fri Nov  3 00:54:32 2006
@@ -25,7 +25,7 @@
 import org.apache.hivemind.definition.RegistryDefinition;
 import org.apache.hivemind.impl.RegistryBuilder;
 import org.apache.hivemind.impl.XmlModuleReader;
-import org.apache.hivemind.impl.XmlRegistryProvider;
+import org.apache.hivemind.impl.HivemoduleProvider;
 import org.apache.hivemind.util.FileResource;
 import org.apache.hivemind.util.URLResource;
 import org.apache.tools.ant.BuildException;
@@ -142,7 +142,7 @@
     
     private void enqueueJar(File jarFile, RegistryDefinition definition) throws IOException
     {
-        URL jarRootURL = new URL("jar:" + jarFile.toURL() + "!/" + XmlRegistryProvider.HIVE_MODULE_XML);
+        URL jarRootURL = new URL("jar:" + jarFile.toURL() + "!/" + HivemoduleProvider.HIVE_MODULE_XML);
 
         Resource jarResource = new URLResource(jarRootURL);
         enqueue(jarResource, definition);

Copied: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/HivemoduleProvider.java
(from r470270, hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java)
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/HivemoduleProvider.java?view=diff&rev=470727&p1=hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java&r1=470270&p2=hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/HivemoduleProvider.java&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/HivemoduleProvider.java
Fri Nov  3 00:54:32 2006
@@ -6,9 +6,13 @@
 import org.apache.hivemind.ErrorHandler;
 import org.apache.hivemind.definition.RegistryDefinition;
 
-public class XmlRegistryProvider implements RegistryProvider
+/**
+ * Implementation of {@link RegistryProvider} that loads all xml modules
+ * defined in <code>META-INF/hivemodule.xml</code> files. 
+ */
+public class HivemoduleProvider implements RegistryProvider
 {
-    private static final Log LOG = LogFactory.getLog(RegistryBuilder.class);
+    private static final Log LOG = LogFactory.getLog(HivemoduleProvider.class);
 
     /**
      * The default path, within a JAR or the classpath, to the XML HiveMind module deployment
@@ -21,12 +25,12 @@
     
     private String _resourcePath;
 
-    public XmlRegistryProvider()
+    public HivemoduleProvider()
     {
         this(new DefaultClassResolver(), HIVE_MODULE_XML);
     }
 
-    public XmlRegistryProvider(ClassResolver classResolver, String resourcePath)
+    public HivemoduleProvider(ClassResolver classResolver, String resourcePath)
     {
         _classResolver = classResolver;
         _resourcePath = resourcePath;
@@ -41,5 +45,5 @@
 
         xmlModuleReader.readClassPathModules(_resourcePath);
     }
-    
+
 }

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryInterceptorConstructor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryInterceptorConstructor.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryInterceptorConstructor.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryInterceptorConstructor.java
Fri Nov  3 00:54:32 2006
@@ -22,7 +22,6 @@
 import org.apache.hivemind.Orderable;
 import org.apache.hivemind.ServiceInterceptorFactory;
 import org.apache.hivemind.TranslatorManager;
-import org.apache.hivemind.impl.natures.XmlRegistryNature;
 import org.apache.hivemind.impl.natures.XmlServicePointNature;
 import org.apache.hivemind.internal.AbstractServiceInterceptorConstructor;
 import org.apache.hivemind.internal.Module;
@@ -90,9 +89,6 @@
                 // TODO annotations: Externalize message
                 throw new ApplicationRuntimeException("ServicePoint has no xml nature");
             }
-            XmlRegistryNature xmlRegistryNature = (XmlRegistryNature) contributingModule.getRegistry().getNature(XmlRegistryNature.class);
-            TranslatorManager translatorManager = xmlRegistryNature.getTranslationManager();
-
             Schema schema = xmlNature.getParametersSchema();
             if (schema != null) {
 
@@ -100,7 +96,7 @@
                         schema);
                 
                 _convertedParameters = constructParametersContainer(schema.getRootElementClassName(),
factoryPoint.getModule());
-                processor.process(_convertedParameters, _parameters, contributingModule,
translatorManager);
+                processor.process(_convertedParameters, _parameters, contributingModule);
             }
         }
     }

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java
Fri Nov  3 00:54:32 2006
@@ -24,7 +24,6 @@
 import org.apache.hivemind.ServiceImplementationFactoryParameters;
 import org.apache.hivemind.TranslatorManager;
 import org.apache.hivemind.definition.construction.ImplementationConstructionContext;
-import org.apache.hivemind.impl.natures.XmlRegistryNature;
 import org.apache.hivemind.impl.natures.XmlServicePointNature;
 import org.apache.hivemind.internal.AbstractServiceImplementationConstructor;
 import org.apache.hivemind.internal.Module;
@@ -91,9 +90,6 @@
                 // TODO annotations:
                 throw new ApplicationRuntimeException("ServicePoint has no xml nature");
             }
-            XmlRegistryNature xmlRegistryNature = (XmlRegistryNature) contributingModule.getRegistry().getNature(XmlRegistryNature.class);
-            TranslatorManager translatorManager = xmlRegistryNature.getTranslationManager();
-
             _factory = (ServiceImplementationFactory) factoryPoint
                     .getService(ServiceImplementationFactory.class);
 
@@ -104,9 +100,9 @@
                 checkParameterCounts(errorLog, expected);
 
                 SchemaProcessorImpl processor = new SchemaProcessorImpl(errorLog, schema);
-    
+                
                 _convertedParameters = constructParametersContainer(schema.getRootElementClassName(),
factoryPoint.getModule());
-                processor.process(_convertedParameters, _parameters, contributingModule,
translatorManager);
+                processor.process(_convertedParameters, _parameters, contributingModule);
             }
         }
     }

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java
Fri Nov  3 00:54:32 2006
@@ -217,8 +217,7 @@
      * Processes a single extension.
      * @param container  the container object in that the parsed elements are placed
      */
-    public void process(Object container, List elements, Module contributingModule,
-            TranslatorManager translatorManager)
+    public void process(Object container, List elements, Module contributingModule)
     {
         if (elements == null)
             return;
@@ -238,7 +237,6 @@
         push(container);
 
         _contributingModule = contributingModule;
-        _translatorManager = translatorManager;
 
         int count = elements.size();
 
@@ -321,6 +319,10 @@
 
     public Translator getTranslator(String translator)
     {
+        if (_translatorManager == null) {
+            _translatorManager = (TranslatorManager) _contributingModule.getService(TranslatorManager.class);
+        }
+        
         return _translatorManager.getTranslator(translator);
     }
 }

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java
Fri Nov  3 00:54:32 2006
@@ -26,7 +26,6 @@
 import org.apache.hivemind.ErrorHandler;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.TranslatorManager;
-import org.apache.hivemind.internal.RegistryInfrastructure;
 import org.apache.hivemind.schema.Translator;
 import org.apache.hivemind.schema.rules.ClassTranslator;
 import org.apache.hivemind.schema.rules.InstanceTranslator;
@@ -34,15 +33,7 @@
 import org.apache.hivemind.schema.rules.SmartTranslator;
 
 /**
- * Manages translators for {@link org.apache.hivemind.impl.RegistryInfrastructureImpl}.
- * Translators may be a shared, cached instance.
- * (Translators should be stateless). Translators are identified by a constructor, which
may be
- * the name of a translator defined in the <code>hivemind.Translators</code>
extension point
- * (a single builtin translator, <code>class</code>, is hardcoded). Alternately,
the name may
- * consist of a translator name, a comma, and an initializer string for the service (example:
- * <code>int,min=5</code>).
- * 
- * @author Howard Lewis Ship
+ * Implementation of {@link TranslatorManager}
  */
 public class TranslatorManagerImpl implements TranslatorManager
 {
@@ -52,8 +43,6 @@
 
     private ErrorHandler _errorHandler;
 
-    private RegistryInfrastructure _registry;
-
     /**
      * Map of Class, keyed on translator name, used to instantiate new
      * {@link org.apache.hivemind.schema.Translator}s. Loaded from the
@@ -63,11 +52,18 @@
 
     private Map _translatorsCache = new HashMap();
 
+    private List _contributedTranslators;
+    
     private boolean _translatorsLoaded;
+    
+    public TranslatorManagerImpl(List translators)
+    {
+        this(translators, new DefaultErrorHandler());
+    }
 
-    public TranslatorManagerImpl(RegistryInfrastructure registry, ErrorHandler errorHandler)
+    public TranslatorManagerImpl(List translators, ErrorHandler errorHandler)
     {
-        _registry = registry;
+        _contributedTranslators = translators;
         _errorHandler = errorHandler;
 
         // Seed the basic translators used to "bootstrap" the
@@ -93,7 +89,7 @@
         // The cache is preloaded with the hardcoded translators.
 
         if (!_translatorsLoaded && !_translatorsCache.containsKey(constructor))
-            loadTranslators();
+            loadContributedTranslators();
 
         Translator result = (Translator) _translatorsCache.get(constructor);
 
@@ -160,18 +156,21 @@
         return result;
     }
 
-    private void loadTranslators()
+    /**
+     * Load the contributed translators. This is done as late as possible since the
+     * parsing of the xml contributes will trigger a recursive call. The configuration
+     * is lazy so that parsing is executed on first element access.
+     */
+    private void loadContributedTranslators()
     {
         // Prevent endless recursion!
 
         _translatorsLoaded = true;
 
-        List contributions = (List) _registry.getConfiguration(TRANSLATORS_CONFIGURATION_ID,
null);
- 
         Map locations = new HashMap();
         locations.put("class", null);
 
-        Iterator i = contributions.iterator();
+        Iterator i = _contributedTranslators.iterator();
         while (i.hasNext())
         {
             TranslatorContribution c = (TranslatorContribution) i.next();

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlContributionImpl.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlContributionImpl.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlContributionImpl.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlContributionImpl.java
Fri Nov  3 00:54:32 2006
@@ -23,7 +23,6 @@
 import org.apache.hivemind.definition.construction.ContributionConstructionContext;
 import org.apache.hivemind.definition.construction.ContributionConstructor;
 import org.apache.hivemind.impl.natures.XmlConfigurationPointNature;
-import org.apache.hivemind.impl.natures.XmlRegistryNature;
 import org.apache.hivemind.internal.Module;
 import org.apache.hivemind.schema.Schema;
 
@@ -77,13 +76,10 @@
         
         Module contributingModule = context.getDefiningModule();
 
-        XmlRegistryNature xmlRegistryNature = (XmlRegistryNature) contributingModule.getRegistry().getNature(XmlRegistryNature.class);
-        TranslatorManager translatorManager = xmlRegistryNature.getTranslationManager();
-
         Schema contributionsSchema = xmlNature.getSchema();
         if (contributionsSchema != null) {
             SchemaProcessorImpl processor = new SchemaProcessorImpl(context.getConfigurationPoint().getErrorLog(),
contributionsSchema);
-            processor.process(container, getElements(), contributingModule, translatorManager);
+            processor.process(container, getElements(), contributingModule);
         } else {
             // Expect a list that was created by {@link XmlConfigurationConstructor} for
             // backward compatibility reasons

Added: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlCoreServicesProvider.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlCoreServicesProvider.java?view=auto&rev=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlCoreServicesProvider.java
(added)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlCoreServicesProvider.java
Fri Nov  3 00:54:32 2006
@@ -0,0 +1,65 @@
+package org.apache.hivemind.impl;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.TranslatorManager;
+import org.apache.hivemind.definition.ModuleDefinition;
+import org.apache.hivemind.definition.ModuleDefinitionHelper;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.definition.ServicePointDefinition;
+import org.apache.hivemind.definition.construction.ImplementationConstructionContext;
+import org.apache.hivemind.definition.construction.ImplementationConstructor;
+import org.apache.hivemind.internal.AbstractServiceImplementationConstructor;
+import org.apache.hivemind.internal.ServiceModel;
+
+/**
+ * Implementation of {@link RegistryProvider} that defines core services
+ * needed by the xml implementation. Theses services can not be defined in
+ * xml because that would cause recursive behaviour.
+ */
+public class XmlCoreServicesProvider implements RegistryProvider
+{
+    private static final Log LOG = LogFactory.getLog(XmlCoreServicesProvider.class);
+
+    public void process(RegistryDefinition registryDefinition, ErrorHandler errorHandler)
+    {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Adding xml core services to registry");  
+        }
+        
+        // The "hivemind" module is available here only if the HivemoduleProvider
+        // has been executed before. This order is defined in the MANIFEST.MF file of the
xml module 
+        ModuleDefinition moduleDefinition = registryDefinition.getModule("hivemind");
+        if (moduleDefinition == null) {
+            throw new ApplicationRuntimeException("Module 'hivemind' not found.");
+        }
+        addTranslatorManager(moduleDefinition, errorHandler);
+    }
+    
+    /**
+     * @see TranslatorManager
+     */
+    private void addTranslatorManager(ModuleDefinition md, final ErrorHandler errorHandler)
+    {
+        ModuleDefinitionHelper helper = new ModuleDefinitionHelper(md);
+        ServicePointDefinition spd = helper.addServicePoint("TranslationManager", TranslatorManager.class.getName());
+
+        // Define inline implementation constructor, that wires the Translators configuration
+        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(md.getLocation())
+        {
+            public Object constructCoreServiceImplementation(ImplementationConstructionContext
context)
+            {
+                List translators = (List) context.getConfiguration("Translators");
+                TranslatorManager result = new TranslatorManagerImpl(translators, errorHandler);
+                return result;
+            }
+        };
+        helper.addServiceImplementation(spd, constructor, ServiceModel.PRIMITIVE);
+        
+    }
+    
+}

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java
Fri Nov  3 00:54:32 2006
@@ -104,7 +104,7 @@
     private void initXmlRegistryNature()
     {
         if (getXmlRegistryNature() == null) {
-            _registryDefinition.addNature(XmlRegistryNature.class, new XmlRegistryNature(_errorHandler));
+            _registryDefinition.addNature(XmlRegistryNature.class, new XmlRegistryNature());
         }
     }
 

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java
Fri Nov  3 00:54:32 2006
@@ -5,16 +5,12 @@
 import java.util.Map;
 
 import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.TranslatorManager;
 import org.apache.hivemind.definition.RegistryNature;
-import org.apache.hivemind.impl.TranslatorManagerImpl;
 import org.apache.hivemind.internal.RegistryInfrastructure;
 import org.apache.hivemind.schema.Schema;
 
 public class XmlRegistryNature implements RegistryNature
 {
-    private TranslatorManager _translationManager;
-    private ErrorHandler _errorHandler;
     private RegistryInfrastructure _registry;
 
     /**
@@ -22,25 +18,10 @@
      */
     private Map _schemas = new HashMap();
 
-    public XmlRegistryNature(ErrorHandler handler)
+    public XmlRegistryNature()
     {
-        _errorHandler = handler;
     }
 
-    public TranslatorManager getTranslationManager()
-    {
-        if (_translationManager == null) {
-            _translationManager = new TranslatorManagerImpl(_registry, _errorHandler);
-        }
-        
-        return _translationManager;
-    }
-
-    public void setTranslationManager(TranslatorManager translationManager)
-    {
-        _translationManager = translationManager;
-    }
-    
     public void addSchema(String qualifiedSchemaId, Schema schema)
     {
         _schemas.put(qualifiedSchemaId, schema);

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java
Fri Nov  3 00:54:32 2006
@@ -24,8 +24,6 @@
 import org.apache.hivemind.Element;
 import org.apache.hivemind.ErrorHandler;
 import org.apache.hivemind.HiveMind;
-import org.apache.hivemind.TranslatorManager;
-import org.apache.hivemind.impl.natures.XmlRegistryNature;
 import org.apache.hivemind.internal.Module;
 import org.apache.hivemind.schema.SchemaProcessor;
 import org.apache.hivemind.schema.Translator;
@@ -152,9 +150,6 @@
         if (translator == null)
             return new NullTranslator();
         
-        XmlRegistryNature xmlNature = (XmlRegistryNature) processor.getContributingModule().getRegistry().getNature(XmlRegistryNature.class);
-        TranslatorManager translatorManager = xmlNature.getTranslationManager();
-
-        return translatorManager.getTranslator(translator);
+        return processor.getTranslator(translator);
     }
 }

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java
Fri Nov  3 00:54:32 2006
@@ -20,7 +20,6 @@
 import org.apache.hivemind.Location;
 import org.apache.hivemind.ServiceImplementationFactoryParameters;
 import org.apache.hivemind.TranslatorManager;
-import org.apache.hivemind.impl.natures.XmlRegistryNature;
 import org.apache.hivemind.internal.Module;
 import org.apache.hivemind.schema.Translator;
 import org.apache.hivemind.util.ConstructorUtils;
@@ -51,8 +50,7 @@
 
         if (result == null)
         {
-            XmlRegistryNature xmlNature = (XmlRegistryNature) factoryParameters.getInvokingModule().getRegistry().getNature(XmlRegistryNature.class);
-            TranslatorManager translatorManager = xmlNature.getTranslationManager();
+            TranslatorManager translatorManager = (TranslatorManager) factoryParameters.getInvokingModule().getService(TranslatorManager.class);
             Translator translator = translatorManager.getTranslator(_translatorName);
 
             result = translator.translate(

Modified: hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestInvokeFactoryServiceConstructor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestInvokeFactoryServiceConstructor.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestInvokeFactoryServiceConstructor.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestInvokeFactoryServiceConstructor.java
Fri Nov  3 00:54:32 2006
@@ -27,11 +27,9 @@
 import org.apache.hivemind.Registry;
 import org.apache.hivemind.ServiceImplementationFactory;
 import org.apache.hivemind.definition.construction.ImplementationConstructionContext;
-import org.apache.hivemind.impl.natures.XmlRegistryNature;
 import org.apache.hivemind.impl.natures.XmlServicePointNature;
 import org.apache.hivemind.internal.ImplementationConstructionContextImpl;
 import org.apache.hivemind.internal.Module;
-import org.apache.hivemind.internal.RegistryInfrastructure;
 import org.apache.hivemind.internal.ServicePoint;
 import org.apache.hivemind.schema.impl.SchemaImpl;
 import org.apache.hivemind.xml.XmlTestCase;
@@ -49,9 +47,6 @@
         MockControl moduleControl = newControl(Module.class);
         Module module = (Module) moduleControl.getMock();
 
-        MockControl registryControl = newControl(RegistryInfrastructure.class);
-        RegistryInfrastructure registry = (RegistryInfrastructure) registryControl.getMock();
-
         MockControl factoryPointControl = newControl(ServicePoint.class);
         ServicePoint factoryPoint = (ServicePoint) factoryPointControl.getMock();
 
@@ -69,9 +64,6 @@
         xmlNature.setParametersCount(Occurances.REQUIRED);
         xmlNature.setParametersSchema(schema);
         
-        MockControl xmlRegistryNatureControl = newControl(XmlRegistryNature.class);
-        XmlRegistryNature xmlRegistryNature = (XmlRegistryNature) xmlRegistryNatureControl.getMock();
-
         Location location = newLocation();
         InvokeFactoryServiceConstructor c = new InvokeFactoryServiceConstructor(location,
"module");
 
@@ -88,12 +80,6 @@
         module.getServicePoint("foo.bar.Baz");
         moduleControl.setReturnValue(factoryPoint);
         
-        module.getRegistry();
-        moduleControl.setReturnValue(registry);
-        
-        registry.getNature(XmlRegistryNature.class);
-        registryControl.setReturnValue(xmlRegistryNature);
-        
         module.resolveType(ArrayList.class.getName());
         moduleControl.setReturnValue(ArrayList.class);
 
@@ -103,9 +89,6 @@
         factoryPoint.getModule();
         factoryPointControl.setReturnValue(module);
 
-        xmlRegistryNature.getTranslationManager();
-        xmlRegistryNatureControl.setReturnValue(null);
-        
         String message = XmlImplMessages
                 .wrongNumberOfParameters("foo.bar.Baz", 0, Occurances.REQUIRED);
 

Modified: hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
Fri Nov  3 00:54:32 2006
@@ -99,6 +99,9 @@
 
         m.expandSymbols("flintstone", null);
         control.setReturnValue("flintstone");
+        
+        m.getService(TranslatorManager.class);
+        control.setReturnValue(tm);
 
         tm.getTranslator("smart");
         tmControl.setReturnValue(new NullTranslator());
@@ -106,7 +109,7 @@
         replayControls();
 
         List dest = new ArrayList();
-        p.process(dest, elements, m, tm);
+        p.process(dest, elements, m);
 
         assertEquals(1, dest.size());
         StringHolder h = (StringHolder) dest.get(0);
@@ -124,9 +127,6 @@
         MockControl registryControl = newControl(RegistryInfrastructure.class);
         RegistryInfrastructure registry = (RegistryInfrastructure) registryControl.getMock();
 
-        MockControl tmControl = newControl(TranslatorManager.class);
-        TranslatorManager tm = (TranslatorManager) tmControl.getMock();
-
         ElementModelImpl em = new ElementModelImpl("module");
 
         em.setElementName("fred");
@@ -167,7 +167,7 @@
         replayControls();
 
         List dest = new ArrayList();
-        p.process(dest, elements, m, tm);
+        p.process(dest, elements, m);
 
         assertEquals(1, dest.size());
         StringHolder h = (StringHolder) dest.get(0);
@@ -229,6 +229,9 @@
 
         m.expandSymbols("wilma", null);
         control.setReturnValue("wilma");
+        
+        m.getService(TranslatorManager.class);
+        control.setReturnValue(tm);
 
         tm.getTranslator("service");
         tmControl.setReturnValue(new NullTranslator());
@@ -236,7 +239,7 @@
         replayControls();
 
         List dest = new ArrayList();
-        p.process(dest, elements, m, tm);
+        p.process(dest, elements, m);
 
         assertEquals(1, dest.size());
         StringHolder h = (StringHolder) dest.get(0);
@@ -338,6 +341,9 @@
         tm.getTranslator("cartoon");
         tmControl.setReturnValue(t);
 
+        m.getService(TranslatorManager.class);
+        control.setReturnValue(tm);
+
         Object flintstoneKey = new Object();
         t.translate(m, Object.class, "flintstone", element.getLocation());
         tControl.setReturnValue(flintstoneKey);
@@ -345,7 +351,7 @@
         replayControls();
 
         Map dest = new HashMap();
-        p.process(dest, elements, m, tm);
+        p.process(dest, elements, m);
 
         assertEquals(1, dest.size());
         StringHolder h = (StringHolder) dest.get(flintstoneKey);
@@ -438,6 +444,9 @@
         m1.expandSymbols("flintstone", location1);
         control1.setReturnValue("flintstone");
         
+        m1.getService(TranslatorManager.class);
+        control1.setReturnValue(tm);
+        
         m1.expandSymbols("flintstone", location1);
         control1.setReturnValue("flintstone");
 
@@ -468,11 +477,11 @@
 
         tm.getTranslator("qualified-id");
         tmControl.setReturnValue(t2);
-
+        
         String flintstoneKeyModule2 = "m2.flintstone";
         t2.translate(m2, String.class, "flintstone", element2.getLocation());
         tControl2.setReturnValue(flintstoneKeyModule2);
-
+        
         t2.translate(m2, Object.class, "flintstone", element2.getLocation());
         tControl2.setReturnValue(flintstoneKeyModule2);
 
@@ -483,8 +492,8 @@
         replayControls();
 
         Map dest = new HashMap();
-        p.process(dest, elements1, m1, tm);
-        p.process(dest, elements2, m2, tm);
+        p.process(dest, elements1, m1);
+        p.process(dest, elements2, m2);
 
         assertEquals(2, dest.size());
 

Modified: hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestTranslatorManager.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestTranslatorManager.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestTranslatorManager.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestTranslatorManager.java
Fri Nov  3 00:54:32 2006
@@ -19,9 +19,7 @@
 
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.internal.RegistryInfrastructure;
 import org.apache.hivemind.test.HiveMindTestCase;
-import org.easymock.MockControl;
 
 /**
  * Tests for {@link org.apache.hivemind.impl.TranslatorManagerImpl}.
@@ -30,25 +28,12 @@
  */
 public class TestTranslatorManager extends HiveMindTestCase
 {
-    protected RegistryInfrastructure createRegistryForContribution(TranslatorContribution
tc)
-    {
-        List l = Collections.singletonList(tc);
-
-        MockControl c = newControl(RegistryInfrastructure.class);
-        RegistryInfrastructure result = (RegistryInfrastructure) c.getMock();
-
-        result.getConfiguration(TranslatorManagerImpl.TRANSLATORS_CONFIGURATION_ID, null);
-        c.setReturnValue(l);
-
-        return result;
-    }
-
     public void testNoClassOrService()
     {
         TranslatorContribution tc = new TranslatorContribution();
         tc.setName("invalid");
 
-        RegistryInfrastructure r = createRegistryForContribution(tc);
+        List l = Collections.singletonList(tc);
 
         ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
 
@@ -61,7 +46,7 @@
 
         replayControls();
 
-        TranslatorManagerImpl tm = new TranslatorManagerImpl(r, eh);
+        TranslatorManagerImpl tm = new TranslatorManagerImpl(l, eh);
 
         try
         {

Modified: hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet.java?view=diff&rev=470727&r1=470726&r2=470727
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet.java
Fri Nov  3 00:54:32 2006
@@ -17,10 +17,7 @@
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.ServiceImplementationFactoryParameters;
 import org.apache.hivemind.TranslatorManager;
-import org.apache.hivemind.impl.DefaultErrorHandler;
-import org.apache.hivemind.impl.natures.XmlRegistryNature;
 import org.apache.hivemind.internal.Module;
-import org.apache.hivemind.internal.RegistryInfrastructure;
 import org.apache.hivemind.schema.Translator;
 import org.apache.hivemind.test.HiveMindTestCase;
 import org.easymock.MockControl;
@@ -32,9 +29,6 @@
         MockControl moduleControl = newControl(Module.class);
         Module module = (Module) moduleControl.getMock();
         
-        MockControl registryControl = newControl(RegistryInfrastructure.class);
-        RegistryInfrastructure registry = (RegistryInfrastructure) registryControl.getMock();
-
         MockControl translatorControl = newControl(Translator.class);
         Translator translator = (Translator) translatorControl.getMock();
 
@@ -52,15 +46,9 @@
 
         params.getInvokingModule();
         paramsControl.setDefaultReturnValue(module);
-
-        XmlRegistryNature xmlNature = new XmlRegistryNature(new DefaultErrorHandler());
-        xmlNature.setTranslationManager(tm);
-
-        module.getRegistry();
-        moduleControl.setReturnValue(registry);
         
-        registry.getNature(XmlRegistryNature.class);
-        registryControl.setReturnValue(xmlNature);
+        module.getService(TranslatorManager.class);
+        moduleControl.setReturnValue(tm);
 
         tm.getTranslator("foo");
         tmControl.setReturnValue(translator);
@@ -81,9 +69,6 @@
         MockControl moduleControl = newControl(Module.class);
         Module module = (Module) moduleControl.getMock();
         
-        MockControl registryControl = newControl(RegistryInfrastructure.class);
-        RegistryInfrastructure registry = (RegistryInfrastructure) registryControl.getMock();
-
         MockControl translatorControl = newControl(Translator.class);
         Translator translator = (Translator) translatorControl.getMock();
 
@@ -102,14 +87,8 @@
         params.getInvokingModule();
         paramsControl.setDefaultReturnValue(module);
 
-        XmlRegistryNature xmlNature = new XmlRegistryNature(new DefaultErrorHandler());
-        xmlNature.setTranslationManager(tm);
-
-        module.getRegistry();
-        moduleControl.setReturnValue(registry);
-        
-        registry.getNature(XmlRegistryNature.class);
-        registryControl.setReturnValue(xmlNature);
+        module.getService(TranslatorManager.class);
+        moduleControl.setReturnValue(tm);
 
         tm.getTranslator("foo");
         tmControl.setReturnValue(translator);



Mime
View raw message