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/java/org/apache/hivemind/service/impl BuilderFactoryLogic.java
Date Wed, 10 Nov 2004 20:51:24 GMT
hlship      2004/11/10 12:51:23

  Modified:    .        status.xml
               framework/src/java/org/apache/hivemind/util
                        ConstructorUtils.java
               framework/src/java/org/apache/hivemind/parse
                        XmlResourceProcessor.java
               framework/src/java/org/apache/hivemind/service/impl
                        BuilderFactoryLogic.java
  Added:       framework/src/test/org/apache/hivemind/util
                        TestConstructorUtils.java
               framework/src/test/org/apache/hivemind/service/impl
                        InitializerErrorRunnable.java
                        TestBuilderFactory.java
  Log:
  HIVEMIND-77: Report real exceptoin in BuilderFactoryLogic, not the wrapping InvocationTargetException.
  
  Revision  Changes    Path
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/util/TestConstructorUtils.java
  
  Index: TestConstructorUtils.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.util;
  
  import org.apache.hivemind.ApplicationRuntimeException;
  import org.apache.hivemind.test.HiveMindTestCase;
  
  /**
   * Tests for {@link org.apache.hivemind.util.ConstructorUtils}. Alas (for the moment), just
fills a
   * few gaps ... most of the code is tested indirectly by code that uses it.
   * 
   * @author Howard M. Lewis Ship
   * @since 1.1
   */
  public class TestConstructorUtils extends HiveMindTestCase
  {
      public static class Troublemaker
      {
          public Troublemaker(ApplicationRuntimeException ex)
          {
              throw ex;
          }
      }
  
      public void testInvocationTargetException()
      {
          Throwable inner = new ApplicationRuntimeException("Inner exception.");
  
          try
          {
              ConstructorUtils.invokeConstructor(Troublemaker.class, new Object[]
              { inner });
  
              unreachable();
          }
          catch (ApplicationRuntimeException ex)
          {
              String message = UtilMessages.invokeFailed(
                      Troublemaker.class.getConstructors()[0],
                      inner);
  
              assertEquals(message, ex.getMessage());
              assertSame(inner, ex.getCause());
          }
      }
  }
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/InitializerErrorRunnable.java
  
  Index: InitializerErrorRunnable.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.ApplicationRuntimeException;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 1.1
   */
  public class InitializerErrorRunnable implements Runnable
  {
  
      public void run()
      {
          //
      }
  
      public void initializeService()
      {
          throw new ApplicationRuntimeException("Failure in initializeService().");
      }
  }
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/TestBuilderFactory.java
  
  Index: TestBuilderFactory.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.commons.logging.Log;
  import org.apache.hivemind.ApplicationRuntimeException;
  import org.apache.hivemind.ErrorLog;
  import org.apache.hivemind.Location;
  import org.apache.hivemind.ServiceImplementationFactoryParameters;
  import org.apache.hivemind.impl.DefaultClassResolver;
  import org.apache.hivemind.internal.Module;
  import org.apache.hivemind.test.AggregateArgumentsMatcher;
  import org.apache.hivemind.test.ArgumentMatcher;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.apache.hivemind.test.TypeMatcher;
  import org.easymock.MockControl;
  
  /**
   * Additional tests for {@link org.apache.hivemind.service.impl.BuilderFactoryLogic}.
   * 
   * @author Howard M. Lewis Ship
   * @since 1.1
   */
  public class TestBuilderFactory extends HiveMindTestCase
  {
      /**
       * Tests for errors when actually invoking the initializer method (as opposed to an
error
       * finding the method).
       * 
       * @since 1.1
       */
      public void testErrorInInitializer() throws Exception
      {
          Location l = fabricateLocation(17);
  
          MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
          ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters)
fpc
                  .getMock();
  
          Log log = (Log) newMock(Log.class);
  
          MockControl mc = newControl(Module.class);
          Module module = (Module) mc.getMock();
  
          MockControl errorLogc = newControl(ErrorLog.class);
          ErrorLog errorLog = (ErrorLog) errorLogc.getMock();
  
          fp.getLog();
          fpc.setReturnValue(log);
  
          fp.getServiceId();
          fpc.setReturnValue("foo.Bar");
  
          fp.getInvokingModule();
          fpc.setReturnValue(module);
  
          module.getClassResolver();
          mc.setReturnValue(new DefaultClassResolver());
  
          fp.getErrorLog();
          fpc.setReturnValue(errorLog);
  
          Throwable cause = new ApplicationRuntimeException("Failure in initializeService().");
  
          String message = ServiceMessages.unableToInitializeService(
                  "foo.Bar",
                  "initializeService",
                  InitializerErrorRunnable.class,
                  cause);
  
          errorLog.error(message, l, new ApplicationRuntimeException(""));
          errorLogc.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[]
          { null, null, new TypeMatcher() }));
  
          BuilderParameter p = new BuilderParameter();
          p.setClassName(InitializerErrorRunnable.class.getName());
          p.setLocation(l);
  
          replayControls();
  
          BuilderFactoryLogic logic = new BuilderFactoryLogic(fp, p);
  
          assertNotNull(logic.createService());
  
          verifyControls();
      }
  }
  
  
  1.81      +5 -1      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- status.xml	9 Nov 2004 20:58:20 -0000	1.80
  +++ status.xml	10 Nov 2004 20:51:23 -0000	1.81
  @@ -68,7 +68,7 @@
         <action type="fix" dev="HLS" fixes-bug="HIVEMIND-68">
           Properly report the actual method name when invoking a service initializer method.
         </action>
  -      <action type="add" dev="HLS">
  +      <action type="add" dev="HLS" fixes-bug="HIVEMIND-66">
           Move some logic related to primitive Java types and arrays from Tapestry directly
