You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by ah...@apache.org on 2006/10/31 17:28:56 UTC

svn commit: r469541 - in /hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind: impl/ impl/servicemodel/ internal/

Author: ahuegen
Date: Tue Oct 31 08:28:55 2006
New Revision: 469541

URL: http://svn.apache.org/viewvc?view=rev&rev=469541
Log:
Restructured outer and inner proxies. The extension point id is handed in as constructor parameter.
This allows to reuse proxy classes for different extension points.

Modified:
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServicePoint.java

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java?view=diff&rev=469541&r1=469540&r2=469541
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java Tue Oct 31 08:28:55 2006
@@ -302,15 +302,18 @@
 
             // Create the outer proxy.
 
-            Object result = proxyClass.newInstance();
+            Constructor co = proxyClass.getConstructor(new Class[]
+            { String.class });
+
+            Object result = co.newInstance(new Object[] { getExtensionPointId() });
 
             // The inner proxy's construct invokes a method on the
             // outer proxy to connect the two.
 
-            Constructor c = innerProxyClass.getConstructor(new Class[]
-            { proxyClass, getClass() });
+            Constructor ci = innerProxyClass.getConstructor(new Class[]
+            { String.class, proxyClass, getClass() });
 
-            c.newInstance(new Object[] { result, this });
+            ci.newInstance(new Object[] { getExtensionPointId(), result, this });
 
             return result;
         }
