You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by hl...@apache.org on 2004/06/18 23:39:01 UTC

cvs commit: jakarta-hivemind/framework/src/test/hivemind/test/services/impl ClassResolverHolderImpl.java

hlship      2004/06/18 14:39:01

  Modified:    framework/src/test/hivemind/test/services
                        TestBuilderFactory.java
               framework/src/java/org/apache/hivemind/util
                        ClassAdaptor.java PropertyUtils.java
                        PropertyAdaptor.java
               library/src/descriptor/META-INF hivemodule.sdl
               framework/src/descriptor/META-INF hivemodule.sdl
               framework/src/documentation/content/xdocs/hivemind
                        BuilderFactory.xml
               framework/src/java/org/apache/hivemind/service/impl
                        BuilderFacet.java BuilderMessagesFacet.java
                        BuilderErrorHandlerFacet.java
                        BuilderServiceIdFacet.java BuilderLogFacet.java
                        BuilderFactory.java
               framework/src/test/org/apache/hivemind/util
                        TestPropertyUtils.java
               .        status.xml
  Added:       framework/src/test/hivemind/test/services
                        AutowireTarget.java SetClassResolver.sdl
                        ConstructClassResolver.sdl ClassResolverHolder.java
               framework/src/java/org/apache/hivemind/service/impl
                        BuilderClassResolverFacet.java
               framework/src/test/hivemind/test/services/impl
                        ClassResolverHolderImpl.java
  Log:
  Extend BuilderFactory to set a property to a ClassResolver, and to autowire properties with set names and types, if present.
  
  Revision  Changes    Path
  1.5       +116 -1    jakarta-hivemind/framework/src/test/hivemind/test/services/TestBuilderFactory.java
  
  Index: TestBuilderFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/TestBuilderFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestBuilderFactory.java	10 Jun 2004 19:49:40 -0000	1.4
  +++ TestBuilderFactory.java	18 Jun 2004 21:39:00 -0000	1.5
  @@ -14,17 +14,31 @@
   
   package hivemind.test.services;
   
  +import java.util.Collections;
  +
  +import org.apache.commons.logging.LogFactory;
  +import org.apache.hivemind.ClassResolver;
   import org.apache.hivemind.ErrorHandler;
  +import org.apache.hivemind.Messages;
  +import org.apache.hivemind.impl.DefaultClassResolver;
   import org.apache.hivemind.impl.DefaultErrorHandler;
  +import org.apache.hivemind.impl.MessagesImpl;
   import org.apache.hivemind.internal.Module;
   import org.apache.hivemind.internal.RegistryInfrastructure;
  +import org.apache.hivemind.service.impl.BuilderClassResolverFacet;
   import org.apache.hivemind.service.impl.BuilderErrorHandlerFacet;
   import org.apache.hivemind.service.impl.BuilderFacet;
  +import org.apache.hivemind.service.impl.BuilderFactory;
  +import org.apache.hivemind.service.impl.BuilderLogFacet;
  +import org.apache.hivemind.service.impl.BuilderMessagesFacet;
  +import org.apache.hivemind.service.impl.BuilderParameter;
  +import org.apache.hivemind.service.impl.BuilderServiceIdFacet;
   import org.apache.hivemind.test.HiveMindTestCase;
   import org.easymock.MockControl;
   
   /**
  - * Tests for the standard {@link org.apache.hivemind.service.impl.BuilderFactory} service.
  + * Tests for the standard {@link org.apache.hivemind.service.impl.BuilderFactory} service
  + * and various implementations of {@link org.apache.hivemind.service.impl.BuilderFacet}.
    *
    * @author Howard Lewis Ship
    */
  @@ -99,5 +113,106 @@
                   ErrorHandlerHolder.class);
   
           assertNotNull(h.getErrorHandler());
  +    }
  +
  +    public void testBuilderClassResolverFacet()
  +    {
  +        ClassResolver cr = new DefaultClassResolver();
  +
  +        MockControl control = MockControl.createStrictControl(Module.class);
  +        Module module = (Module) control.getMock();
  +
  +        module.getClassResolver();
  +        control.setReturnValue(cr);
  +
  +        control.replay();
  +
  +        BuilderClassResolverFacet fc = new BuilderClassResolverFacet();
  +
  +        Object result = fc.getFacetValue(null, module, null);
  +
  +        assertSame(cr, result);
  +
  +        control.verify();
  +    }
  +
  +    public void testSetClassResolver() throws Exception
  +    {
  +        RegistryInfrastructure r = buildFrameworkRegistry("SetClassResolver.sdl");
  +
  +        ClassResolverHolder h =
  +            (ClassResolverHolder) r.getService(
  +                "hivemind.test.services.SetClassResolver",
  +                ClassResolverHolder.class);
  +
  +        assertNotNull(h.getClassResolver());
  +    }
  +
  +    public void testConstructClassResolver() throws Exception
  +    {
  +        RegistryInfrastructure r = buildFrameworkRegistry("ConstructClassResolver.sdl");
  +
  +        ClassResolverHolder h =
  +            (ClassResolverHolder) r.getService(
  +                "hivemind.test.services.ConstructClassResolver",
  +                ClassResolverHolder.class);
  +
  +        assertNotNull(h.getClassResolver());
  +    }
  +
  +    public void testAutowire()
  +    {
  +        BuilderFactory factory = new BuilderFactory();
  +        BuilderParameter p = new BuilderParameter();
  +
  +        p.setClassName(AutowireTarget.class.getName());
  +        p.addProperty(new BuilderLogFacet());
  +        p.addProperty(new BuilderClassResolverFacet());
  +        p.addProperty(new BuilderMessagesFacet());
  +        p.addProperty(new BuilderErrorHandlerFacet());
  +        p.addProperty(new BuilderServiceIdFacet());
  +
  +        MockControl c = MockControl.createStrictControl(Module.class);
  +        Module module = (Module) c.getMock();
  +
  +        ErrorHandler eh = new DefaultErrorHandler();
  +        ClassResolver cr = new DefaultClassResolver();
  +
  +        MockControl messagesControl = MockControl.createStrictControl(Messages.class);
  +        Messages messages = (Messages) messagesControl.getMock();
  +
  +        module.getErrorHandler();
  +        c.setReturnValue(eh);
  +
  +        module.getClassResolver();
  +        c.setReturnValue(cr);
  +
  +        module.getClassResolver();
  +        c.setReturnValue(cr);
  +
  +        module.getMessages();
  +        c.setReturnValue(messages);
  +
  +        module.getErrorHandler();
  +        c.setReturnValue(eh);
  +
  +        c.replay();
  +        messagesControl.replay();
  +
  +        AutowireTarget t =
  +            (AutowireTarget) factory.createCoreServiceImplementation(
  +                "foo.bar.Baz",
  +                Runnable.class,
  +                module,
  +                Collections.singletonList(p));
  +
  +        assertSame(eh, t.getErrorHandler());
  +        assertSame(cr, t.getClassResolver());
  +        assertSame(messages, t.getMessages());
  +        assertSame(LogFactory.getLog("foo.bar.Baz"), t.getLog());
  +        assertEquals("foo.bar.Baz", t.getServiceId());
  +
  +        c.verify();
  +        messagesControl.verify();
       }
   }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/services/AutowireTarget.java
  
  Index: AutowireTarget.java
  ===================================================================
  // Copyright 2004 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 hivemind.test.services;
  
  import org.apache.commons.logging.Log;
  import org.apache.hivemind.ClassResolver;
  import org.apache.hivemind.ErrorHandler;
  import org.apache.hivemind.Messages;
  
  public class AutowireTarget implements Runnable
  {
      private Log _log;
      private ErrorHandler _errorHandler;
      private ClassResolver _classResolver;
      private String _serviceId;
      private Messages _messages;
  
      public ClassResolver getClassResolver()
      {
          return _classResolver;
      }
  
      public ErrorHandler getErrorHandler()
      {
          return _errorHandler;
      }
  
      public Log getLog()
      {
          return _log;
      }
  
      public Messages getMessages()
      {
          return _messages;
      }
  
      public String getServiceId()
      {
          return _serviceId;
      }
  
      public void setClassResolver(ClassResolver resolver)
      {
          _classResolver = resolver;
      }
  
      public void setErrorHandler(ErrorHandler handler)
      {
          _errorHandler = handler;
      }
  
      public void setLog(Log log)
      {
          _log = log;
      }
  
      public void setMessages(Messages messages)
      {
          _messages = messages;
      }
  
      public void setServiceId(String string)
      {
          _serviceId = string;
      }
  
      public void run()
      {
  
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/services/SetClassResolver.sdl
  
  Index: SetClassResolver.sdl
  ===================================================================
  //  Copyright 2004 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.
  
  module (id=hivemind.test.services version="1.0.0")
  {
    service-point (id=SetClassResolver interface=hivemind.test.services.ClassResolverHolder)
    {
      invoke-factory (service-id=hivemind.BuilderFactory)
      {
        construct (class=hivemind.test.services.impl.ClassResolverHolderImpl 
          class-resolver-property=classResolver)
      }
    }
  }
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/services/ConstructClassResolver.sdl
  
  Index: ConstructClassResolver.sdl
  ===================================================================
  //  Copyright 2004 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.
  
  module (id=hivemind.test.services version="1.0.0")
  {
    service-point (id=ConstructClassResolver interface=hivemind.test.services.ClassResolverHolder)
    {
      invoke-factory (service-id=hivemind.BuilderFactory)
      {
        construct (class=hivemind.test.services.impl.ClassResolverHolderImpl)
        {
          class-resolver
        }
      }
    }
  }
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/services/ClassResolverHolder.java
  
  Index: ClassResolverHolder.java
  ===================================================================
  // Copyright 2004 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 hivemind.test.services;
  
  import org.apache.hivemind.ClassResolver;
  
  /**
   * Used with the {@link hivemind.test.services.TestBuilderFactory} tests.
   *
   * @author Howard Lewis Ship
   */
  public interface ClassResolverHolder
  {
      public ClassResolver getClassResolver();
      
  }
  
  
  
  1.5       +22 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/util/ClassAdaptor.java
  
  Index: ClassAdaptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/util/ClassAdaptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ClassAdaptor.java	15 Jun 2004 13:42:33 -0000	1.4
  +++ ClassAdaptor.java	18 Jun 2004 21:39:00 -0000	1.5
  @@ -87,6 +87,28 @@
           return a.getPropertyType();
       }
   
  +    /**
  +     * Returns true if the named property exists and is readable.
  +     */
  +
  +    public boolean isReadable(String propertyName)
  +    {
  +        PropertyAdaptor result = (PropertyAdaptor) _propertyAdaptorMap.get(propertyName);
  +
  +        return result != null && result.isReadable();
  +    }
  +
  +    /**
  +     * Returns true if the named property exists and is writable.
  +     */
  +
  +    public boolean isWritable(String propertyName)
  +    {
  +        PropertyAdaptor result = (PropertyAdaptor) _propertyAdaptorMap.get(propertyName);
  +
  +        return result != null && result.isWritable();
  +    }
  +
       private PropertyAdaptor getAdaptor(Object target, String propertyName)
       {
           PropertyAdaptor result = (PropertyAdaptor) _propertyAdaptorMap.get(propertyName);
  
  
  
  1.5       +17 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/util/PropertyUtils.java
  
  Index: PropertyUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/util/PropertyUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PropertyUtils.java	15 Jun 2004 13:42:33 -0000	1.4
  +++ PropertyUtils.java	18 Jun 2004 21:39:00 -0000	1.5
  @@ -49,6 +49,23 @@
       }
   
       /**
  +     * Returns true of the instance contains a writable property of the given type.
  +     * 
  +     * @param target the object to inspect
  +     * @param propertyName the name of the property to check
  +     */
  +
  +    public static boolean isWritable(Object target, String propertyName)
  +    {
  +        return getAdaptor(target).isWritable(propertyName);
  +    }
  +
  +	public static boolean isReadable(Object target, String propertyName)
  +	{
  +		return getAdaptor(target).isReadable(propertyName);
  +	}
  +
  +    /**
        * Updates the property of the target object.
        * 
        * @param target the object to update
  
  
  
  1.5       +17 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/util/PropertyAdaptor.java
  
  Index: PropertyAdaptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/util/PropertyAdaptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PropertyAdaptor.java	15 Jun 2004 13:42:33 -0000	1.4
  +++ PropertyAdaptor.java	18 Jun 2004 21:39:00 -0000	1.5
  @@ -75,6 +75,14 @@
       }
   
       /**
  +     * Returns true if there's a write method for the property.
  +     */
  +    public boolean isWritable()
  +    {
  +        return _writeMethod != null;
  +    }
  +
  +    /**
        * Reads the property of the target object.
        * 
        * @param target the object to read a property from
  @@ -101,5 +109,14 @@
                   null,
                   ex);
           }
  +    }
  +
  +    /**
  +     * Returns true if there's a read method for the property.
  +     */
  +
  +    public boolean isReadable()
  +    {
  +        return _readMethod != null;
       }
   }
  
  
  
  1.13      +2 -2      jakarta-hivemind/library/src/descriptor/META-INF/hivemodule.sdl
  
  Index: hivemodule.sdl
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/descriptor/META-INF/hivemodule.sdl,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- hivemodule.sdl	17 Jun 2004 15:16:14 -0000	1.12
  +++ hivemodule.sdl	18 Jun 2004 21:39:00 -0000	1.13
  @@ -214,7 +214,7 @@
   	  
   	  invoke-factory (service-id=hivemind.BuilderFactory)
   	  {
  -	    construct (class=org.apache.hivemind.lib.factory.BeanFactoryBuilder service-id-property=serviceId error-handler-property=errorHandler)
  +	    construct (class=org.apache.hivemind.lib.factory.BeanFactoryBuilder)
   	  }
   	}
   	
  @@ -291,7 +291,7 @@
   	  
   	  invoke-factory (service-id=hivemind.BuilderFactory)
   	  {
  -	    construct (class=org.apache.hivemind.lib.pipeline.PipelineFactory service-id-property=serviceId error-handler-property=errorHandler)
  +	    construct (class=org.apache.hivemind.lib.pipeline.PipelineFactory)
   	    {
   	      set-service (property=classFactory service-id=hivemind.ClassFactory)
   	      set-service (property=defaultImplementationBuilder service-id=DefaultImplementationBuilder)
  
  
  
  1.13      +40 -23    jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.sdl
  
  Index: hivemodule.sdl
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.sdl,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- hivemodule.sdl	17 Jun 2004 15:16:14 -0000	1.12
  +++ hivemodule.sdl	18 Jun 2004 21:39:00 -0000	1.13
  @@ -99,8 +99,7 @@
   
   		invoke-factory (service-id=BuilderFactory)
   		{
  -			construct (class=org.apache.hivemind.service.impl.DefaultsSymbolSource log-property=log 
  -				error-handler-property=errorHandler initialize-method=initializeService)
  +			construct (class=org.apache.hivemind.service.impl.DefaultsSymbolSource initialize-method=initializeService)
   			{
   			  set-configuration (configuration-id=FactoryDefaults property=defaults)
   			}
  @@ -119,8 +118,7 @@
   
   		invoke-factory (service-id=BuilderFactory)
   		{
  -			construct (class=org.apache.hivemind.service.impl.DefaultsSymbolSource log-property=log
  -				error-handler-property=errorHandler initialize-method=initializeService)
  +			construct (class=org.apache.hivemind.service.impl.DefaultsSymbolSource initialize-method=initializeService)
   			{
   			  set-configuration (configuration-id=ApplicationDefaults property=defaults)
   			}
  @@ -186,8 +184,7 @@
   		
   		invoke-factory (service-id=BuilderFactory model=primitive)
   		{
  -			construct (class=org.apache.hivemind.service.impl.LoggingInterceptorFactory
  -					service-id-property=serviceId)
  +			construct (class=org.apache.hivemind.service.impl.LoggingInterceptorFactory)
   			{
   				set-service (property=factory service-id=ClassFactory)
   			}
  @@ -239,6 +236,11 @@
   				    "The name of a property to assign the module's ErrorHandler to."
   				}
   				
  +				attribute (name=class-resolver-property)
  +				{
  +					"The name of a property to assign the mdoule's ClassResolver to."
  +				}
  +				
   				rules
   				{
   					create-object (class=org.apache.hivemind.service.impl.BuilderParameter)
  @@ -261,6 +263,10 @@
   					create-object (class=org.apache.hivemind.service.impl.BuilderErrorHandlerFacet)
   					read-attribute (attribute=error-handler-property property=propertyName)
   					invoke-parent (method=addProperty depth=4)
  +					
  +					create-object (class=org.apache.hivemind.service.impl.BuilderClassResolverFacet)
  +					read-attribute (attribute=class-resolver-property property=propertyName)
  +					invoke-parent (method=addProperty depth=5)
   				}
   			
   				element (name=string)
  @@ -271,7 +277,7 @@
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-content (property=value)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}
   					
  @@ -283,7 +289,7 @@
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-content (property=value)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}
   				
  @@ -295,7 +301,7 @@
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-content (property=value)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}  		
   				}
   
  @@ -307,7 +313,7 @@
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-content (property=value)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}				
   
  @@ -319,7 +325,7 @@
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-content (property=value)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}		  	
     	
  @@ -331,7 +337,7 @@
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-content (property=value)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}				  	
   
  @@ -343,7 +349,7 @@
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-content (property=value)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}			  	
   
  @@ -354,7 +360,7 @@
   					rules
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderLogFacet)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}		
   				
  @@ -365,9 +371,20 @@
   				  rules
   				  {
   				    create-object (class=org.apache.hivemind.service.impl.BuilderErrorHandlerFacet)
  -				    invoke-parent (method=addParameter depth=5)
  +				    invoke-parent (method=addParameter depth=6)
   				  }
  -				}				
  +				}			
  +				
  +				element (name=class-resolver)
  +				{
  +				  "Placeholder for the module's ClassResolver instance passed in as a constructor parameter."
  +				  
  +				  rules
  +				  {
  +				    create-object (class=org.apache.hivemind.service.impl.BuilderClassResolverFacet)
  +				    invoke-parent (method=addParameter depth=6)				  
  +				  }
  +				}	
   
   				element (name=messages)
   				{
  @@ -376,7 +393,7 @@
   					rules
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderMessagesFacet)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}
   				
  @@ -387,7 +404,7 @@
   					rules
   					{
   						create-object (class=org.apache.hivemind.service.impl.BuilderServiceIdFacet)
  -						invoke-parent (method=addParameter depth=5)
  +						invoke-parent (method=addParameter depth=6)
   					}
   				}
   				
  @@ -411,7 +428,7 @@
   						create-object (class=org.apache.hivemind.service.impl.BuilderSmartPropertyFacet)
   						read-attribute (property=propertyName attribute=property)
   						read-attribute (property=attributeValue attribute=value)
  -						invoke-parent (method=addProperty depth=5)
  +						invoke-parent (method=addProperty depth=6)
   					}
   				}
   				
  @@ -434,7 +451,7 @@
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-attribute (property=propertyName attribute=property)
   						read-attribute (property=value attribute=service-id)
  -						invoke-parent (method=addProperty depth=5)
  +						invoke-parent (method=addProperty depth=6)
   					}
   				}
   				
  @@ -458,7 +475,7 @@
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-attribute (property=propertyName attribute=property)
   						read-attribute (property=value attribute=configuration-id)
  -						invoke-parent (method=addProperty depth=5)
  +						invoke-parent (method=addProperty depth=6)
   					}
   				}
   					
  @@ -481,7 +498,7 @@
   						create-object (class=org.apache.hivemind.service.impl.BuilderPropertyFacet)
   						read-attribute (property=propertyName attribute=property)
   						read-attribute (property=value attribute=path)
  -						invoke-parent (method=addProperty depth=5)
  +						invoke-parent (method=addProperty depth=6)
   					}
   				}
   				
  @@ -507,7 +524,7 @@
   				  		create-object (class=org.apache.hivemind.service.impl.EventRegistration)
   				  		read-attribute (property=producer attribute=service-id)
   				  		read-attribute (property=eventSetName attribute=event-set)
  -				  		invoke-parent (method=addEventRegistration depth=5)
  +				  		invoke-parent (method=addEventRegistration depth=6)
   				  	}
   				}
   			}  // element construct
  
  
  
  1.3       +47 -1     jakarta-hivemind/framework/src/documentation/content/xdocs/hivemind/BuilderFactory.xml
  
  Index: BuilderFactory.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/documentation/content/xdocs/hivemind/BuilderFactory.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BuilderFactory.xml	10 Jun 2004 19:49:39 -0000	1.2
  +++ BuilderFactory.xml	18 Jun 2004 21:39:00 -0000	1.3
  @@ -34,12 +34,13 @@
   {
     construct (class=... log-property=... messages-property=...
       service-id-property=... initialize-method=...
  -    error-handler-property=...)
  +    error-handler-property=... class-resolver-property=...)
     {
       log
       messages
       service-id
       error-handler
  +    class-resolver
       string { ... }
       boolean { ... }
       configuration { ... }
  @@ -72,6 +73,8 @@
   					<td>yes</td>
   					<td>The fully qualified name of the class to instantiate.</td>
   				</tr>
  +        <tr><td>class-resolver-property</td><td>no</td><td>The property to receive the module's
  +          &api.ClassResolver;.</td></tr>
           <tr><td>error-handler-property</td>
             <td>no</td>
             <td> The name of a property to recieve the module's 
  @@ -110,6 +113,49 @@
   				and are used to supply constructor parameters and configure properties
   				of the constructed service implementation.</p>
   		</section>
  +    
  +    <section>
  +      <title>Autowiring</title>
  +      
  +      <p>
  +        BuilderFactory will automatically set certain common properties of the service implementation.
  +        By using standard names (and standard types), the need to specify
  +        attributes <code>log-property</code>, <code>error-handler-property</code>, etc. is avoided.
  +        Simply by having a writable property with the correct name and type is sufficient:
  +        
  +      </p>
  +      
  +      <table>
  +        <tr>
  +          <th>Property name</th>
  +          <th>Property Type</th>
  +        </tr>
  +        <tr>
  +          <td>classResolver</td>
  +          <td>&api.ClassResolver;</td>
  +        </tr>
  +        <tr>
  +          <td>errorHandler</td>
  +          <td>&api.ErrorHandler;</td>
  +        </tr>
  +        <tr>
  +          <td>log</td>
  +          <td>
  +            <code>org.apache.commons.logging.Log</code>
  +          </td>
  +        </tr>
  +        <tr>
  +          <td>messages</td>
  +          <td>&api.Messages;</td>
  +        </tr>
  +        <tr>
  +          <td>serviceId</td>
  +          <td>String</td>
  +        </tr>
  +      </table>
  +      
  +    </section>
  +    
   		<section>
   			<title>Constructor Parameter Elements</title>
   			<p>The following table summarizes the elements which can be used to
  
  
  
  1.6       +46 -4     jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java
  
  Index: BuilderFacet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BuilderFacet.java	5 Jun 2004 19:09:13 -0000	1.5
  +++ BuilderFacet.java	18 Jun 2004 21:39:01 -0000	1.6
  @@ -16,6 +16,7 @@
   
   import org.apache.hivemind.impl.BaseLocatable;
   import org.apache.hivemind.internal.Module;
  +import org.apache.hivemind.util.PropertyUtils;
   
   /**
    * Represents one facet of constructing a service implementation instance.
  @@ -40,10 +41,7 @@
        * @param targetType the desired property type (extracted from the property type
        * of the property to be updated, when a property is known)
        */
  -    public abstract Object getFacetValue(
  -        String serviceId,
  -        Module invokingModule,
  -        Class targetType);
  +    public abstract Object getFacetValue(String serviceId, Module invokingModule, Class targetType);
   
       public String getPropertyName()
       {
  @@ -53,6 +51,50 @@
       public void setPropertyName(String string)
       {
           _propertyName = string;
  +    }
  +
  +    public void autowire(Object target, String serviceId, Module invokingModule)
  +    {
  +        if (_propertyName != null)
  +            return;
  +
  +        String defaultPropertyName = getDefaultPropertyName();
  +
  +        if (defaultPropertyName == null)
  +            return;
  +
  +        Class facetType = getFacetType();
  +
  +        if (facetType == null)
  +            return;
  +
  +        if (PropertyUtils.isWritable(target, defaultPropertyName)
  +            && PropertyUtils.getPropertyType(target, defaultPropertyName).isAssignableFrom(
  +                facetType))
  +            PropertyUtils.write(
  +                target,
  +                defaultPropertyName,
  +                getFacetValue(serviceId, invokingModule, facetType));
  +    }
  +    
  +    /**
  +     * Returns null. Subclasses can provide the default name for a property used
  +     * by {@link #autowire(Object)}.
  +     */
  +    protected String getDefaultPropertyName()
  +    {
  +        return null;
  +    }
  +
  +    /**
  +     * Returns the type of property assigned by this facet, if known. Returns null
  +     * otherwise.  This implementation returns null.  Used by 
  +     * {@link #autowire(Object, String, Module)}.
  +     */
  +
  +    protected Class getFacetType()
  +    {
  +        return null;
       }
   
   }
  
  
  
  1.5       +11 -4     jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java
  
  Index: BuilderMessagesFacet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BuilderMessagesFacet.java	10 Jun 2004 19:49:39 -0000	1.4
  +++ BuilderMessagesFacet.java	18 Jun 2004 21:39:01 -0000	1.5
  @@ -14,6 +14,7 @@
   
   package org.apache.hivemind.service.impl;
   
  +import org.apache.hivemind.Messages;
   import org.apache.hivemind.internal.Module;
   
   /**
  @@ -26,12 +27,18 @@
   public class BuilderMessagesFacet extends BuilderFacet
   {
   
  -    public Object getFacetValue(
  -        String point,
  -        Module invokingModule,
  -        Class targetType)
  +    public Object getFacetValue(String point, Module invokingModule, Class targetType)
       {
           return invokingModule.getMessages();
       }
   
  +	protected String getDefaultPropertyName()
  +	{
  +		return "messages";
  +	}
  +
  +	protected Class getFacetType()
  +	{
  +		return Messages.class;
  +	}
   }
  
  
  
  1.2       +10 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java
  
  Index: BuilderErrorHandlerFacet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BuilderErrorHandlerFacet.java	10 Jun 2004 19:49:39 -0000	1.1
  +++ BuilderErrorHandlerFacet.java	18 Jun 2004 21:39:01 -0000	1.2
  @@ -14,6 +14,7 @@
   
   package org.apache.hivemind.service.impl;
   
  +import org.apache.hivemind.ErrorHandler;
   import org.apache.hivemind.internal.Module;
   
   /**
  @@ -30,4 +31,13 @@
           return invokingModule.getErrorHandler();
       }
   
  +	protected String getDefaultPropertyName()
  +	{
  +		return "errorHandler";
  +	}
  +
  +	protected Class getFacetType()
  +	{
  +		return ErrorHandler.class;
  +	}
   }
  
  
  
  1.5       +9 -0      jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderServiceIdFacet.java
  
  Index: BuilderServiceIdFacet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderServiceIdFacet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BuilderServiceIdFacet.java	5 Jun 2004 19:09:13 -0000	1.4
  +++ BuilderServiceIdFacet.java	18 Jun 2004 21:39:01 -0000	1.5
  @@ -30,4 +30,13 @@
           return serviceId;
       }
   
  +    protected String getDefaultPropertyName()
  +    {
  +        return "serviceId";
  +    }
  +
  +    protected Class getFacetType()
  +    {
  +        return String.class;
  +    }
   }
  
  
  
  1.5       +10 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java
  
  Index: BuilderLogFacet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BuilderLogFacet.java	17 Jun 2004 15:16:13 -0000	1.4
  +++ BuilderLogFacet.java	18 Jun 2004 21:39:01 -0000	1.5
  @@ -14,6 +14,7 @@
   
   package org.apache.hivemind.service.impl;
   
  +import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.hivemind.internal.Module;
   
  @@ -30,4 +31,13 @@
           return LogFactory.getLog(serviceId);
       }
   
  +    protected String getDefaultPropertyName()
  +    {
  +        return "log";
  +    }
  +
  +    protected Class getFacetType()
  +    {
  +        return Log.class;
  +    }
   }
  
  
  
  1.11      +6 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactory.java
  
  Index: BuilderFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactory.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BuilderFactory.java	15 Jun 2004 19:26:37 -0000	1.10
  +++ BuilderFactory.java	18 Jun 2004 21:39:01 -0000	1.11
  @@ -115,8 +115,13 @@
               BuilderFacet facet = (BuilderFacet) properties.get(i);
               String propertyName = facet.getPropertyName();
   
  +			// Facets that can autowire, should.
  +			
  +            facet.autowire(target, serviceId, invokingModule);
  +
               // There will be a facet for log, messages, service-id, etc. even if no
  -            // property name is specified, so we skip it here.
  +            // property name is specified, so we skip it here.  In many cases, those
  +            // facets will have just done an autowire.
   
               if (propertyName == null)
                   continue;
  
  
  
  1.1                  jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderClassResolverFacet.java
  
  Index: BuilderClassResolverFacet.java
  ===================================================================
  // Copyright 2004 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.service.impl;
  
  import org.apache.hivemind.ClassResolver;
  import org.apache.hivemind.internal.Module;
  
  /**
   * {@link org.apache.hivemind.service.impl.BuilderFacet} whose
   * value is the {@link org.apache.hivemind.ClassResolver} of
   * the contributing module.
   *
   * @author Howard Lewis Ship
   */
  public class BuilderClassResolverFacet extends BuilderFacet
  {
  
      public Object getFacetValue(String serviceId, Module invokingModule, Class targetType)
      {
          return invokingModule.getClassResolver();
      }
  
      protected String getDefaultPropertyName()
      {
          return "classResolver";
      }
  
      protected Class getFacetType()
      {
          return ClassResolver.class;
      }
  
  }
  
  
  
  1.4       +20 -0     jakarta-hivemind/framework/src/test/org/apache/hivemind/util/TestPropertyUtils.java
  
  Index: TestPropertyUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/util/TestPropertyUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestPropertyUtils.java	15 Jun 2004 13:42:33 -0000	1.3
  +++ TestPropertyUtils.java	18 Jun 2004 21:39:01 -0000	1.4
  @@ -282,4 +282,24 @@
   
           assertEquals(int.class, PropertyUtils.getPropertyType(b, "value"));
       }
  +
  +    public void testIsReadable()
  +    {
  +        Bean b = new Bean();
  +
  +        assertEquals(true, PropertyUtils.isReadable(b, "value"));
  +        assertEquals(false, PropertyUtils.isReadable(b, "noSuchProperty"));
  +        assertEquals(true, PropertyUtils.isReadable(b, "class"));
  +        assertEquals(false, PropertyUtils.isReadable(b, "writeOnly"));
  +    }
  +
  +    public void testIsWriteable()
  +    {
  +        Bean b = new Bean();
  +        
  +        assertEquals(true, PropertyUtils.isWritable(b, "value"));
  +        assertEquals(true, PropertyUtils.isWritable(b, "writeOnly"));
  +        assertEquals(false, PropertyUtils.isWritable(b, "doesNotExist"));
  +        assertEquals(false, PropertyUtils.isWritable(b, "class"));
  +    }
   }
  
  
  
  1.10      +34 -38    jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- status.xml	18 Jun 2004 13:50:41 -0000	1.9
  +++ status.xml	18 Jun 2004 21:39:01 -0000	1.10
  @@ -15,30 +15,25 @@
      limitations under the License.
   -->
   <status>
  -
     <developers>
  -    <person name="Howard M. Lewis Ship"  email="hlship@comcast.net" id="HLS" />
  -   </developers>
  -
  - 
  +    <person name="Howard M. Lewis Ship" email="hlship@comcast.net" id="HLS" />
  +  </developers>
     <todo>
       <actions priority="Release 1.0">
  -			<action context="lib" dev="HLS">JMX Integration</action>
  +      <action context="lib" dev="HLS">JMX Integration</action>
       </actions>
  -
     </todo>
  -
  -	<changes>
  +  <changes>
       <release version="1.0-beta-1" date="unreleased">
         <action type="update" dev="HLS">Added change log. </action>
         <action type="update" dev="HLS">Refactored ClassFab and related classes 
           for easier reuse outside of HiveMind. Added a new suite of tests 
           related to ClassFab.</action>
  -      <action type="add" dev="HLS">Created two new services in hivemind-lib 
  -        for creating default implementations of arbitrary interfaces 
  -        (<link href="site:hivemind.lib.DefaultImplementationBuilder">DefaultImplementationBuilder</link>) 
  -        and for using that to create placeholder 
  -        services (<link href="site:hivemind.lib.PlaceholderFactory">PlaceholderFactory</link>).</action>
  +      <action type="add" dev="HLS">Created two new services in hivemind-lib for 
  +        creating default implementations of arbitrary interfaces (<link 
  +        href="site:hivemind.lib.DefaultImplementationBuilder">DefaultImplementationBuilder</link>) 
  +        and for using that to create placeholder services (<link 
  +        href="site:hivemind.lib.PlaceholderFactory">PlaceholderFactory</link>).</action>
         <action type="add" dev="HLS">Created MessageFormatter class as a wrapper 
           around ResourceBundle and an easy way for individual packages to gain 
           access to runtime messages. </action>
  @@ -47,28 +42,29 @@
           attribute).</action>
         <action type="add" dev="HLS">Added the <code>qualified-id</code> and 
           <code>id-list</code> translators.</action>
  -      <action type="add" dev="HLS">Added the 
  -        <link href="site:hivemind.lib.PipelineFactory">hivemind.lib.PipelineFactory</link> and related code, schemas, 
  -        tests and documentation. </action>
  -      <action type="fix" dev="HLS" fixes-bug="HIVEMIND-4">
  -        Enhance logging of exceptions when setting a service property to a contribution
  -      </action>
  -      <action type="add" dev="HLS">
  -        Added service <link href="site:hivemind.lib.BeanFactoryBuilder">hivemind.lib.BeanFactoryBuilder</link>.     
  -      </action>
  -      <action type="update" dev="HLS">
  -        Removed the &lt;description&gt; element from the module descriptor format; descriptions are now
  -        provided as enclosed text for element that support descriptions.
  -      </action>
  -      <action type="update" dev="HLS">
  -        Changed the MethodMatcher classes to use a MethodSignature rather than a Method.
  -      </action>
  -      <action type="update" dev="HLS">
  -        Changed MessageFormatter to automatically convert Throwables into their message or class name.
  -      </action>
  -      <action type="add" dev="HLS">
  -        Added FileResource.
  -      </action>
  +      <action type="add" dev="HLS">Added the <link 
  +        href="site:hivemind.lib.PipelineFactory">hivemind.lib.PipelineFactory</link> 
  +        and related code, schemas, tests and documentation. </action>
  +      <action type="fix" dev="HLS" fixes-bug="HIVEMIND-4"> Enhance logging of 
  +        exceptions when setting a service property to a contribution </action>
  +      <action type="add" dev="HLS"> Added service <link 
  +        href="site:hivemind.lib.BeanFactoryBuilder">hivemind.lib.BeanFactoryBuilder</link>. 
  +        </action>
  +      <action type="update" dev="HLS"> Removed the &lt;description&gt; element 
  +        from the module descriptor format; descriptions are now provided as 
  +        enclosed text for element that support descriptions. </action>
  +      <action type="update" dev="HLS"> Changed the MethodMatcher classes to use 
  +        a MethodSignature rather than a Method. </action>
  +      <action type="update" dev="HLS"> Changed MessageFormatter to 
  +        automatically convert Throwables into their message or class name. 
  +        </action>
  +      <action type="add" dev="HLS"> Added FileResource. </action>
  +      <action type="update" dev="HLS"> Extended <link 
  +        href="site.hivemind.BuilderFactory">hivemind.BuilderFactory</link> to 
  +        be able to set the <code>ClassResolver</code>; for a service 
  +        implementation, and to autowire common properties (log, messages, 
  +        serviceId, errorHandler, classResolver) if the properties are writeable 
  +        and of the correct type. </action>
       </release>
  -	</changes>
  -	</status>
  \ No newline at end of file
  +  </changes>
  +</status>
  \ No newline at end of file
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/services/impl/ClassResolverHolderImpl.java
  
  Index: ClassResolverHolderImpl.java
  ===================================================================
  // Copyright 2004 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 hivemind.test.services.impl;
  
  import hivemind.test.services.ClassResolverHolder;
  
  import org.apache.hivemind.ClassResolver;
  
  /**
   * Used with {@link hivemind.test.services.TestBuilderFactory}.
   *
   * @author Howard Lewis Ship
   */
  public class ClassResolverHolderImpl implements ClassResolverHolder
  {
      private ClassResolver _classResolver;
  
      public ClassResolverHolderImpl()
      {
      }
  
      public ClassResolverHolderImpl(ClassResolver resolver)
      {
          _classResolver = resolver;
      }
  
      public ClassResolver getClassResolver()
      {
          return _classResolver;
      }
  
      public void setClassResolver(ClassResolver resolver)
      {
          _classResolver = resolver;
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org