epugh       2003/08/24 12:39:24

  Modified:    security/src/java/org/apache/fulcrum/security/util
                        PermissionSet.java RoleSet.java GroupSet.java
                        SecuritySet.java
  Log:
  Get *Set's to implement the Set interface!  Mostly works, however hibernate doesn't
  like to map them as sets for some reason..
  
  Revision  Changes    Path
  1.2       +4 -3      
jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/PermissionSet.java
  
  Index: PermissionSet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/PermissionSet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PermissionSet.java        23 Aug 2003 03:56:23 -0000      1.1
  +++ PermissionSet.java        24 Aug 2003 19:39:24 -0000      1.2
  @@ -191,6 +191,7 @@
        */
       public Permission getPermissionByName(String permissionName)
       {
  +             permissionName=permissionName.toLowerCase();
           return (StringUtils.isNotEmpty(permissionName))
                   ? (Permission) nameMap.get(permissionName) : null;
       }
  @@ -203,10 +204,10 @@
        * @return Permission if argument matched a Permission in this
        * PermissionSet; null if no match.
        */
  -    public Permission getPermissionById(int permissionId)
  +    public Permission getPermissionById(long permissionId)
       {
           return (permissionId != 0) 
  -                ? (Permission) idMap.get(new Integer(permissionId)) : null;
  +                ? (Permission) idMap.get(new Long(permissionId)) : null;
       }
   
       /**
  
  
  
  1.2       +4 -3      
jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/RoleSet.java
  
  Index: RoleSet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/RoleSet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RoleSet.java      23 Aug 2003 03:56:23 -0000      1.1
  +++ RoleSet.java      24 Aug 2003 19:39:24 -0000      1.2
  @@ -188,6 +188,7 @@
        */
       public Role getRoleByName(String roleName)
       {
  +             roleName=roleName.toLowerCase();
           return (StringUtils.isNotEmpty(roleName))
                   ? (Role) nameMap.get(roleName) : null;
       }
  @@ -200,10 +201,10 @@
        * @return Role if argument matched a Role in this RoleSet; null
        * if no match.
        */
  -    public Role getRoleById(int roleId)
  +    public Role getRoleById(long roleId)
       {
           return (roleId != 0) 
  -                ? (Role) idMap.get(new Integer(roleId)) : null;
  +                ? (Role) idMap.get(new Long(roleId)) : null;
       }
   
       /**
  
  
  
  1.2       +7 -4      
jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/GroupSet.java
  
  Index: GroupSet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/GroupSet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GroupSet.java     23 Aug 2003 03:56:23 -0000      1.1
  +++ GroupSet.java     24 Aug 2003 19:39:24 -0000      1.2
  @@ -111,7 +111,7 @@
           idMap.put(getIdAsObject(group.getId()), group);
           return res;
       }
  -
  +             
       /**
        * Adds the Groups in a Collection to this GroupSet.
        *
  @@ -189,6 +189,7 @@
        */
       public Group getGroupByName(String groupName)
       {
  +     groupName=groupName.toLowerCase();
           return (StringUtils.isNotEmpty(groupName))
                   ? (Group) nameMap.get(groupName) : null;
       }
  @@ -201,10 +202,10 @@
        * @return Group if argument matched a Group in this
        * GroupSet; null if no match.
        */
  -    public Group getGroupById(int groupId)
  +    public Group getGroupById(long groupId)
       {
           return (groupId != 0)
  -                ? (Group) idMap.get(new Integer(groupId)) : null;
  +                ? (Group) idMap.get(new Long(groupId)) : null;
       }
   
       /**
  @@ -244,4 +245,6 @@
   
           return sb.toString();
       }
  +    
  +  
   }
  
  
  
  1.2       +108 -32   
jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/SecuritySet.java
  
  Index: SecuritySet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/util/SecuritySet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SecuritySet.java  23 Aug 2003 03:56:23 -0000      1.1
  +++ SecuritySet.java  24 Aug 2003 19:39:24 -0000      1.2
  @@ -1,5 +1,4 @@
   package org.apache.fulcrum.security.util;
  -
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  @@ -54,7 +53,7 @@
    * <http://www.apache.org/>.
    */
   import java.io.Serializable;
  -
  +import java.util.Collection;
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Map;
  @@ -62,29 +61,26 @@
   import java.util.TreeMap;
   
   import org.apache.commons.lang.StringUtils;
  -
   /**
    * This class represents a set of Security Entities.
    * It makes it easy to build a UI.
    * It wraps a TreeSet object to enforce that only relevant
    * methods are available.
    * TreeSet's contain only unique Objects (no duplicates).
  - *
  + 
  + * @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Brett McLaughlin</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Marco Kn&uuml;ttel</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
    * @version $Id$
    */
  -public abstract class SecuritySet
  -        implements Serializable
  +public abstract class SecuritySet implements Serializable, Set
   {
       /** Map for "name" -> "security object" */
       protected Map nameMap = null;
  -
       /** Map for "id" -> "security object" */
       protected Map idMap = null;
  -
       /**
        * Constructs an empty Set
        */
  @@ -93,7 +89,6 @@
           nameMap = new TreeMap();
           idMap = new TreeMap();
       }
  -
       /**
        * Returns a set of security objects in this object.
        *
  @@ -104,7 +99,6 @@
       {
           return new HashSet(nameMap.values());
       }
  -
       /**
        * Returns a set of Names in this Object.
        *
  @@ -115,7 +109,6 @@
       {
           return nameMap.keySet();
       }
  -
       /**
        * Returns a set of Id values in this Object.
        *
  @@ -126,7 +119,6 @@
       {
           return idMap.keySet();
       }
  -
       /**
        * Removes all Objects from this Set.
        */
  @@ -135,9 +127,6 @@
           nameMap.clear();
           idMap.clear();
       }
  -
  -
  -
       /**
        * Searches if an Object with a given name is in the
        * Set
  @@ -148,9 +137,9 @@
        */
       public boolean containsName(String name)
       {
  +     name = name.toLowerCase();
           return (StringUtils.isNotEmpty(name)) ? nameMap.containsKey(name) : false;
       }
  -
       /**
        * Searches if an Object with a given Id is in the
        * Set
  @@ -159,11 +148,10 @@
        * @return True if argument matched an Object in this Set; false
        * if no match.
        */
  -    public boolean containsId(int id)
  +    public boolean containsId(long id)
       {
  -        return (id == 0) ? false:  idMap.containsKey(new Integer(id));
  +        return (id == 0) ? false : idMap.containsKey(new Long(id));
       }
  -
       /**
        * Returns an Iterator for Objects in this Set.
        *
  @@ -173,9 +161,6 @@
       {
           return nameMap.values().iterator();
       }
  -
  -
  -
       /**
        * Returns size (cardinality) of this set.
        *
  @@ -185,7 +170,6 @@
       {
           return nameMap.size();
       }
  -
       /**
        * list of role names in this set
        *
  @@ -194,21 +178,113 @@
       public String toString()
       {
           StringBuffer sbuf = new StringBuffer(12 * size());
  -        for(Iterator it = nameMap.keySet().iterator(); it.hasNext(); )
  +        for (Iterator it = nameMap.keySet().iterator(); it.hasNext();)
           {
               sbuf.append((String) it.next());
  -
  -            if(it.hasNext())
  +            if (it.hasNext())
               {
                   sbuf.append(", ");
               }
           }
           return sbuf.toString();
       }
  -    
  -    protected Integer getIdAsObject(int id){
  -     return new Integer(id);
  +    protected Long getIdAsObject(long id)
  +    {
  +        return new Long(id);
  +    }
  +    // methods from Set
  +    public boolean addAll(Collection collection)
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +        return add(collection);
  +    }
  +    public boolean isEmpty()
  +    {
  +        return nameMap.isEmpty();
  +    }
  +    public boolean containsAll(Collection collection)
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +        for (Iterator i = collection.iterator(); i.hasNext();)
  +        {
  +            Object object = i.next();
  +            if (!contains(object))
  +            {
  +                return false;
  +            }
  +        }
  +        return true;
  +    }
  +    public boolean removeAll(Collection collection)
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +        boolean changed = false;
  +        for (Iterator i = collection.iterator(); i.hasNext();)
  +        {
  +            Object object = i.next();
  +            boolean result = remove(object);
  +            if (result)
  +            {
  +                changed = true;
  +            }
  +        }
  +        return changed;
  +    }
  +    public boolean retainAll(Collection collection)
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +        throw new RuntimeException("not implemented");
  +    }
  +    /* (non-Javadoc)
  +     * @see java.util.Collection#toArray()
  +     */
  +    public Object[] toArray()
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +             throw new RuntimeException("not implemented");
  +    }
  +    /* (non-Javadoc)
  +     * @see java.util.Collection#add(java.lang.Object)
  +     */
  +    public boolean add(Object o)
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +             Collection c = new HashSet();
  +             c.add(o);
  +             return add(c);
  +             
  +    }
  +    /* (non-Javadoc)
  +     * @see java.util.Collection#contains(java.lang.Object)
  +     */
  +    public boolean contains(Object o)
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +             throw new RuntimeException("not implemented");
  +    }
  +    /* (non-Javadoc)
  +     * @see java.util.Collection#remove(java.lang.Object)
  +     */
  +    public boolean remove(Object o)
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +             throw new RuntimeException("not implemented");
  +    }
  +    /* (non-Javadoc)
  +     * @see java.util.Collection#toArray(java.lang.Object[])
  +     */
  +    public Object[] toArray(Object[] a)
  +    {
  +             System.out.println("here we go!");
  +             System.err.println("here we go err!");
  +             throw new RuntimeException("not implemented");
       }
  -    
   }
  -
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to