You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by le...@apache.org on 2004/08/28 23:12:10 UTC

cvs commit: jakarta-commons/attributes/api/src/java/org/apache/commons/attributes ParameterIndexOutOfBoundsException.java SealedAttributeException.java Attributes.java CircularDependencyError.java DefaultCachedRepository.java DefaultSealable.java

leosutic    2004/08/28 14:12:10

  Modified:    attributes/api/src/java/org/apache/commons/attributes
                        Attributes.java CircularDependencyError.java
                        DefaultCachedRepository.java DefaultSealable.java
  Added:       attributes/api/src/java/org/apache/commons/attributes
                        ParameterIndexOutOfBoundsException.java
                        SealedAttributeException.java
  Log:
   + CircularDependencyError now expects a list of Class instances
     instead of a list of any object type. The old behavior is still
     supported and will remain so.
  
   + CircularDependencyError now shows the full circle of dependencies.
  
   + Added a ParameterIndexOutOfBoundsException to be thrown when
     the client tries to retrieve attributes from a parameter of a
     constructor or method and the parameter index is out of bounds.
  
   + Added a SealedAttributeException to be thrown when an attempt to
     modify a sealed attribute is made. The exception is a subclass
     of the IllegalStateException that used to be thrown.
  
  Revision  Changes    Path
  1.3       +169 -33   jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/Attributes.java
  
  Index: Attributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/Attributes.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Attributes.java	27 Aug 2004 21:30:10 -0000	1.2
  +++ Attributes.java	28 Aug 2004 21:12:10 -0000	1.3
  @@ -49,8 +49,17 @@
    *     or other "Error-like" conditions.
    * </ul>
    *
  + * <h3>Null References</h3>
  + *
  + * <p>If a parameter to a method may not be null, and a null is passed to the
  + * method, a {@link java.lang.NullPointerException} will be thrown, with the
  + * parameter name in the message.
  + *
  + * <p>Rationale for using this instead of {@link java.lang.IllegalArgumentException}
  + * is that it is more precise - the reference was null.
  + *
    * <h3>Performance Notes</h3>
  - * The process of loading attributes for a class is a
  + * <p>The process of loading attributes for a class is a
    * (relatively) time-consuming process, as it involves some dynamic linking 
    * in the form of inheritable attributes, a lot of reflection and so on. However,
    * once loaded the attributes are cached, so repeated access to them are fast.
  @@ -114,24 +123,20 @@
       private static List initList = new ArrayList ();
       
       private synchronized static CachedRepository getCachedRepository (Class clazz) throws RepositoryError, CircularDependencyError {
  -        if (classRepositories.containsKey (clazz)) {
  +        if (initList.contains (clazz)) {
  +            List dependencyList = new ArrayList ();
  +            dependencyList.addAll (initList);
  +            dependencyList.add (clazz);
  +            throw new CircularDependencyError (clazz.getName (), dependencyList);
  +        } else if (classRepositories.containsKey (clazz)) {
               CachedRepository cr = (CachedRepository) classRepositories.get (clazz);
  -            if (cr == null) {
  -                // Circular references.
  -                List dependencyList = new ArrayList ();
  -                dependencyList.addAll (initList);
  -                throw new CircularDependencyError (clazz.getName (), dependencyList);
  -            } else {
  -                return cr;
  -            }
  +            return cr;
           } else {
               // Indicate that we're loading it.
               CachedRepository cached = null;
               
  -            initList.add (clazz.getName ());
  +            initList.add (clazz);
               try {
  -                classRepositories.put (clazz, null);
  -                
                   Class attributeRepo = null;
                   AttributeRepositoryClass repo = EmptyAttributeRepositoryClass.INSTANCE;
                   try {
  @@ -163,7 +168,9 @@
       /**
        * Selects from a collection of attributes one attribute with a given class.
        *
  -     * @return the attribute instance, or null of none could be found.
  +     * @param attrs the collection of attribute instances to select from.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @return the attribute instance, or <code>null</code> of none could be found.
        * @throws MultipleAttributesError if the collection contains more than one
        *         instance of the specified class.
        */
  @@ -187,7 +194,9 @@
       /**
        * Get one attributes of a given type from a class.
        *
  -     * @return the attribute instance, or null of none could be found.
  +     * @param clazz the class. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @return the attribute instance, or <code>null</code> of none could be found.
        * @throws MultipleAttributesError if the collection contains more than one
        *         instance of the specified class.
        *
  @@ -200,7 +209,9 @@
       /**
        * Get one attributes of a given type from a field.
        *
  -     * @return the attribute instance, or null of none could be found.
  +     * @param field the field. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @return the attribute instance, or <code>null</code> of none could be found.
        * @throws MultipleAttributesError if the collection contains more than one
        *         instance of the specified class.
        *
  @@ -213,20 +224,24 @@
       /**
        * Get one attributes of a given type from a constructor.
        *
  -     * @return the attribute instance, or null of none could be found.
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @return the attribute instance, or <code>null</code> of none could be found.
        * @throws MultipleAttributesError if the collection contains more than one
        *         instance of the specified class.
        *
        * @since 2.1
        */
  -    public static Object getAttribute (Constructor ctor, Class attributeClass) throws RepositoryError, MultipleAttributesError {
  -        return getAttribute (getAttributes (ctor), attributeClass);
  +    public static Object getAttribute (Constructor constructor, Class attributeClass) throws RepositoryError, MultipleAttributesError {
  +        return getAttribute (getAttributes (constructor), attributeClass);
       }
       
       /**
        * Get one attributes of a given type from a method.
        *
  -     * @return the attribute instance, or null of none could be found.
  +     * @param method the method. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @return the attribute instance, or <code>null</code> of none could be found.
        * @throws MultipleAttributesError if the collection contains more than one
        *         instance of the specified class.
        *
  @@ -239,9 +254,14 @@
       /**
        * Get one attributes of a given type from a parameter.
        *
  -     * @return the attribute instance, or null of none could be found.
  +     * @param method the method. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @param parameter index of the parameter in the method's parameter list.
  +     * @return the attribute instance, or <code>null</code> of none could be found.
        * @throws MultipleAttributesError if the collection contains more than one
        *         instance of the specified class.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the method accepts.
        *
        * @since 2.1
        */
  @@ -252,9 +272,14 @@
       /**
        * Get one attributes of a given type from a constructor's parameter.
        *
  -     * @return the attribute instance, or null of none could be found.
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     * @param parameter index of the parameter in the method's parameter list.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @return the attribute instance, or <code>null</code> of none could be found.
        * @throws MultipleAttributesError if the collection contains more than one
        *         instance of the specified class.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the constructor accepts.
        *
        * @since 2.1
        */
  @@ -265,7 +290,9 @@
       /**
        * Get one attributes of a given type from a method's return value.
        *
  -     * @return the attribute instance, or null of none could be found.
  +     * @param method the method. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @return the attribute instance, or <code>null</code> of none could be found.
        * @throws MultipleAttributesError if the collection contains more than one
        *         instance of the specified class.
        *
  @@ -278,6 +305,8 @@
       /**
        * Gets all attributes for a class.
        *
  +     * @param clazz the class. May not be <code>null</code>.    
  +     *
        * @since 2.1
        */
       public static Collection getAttributes (Class clazz) throws RepositoryError {
  @@ -291,6 +320,8 @@
       /**
        * Gets all attributes for a method.
        *
  +     * @param method the method. May not be <code>null</code>.
  +     *
        * @since 2.1
        */
       public static Collection getAttributes (Method method) throws RepositoryError {
  @@ -304,15 +335,29 @@
       /**
        * Gets all attributes for a parameter of a method.
        *
  +     * @param method the method. May not be <code>null</code>.
  +     * @param parameter the index of the parameter in the method's parameter list.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the method accepts.
  +     *    
        * @since 2.1
        */
       public static Collection getParameterAttributes (Method method, int parameter) throws RepositoryError {
  +        if (method == null) {
  +            throw new NullPointerException ("method");
  +        }
  +        
           return getCachedRepository (method.getDeclaringClass()).getParameterAttributes (method, parameter);
       }
       
       /**
        * Gets all attributes for a parameter of a constructor.
        *
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     * @param parameter the index of the parameter in the constructor's parameter list.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the constructor accepts.
  +     *
        * @since 2.1
        */
       public static Collection getParameterAttributes (Constructor constructor, int parameter) throws RepositoryError {
  @@ -325,6 +370,8 @@
       /**
        * Gets all attributes for the return value of a method.
        *
  +     * @param method the method. May not be <code>null</code>.
  +     *
        * @since 2.1
        */
       public static Collection getReturnAttributes (Method method) throws RepositoryError {
  @@ -337,6 +384,8 @@
       /**
        * Gets all attributes for a field.
        *
  +     * @param field the field. May not be <code>null</code>.
  +     *
        * @since 2.1
        */
       public static Collection getAttributes (Field field) throws RepositoryError {
  @@ -349,13 +398,15 @@
       /**
        * Gets all attributes for a constructor.
        *
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     *
        * @since 2.1
        */
  -    public static Collection getAttributes (Constructor cons) throws RepositoryError {
  -        if (cons == null) {
  -            throw new NullPointerException ("cons");
  +    public static Collection getAttributes (Constructor constructor) throws RepositoryError {
  +        if (constructor == null) {
  +            throw new NullPointerException ("constructor");
           }
  -        return getCachedRepository (cons.getDeclaringClass()).getAttributes (cons);
  +        return getCachedRepository (constructor.getDeclaringClass()).getAttributes (constructor);
       }
       
       /**
  @@ -380,6 +431,9 @@
        * Get all attributes of a given type from a class. For all objects o in the returned 
        * collection, <code>o.getClass() == attributeClass</code>.
        *
  +     * @param clazz the class. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
       public static Collection getAttributes (Class clazz, Class attributeClass) throws RepositoryError {
  @@ -390,6 +444,9 @@
        * Get all attributes of a given type from a field. For all objects o in the returned 
        * collection, <code>o.getClass() == attributeClass</code>.
        *
  +     * @param field the field. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
       public static Collection getAttributes (Field field, Class attributeClass) throws RepositoryError {
  @@ -400,16 +457,22 @@
        * Get all attributes of a given type from a constructor. For all objects o in the returned 
        * collection, <code>o.getClass() == attributeClass</code>.
        *
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
  -    public static Collection getAttributes (Constructor ctor, Class attributeClass) throws RepositoryError {
  -        return getAttributes (getAttributes (ctor), attributeClass);
  +    public static Collection getAttributes (Constructor constructor, Class attributeClass) throws RepositoryError {
  +        return getAttributes (getAttributes (constructor), attributeClass);
       }
       
       /**
        * Get all attributes of a given type from a method. For all objects o in the returned 
        * collection, <code>o.getClass() == attributeClass</code>.
        *
  +     * @param method the method. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
       public static Collection getAttributes (Method method, Class attributeClass) throws RepositoryError {
  @@ -420,6 +483,12 @@
        * Get all attributes of a given type from a method's parameter. For all objects o in the returned 
        * collection, <code>o.getClass() == attributeClass</code>.
        *
  +     * @param method the method. May not be <code>null</code>.
  +     * @param parameter index of the parameter in the method's parameter list
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the method accepts.
  +     *
        * @since 2.1
        */
       public static Collection getParameterAttributes (Method method, int parameter, Class attributeClass) throws RepositoryError {
  @@ -430,6 +499,12 @@
        * Get all attributes of a given type from a method's parameter. For all objects o in the returned 
        * collection, <code>o.getClass() == attributeClass</code>.
        *
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     * @param parameter index of the parameter in the constructor's parameter list
  +     * @param attributeClass the type of attribute. May be <code>null</code>, but this will not match anything.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the constructor accepts.
  +     *
        * @since 2.1
        */
       public static Collection getParameterAttributes (Constructor constructor, int parameter, Class attributeClass) throws RepositoryError {
  @@ -440,6 +515,9 @@
        * Get all attributes of a given type from a method's return value. For all objects o in the returned 
        * collection, <code>o.getClass() == attributeClass</code>.
        *
  +     * @param method the method
  +     * @param attributeClass the type of attribute wanted. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
       public static Collection getReturnAttributes (Method method, Class attributeClass) throws RepositoryError {
  @@ -468,6 +546,9 @@
        * Tests if a class has an attribute of a given type. That is, is there any attribute
        * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
        *
  +     * @param class the class. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
       public static boolean hasAttributeType (Class clazz, Class attributeClass) throws RepositoryError {
  @@ -478,6 +559,9 @@
        * Tests if a field has an attribute of a given type. That is, is there any attribute
        * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
        *
  +     * @param field the field. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
       public static boolean hasAttributeType (Field field, Class attributeClass) throws RepositoryError {
  @@ -488,16 +572,22 @@
        * Tests if a constructor has an attribute of a given type. That is, is there any attribute
        * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
        *
  +     * @param ctor the constructor. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
  -    public static boolean hasAttributeType (Constructor ctor, Class attributeClass) throws RepositoryError {
  -        return hasAttributeType (getAttributes (ctor), attributeClass);
  +    public static boolean hasAttributeType (Constructor constructor, Class attributeClass) throws RepositoryError {
  +        return hasAttributeType (getAttributes (constructor), attributeClass);
       }
       
       /**
        * Tests if a method has an attribute of a given type. That is, is there any attribute
        * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
        *
  +     * @param method the method. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
       public static boolean hasAttributeType (Method method, Class attributeClass) throws RepositoryError {
  @@ -508,6 +598,12 @@
        * Tests if a method's parameter has an attribute of a given type. That is, is there any attribute
        * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
        *
  +     * @param method the method. May not be <code>null</code>.
  +     * @param parameter the index of the parameter in the method's parameter list.
  +     * @param attributeClass the type of attribute. May be <code>null</code>, but this will not match anything.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the method accepts.
  +     *
        * @since 2.1
        */
       public static boolean hasParameterAttributeType (Method method, int parameter, Class attributeClass) throws RepositoryError {
  @@ -518,6 +614,12 @@
        * Tests if a constructor's parameter has an attribute of a given type. That is, is there any attribute
        * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
        *
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     * @param parameter the index of the parameter in the constructor's parameter list.
  +     * @param attributeClass the type of attribute. May be <code>null</code>, but this will not match anything.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the constructor accepts.
  +     *
        * @since 2.1
        */
       public static boolean hasParameterAttributeType (Constructor constructor, int parameter, Class attributeClass) throws RepositoryError {
  @@ -528,6 +630,9 @@
        * Tests if a method's return value has an attribute of a given type. That is, is there any attribute
        * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
        *
  +     * @param method the method. May not be <code>null</code>.
  +     * @param attributeClass the type of attribute. May be <code>null</code>, but this will not match anything.
  +     *
        * @since 2.1
        */
       public static boolean hasReturnAttributeType (Method method, Class attributeClass) throws RepositoryError {
  @@ -548,6 +653,9 @@
        * Tests if a class has an attribute. That is, is there any attribute
        * <code>attr</code> such that <code>attr.equals(attribute)</code>?
        *
  +     * @param clazz the class. May not be <code>null</code>.
  +     * @param attribute the attribute to compare to.
  +     *
        * @since 2.1
        */
       public static boolean hasAttribute (Class clazz, Object attribute) throws RepositoryError {
  @@ -558,6 +666,9 @@
        * Tests if a field has an attribute. That is, is there any attribute
        * <code>attr</code> such that <code>attr.equals(attribute)</code>?
        *
  +     * @param field the field. May not be <code>null</code>.
  +     * @param attribute the attribute to compare to.
  +     *
        * @since 2.1
        */
       public static boolean hasAttribute (Field field, Object attribute) throws RepositoryError {
  @@ -568,16 +679,22 @@
        * Tests if a constructor has an attribute. That is, is there any attribute
        * <code>attr</code> such that <code>attr.equals(attribute)</code>?
        *
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     * @param attribute the attribute to compare to.
  +     *
        * @since 2.1
        */
  -    public static boolean hasAttribute (Constructor ctor, Object attribute) throws RepositoryError {
  -        return hasAttribute (getAttributes (ctor), attribute);
  +    public static boolean hasAttribute (Constructor constructor, Object attribute) throws RepositoryError {
  +        return hasAttribute (getAttributes (constructor), attribute);
       }
       
       /**
        * Tests if a method has an attribute. That is, is there any attribute
        * <code>attr</code> such that <code>attr.equals(attribute)</code>?
        *
  +     * @param method the method. May not be <code>null</code>.
  +     * @param attribute the attribute to compare to.
  +     *
        * @since 2.1
        */
       public static boolean hasAttribute (Method method, Object attribute) throws RepositoryError {
  @@ -587,6 +704,12 @@
       /**
        * Tests if a method's parameter has an attribute. That is, is there any attribute
        * <code>attr</code> such that <code>attr.equals(attribute)</code>?
  +     *    
  +     * @param method the method. May not be <code>null</code>.
  +     * @param parameter the index of the parameter in the method's parameter list.
  +     * @param attribute the attribute to compare to.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the method accepts.
        *
        * @since 2.1
        */
  @@ -598,6 +721,12 @@
        * Tests if a constructor's parameter has an attribute. That is, is there any attribute
        * <code>attr</code> such that <code>attr.equals(attribute)</code>?
        *
  +     * @param constructor the constructor. May not be <code>null</code>.
  +     * @param parameter the index of the parameter in the constructor's parameter list.
  +     * @param attribute the attribute to compare to.
  +     * @throws ParameterIndexOutOfBoundsException if the parameter index is < 0 or greater than the number 
  +     *                                            of parameters the constructor accepts.
  +     *
        * @since 2.1
        */
       public static boolean hasParameterAttribute (Constructor constructor, int parameter, Object attribute) throws RepositoryError {
  @@ -608,6 +737,9 @@
        * Tests if a method's return value has an attribute. That is, is there any attribute
        * <code>attr</code> such that <code>attr.equals(attribute)</code>?
        *
  +     * @param method the method. May not be <code>null</code>.
  +     * @param attribute the attribute to compare to.
  +     *
        * @since 2.1
        */
       public static boolean hasReturnAttribute (Method method, Object attribute) throws RepositoryError {
  @@ -628,6 +760,10 @@
        * @since 2.1
        */
       public static synchronized void setAttributes (RuntimeAttributeRepository repo) throws IllegalStateException {
  +        if (repo == null) {
  +            throw new NullPointerException ("repo");
  +        }
  +        
           repo.seal ();
           
           Class clazz = repo.getDefinedClass ();
  
  
  
  1.3       +18 -3     jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/CircularDependencyError.java
  
  Index: CircularDependencyError.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/CircularDependencyError.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CircularDependencyError.java	27 Aug 2004 21:30:10 -0000	1.2
  +++ CircularDependencyError.java	28 Aug 2004 21:12:10 -0000	1.3
  @@ -30,11 +30,16 @@
        * Create a new CircularDependencyError.
        *
        * @param className the name of the class that started it all.
  -     * @param dependencyList a list of the classes that the original
  +     * @param dependencyList a list of the classes ({@link java.lang.Class}) 
  +     *                       that the original
        *                       class depended on, the classes they
        *                       depended on, and so on. The list should
        *                       show the chain of dependencies that resulted
  -     *                       in the exception being thrown.
  +     *                       in the exception being thrown. <b>Note</b>:
  +     *                       Versions prior to 2.2 accepted a list of Objects
  +     *                       of any type. This is still supported, but the
  +     *                       formatting may suffer. Please only use lists of
  +     *                       {@link java.lang.Class}.
        *
        * @since 2.1
        */
  @@ -53,7 +58,17 @@
           StringBuffer sb = new StringBuffer ();
           Iterator iter = dependencyList.iterator ();
           while (iter.hasNext ()) {
  -            sb.append (iter.next ());
  +            Object o = iter.next ();
  +            
  +            // Test that the user really passed in a Class. Versions
  +            // prior to 2.2 received Strings instead, and any user that
  +            // used the code would find it broken.
  +            if (o != null && o instanceof Class) {
  +                sb.append (((Class) o).getName ());
  +            } else {
  +                sb.append (o);
  +            }
  +            
               if (iter.hasNext ()) {
                   sb.append (" -> ");
               }
  
  
  
  1.3       +8 -3      jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/DefaultCachedRepository.java
  
  Index: DefaultCachedRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/DefaultCachedRepository.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultCachedRepository.java	27 Aug 2004 21:30:10 -0000	1.2
  +++ DefaultCachedRepository.java	28 Aug 2004 21:12:10 -0000	1.3
  @@ -46,8 +46,10 @@
           private Collection attributes = EMPTY_COLLECTION;
           private List parameterAttributes = new ArrayList ();
           private Collection returnAttributes = EMPTY_COLLECTION;
  +        private final String methodName;
           
  -        public MethodAttributeBundle () {
  +        public MethodAttributeBundle (String methodName) {
  +            this.methodName = methodName;
           }
           
           public Collection getAttributes () {
  @@ -59,6 +61,9 @@
           }
           
           public Collection getParameterAttributes (int index) {
  +            if (index < 0 || index >= parameterAttributes.size ()) {
  +                throw new ParameterIndexOutOfBoundsException (methodName, index, parameterAttributes.size ());
  +            }
               return (Collection) parameterAttributes.get (index);
           }
           
  @@ -91,10 +96,10 @@
           // ---- Fix up method attributes
           Method[] methods = clazz.getDeclaredMethods ();
           for (int i = 0; i < methods.length; i++) {
  -            MethodAttributeBundle bundle = new MethodAttributeBundle ();
               
               Method m = methods[i];
               String key = Util.getSignature (m);
  +            MethodAttributeBundle bundle = new MethodAttributeBundle (m.toString ());
               
               List attributeBundle = null;
               if (repo.getMethodAttributes ().containsKey (key)) {
  @@ -154,7 +159,7 @@
               if (repo.getConstructorAttributes ().containsKey (key)) {
                   List attributeBundle = null;
                   attributeBundle = (List) repo.getConstructorAttributes ().get (key);
  -                MethodAttributeBundle bundle = new MethodAttributeBundle ();
  +                MethodAttributeBundle bundle = new MethodAttributeBundle (ctor.toString ());
                   
                   bundle.setAttributes ((Collection) attributeBundle.get (0));
                   // ---- Parameter attributes
  
  
  
  1.3       +1 -1      jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/DefaultSealable.java
  
  Index: DefaultSealable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/DefaultSealable.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultSealable.java	27 Aug 2004 21:30:10 -0000	1.2
  +++ DefaultSealable.java	28 Aug 2004 21:12:10 -0000	1.3
  @@ -45,7 +45,7 @@
        */
       protected void checkSealed () throws IllegalStateException {
           if (sealed) {
  -            throw new IllegalStateException ("sealed");
  +            throw new SealedAttributeException ();
           }
       }
       
  
  
  
  1.1                  jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/ParameterIndexOutOfBoundsException.java
  
  Index: ParameterIndexOutOfBoundsException.java
  ===================================================================
  /*
   * Copyright 2003-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.commons.attributes;
  
  /**
   * Thrown when attempting to get attributes for a parameter of a constructor or method
   * and the parameter index is out of bounds.
   *
   * <p><b>Note:</b> for performance reasons, this exception is only thrown when the 
   * Commons Attribute runtime can quickly determine that the index is out of bounds.
   * Therefore, you may sometimes be able to pass an invalid index and not receive this
   * exception. For example, if the runtime knows that the method or constructor has
   * no attributes at all, an empty collection / null or false (as appropriate) will be 
   * returned instead. Put simply, <i>don't</i> use this exception to test how many parameters
   * a method or constructor has.
   *
   * @since 2.2
   */
  public class ParameterIndexOutOfBoundsException extends IndexOutOfBoundsException {
      
      /**
       * Create a new ParameterIndexOutOfBoundsException.
       *
       * @param methodOrConstructorName the name of the method or constructor whose parameter
       *                                the client tried to get attributes for.
       * @param index the index supplied by the client.
       * @param maxIndex the maximum + 1 parameter index allowed. For example, if a method takes
       *                 two parameters, the maximum allowed index is 1, and this parameter should
       *                 be set to 2. There is no minIndex parameter - it is assumed to be 0.
       */ 
      public ParameterIndexOutOfBoundsException (String methodOrConstructorName, int index, int maxIndex) {
          super (formatMessage (methodOrConstructorName, index, maxIndex));
      }
      
      private static String formatMessage (String methodOrConstructorName, int index, int maxIndex) {
          if (index < 0) {
              return String.valueOf (index);
          } else {
              return index + ". " + methodOrConstructorName + " has " + maxIndex + " parameters.";
          }
      }
  }
  
  
  1.1                  jakarta-commons/attributes/api/src/java/org/apache/commons/attributes/SealedAttributeException.java
  
  Index: SealedAttributeException.java
  ===================================================================
      /*
       * Copyright 2003-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.commons.attributes;
  
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * Thrown when an attempt is made to modify a {@link Sealable} attribute
   * that has been sealed.
   *
   * @see Sealable#seal()
   * @since 2.2
   */
  public class SealedAttributeException extends IllegalStateException {
      
      public SealedAttributeException () {
          super ("sealed");
      }
  }
  
  

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