hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject cvs commit: jakarta-hivemind status.xml
Date Wed, 27 Apr 2005 12:23:46 GMT
knut        2005/04/27 05:23:46

  Modified:    framework/src/java/org/apache/hivemind/service/impl
                        BuilderPropertyFacet.java
               .        status.xml
  Added:       framework/src/test/org/apache/hivemind/service/impl
                        TestBuilderPropertyFacet.java
  Log:
  Cache translated values in BuilderPropertyFacet (see HIVEMIND-99)
  
  Revision  Changes    Path
  1.11      +25 -7     jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java
  
  Index: BuilderPropertyFacet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BuilderPropertyFacet.java	10 Jan 2005 13:14:59 -0000	1.10
  +++ BuilderPropertyFacet.java	27 Apr 2005 12:23:46 -0000	1.11
  @@ -14,6 +14,9 @@
   
   package org.apache.hivemind.service.impl;
   
  +import java.util.HashMap;
  +import java.util.Map;
  +
   import org.apache.hivemind.ApplicationRuntimeException;
   import org.apache.hivemind.ServiceImplementationFactoryParameters;
   import org.apache.hivemind.schema.Translator;
  @@ -32,17 +35,32 @@
   
       private String _literalValue;
   
  +    /**
  +     * Cache for translated values to prevent calling
  +     * {@link Translator#translate(Module, Class, String, Location)} twice.
  +     */
  +    private Map _valuesCache = new HashMap();
  +
       public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters,
               Class targetType)
       {
  -        Translator translator = factoryParameters.getInvokingModule()
  -                .getTranslator(_translatorName);
  +        Object result = _valuesCache.get(targetType);
  +
  +        if (result == null)
  +        {
  +            Translator translator = factoryParameters.getInvokingModule().getTranslator(
  +                    _translatorName);
  +
  +            result = translator.translate(
  +                    factoryParameters.getInvokingModule(),
  +                    targetType,
  +                    _literalValue,
  +                    getLocation());
  +
  +            _valuesCache.put(targetType, result);
  +        }
   
  -        return translator.translate(
  -                factoryParameters.getInvokingModule(),
  -                targetType,
  -                _literalValue,
  -                getLocation());
  +        return result;
       }
   
       public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters,
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet.java
  
  Index: TestBuilderPropertyFacet.java
  ===================================================================
  //Copyright 2005 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.ServiceImplementationFactoryParameters;
  import org.apache.hivemind.internal.Module;
  import org.apache.hivemind.schema.Translator;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.easymock.MockControl;
  
  public class TestBuilderPropertyFacet extends HiveMindTestCase
  {
      public void testCachingOfTranslatedValues() throws Exception
      {
          MockControl moduleControl = newControl(Module.class);
          Module module = (Module) moduleControl.getMock();
  
          MockControl translatorControl = newControl(Translator.class);
          Translator translator = (Translator) translatorControl.getMock();
  
          MockControl paramsControl = newControl(ServiceImplementationFactoryParameters.class);
          ServiceImplementationFactoryParameters params = (ServiceImplementationFactoryParameters)
paramsControl
                  .getMock();
  
          BuilderPropertyFacet facet = new BuilderPropertyFacet();
  
          facet.setTranslator("foo");
          facet.setValue("bar");
  
          params.getInvokingModule();
          paramsControl.setDefaultReturnValue(module);
  
          module.getTranslator("foo");
          moduleControl.setDefaultReturnValue(translator);
  
          translator.translate(module, Object.class, "bar", null);
          translatorControl.setReturnValue("BAR");
  
          replayControls();
  
          facet.isAssignableToType(params, Object.class);
          facet.getFacetValue(params, Object.class);
  
          verifyControls();
      }
  }
  
  
  
  1.125     +1 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.124
  retrieving revision 1.125
  diff -u -r1.124 -r1.125
  --- status.xml	27 Apr 2005 10:49:40 -0000	1.124
  +++ status.xml	27 Apr 2005 12:23:46 -0000	1.125
  @@ -42,6 +42,7 @@
         <action type="add" dev="HLS" due-to="Achim Hügen" fixes-bug="HIVEMIND-97">
Apply Achim Hügen's JMX patch. </action>
         <action type="updated" dev="HLS"> Update to Javassist 3.0. </action>
         <action type="fix" dev="KW" due-to="Michael Frericks" fixes-bug="HIVEMIND-100">
Translate unique attribute values before checking uniqueness. </action>
  +      <action type="fix" dev="KW" fixes-bug="HIVEMIND-99"> Cache translated values
in BuilderPropertyFacet. </action>
       </release>
       <release version="1.1-alpha-3" date="Mar 22 2005">
         <action type="fix" dev="JC" fixes-bug="HIVEMIND-96" >Interceptors can now be
ordered by name rather than interceptor factory id.</action>
  
  
  

---------------------------------------------------------------------
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