into DefaultClassResolver.
         </action>
         <action type="update" dev="HLS">
  @@ -99,6 +99,10 @@
           <action type="fix" dev="HLS" fixes-bug="HIVEMIND-76">
             Improve MethodSignature and MethodIterator to filter out duplicate methods that
differ
             only in terms of thrown exceptions.
  +        </action>
  +        <action type="fix" dev="HLS" fixes-bug="HIVEMIND-77">
  +          Change BuilderFactoryLogic to report the actual exception, not the InvocationTargetException,
  +          when an exception is thrown by a constructor or by a initializer method invocation.
           </action>
       </release>
   
  
  
  
  1.7       +20 -14    jakarta-hivemind/framework/src/java/org/apache/hivemind/util/ConstructorUtils.java
  
  Index: ConstructorUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/util/ConstructorUtils.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConstructorUtils.java	9 Nov 2004 11:24:29 -0000	1.6
  +++ ConstructorUtils.java	10 Nov 2004 20:51:23 -0000	1.7
  @@ -15,6 +15,7 @@
   package org.apache.hivemind.util;
   
   import java.lang.reflect.Constructor;
  +import java.lang.reflect.InvocationTargetException;
   import java.util.HashMap;
   import java.util.Map;
   
  @@ -22,7 +23,7 @@
   
   /**
    * Static methods for invoking constructors.
  - *
  + * 
    * @author Howard Lewis Ship
    */
   public class ConstructorUtils
  @@ -33,7 +34,8 @@
        */
       private static final Map _primitiveMap = new HashMap();
   
  -    static {
  +    static
  +    {
           _primitiveMap.put(boolean.class, Boolean.class);
           _primitiveMap.put(byte.class, Byte.class);
           _primitiveMap.put(char.class, Character.class);
  @@ -53,11 +55,13 @@
       /**
        * Searches for a constructor matching against the provided arguments.
        * 
  -     * @param targetClass the class to be instantiated
  -     * @param parameters the parameters to pass to the constructor (may be null or empty)
  +     * @param targetClass
  +     *            the class to be instantiated
  +     * @param parameters
  +     *            the parameters to pass to the constructor (may be null or empty)
        * @return the new instance
  -     * @throws ApplicationRuntimeException on any failure
  -     * 
  +     * @throws ApplicationRuntimeException
  +     *             on any failure
        */
       public static Object invokeConstructor(Class targetClass, Object[] parameters)
       {
  @@ -72,10 +76,8 @@
           return invokeMatchingConstructor(targetClass, parameterTypes, parameters);
       }
   
  -    private static Object invokeMatchingConstructor(
  -        Class targetClass,
  -        Class[] parameterTypes,
  -        Object[] parameters)
  +    private static Object invokeMatchingConstructor(Class targetClass, Class[] parameterTypes,
  +            Object[] parameters)
       {
           Constructor[] constructors = targetClass.getConstructors();
   
  @@ -87,9 +89,7 @@
                   return invoke(c, parameters);
           }
   
  -        throw new ApplicationRuntimeException(
  -            UtilMessages.noMatchingConstructor(targetClass),
  -            null);
  +        throw new ApplicationRuntimeException(UtilMessages.noMatchingConstructor(targetClass),
null);
       }
   
       private static boolean isMatch(Constructor c, Class[] types)
  @@ -135,9 +135,15 @@
           {
               return c.newInstance(parameters);
           }
  +        catch (InvocationTargetException ex)
  +        {
  +            Throwable cause = ex.getTargetException();
  +
  +            throw new ApplicationRuntimeException(UtilMessages.invokeFailed(c, cause),
null, cause);
  +        }
           catch (Exception ex)
           {
               throw new ApplicationRuntimeException(UtilMessages.invokeFailed(c, ex), null,
ex);
           }
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.2       +1 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/XmlResourceProcessor.java
  
  Index: XmlResourceProcessor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/XmlResourceProcessor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlResourceProcessor.java	10 Nov 2004 13:26:21 -0000	1.1
  +++ XmlResourceProcessor.java	10 Nov 2004 20:51:23 -0000	1.2
  @@ -1,4 +1,4 @@
  -//Copyright 2004 The Apache Software Foundation
  +//  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.
  
  
  
  1.8       +10 -5     jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java
  
  Index: BuilderFactoryLogic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BuilderFactoryLogic.java	9 Nov 2004 11:24:30 -0000	1.7
  +++ BuilderFactoryLogic.java	10 Nov 2004 20:51:23 -0000	1.8
  @@ -112,12 +112,10 @@
           {
               return instantiateConstructorAutowiredInstance(serviceClass);
           }
  -        else
  -        {
  -            Object[] constructorParameters = buildConstructorParameters(parameters);
   
  -            return ConstructorUtils.invokeConstructor(serviceClass, constructorParameters);
  -        }
  +        Object[] constructorParameters = buildConstructorParameters(parameters);
  +
  +        return ConstructorUtils.invokeConstructor(serviceClass, constructorParameters);
       }
   
       private Object[] buildConstructorParameters(List parameters)
  @@ -239,6 +237,13 @@
           try
           {
               findAndInvokeInitializerMethod(service, searchMethodName, allowMissing);
  +        }
  +        catch (InvocationTargetException ex)
  +        {
  +            Throwable cause = ex.getTargetException();
  +
  +            error(ServiceMessages.unableToInitializeService(_serviceId, searchMethodName,
service
  +                    .getClass(), cause), _parameter.getLocation(), cause);
           }
           catch (Exception ex)
           {
  
  
  

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