hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/test/hivemind/test/config ObjectTranslator.xml
Date Sat, 17 Jul 2004 21:32:16 GMT
hlship      2004/07/17 14:32:16

  Modified:    framework/src/documentation/content/xdocs/hivemind
                        ObjectProviders.xml BuilderFactory.xml
               framework/src/descriptor/META-INF hivemodule.sdl
               .        status.xml
               framework/src/java/org/apache/hivemind/service/impl
                        ServiceMessages.java ServiceStrings.properties
  Added:       framework/src/test/org/apache/hivemind/service/impl
                        TestObjectProviders.java TestObjectTranslator.java
               framework/src/java/org/apache/hivemind/service/impl
                        ServicePropertyObjectProvider.java
               framework/src/test/hivemind/test/config ObjectTranslator.xml
  Removed:     framework/src/test/org/apache/hivemind/services/impl
                        TestObjectTranslator.java TestObjectProviders.java
  Log:
  Add service-property object provider.
  
  Revision  Changes    Path
  1.2       +20 -0     jakarta-hivemind/framework/src/documentation/content/xdocs/hivemind/ObjectProviders.xml
  
  Index: ObjectProviders.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/documentation/content/xdocs/hivemind/ObjectProviders.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectProviders.xml	16 Jul 2004 23:15:39 -0000	1.1
  +++ ObjectProviders.xml	17 Jul 2004 21:32:16 -0000	1.2
  @@ -44,6 +44,7 @@
       <tr>
         <th>Prefix</th>
         <th>Descripton</th>
  +      <th>Example</th>
       </tr>
       
       <tr>
  @@ -55,20 +56,39 @@
             Provided by the HiveMind library.
           </note>
           </td>
  +        
  +        <td>
  +          bean:ValidatorFactory:string,required
  +        </td>
       </tr>
       <tr>
         <td>configuration</td>
         <td>The locator is the id of a configuration.</td>
  +      <td>
  +        configuration:MyConfiguration
  +      </td>
       </tr>
       
       <tr>
         <td>instance</td>
         <td>The locator is a fully qualified class name, which must have a public no
arguments contructor.</td>
  +      <td>
  +        instance:com.example.MyObject
  +      </td>
       </tr>
       
       <tr>
         <td>service</td>
         <td>The locator is the id of a service.</td>
  +      <td>service:MyService</td>
  +    </tr>
  +    
  +    <tr>
  +      <td>service-property</td>
  +      <td>The locator provides a service id and a property name (provided by that
service), seperated with a colon.</td>
  +      <td>
  +        service-property:MyService:activeRequest
  +      </td>
       </tr>
       
       
  
  
  
  1.5       +9 -0      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BuilderFactory.xml	16 Jul 2004 23:15:39 -0000	1.4
  +++ BuilderFactory.xml	17 Jul 2004 21:32:16 -0000	1.5
  @@ -62,6 +62,15 @@
   			the implementation class and set common service properties. Nested
   			elements supply the constructor parameters and configure other specific
   			properties of the implementation (the <code>set-...</code> elements).</p>
  +      
  +      <note>
  +     BuilderFactory is a complex tool, with support for both constructor dependency injection
and
  +     property dependency injection. Many of the options are rarely used; the most general
