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/sdl SDLMessages.java
Date Fri, 18 Jun 2004 13:50:03 GMT
hlship      2004/06/18 06:50:03

  Modified:    framework/src/java/org/apache/hivemind/servlet
                        ServletMessages.java
               framework/src/java/org/apache/hivemind/order
                        OrdererMessages.java
               framework/src/java/org/apache/hivemind/impl/servicemodel
                        ServiceModelMessages.java
               framework/src/java/org/apache/hivemind/impl
                        ImplMessages.java MessageFormatter.java
               framework/src/java/org/apache/hivemind/service/impl
                        ServiceMessages.java
               framework/src/java/org/apache/hivemind/schema/rules
                        RulesMessages.java
               framework/src/java/org/apache/hivemind/parse
                        ParseMessages.java
               framework/src/java/org/apache/hivemind/methodmatch
                        MethodMatchMessages.java
               framework/src/java/org/apache/hivemind/sdl SDLMessages.java
  Log:
  Change MessageFormatter to automatically convert Throwable instances into their message,
or their class name.
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/ServletMessages.java
  
  Index: ServletMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/ServletMessages.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServletMessages.java	17 Jun 2004 15:16:13 -0000	1.2
  +++ ServletMessages.java	18 Jun 2004 13:50:03 -0000	1.3
  @@ -28,7 +28,7 @@
   
       public static String filterCleanupError(Throwable cause)
       {
  -        return _formatter.format("filter-cleanup-error", _formatter.extractMessage(cause));
  +        return _formatter.format("filter-cleanup-error", cause);
       }
   
       public static String filterInit()
  
  
  
  1.5       +2 -6      jakarta-hivemind/framework/src/java/org/apache/hivemind/order/OrdererMessages.java
  
  Index: OrdererMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/order/OrdererMessages.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- OrdererMessages.java	17 Jun 2004 15:16:14 -0000	1.4
  +++ OrdererMessages.java	18 Jun 2004 13:50:03 -0000	1.5
  @@ -45,7 +45,7 @@
   
       public static String exception(String objectType, Throwable cause)
       {
  -        return _formatter.format("Orderer.exception", objectType, _formatter.extractMessage(cause));
  +        return _formatter.format("Orderer.exception", objectType, cause);
       }
   
       public static String dupeLeader(
  @@ -83,11 +83,7 @@
           ObjectOrdering trigger,
           Throwable cause)
       {
  -        return _formatter.format(
  -            "dependency-cycle",
  -            objectType,
  -            trigger.getName(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("dependency-cycle", objectType, trigger.getName(), cause);
       }
   
       public static String badDependency(
  
  
  
  1.4       +1 -4      jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/ServiceModelMessages.java
  
  Index: ServiceModelMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/ServiceModelMessages.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServiceModelMessages.java	17 Jun 2004 15:16:14 -0000	1.3
  +++ ServiceModelMessages.java	18 Jun 2004 13:50:03 -0000	1.4
  @@ -51,9 +51,6 @@
   
       public static String unableToConstructService(ServicePoint point, Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-construct-service",
  -            point.getExtensionPointId(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-construct-service", point.getExtensionPointId(),
cause);
       }
   }
  
  
  
  1.10      +5 -15     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
  
  Index: ImplMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ImplMessages.java	17 Jun 2004 15:16:11 -0000	1.9
  +++ ImplMessages.java	18 Jun 2004 13:50:03 -0000	1.10
  @@ -89,7 +89,7 @@
           return _formatter.format(
               "translator-instantiation-failure",
               translatorClass.getName(),
  -            _formatter.extractMessage(cause));
  +            cause);
       }
   
       public static String noSuchServicePoint(String serviceId)
  @@ -99,11 +99,7 @@
   
       public static String unableToLoadClass(String name, ClassLoader loader, Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-load-class",
  -            name,
  -            loader,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-load-class", name, loader, cause);
       }
   
       public static String nullInterceptor(
  @@ -143,15 +139,12 @@
   
       public static String unableToParse(Resource resource, Throwable cause)
       {
  -        return _formatter.format("unable-to-parse", resource, _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-parse", resource, cause);
       }
   
       public static String unableToFindModules(ClassResolver resolver, Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-find-modules",
  -            resolver,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-find-modules", resolver, cause);
       }
   
       public static String duplicateModuleId(Module existingModule, ModuleDescriptor descriptor)
  @@ -279,10 +272,7 @@
           RegistryShutdownListener listener,
           Throwable cause)
       {
  -        return _formatter.format(
  -            "shutdown-coordinator-failure",
  -            listener,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("shutdown-coordinator-failure", listener, cause);
       }
   
       public static String unlocatedError(String message)
  
  
  
  1.6       +21 -4     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/MessageFormatter.java
  
  Index: MessageFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/MessageFormatter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MessageFormatter.java	17 Jun 2004 15:16:11 -0000	1.5
  +++ MessageFormatter.java	18 Jun 2004 13:50:03 -0000	1.6
  @@ -20,6 +20,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.hivemind.HiveMind;
   
   /**
    * A wrapper around {@link java.util.ResourceBundle} that makes
  @@ -81,6 +82,14 @@
           return format(key, new Object[] { arg1, arg2, arg3 });
       }
   
  +	/**
  +	 * Formats a message using the key to obtain a pattern, and passing the arguments.
  +	 * 
  +	 * <p>
  +	 * It is common to pass an exception instance as an arg.  Those are treated specially:
  +	 * The exception instance is replaced with its message {@link Throwable#getMessage()}.
If the
  +	 * message is blank (null or empty), then the exception's class name is used.
  +	 */
       public String format(String key, Object[] args)
       {
           String pattern = getMessage(key);
  @@ -88,6 +97,16 @@
           if (args == null)
               return pattern;
   
  +        for (int i = 0; i < args.length; i++)
  +        {
  +            if (args[i] instanceof Throwable)
  +            {
  +                Throwable t = (Throwable) args[i];
  +
  +                args[i] = extractMessage(t);
  +            }
  +        }
  +
           try
           {
               return MessageFormat.format(pattern, args);
  @@ -104,17 +123,15 @@
        * Extracts the message from an exception. If the message is null, the the class name
        * of the exception is returned.
        * 
  -     * <p>
  -     * Note: probably should be a static method!
        */
  -    public String extractMessage(Throwable t)
  +    private String extractMessage(Throwable t)
       {
           if (t == null)
               return null;
   
           String message = t.getMessage();
   
  -        if (message == null)
  +        if (HiveMind.isBlank(message))
               return t.getClass().getName();
   
           return message;
  
  
  
  1.8       +12 -46    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ServiceMessages.java	17 Jun 2004 15:16:13 -0000	1.7
  +++ ServiceMessages.java	18 Jun 2004 13:50:03 -0000	1.8
  @@ -42,11 +42,7 @@
       {
           return _formatter.format(
               "unable-to-initialize-service",
  -            new Object[] {
  -                serviceId,
  -                methodName,
  -                serviceClass.getName(),
  -                _formatter.extractMessage(ex)});
  +            new Object[] { serviceId, methodName, serviceClass.getName(), ex });
       }
   
       public static String errorInstantiatingInterceptor(
  @@ -62,16 +58,12 @@
                   stack.getServiceInterface().getName(),
                   stack.getServiceExtensionPointId(),
                   interceptorClass.getName(),
  -                _formatter.extractMessage(cause)});
  +                cause });
       }
   
       public static String unableToAddField(String fieldName, CtClass ctClass, Throwable
cause)
       {
  -        return _formatter.format(
  -            "unable-to-add-field",
  -            fieldName,
  -            ctClass.getName(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-add-field", fieldName, ctClass.getName(), cause);
       }
   
       public static String unableToAddMethod(
  @@ -79,41 +71,27 @@
           CtClass ctClass,
           Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-add-method",
  -            methodSignature,
  -            ctClass.getName(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-add-method", methodSignature, ctClass.getName(),
cause);
       }
   
       public static String unableToAddConstructor(CtClass ctClass, Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-add-constructor",
  -            ctClass.getName(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-add-constructor", ctClass.getName(), cause);
       }
   
       public static String unableToWriteClass(CtClass ctClass, Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-write-class",
  -            ctClass.getName(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-write-class", ctClass.getName(), cause);
       }
   
       public static String unableToCreateClass(String name, Class superClass, Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-create-class",
  -            name,
  -            superClass.getName(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-create-class", name, superClass.getName(),
cause);
       }
   
       public static String unableToLookupClass(String name, Throwable cause)
       {
  -        return _formatter.format("unable-to-lookup", name, _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-lookup", name, cause);
       }
   
       public static String duplicateSymbol(String symbol, Location priorLocation)
  @@ -150,20 +128,12 @@
       {
           return _formatter.format(
               "unable-to-add-listener",
  -            new Object[] {
  -                consumer,
  -                producer,
  -                set.getName(),
  -                location,
  -                _formatter.extractMessage(cause)});
  +            new Object[] { consumer, producer, set.getName(), location, cause });
       }
   
       public static String unableToIntrospectClass(Class targetClass, Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-introspect-class",
  -            targetClass.getName(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-introspect-class", targetClass.getName(), cause);
       }
   
       public static String unableToAddCatch(Class exceptionClass, CtMethod method, Throwable
cause)
  @@ -172,7 +142,7 @@
               "unable-to-add-catch",
               exceptionClass.getName(),
               method.getDeclaringClass().getName(),
  -            _formatter.extractMessage(cause));
  +            cause);
       }
   
       public static String duplicateMethodInClass(MethodSignature ms, ClassFabImpl cf)
  @@ -185,10 +155,6 @@
           String className,
           Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-extend-method",
  -            ms,
  -            className,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-extend-method", ms, className, cause);
       }
   }
  
  
  
  1.5       +8 -26     jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/RulesMessages.java
  
  Index: RulesMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/RulesMessages.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RulesMessages.java	17 Jun 2004 15:16:13 -0000	1.4
  +++ RulesMessages.java	18 Jun 2004 13:50:03 -0000	1.5
  @@ -46,16 +46,12 @@
                   target,
                   processor.getElementPath(),
                   HiveMind.getLocationString(element),
  -                _formatter.extractMessage(cause)});
  +                cause });
       }
   
       public static String unableToSetProperty(String propertyName, Object target, Throwable
cause)
       {
  -        return _formatter.format(
  -            "unable-to-set-property",
  -            propertyName,
  -            target,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-set-property", propertyName, target, cause);
       }
   
       public static String invalidBooleanValue(String inputValue)
  @@ -65,11 +61,7 @@
   
       public static String errorCreatingObject(String className, Location location, Throwable
cause)
       {
  -        return _formatter.format(
  -            "error-creating-object",
  -            className,
  -            location,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("error-creating-object", className, location, cause);
       }
   
       public static String invalidDoubleValue(String inputValue)
  @@ -94,11 +86,7 @@
   
       public static String enumError(Class enumClass, String fieldName, Throwable cause)
       {
  -        return _formatter.format(
  -            "enum-error",
  -            enumClass.getName(),
  -            fieldName,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("enum-error", enumClass.getName(), fieldName, cause);
       }
   
       public static String invalidIntValue(String inputValue)
  @@ -124,7 +112,7 @@
       {
           return _formatter.format(
               "error-invoking-method",
  -            new Object[] { methodName, parent, location, _formatter.extractMessage(cause)});
  +            new Object[] { methodName, parent, location, cause });
       }
   
       public static String invalidLongValue(String inputValue)
  @@ -150,10 +138,7 @@
       {
           return _formatter.format(
               "read-attribute-failure",
  -            new Object[] {
  -                attributeName,
  -                processor.getElementPath(),
  -                _formatter.extractMessage(cause)});
  +            new Object[] { attributeName, processor.getElementPath(), cause });
       }
   
       public static String readContentFailure(
  @@ -161,10 +146,7 @@
           Element element,
           Throwable cause)
       {
  -        return _formatter.format(
  -            "read-content-failure",
  -            processor.getElementPath(),
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("read-content-failure", processor.getElementPath(), cause);
       }
   
       public static String resourceLocalizationError(String inputValue, Module contributingModule)
  @@ -194,6 +176,6 @@
               "smart-translator-error",
               inputValue,
               propertyType.getName(),
  -            _formatter.extractMessage(cause));
  +            cause);
       }
   }
  
  
  
  1.6       +3 -10     jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseMessages.java
  
  Index: ParseMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseMessages.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ParseMessages.java	17 Jun 2004 15:16:11 -0000	1.5
  +++ ParseMessages.java	18 Jun 2004 13:50:03 -0000	1.6
  @@ -89,24 +89,17 @@
   
       public static String unableToInitialize(Throwable cause)
       {
  -        return _formatter.format("unable-to-initialize", _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-initialize", cause);
       }
   
       public static String badRuleClass(String className, Location location, Throwable cause)
       {
  -        return _formatter.format(
  -            "bad-rule-class",
  -            className,
  -            location,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("bad-rule-class", className, location, cause);
       }
   
       public static String errorReadingDescriptor(Resource resource, Throwable cause)
       {
  -        return _formatter.format(
  -            "error-reading-descriptor",
  -            resource,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("error-reading-descriptor", resource, cause);
       }
   
       public static String missingResource(Resource resource)
  
  
  
  1.3       +1 -4      jakarta-hivemind/framework/src/java/org/apache/hivemind/methodmatch/MethodMatchMessages.java
  
  Index: MethodMatchMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/methodmatch/MethodMatchMessages.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MethodMatchMessages.java	17 Jun 2004 15:16:13 -0000	1.2
  +++ MethodMatchMessages.java	18 Jun 2004 13:50:03 -0000	1.3
  @@ -39,9 +39,6 @@
   
       public static String exceptionAtLocation(Location location, Throwable cause)
       {
  -        return _formatter.format(
  -            "exception-at-location",
  -            location,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("exception-at-location", location, cause);
       }
   }
  
  
  
  1.3       +2 -5      jakarta-hivemind/framework/src/java/org/apache/hivemind/sdl/SDLMessages.java
  
  Index: SDLMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/sdl/SDLMessages.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SDLMessages.java	17 Jun 2004 15:16:15 -0000	1.2
  +++ SDLMessages.java	18 Jun 2004 13:50:03 -0000	1.3
  @@ -42,14 +42,11 @@
   
       public static String parseError(Resource resource, Throwable cause)
       {
  -        return _formatter.format("parse-error", resource, _formatter.extractMessage(cause));
  +        return _formatter.format("parse-error", resource, cause);
       }
   
       public static String unableToCloseStream(Resource resource, Throwable cause)
       {
  -        return _formatter.format(
  -            "unable-to-close-stream",
  -            resource,
  -            _formatter.extractMessage(cause));
  +        return _formatter.format("unable-to-close-stream", resource, cause);
       }
   }
  
  
  

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