hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r513021 - in /hivemind/hivemind2/trunk: examples/src/java/org/apache/examples/definition/ framework/src/java/org/apache/hivemind/definition/impl/ framework/src/java/org/apache/hivemind/impl/
Date Wed, 28 Feb 2007 22:46:15 GMT
Author: ahuegen
Date: Wed Feb 28 14:46:14 2007
New Revision: 513021

URL: http://svn.apache.org/viewvc?view=rev&rev=513021
Log:
Java Registry Definition API example

Added:
    hivemind/hivemind2/trunk/examples/src/java/org/apache/examples/definition/
    hivemind/hivemind2/trunk/examples/src/java/org/apache/examples/definition/JavaDefinitionExample.java
Modified:
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/definition/impl/ModuleDefinitionImpl.java
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java

Added: hivemind/hivemind2/trunk/examples/src/java/org/apache/examples/definition/JavaDefinitionExample.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/examples/src/java/org/apache/examples/definition/JavaDefinitionExample.java?view=auto&rev=513021
==============================================================================
--- hivemind/hivemind2/trunk/examples/src/java/org/apache/examples/definition/JavaDefinitionExample.java
(added)
+++ hivemind/hivemind2/trunk/examples/src/java/org/apache/examples/definition/JavaDefinitionExample.java
Wed Feb 28 14:46:14 2007
@@ -0,0 +1,100 @@
+package org.apache.examples.definition;
+
+import org.apache.examples.Adder;
+import org.apache.examples.Calculator;
+import org.apache.examples.impl.AdderImpl;
+import org.apache.examples.impl.CalculatorImpl;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.Registry;
+import org.apache.hivemind.Resource;
+import org.apache.hivemind.definition.ImplementationConstructionContext;
+import org.apache.hivemind.definition.ImplementationConstructor;
+import org.apache.hivemind.definition.ImplementationDefinition;
+import org.apache.hivemind.definition.ModuleDefinition;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.definition.Visibility;
+import org.apache.hivemind.definition.impl.ImplementationDefinitionImpl;
+import org.apache.hivemind.definition.impl.ModuleDefinitionImpl;
+import org.apache.hivemind.definition.impl.RegistryDefinitionImpl;
+import org.apache.hivemind.definition.impl.ServicePointDefinitionImpl;
+import org.apache.hivemind.impl.CreateClassServiceConstructor;
+import org.apache.hivemind.impl.DefaultClassResolver;
+import org.apache.hivemind.impl.LocationImpl;
+import org.apache.hivemind.impl.RegistryBuilder;
+import org.apache.hivemind.internal.AbstractServiceImplementationConstructor;
+import org.apache.hivemind.internal.ServiceModel;
+import org.apache.hivemind.util.ClasspathResource;
+
+/**
+ * Demonstrates the use of the java registry definition API.
+ * 
+ * @author Achim Huegen
+ */
+public class JavaDefinitionExample
+{
+    public static void main(String[] args)
+    {
+        JavaDefinitionExample example = new JavaDefinitionExample();
+        Registry registry = example.constructRegistry();
+        
+        Calculator calculator = (Calculator) registry.getService(Calculator.class);
+        double result = calculator.add(10, 20);
+        System.out.println("Result: " + result);
+    }
+    
+    private Registry constructRegistry()
+    {
+        RegistryDefinition registryDefinition = new RegistryDefinitionImpl();
+        ModuleDefinition module = defineModule(registryDefinition);
+        registryDefinition.addModule(module);
+        
+        RegistryBuilder builder = new RegistryBuilder(registryDefinition);
+        Registry registry = builder.constructRegistry();
+        return registry;
+    }
+
+    private ModuleDefinition defineModule(RegistryDefinition registryDefinition)
+    {
+        ModuleDefinitionImpl module = new ModuleDefinitionImpl("calculator", createLocation());
+         
+        // Define the calculator service
+        ServicePointDefinitionImpl calculatorService = new ServicePointDefinitionImpl(module,

+                "Calculator", null, Visibility.PUBLIC, Calculator.class.getName());
+
+        // Define inline implementation constructor, that wires the Adder service
+        ImplementationConstructor calculatorConstructor = new AbstractServiceImplementationConstructor(createLocation())
+        {
+            public Object constructCoreServiceImplementation(ImplementationConstructionContext
context)
+            {
+                CalculatorImpl result = new CalculatorImpl();
+                result.setAdder((Adder) context.getService(Adder.class));
+                return result;
+            }
+        };
+        ImplementationDefinition calculatorImplementation = new ImplementationDefinitionImpl(module,
null, 
+                calculatorConstructor, ServiceModel.PRIMITIVE, true);
+        calculatorService.addImplementation(calculatorImplementation);
+        module.addServicePoint(calculatorService);
+        
+        // Define the adder service
+        ServicePointDefinitionImpl adderService = new ServicePointDefinitionImpl(module,

+                "Adder", null, Visibility.PUBLIC, Adder.class.getName());
+
+        ImplementationDefinition adderImplementation = new ImplementationDefinitionImpl(module,
null, 
+                new CreateClassServiceConstructor(createLocation(), AdderImpl.class.getName()),

+                ServiceModel.PRIMITIVE, true);
+        adderService.addImplementation(adderImplementation);
+        module.addServicePoint(adderService);
+        
+        return module;
+    }
+    
+    protected static Location createLocation()
+    {
+        String path = "/" + JavaDefinitionExample.class.getName().replace('.', '/');
+
+        Resource r = new ClasspathResource(new DefaultClassResolver(), path);
+
+        return new LocationImpl(r, 1);
+    }    
+}

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/definition/impl/ModuleDefinitionImpl.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/definition/impl/ModuleDefinitionImpl.java?view=diff&rev=513021&r1=513020&r2=513021
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/definition/impl/ModuleDefinitionImpl.java
(original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/definition/impl/ModuleDefinitionImpl.java
Wed Feb 28 14:46:14 2007
@@ -33,6 +33,7 @@
 import org.apache.hivemind.definition.InterceptorDefinition;
 import org.apache.hivemind.definition.ServicePointDefinition;
 import org.apache.hivemind.definition.UnresolvedExtension;
+import org.apache.hivemind.impl.DefaultClassResolver;
 
 /**
  * Default implementation of {@link ExtensionDefinition}.
@@ -63,10 +64,14 @@
     
     private Collection _unresolvedConfigurationParsers = new ArrayList();
     
-    public ModuleDefinitionImpl()
+    /**
+     * @param id  the id of the module 
+     */
+    public ModuleDefinitionImpl(String id, Location location)
     {
-    }
-
+        this(id, location, new DefaultClassResolver(), null);
+    }    
+    
     /**
      * @param id  the id of the module 
      * @param location  the location of the module 

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java?view=diff&rev=513021&r1=513020&r2=513021
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java
(original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java
Wed Feb 28 14:46:14 2007
@@ -127,7 +127,7 @@
      */
     public Registry constructRegistry()
     {
-        return constructRegistry();
+        return constructRegistry(Locale.getDefault());
     }
     
     /**



Mime
View raw message