You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2003/11/05 00:31:59 UTC

cvs commit: jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation MessagesBundle.properties ClassValidator.java

jkeyes      2003/11/04 15:31:59

  Modified:    cli/src/java/org/apache/commons/cli2/validation
                        ClassValidator.java
  Added:       cli/src/java/org/apache/commons/cli2/validation
                        MessagesBundle.properties
  Log:
  
- i18n
  
  Revision  Changes    Path
  1.3       +30 -12    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/ClassValidator.java
  
  Index: ClassValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/ClassValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ClassValidator.java	20 Oct 2003 21:40:44 -0000	1.2
  +++ ClassValidator.java	4 Nov 2003 23:31:59 -0000	1.3
  @@ -63,25 +63,35 @@
   import java.util.List;
   import java.util.ListIterator;
   
  +import org.apache.commons.cli2.resources.ResourceHelper;
  +
   /**
    * @author Rob Oxspring
    */
   public class ClassValidator implements Validator {
   
  -    private boolean loadable = false;
  -    private boolean instance = false;
  +    /** i18n */
  +    private static final ResourceHelper resources =
  +        ResourceHelper.getResourceHelper(ClassValidator.class);
  +    
  +    private boolean loadable;
  +    private boolean instance;
   
       private ClassLoader loader;
   
  -    /* (non-Javadoc)
  +    /**
        * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
        */
       public void validate(final List values) throws InvalidArgumentException {
  +        
           for (final ListIterator i = values.listIterator(); i.hasNext();) {
               final String name = (String) i.next();
   
               if (!isPotentialClassName(name)) {
  -                throw new InvalidArgumentException("Bad class name: " + name);
  +                throw new InvalidArgumentException(
  +                    resources.getMessage(
  +                        "ClassValidator.error.bad.classname",
  +                        name));
               }
   
               if (loadable || instance) {
  @@ -97,17 +107,25 @@
                           i.set(clazz);
                       }
                   }
  -                catch (ClassNotFoundException cnfe) {
  +                catch (final ClassNotFoundException exp) {
                       throw new InvalidArgumentException(
  -                        "Class not found: " + name);
  +                        resources.getMessage(
  +                            "ClassValidator.error.class.notfound",
  +                            name));
                   }
  -                catch (IllegalAccessException iae) {
  +                catch (final IllegalAccessException exp) {
                       throw new InvalidArgumentException(
  -                        "Cannot create instance: " + name);
  +                        resources.getMessage(
  +                            "ClassValidator.error.class.access",
  +                            name,
  +                            exp.getMessage()));
                   }
  -                catch (InstantiationException iae) {
  +                catch (final InstantiationException exp) {
                       throw new InvalidArgumentException(
  -                        "Cannot create instance: " + name);
  +                        resources.getMessage(
  +                            "ClassValidator.error.class.access",
  +                            name,
  +                            exp.getMessage()));
                   }
               }
           }
  
  
  
  1.1                  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/MessagesBundle.properties
  
  Index: MessagesBundle.properties
  ===================================================================
  ClassValidator.error.bad.classname = The class name "{0}" is invalid.
  ClassValidator.error.class.notfound = The class "{0}" could not be found.
  ClassValidator.error.class.access = The class "{0}" could not be accessed.  Reason: {1}.
  ClassValidator.error.class.create = The class "{0}" could not be created.  Reason: {1}.
  
  
  

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