purpose
  +     and most frequently used are <link href="#set">set</link>, <link href="#set-object">set-object</link>
  +     and <link href="#event-listener">event-listener</link> (along with
  +     <link href="#Autowiring">autowiring of certain properties</link>).
  +      </note>
  +      
   		<section>
   			<title>construct</title>
   			<table>
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/TestObjectProviders.java
  
  Index: TestObjectProviders.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 hivemind.test.services.StringHolder;
  import hivemind.test.services.impl.StringHolderImpl;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.hivemind.ApplicationRuntimeException;
  import org.apache.hivemind.Location;
  import org.apache.hivemind.impl.DefaultClassResolver;
  import org.apache.hivemind.internal.Module;
  import org.apache.hivemind.service.impl.ConfigurationObjectProvider;
  import org.apache.hivemind.service.impl.ObjectInstanceObjectProvider;
  import org.apache.hivemind.service.impl.ServiceObjectProvider;
  import org.apache.hivemind.service.impl.ServicePropertyObjectProvider;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.easymock.MockControl;
  
  /**
   * Tests for several implementations of {@link org.apache.hivemind.service.ObjectProvider}.
   *
   * @author Howard Lewis Ship
   */
  public class TestObjectProviders extends HiveMindTestCase
  {
      public void testServiceObjectProvider()
      {
          ServiceObjectProvider p = new ServiceObjectProvider();
  
          String expected = "EXPECTED RESULT";
  
          MockControl mc = newControl(Module.class);
          Module m = (Module) mc.getMock();
  
          m.getService("fred", Location.class);
          mc.setReturnValue(expected);
  
          replayControls();
  
          Object actual = p.provideObject(m, Location.class, "fred");
  
          assertSame(expected, actual);
  
          verifyControls();
      }
  
      public void testConfigurationObjectProvider()
      {
          ConfigurationObjectProvider p = new ConfigurationObjectProvider();
  
          List expected = new ArrayList();
  
          MockControl mc = newControl(Module.class);
          Module m = (Module) mc.getMock();
  
          m.getConfiguration("barney");
          mc.setReturnValue(expected);
  
          replayControls();
  
          Object actual = p.provideObject(m, List.class, "barney");
  
          assertSame(expected, actual);
  
          verifyControls();
      }
  
      public void testInstanceProvider()
      {
          ObjectInstanceObjectProvider p = new ObjectInstanceObjectProvider();
  
          MockControl mc = newControl(Module.class);
          Module m = (Module) mc.getMock();
  
          m.getClassResolver();
          mc.setReturnValue(new DefaultClassResolver());
  
          replayControls();
  
          Object actual = p.provideObject(m, List.class, "java.util.ArrayList");
  
          assertTrue(actual.getClass().equals(ArrayList.class));
  
          verifyControls();
      }
  
      public void testInstanceProviderFailure()
      {
          ObjectInstanceObjectProvider p = new ObjectInstanceObjectProvider();
  
          MockControl mc = newControl(Module.class);
          Module m = (Module) mc.getMock();
  
          m.getClassResolver();
          mc.setReturnValue(new DefaultClassResolver());
  
          replayControls();
  
          try
          {
              p.provideObject(m, List.class, "java.util.List");
              unreachable();
          }
          catch (ApplicationRuntimeException ex)
          {
              assertExceptionSubstring(ex, "Error instantiating instance of class java.util.List");
          }
  
          verifyControls();
      }
  
      public void testServicePropertyObjectProvider()
      {
          MockControl mc = newControl(Module.class);
          Module m = (Module) mc.getMock();
  
          StringHolder h = new StringHolderImpl();
  
          h.setValue("abracadabra");
  
          m.getService("MyService", Object.class);
          mc.setReturnValue(h);
  
          replayControls();
  
          ServicePropertyObjectProvider p = new ServicePropertyObjectProvider();
  
          Object result = p.provideObject(m, String.class, "MyService:value");
  
          assertEquals(h.getValue(), result);
  
          verifyControls();
      }
  
      public void testServicePropertyObjectProviderWithInvalidLocator()
      {
          ServicePropertyObjectProvider p = new ServicePropertyObjectProvider();
  
          try
          {
              p.provideObject(null, null, "MyService");
              unreachable();
          }
          catch (ApplicationRuntimeException ex)
          {
              assertExceptionSubstring(
                  ex,
                  ServiceMessages.invalidServicePropertyLocator("MyService"));
          }
      }
  
      // TODO: Integration test that proves the SDL is valid.
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/TestObjectTranslator.java
  
  Index: TestObjectTranslator.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 java.util.ArrayList;
  import java.util.Collections;
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.hivemind.ErrorHandler;
  import org.apache.hivemind.Location;
  import org.apache.hivemind.internal.Module;
  import org.apache.hivemind.service.ObjectProvider;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.easymock.MockControl;
  
  /**
   * Tests for {@link org.apache.hivemind.service.impl.ObjectTranslator}.
   *
   * @author Howard Lewis Ship
   */
  public class TestObjectTranslator extends HiveMindTestCase
  {
  
      public void testDupePrefix()
      {
          Location l1 = fabricateLocation(13);
          Location l2 = fabricateLocation(97);
  
          List l = new ArrayList();
  
          ObjectProviderContribution c1 = new ObjectProviderContribution();
          c1.setPrefix("dupe");
          c1.setLocation(l1);
          l.add(c1);
  
          ObjectProviderContribution c2 = new ObjectProviderContribution();
          c2.setPrefix("dupe");
          c2.setLocation(l2);
  
          l.add(c2);
  
          ObjectTranslator ot = new ObjectTranslator();
  
          Log log = (Log) newMock(Log.class);
          ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
  
          ot.setLog(log);
          ot.setErrorHandler(eh);
          ot.setContributions(l);
  
          eh.error(
              log,
              "Object provider prefix 'dupe' duplicates a previous prefix at " + l1 + ".",
              l2,
              null);
  
          replayControls();
  
          ot.initializeService();
  
          verifyControls();
      }
  
      public void testBadLocator()
      {
          ObjectTranslator ot = new ObjectTranslator();
  
          Module module = (Module) newMock(Module.class);
  
          Log log = (Log) newMock(Log.class);
          ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
  
          ot.setLog(log);
          ot.setErrorHandler(eh);
          ot.setContributions(Collections.EMPTY_LIST);
  
          ot.initializeService();
  
          eh.error(
              log,
              "Object provider selector 'badprefix' is not properly formatted.",
              null,
              null);
  
          replayControls();
  
          Object result = ot.translate(module, Object.class, "badprefix");
  
          assertNull(result);
  
          verifyControls();
      }
  
      public void testUnknownPrefix()
      {
          ObjectTranslator ot = new ObjectTranslator();
  
          Module module = (Module) newMock(Module.class);
  
          Log log = (Log) newMock(Log.class);
          ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
  
          ot.setLog(log);
          ot.setErrorHandler(eh);
          ot.setContributions(Collections.EMPTY_LIST);
  
          ot.initializeService();
  
          eh.error(log, "No object provider exists for prefix 'zap'.", null, null);
  
          replayControls();
  
          Object result = ot.translate(module, Object.class, "zap:foo");
  
          assertNull(result);
  
          verifyControls();
      }
  
      public void testSuccess()
      {
          MockControl c = newControl(ObjectProvider.class);
          ObjectProvider p = (ObjectProvider) c.getMock();
  
          ObjectProviderContribution opc = new ObjectProviderContribution();
          opc.setPrefix("fetch");
          opc.setProvider(p);
  
          ObjectTranslator ot = new ObjectTranslator();
          ot.setContributions(Collections.singletonList(opc));
  
          ot.initializeService();
  
          Module module = (Module) newMock(Module.class);
  
          p.provideObject(module, Integer.class, "zap");
          Object value = new Integer(13);
  
          c.setReturnValue(value);
  
          replayControls();
  
          Object result = ot.translate(module, Integer.class, "fetch:zap");
  
          assertSame(value, result);
  
          verifyControls();
      }
  
      public void testNullInput()
      {
          ObjectTranslator ot = new ObjectTranslator();
  
          assertNull(ot.translate(null, null, null));
      }
  }
  
  
  
  1.15      +8 -0      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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- hivemodule.sdl	16 Jul 2004 23:15:40 -0000	1.14
  +++ hivemodule.sdl	17 Jul 2004 21:32:16 -0000	1.15
  @@ -863,10 +863,18 @@
      	  create-instance (class=org.apache.hivemind.service.impl.ObjectInstanceObjectProvider)
      	}
      	
  +   	service-point (id=ServicePropertyObjectProvider interface=org.apache.hivemind.service.ObjectProvider)
  +   	{
  +   	  "ObjectProvider that will extra a property from a service.  Mapped to the service-property:
prefix."
  +   	  
  +   	  create-instance (class=org.apache.hivemind.service.impl.ServicePropertyObjectProvider)
  +   	}
  +   	
      	contribution (configuration-id=ObjectProviders)
      	{
      	  provider (prefix=service service-id=ServiceObjectProvider)
      	  provider (prefix=configuration service-id=ConfigurationObjectProvider)
      	  provider (prefix=instance service-id=ObjectInstanceObjectProvider)
  +   	  provider (prefix=service-property service-id=ServicePropertyObjectProvider)
      	}
   }
  
  
  
  1.25      +3 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- status.xml	16 Jul 2004 23:15:40 -0000	1.24
  +++ status.xml	17 Jul 2004 21:32:16 -0000	1.25
  @@ -56,6 +56,9 @@
           a new 'object' translator with great flexibility. Extend BuilderFactory
           to add a set-object element that leverages the object translator.
         </action>
  +      <action type="update" dev="HLS">
  +        Created service-property object translator.
  +      </action>
       </release>
     
       <release version="1.0-beta-1" date="Jun 26 2004">
  
  
  
  1.10      +5 -0      jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ServiceMessages.java
  
  Index: ServiceMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ServiceMessages.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ServiceMessages.java	16 Jul 2004 23:15:40 -0000	1.9
  +++ ServiceMessages.java	17 Jul 2004 21:32:16 -0000	1.10
  @@ -177,4 +177,9 @@
       {
           return _formatter.format("error-instantiating-instance", clazz.getName(), cause);
       }
  +
  +    public static String invalidServicePropertyLocator(String locator)
  +    {
  +        return _formatter.format("invalid-service-property-locator", locator);
  +    }
   }
  
  
  
  1.6       +1 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ServiceStrings.properties
  
  Index: ServiceStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ServiceStrings.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServiceStrings.properties	16 Jul 2004 23:15:40 -0000	1.5
  +++ ServiceStrings.properties	17 Jul 2004 21:32:16 -0000	1.6
  @@ -34,4 +34,4 @@
   unknown-provider-prefix=No object provider exists for prefix ''{0}''.
   duplicate-provider-prefix=Object provider prefix ''{0}'' duplicates a previous prefix at
{1}.
   error-instantiating-instance=Error instantiating instance of class {0}: {1}
  -
  +invalid-service-property-locator=''{0}'' is not a valid locator for use with the service-property
