commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosu...@apache.org
Subject cvs commit: jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes EmptyAttributeRepositoryClass.java Util.java InvalidAttributeTargetError.java Attributes.java
Date Sun, 09 May 2004 17:58:38 GMT
leosutic    2004/05/09 10:58:38

  Modified:    attributes/api/src/java/org/apache/commons/attributes
                        Util.java InvalidAttributeTargetError.java
                        Attributes.java
  Added:       attributes/api/src/java/org/apache/commons/attributes
                        EmptyAttributeRepositoryClass.java
  Log:
  Fixed bug that would disable inheritance of attributes for classes that
  didn't have any attributes themselves.
  
  Revision  Changes    Path
  1.7       +6 -5      jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/Util.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Util.java	9 May 2004 13:57:10 -0000	1.6
  +++ Util.java	9 May 2004 17:58:38 -0000	1.7
  @@ -22,6 +22,7 @@
   import java.util.List;
   import java.util.Iterator;
   import java.util.Set;
  +import java.util.Map;
   import java.util.Collection;
   
   class Util {
  @@ -74,12 +75,12 @@
       }
       
       public static void checkTarget (int target, Object attribute, String element) {
  -        Target targetAttr = Attributes.getAttribute (attribute.getClass (), Target.class);
  +        Target targetAttr = (Target) Attributes.getAttribute (attribute.getClass (), Target.class);
           if (targetAttr == null) {
               return;
           }
           
  -        if (targetAttr.getFlags () & target == 0) {
  +        if ((targetAttr.getFlags () & target) == 0) {
               throw new InvalidAttributeTargetError (attribute.getClass ().getName (), element,
targetAttr.getFlags ());
           }
       }
  @@ -95,13 +96,13 @@
           checkTarget (Target.CLASS, repo.getClassAttributes (), owningClass.getName ());
           
           Map fieldAttrs = repo.getFieldAttributes ();
  -        for (Iterator iter = fieldAttrs.keySet (); iter.hasNext ();) {
  +        for (Iterator iter = fieldAttrs.keySet ().iterator(); iter.hasNext ();) {
               String fieldName = (String) iter.next ();
               checkTarget (Target.FIELD, (Collection) fieldAttrs.get (fieldName), owningClass.getName
() + "." + fieldName);
           }
           
           Map ctorAttrs = repo.getConstructorAttributes ();
  -        for (Iterator iter = ctorAttrs.keySet (); iter.hasNext ();) {
  +        for (Iterator iter = ctorAttrs.keySet ().iterator(); iter.hasNext ();) {
               String ctorName = (String) iter.next ();
               List bundle = (List) ctorAttrs.get (ctorName);
               
  @@ -118,7 +119,7 @@
           }
           
           Map methodAttrs = repo.getMethodAttributes ();
  -        for (Iterator iter = methodAttrs.keySet (); iter.hasNext ();) {
  +        for (Iterator iter = methodAttrs.keySet ().iterator(); iter.hasNext ();) {
               String methodName = (String) iter.next ();
               List bundle = (List) methodAttrs.get (methodName);
               
  
  
  
  1.2       +11 -8     jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/InvalidAttributeTargetError.java
  
  Index: InvalidAttributeTargetError.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/InvalidAttributeTargetError.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InvalidAttributeTargetError.java	9 May 2004 13:57:10 -0000	1.1
  +++ InvalidAttributeTargetError.java	9 May 2004 17:58:38 -0000	1.2
  @@ -15,38 +15,41 @@
    */
   package org.apache.commons.attributes;
   
  +import java.util.ArrayList;
  +import java.util.List;
  +
   /**
    * Thrown when one of the Attributes.getAttribute methods find more
    * than one instance of the specified attribute class.
    */
   public class InvalidAttributeTargetError extends Error {
       
  -    public MultipleAttributesError (String attributeClass, String element, int targetFlags)
{
  +    public InvalidAttributeTargetError (String attributeClass, String element, int targetFlags)
{
           super ("Attributes of type " + attributeClass + " can't be applied to " + element
+ ". " + 
               "They can only be applied to: " + flagsToString (targetFlags));
       }
       
       private final static String flagsToString (int flags) {
           List targetNames = new ArrayList ();
  -        if (flags & Target.CLASS > 0) {
  +        if ((flags & Target.CLASS) > 0) {
               targetNames.add ("CLASS");
           }
  -        if (flags & Target.FIELD > 0) {
  +        if ((flags & Target.FIELD) > 0) {
               targetNames.add ("FIELD");
           }
  -        if (flags & Target.METHOD > 0) {
  +        if ((flags & Target.METHOD) > 0) {
               targetNames.add ("METHOD");
           }
  -        if (flags & Target.CONSTRUCTOR > 0) {
  +        if ((flags & Target.CONSTRUCTOR) > 0) {
               targetNames.add ("CONSTRUCTOR");
           }
  -        if (flags & Target.METHOD_PARAMETER > 0) {
  +        if ((flags & Target.METHOD_PARAMETER) > 0) {
               targetNames.add ("METHOD_PARAMETER");
           }
  -        if (flags & Target.CONSTRUCTOR_PARAMETER > 0) {
  +        if ((flags & Target.CONSTRUCTOR_PARAMETER) > 0) {
               targetNames.add ("CONSTRUCTOR_PARAMETER");
           }
  -        if (flags & Target.RETURN > 0) {
  +        if ((flags & Target.RETURN) > 0) {
               targetNames.add ("RETURN");
           }
           
  
  
  
  1.13      +9 -5      jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/Attributes.java
  
  Index: Attributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/Attributes.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Attributes.java	9 May 2004 13:57:10 -0000	1.12
  +++ Attributes.java	9 May 2004 17:58:38 -0000	1.13
  @@ -131,21 +131,25 @@
                   classRepositories.put (clazz, null);
                   
                   Class attributeRepo = null;
  +                AttributeRepositoryClass repo = EmptyAttributeRepositoryClass.INSTANCE;
                   try {
                       attributeRepo = Class.forName (clazz.getName () + "$__attributeRepository",
true, clazz.getClassLoader ());
  -                    AttributeRepositoryClass repo = (AttributeRepositoryClass) attributeRepo.newInstance
();
  -                    
  -                    Util.validateRepository (clazz, repo);
  -                    cached = new DefaultCachedRepository (clazz, repo);
  +                    repo = (AttributeRepositoryClass) attributeRepo.newInstance ();
                   } catch (ClassNotFoundException cnfe) {
  -                    cached = CachedRepository.EMPTY;
  +                    // OK, just means no repo available, so default to empty one.
  +                    repo = EmptyAttributeRepositoryClass.INSTANCE;
                   } catch (InstantiationException ie) {
                       throw new RepositoryError (ie);
                   } catch (IllegalAccessException iae) {
                       throw new RepositoryError (iae);
                   }
  +                cached = new DefaultCachedRepository (clazz, repo);
                   
                   classRepositories.put (clazz, cached);
  +                
  +                if (repo != null) {
  +                    Util.validateRepository (clazz, repo);
  +                }
               } finally {
                   initList.remove (initList.size () - 1);
               }
  
  
  
  1.1                  jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/EmptyAttributeRepositoryClass.java
  
  Index: EmptyAttributeRepositoryClass.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.Collections;
  import java.util.Set;
  import java.util.Map;
  
  /**
   * Empty implementation of AttributeRepositoryClass.
   */
  class EmptyAttributeRepositoryClass implements AttributeRepositoryClass {
      
      public static final AttributeRepositoryClass INSTANCE = new EmptyAttributeRepositoryClass();
      
      public Set getClassAttributes () {
          return Collections.EMPTY_SET;
      }
      
      public Map getFieldAttributes () {
          return Collections.EMPTY_MAP;
      }
      
      public Map getMethodAttributes () {
          return Collections.EMPTY_MAP;
      }
      
      public Map getConstructorAttributes () {
          return Collections.EMPTY_MAP;
      }
  }
  
  

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


Mime
View raw message