hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r504294 - in /hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind: Registry.java impl/ImplMessages.java impl/ImplStrings.properties impl/RegistryImpl.java impl/RegistryInfrastructureImpl.java internal/RegistryInfrastructure.java
Date Tue, 06 Feb 2007 21:12:38 GMT
Author: ahuegen
Date: Tue Feb  6 13:12:37 2007
New Revision: 504294

URL: http://svn.apache.org/viewvc?view=rev&rev=504294
Log:
Retrieval of configurations by type

Modified:
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/Registry.java
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java
    hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/Registry.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/Registry.java?view=diff&rev=504294&r1=504293&r2=504294
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/Registry.java (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/Registry.java Tue Feb
 6 13:12:37 2007
@@ -23,7 +23,6 @@
  * 
  * @author Howard Lewis Ship
  */
-
 public interface Registry
 {
     /**
@@ -56,11 +55,23 @@
      * 
      * @param configurationId
      *            the fully qualified id of the configuration to obtain
-     * @return the configuration container 
+     * @return the configuration 
      * @throws ApplicationRuntimeException
      *             if the configuration does not exist, etc.
      */
     public Object getConfiguration(String configurationId);
+    
+    /**
+     * Finds a configuration of the specified type. Exactly one such configuration may exist
or
+     * an exception is thrown.
+     * 
+     * @param configurationType
+     *            the configuration type
+     * @return  the configuration
+     * @throws org.apache.hivemind.ApplicationRuntimeException
+     *             if no such configuration extension point exists (or visible)
+     */
+    public Object getConfiguration(Class configurationType);
 
     /**
      * Obtains a service from the registry. Typically, what's returned is a proxy, but that's

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplMessages.java?view=diff&rev=504294&r1=504293&r2=504294
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
(original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
Tue Feb  6 13:12:37 2007
@@ -17,6 +17,7 @@
 import java.net.URL;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.hivemind.ClassResolver;
 import org.apache.hivemind.Location;
@@ -181,6 +182,11 @@
         return _formatter.format("no-service-point-for-interface", interfaceClass.getName());
     }
 
+    static String noConfigurationPointForType(Class configurationType)
+    {
+        return _formatter.format("no-configuration-point-for-type", configurationType.getName());
+    }
+
     static String multipleServicePointsForInterface(Class interfaceClass,
             Collection matchingPoints)
     {
@@ -208,7 +214,34 @@
                 interfaceClass.getName(),
                 buffer);
     }
+    
+    static String multipleConfigurationPointsForType(Class configurationType, List configurationPoints)
+    {
+        StringBuffer buffer = new StringBuffer("{");
+
+        boolean following = false;
+
+        Iterator i = configurationPoints.iterator();
+        while (i.hasNext())
+        {
+            if (following)
+                buffer.append(", ");
+
+            ServicePoint p = (ServicePoint) i.next();
+
+            buffer.append(p.getExtensionPointId());
+
+            following = true;
+        }
+
+        buffer.append("}");
 
+        return _formatter.format(
+                "multiple-configuration-points-for-type",
+                configurationType.getName(),
+                buffer);
+    }
+    
     private static String convertModule(Module module)
     {
         if (module == null)
@@ -254,4 +287,6 @@
     {
         return _formatter.format("servicepointdefinition-without-implementation", sd.getQualifiedId());
     }
+
+
 }

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties?view=diff&rev=504294&r1=504293&r2=504294
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
(original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
Tue Feb  6 13:12:37 2007
@@ -20,7 +20,9 @@
 no-such-service-point=Service point {0} does not exist.
 unqualified-service-point=The service id specified ("{0}") is not fully qualified.  Perhaps
you meant one of {1}.
 no-service-point-for-interface=There is no service point for interface {0}.
+no-configuration-point-for-type=There is no configuration point for type {0}.
 multiple-service-points-for-interface=There are multiple service points for interface {0}:
{1}.
+multiple-configuration-points-for-type=There are multiple configuration points for type {0}:
{1}.
 unable-to-load-class=Could not load class {0} from {1}: {2}
 null-interceptor=Service {0} generated a null interceptor (for service point {1}).
 interceptor-does-not-implement-interface=The service interceptor ({0}) generated by service
{1} for service point {2} does not implement the {3} interface defined by the service point.

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java?view=diff&rev=504294&r1=504293&r2=504294
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java
(original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java
Tue Feb  6 13:12:37 2007
@@ -52,6 +52,11 @@
         return _infrastructure.containsService(serviceId, serviceInterface, null);
     }
 
+    public Object getConfiguration(Class configurationType)
+    {
+        return _infrastructure.getConfiguration(configurationType, null);
+    }
+    
     public Object getConfiguration(String configurationId)
     {
         return _infrastructure.getConfiguration(configurationId, null);
@@ -104,4 +109,5 @@
         final Module module = _infrastructure.getModule(moduleId);
         return module == null ? null : module.getMessages();
     }
+
 }

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java?view=diff&rev=504294&r1=504293&r2=504294
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java
(original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java
Tue Feb  6 13:12:37 2007
@@ -64,6 +64,11 @@
      * Map of List (of {@link ServicePoint}, keyed on class name service interface.
      */
     private Map _servicePointsByInterfaceClassName = new HashMap();
+    
+    /**
+     * Map of List (of {@link ConfigurationPoint}, keyed on class name service interface.
+     */
+    private Map _configurationPointsByTypeName = new HashMap();
 
     /**
      * Map of {@link ConfigurationPoint} keyed on fully qualified configuration id.
@@ -144,6 +149,23 @@
         checkStarted();
 
         _configurationPoints.put(point.getExtensionPointId(), point);
+        
+        addConfigurationPointByType(point);
+    }
+
+    private void addConfigurationPointByType(ConfigurationPoint point)
+    {
+        String key = point.getConfigurationType().getName();
+
+        List l = (List) _configurationPointsByTypeName.get(key);
+
+        if (l == null)
+        {
+            l = new LinkedList();
+            _configurationPointsByTypeName.put(key, l);
+        }
+
+        l.add(point);
     }
 
     /**
@@ -269,6 +291,46 @@
         return point.getConfiguration();
     }
 
+    /**
+     * @see org.apache.hivemind.internal.RegistryInfrastructure#getConfiguration(java.lang.Class,
org.apache.hivemind.internal.Module)
+     */
+    public Object getConfiguration(Class configurationType, Module module)
+    {
+        String key = configurationType.getName();
+
+        List configurationPoints = (List) _configurationPointsByTypeName.get(key);
+
+        if (configurationPoints == null)
+            configurationPoints = Collections.EMPTY_LIST;
+
+        ConfigurationPoint point = null;
+        int count = 0;
+
+        Iterator i = configurationPoints.iterator();
+        while (i.hasNext())
+        {
+            ConfigurationPoint cp = (ConfigurationPoint) i.next();
+
+            if (!cp.visibleToModule(module))
+                continue;
+
+            point = cp;
+
+            count++;
+        }
+
+        if (count == 0)
+            throw new ApplicationRuntimeException(ImplMessages
+                    .noConfigurationPointForType(configurationType));
+
+        if (count > 1)
+            throw new ApplicationRuntimeException(ImplMessages.multipleConfigurationPointsForType(
+                    configurationType,
+                    configurationPoints));
+
+        return point.getConfiguration();
+    }
+
     public String toString()
     {
         ToStringBuilder builder = new ToStringBuilder(this);
@@ -312,6 +374,7 @@
 
         _servicePoints = null;
         _servicePointsByInterfaceClassName = null;
+        _configurationPointsByTypeName = null;
         _configurationPoints = null;
         _shutdownCoordinator = null;
         _serviceModelFactories = null;

Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java?view=diff&rev=504294&r1=504293&r2=504294
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java
(original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java
Tue Feb  6 13:12:37 2007
@@ -60,21 +60,35 @@
      */
     public Object getService(Class serviceInterface, Module module);
 
-    /**
-     * Returns the containter of the specified configuration point.
+     /**
+     * Returns the specified configuration.
      * 
      * @param configurationId
      *            the fully qualified id of the configuration
      * @param module
      *            the referencing module, used for visibility checks (null means no module,
which
      *            requires that the configuration be public)
-     * @return  configuration container
+     * @return  the configuration
      * @throws org.apache.hivemind.ApplicationRuntimeException
      *             if no such configuration extension point exists (or visible)
      */
-
     public Object getConfiguration(String configurationId, Module module);
-
+    
+    /**
+     * Finds a configuration of the specified type. Exactly one such configuration may exist
or
+     * an exception is thrown.
+     * 
+     * @param configurationType
+     *            the configuration type
+     * @param module
+     *            the referencing module, used for visibility checks (null means no module,
which
+     *            requires that the configuration be public)
+     * @return  the configuration
+     * @throws org.apache.hivemind.ApplicationRuntimeException
+     *             if no such configuration extension point exists (or visible)
+     */
+    public Object getConfiguration(Class configurationType, Module module);
+    
     /**
      * Returns the configuration point.
      * 



Mime
View raw message