object provider. It should be the id of a service, a comma, and the name of a property provided
by that service.
  
  
  
  1.1                  jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ServicePropertyObjectProvider.java
  
  Index: ServicePropertyObjectProvider.java
  ===================================================================
  package org.apache.hivemind.service.impl;
  
  import org.apache.hivemind.ApplicationRuntimeException;
  import org.apache.hivemind.internal.Module;
  import org.apache.hivemind.service.ObjectProvider;
  import org.apache.hivemind.util.PropertyUtils;
  
  /**
   * {@link org.apache.hivemind.service.ObjectProvider} implementation
   * that obtains a named property from a service.  This provider is
   * mapped to the prefix "service-property", the service id is seperated
   * from the property name by a colon.  Example:
   * <code>service-property:MyService:myProperty</code>
   *
   * @author Howard Lewis Ship
   */
  public class ServicePropertyObjectProvider implements ObjectProvider
  {
  
      public Object provideObject(Module contributingModule, Class propertyType, String locator)
      {
          int commax = locator.indexOf(':');
  
          if (commax < 2)
          {
              throw new ApplicationRuntimeException(
                  ServiceMessages.invalidServicePropertyLocator(locator));
          }
  
          String serviceId = locator.substring(0, commax);
          String propertyName = locator.substring(commax + 1);
  
          Object service = contributingModule.getService(serviceId, Object.class);
  
          return PropertyUtils.read(service, propertyName);
      }
  
  }
  
  
  
  1.6       +1 -1      jakarta-hivemind/framework/src/test/hivemind/test/config/ObjectTranslator.xml
  
  
  
  

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


Mime
View raw message