@@ -354,7 +357,8 @@
      */
     private Class createSingletonProxyClass(Class configurationInterface)
     {
-        ProxyBuilder proxyBuilder = new ProxyBuilder("LazyConstructionProxy", this, configurationInterface, true);
+        ProxyBuilder proxyBuilder = new ProxyBuilder("LazyConstructionProxy", getModule(), getContainerType(), 
+                configurationInterface, true);
 
         ClassFab classFab = proxyBuilder.getClassFab();
 
@@ -398,7 +402,7 @@
 
     private Class createInnerProxyClass(Class configurationInterface, Class deferredProxyClass)
     {
-        ProxyBuilder builder = new ProxyBuilder("InnerProxy", this, configurationInterface, false);
+        ProxyBuilder builder = new ProxyBuilder("InnerProxy", getModule(), getContainerType(), configurationInterface, false);
 
         ClassFab classFab = builder.getClassFab();
 
@@ -413,15 +417,15 @@
 
         body.begin();
 
-        body.addln("super();");
-        body.addln("_deferredProxy = $1;");
-        body.addln("_configurationPoint = $2;");
+        body.addln("this($1);");
+        body.addln("_deferredProxy = $2;");
+        body.addln("_configurationPoint = $3;");
         body.addln("_deferredProxy._setInner(this);");
 
         body.end();
 
         classFab.addConstructor(new Class[]
-        { deferredProxyClass, ConfigurationPointImpl.class }, null, body.toString());
+        { String.class, deferredProxyClass, ConfigurationPointImpl.class }, null, body.toString());
 
         // Method _configuration() will look up the service implementation,
         // then update the deferred proxy to go directly to the

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java?view=diff&rev=469541&r1=469540&r2=469541
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java Tue Oct 31 08:28:55 2006
@@ -17,9 +17,7 @@
 import java.io.Serializable;
 import java.lang.reflect.Modifier;
 
-import org.apache.hivemind.internal.ConfigurationPoint;
 import org.apache.hivemind.internal.Module;
-import org.apache.hivemind.internal.ServicePoint;
 import org.apache.hivemind.internal.ser.ServiceSerializationHelper;
 import org.apache.hivemind.service.BodyBuilder;
 import org.apache.hivemind.service.ClassFab;
@@ -35,67 +33,33 @@
  */
 public final class ProxyBuilder
 {
-    private String _extensionPointId;
-
     private Class _serviceInterface;
 
     private ClassFab _classFab;
 
     private String _type;
 
-    public ProxyBuilder(String type, ServicePoint point)
-    {
-        this(type, point, false);
-    }
-
     /**
      * Constructs a new builder. The type will be incorporated into value returned by the
-     * <code>toString()</code> method. The service extension point is used to identify the service
-     * interface and service id.
+     * <code>toString()</code> method. 
+     * The generated proxy has an constructor that expects the extension point id as single parameter. 
      * 
      * @param type
      *            used as part of the <code>toString()</code> method's return value
-     * @param point
-     *            the service point for which this proxy is being constructed
-     * @param outerProxy
-     *            if false, then the proxy can extend the service points service interface always.
-     *            If true and the service point's declared interface is actually a bean class (not
-     *            an interface), then the proxy will be a subclass of that bean.
-     */
-    public ProxyBuilder(String type, ServicePoint point, boolean outerProxy)
-    {
-        _extensionPointId = point.getExtensionPointId();
-        _type = type;
-
-        init(point.getModule(), point.getServiceInterface(), point.getDeclaredInterface(),
-                outerProxy);
-    }
-    
-    /**
-     * Constructs a new builder. The type will be incorporated into value returned by the
-     * <code>toString()</code> method. The configuration point is used to identify the service
-     * interface and service id.
-     * 
-     * @param type
-     *            used as part of the <code>toString()</code> method's return value
-     * @param point
-     *            the configuration point for which this proxy is being constructed
+     * @param module
+     *            the module that constructs the proxy 
+     * @param serviceInterface
+     *            the interface of the proxied class.  
+     * @param declaredInterface
+     *            the interface of the proxied class or the class itself if the proxied class is actually a POJO.
      * @param outerProxy
      *            if false, then the proxy can extend the configuration points service interface always.
-     *            If true and the service point's declared interface is actually a bean class (not
+     *            If true and the declared interface is actually a bean class (not
      *            an interface), then the proxy will be a subclass of that bean.
      */
-    public ProxyBuilder(String type, ConfigurationPoint point, Class serviceInterface, boolean outerProxy)
+    public ProxyBuilder(String type, Module module, Class serviceInterface, Class declaredInterface, boolean outerProxy)
     {
-        _extensionPointId = point.getExtensionPointId();
         _type = type;
-
-        init(point.getModule(), serviceInterface, point.getContainerType(),
-                outerProxy);
-    }
-    
-    private void init(Module module, Class serviceInterface, Class declaredInterface, boolean outerProxy)
-    {
         _serviceInterface = serviceInterface;
 
         ClassFactory factory = (ClassFactory) module.getService(
@@ -107,6 +71,10 @@
 
         _classFab = factory.newClass(ClassFabUtils.generateClassName(_serviceInterface), baseClass);
 
+        _classFab.addField("_extensionPointId", String.class);
+        
+        _classFab.addConstructor(new Class[] { String.class }, null, "{ _extensionPointId = $1; }");
+        
         if (!extendBeanClass)
             _classFab.addInterface(_serviceInterface);
 
@@ -114,20 +82,19 @@
         // are serializable!
 
         if (outerProxy)
-            addSerializable(_extensionPointId);
+            addSerializable();
     }
 
     /** @since 1.1 */
-    private void addSerializable(String pointId)
+    private void addSerializable()
     {
         _classFab.addInterface(Serializable.class);
 
         BodyBuilder bb = new BodyBuilder();
 
         bb.add(
-                "return {0}.getServiceSerializationSupport().getServiceTokenForService(\"{1}\");",
-                ServiceSerializationHelper.class.getName(),
-                pointId);
+                "return {0}.getServiceSerializationSupport().getServiceTokenForService(_extensionPointId);",
+                ServiceSerializationHelper.class.getName());
 
         MethodSignature sig = new MethodSignature(Object.class, "writeReplace", null, null);
 
@@ -179,7 +146,7 @@
         }
 
         if (!mi.getToString() && addToString)
-            ClassFabUtils.addToStringMethod(_classFab, "<" + _type + " for "
-                    + _extensionPointId + "(" + _serviceInterface.getName() + ")>");
+            ClassFabUtils.addToStringMethod(_classFab, "<" + _type + " for \" + _extensionPointId + \""
+                    + "(" + _serviceInterface.getName() + ")>");
     }
 }

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java?view=diff&rev=469541&r1=469540&r2=469541
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java Tue Oct 31 08:28:55 2006
@@ -53,7 +53,8 @@
     public static Object createDelegatingProxy(String type, ServiceModel serviceModel,
             String delegationMethodName, ServicePoint servicePoint)
     {
-        ProxyBuilder builder = new ProxyBuilder(type, servicePoint);
+        ProxyBuilder builder = new ProxyBuilder(type, servicePoint.getModule(),
+                servicePoint.getServiceInterface(), servicePoint.getDeclaredInterface(), false);
 
         ClassFab classFab = builder.getClassFab();
 
@@ -68,10 +69,10 @@
         try
         {
             Constructor c = proxyClass.getConstructor(new Class[]
-            { serviceModel.getClass() });
+            { String.class, serviceModel.getClass() });
 
             return c.newInstance(new Object[]
-            { serviceModel });
+            { servicePoint.getExtensionPointId(), serviceModel });
         }
         catch (Exception ex)
         {
@@ -97,7 +98,8 @@
     public static RegistryShutdownListener createOuterProxy(Object delegate,
             ServicePoint servicePoint)
     {
-        ProxyBuilder builder = new ProxyBuilder("OuterProxy", servicePoint, true);
+        ProxyBuilder builder = new ProxyBuilder("OuterProxy", servicePoint.getModule(),
+                servicePoint.getServiceInterface(), servicePoint.getDeclaredInterface(), true);
 
         ClassFab classFab = builder.getClassFab();
 
@@ -112,7 +114,7 @@
             return (RegistryShutdownListener) ConstructorUtils.invokeConstructor(
                     proxyClass,
                     new Object[]
-                    { delegate });
+                    { servicePoint.getExtensionPointId(), delegate });
         }
         catch (Exception ex)
         {
@@ -133,7 +135,7 @@
         classFab.addField("_delegate", delegateClass);
 
         classFab.addConstructor(new Class[]
-        { delegateClass }, null, "{ super(); _delegate = $1; }");
+        { String.class, delegateClass }, null, "{ this($1); _delegate = $2; }");
 
         classFab.addInterface(RegistryShutdownListener.class);
         if( RegistryShutdownListener.class.isAssignableFrom( delegateClass ) )
@@ -172,7 +174,7 @@
         classFab.addField("_serviceModel", modelClass);
 
         classFab.addConstructor(new Class[]
-        { modelClass }, null, "{ super(); _serviceModel = $1; }");
+        { String.class, modelClass }, null, "{ this($1); _serviceModel = $2; }");
     }
 
     /**

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java?view=diff&rev=469541&r1=469540&r2=469541
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java Tue Oct 31 08:28:55 2006
@@ -202,7 +202,7 @@
         Class bridgeProxyClass = getBridgeProxyClass(service);
 
         return ConstructorUtils.invokeConstructor(bridgeProxyClass, new Object[]
-        { service });
+        { getServicePoint().getExtensionPointId(), service });
     }
 
     /**
@@ -227,7 +227,8 @@
 
     private Class constructBridgeProxyClass(Object service)
     {
-        ProxyBuilder builder = new ProxyBuilder("BridgeProxy", getServicePoint());
+        ProxyBuilder builder = new ProxyBuilder("BridgeProxy", getServicePoint().getModule(),
+                getServicePoint().getServiceInterface(), getServicePoint().getDeclaredInterface(), false);
 
         ClassFab cf = builder.getClassFab();
 
@@ -236,7 +237,7 @@
         cf.addField("_service", serviceType);
 
         cf.addConstructor(new Class[]
-        { serviceType }, null, "{ super(); _service = $1; }");
+        { String.class, serviceType }, null, "{ this($1); _service = $2; }");
 
         builder.addServiceMethods("_service");
 

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java?view=diff&rev=469541&r1=469540&r2=469541
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java Tue Oct 31 08:28:55 2006
@@ -108,16 +108,18 @@
 
             // Create the outer proxy.
 
-            Object result = proxyClass.newInstance();
+            Constructor co = proxyClass.getConstructor(new Class[] { String.class });
 
+            Object result = co.newInstance(new Object[] { getServicePoint().getExtensionPointId() });
+            
             // The inner proxy's construct invokes a method on the
             // outer proxy to connect the two.
 
             Constructor c = innerProxyClass.getConstructor(new Class[]
-            { proxyClass, getClass() });
+            { String.class, proxyClass, getClass() });
 
             _innerProxy = (SingletonInnerProxy) c.newInstance(new Object[]
-            { result, this });
+            { getServicePoint().getExtensionPointId(), result, this });
 
             RegistryShutdownListener asListener = (RegistryShutdownListener) result;
 
@@ -142,7 +144,8 @@
     {
         ConstructableServicePoint servicePoint = getServicePoint();
 
-        ProxyBuilder proxyBuilder = new ProxyBuilder("SingletonProxy", servicePoint, true);
+        ProxyBuilder proxyBuilder = new ProxyBuilder("SingletonProxy", servicePoint.getModule(),
+                servicePoint.getServiceInterface(), servicePoint.getDeclaredInterface(), true);
 
         ClassFab classFab = proxyBuilder.getClassFab();
 
@@ -190,7 +193,9 @@
         ServicePoint servicePoint = getServicePoint();
 
         Class serviceInterface = servicePoint.getServiceInterface();
-        ProxyBuilder builder = new ProxyBuilder("InnerProxy", servicePoint);
+        
+        ProxyBuilder builder = new ProxyBuilder("InnerProxy", servicePoint.getModule(),
+                serviceInterface, servicePoint.getDeclaredInterface(), false);
 
         ClassFab classFab = builder.getClassFab();
 
@@ -205,15 +210,15 @@
 
         body.begin();
 
-        body.addln("super();");
-        body.addln("_deferredProxy = $1;");
-        body.addln("_serviceModel = $2;");
+        body.addln("this($1);");
+        body.addln("_deferredProxy = $2;");
+        body.addln("_serviceModel = $3;");
         body.addln("_deferredProxy._setInner(this);");
 
         body.end();
 
         classFab.addConstructor(new Class[]
-        { deferredProxyClass, getClass() }, null, body.toString());
+        { String.class, deferredProxyClass, getClass() }, null, body.toString());
 
         // Method _service() will look up the service implementation,
         // then update the deferred proxy to go directly to the

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServicePoint.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServicePoint.java?view=diff&rev=469541&r1=469540&r2=469541
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServicePoint.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServicePoint.java Tue Oct 31 08:28:55 2006
@@ -26,17 +26,18 @@
     /**
      * Returns the type of the service, the interface the service implements. This may be a
      * synthetic interface when the interface for the service point is, in fact, a class.
+     * It equals the class returned by {@link #getDeclaredInterface()} if the declared interface
+     * is a real interface and not a class. 
      */
     public Class getServiceInterface();
 
     /**
      * Returns the interface for the service as specified in the descriptor; starting with release
-     * 1.1 it is possible to define a service in terms of a class (as the interface) and a synthetic
-     * interface is generated where appropriate.
+     * 1.1 it is possible to define a service in terms of a class (as the interface).
+     * In that case the POJO class is returned here.
      * 
      * @since 1.1
      */
-
     public Class getDeclaredInterface();
 
     /**