/[classpath]/classpath/java/util/PropertyPermission.java
ViewVC logotype

Diff of /classpath/java/util/PropertyPermission.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by ericb, Fri Feb 22 05:50:50 2002 UTC revision 1.9 by ericb, Fri Feb 22 07:08:04 2002 UTC
# Line 94  public final class PropertyPermission ex Line 94  public final class PropertyPermission ex
94    private static final int WRITE = 2;    private static final int WRITE = 2;
95    
96    /** The set of actions permitted. */    /** The set of actions permitted. */
97    private transient int actions;    // Package visible for use by PropertyPermissionCollection.
98      transient int actions;
99    
100    /**    /**
101     * The String forms of the actions permitted.     * The String forms of the actions permitted.
# Line 106  public final class PropertyPermission ex Line 107  public final class PropertyPermission ex
107    
108    /**    /**
109     * Constructs a PropertyPermission with the specified property.  Possible     * Constructs a PropertyPermission with the specified property.  Possible
110     * actions are read and write.     * actions are read and write, comma-separated and case-insensitive.
111     *     *
112     * @param name the name of the property     * @param name the name of the property
113     * @param actions the action string     * @param actions the action string
114     * @throws IllegalArgumentException if name string contains an     * @throws IllegalArgumentException if name string contains an
115     *         illegal wildcard or actions string contains an illegal action     *         illegal wildcard or actions string contains an illegal action
116       *         (this includes a null actions string)
117     */     */
118    public PropertyPermission(String name, String actions)    public PropertyPermission(String name, String actions)
119    {    {
120      super(name);      super(name);
121        if (actions == null)
122          throw new IllegalArgumentException();
123      setActions(actions.toLowerCase());      setActions(actions.toLowerCase());
124    }    }
125    
# Line 123  public final class PropertyPermission ex Line 127  public final class PropertyPermission ex
127     * Parse the action string and convert actions from external to internal     * Parse the action string and convert actions from external to internal
128     * form.  This will set the internal actions field.     * form.  This will set the internal actions field.
129     *     *
130     * @param actions the action string     * @param str the action string
131     * @throws IllegalArgumentException if actions string contains an     * @throws IllegalArgumentException if actions string contains an
132     *         illegal action     *         illegal action
133     */     */
134    private void setActions(String actions)    private void setActions(String str)
135    {    {
136      this.actions = 0;      if ("read".equals(str))
137      StringTokenizer actionTokenizer = new StringTokenizer(actions, ",");        actions = READ;
138      while (actionTokenizer.hasMoreElements())      else if ("write".equals(str))
139        {        actions = WRITE;
140          String anAction = actionTokenizer.nextToken();      else if ("read,write".equals(str) || "write,read".equals(str))
141          if ("read".equals(anAction))        actions = READ | WRITE;
142            this.actions |= READ;      else
143          else if ("write".equals(anAction))        throw new IllegalArgumentException("illegal action " + str);
           this.actions |= WRITE;  
         else  
           throw new IllegalArgumentException("illegal action " + anAction);  
       }  
144    }    }
145    
146    /**    /**
# Line 196  public final class PropertyPermission ex Line 196  public final class PropertyPermission ex
196        return false;        return false;
197    
198      // BasicPermission checks for name.      // BasicPermission checks for name.
199      return (!super.implies(p))      return super.implies(p);
       return false;  
   
     return true;  
200    }    }
201    
202    /**    /**
# Line 223  public final class PropertyPermission ex Line 220  public final class PropertyPermission ex
220     * <code>getName().hashCode()</code>.     * <code>getName().hashCode()</code>.
221     *     *
222     * @return the hash code     * @return the hash code
    * @XXX Add this method.  
223     */     */
224      public int hashCode()
225      {
226        return super.hashCode();
227      }
228    
229    /**    /**
230     * Returns the action string.  Note that this may differ from the string     * Returns the action string.  Note that this may differ from the string
231     * given at the constructor:  The actions are converted to lowercase and     * given at the constructor:  The actions are converted to lowercase and
232     * may be reordered.     * may be reordered.
233     *     *
234     * @return one of "", "read", "write", or "read,write"     * @return one of "read", "write", or "read,write"
235     */     */
236    public String getActions()    public String getActions()
237    {    {
# Line 244  public final class PropertyPermission ex Line 243  public final class PropertyPermission ex
243     * PropertyPermission objects.     * PropertyPermission objects.
244     *     *
245     * @return a new empty PermissionCollection     * @return a new empty PermissionCollection
    * @XXX JDK uses a default class, java.util.PropertyPermissionCollection,  
    *  instead of an anonymous class.  
246     */     */
247    public PermissionCollection newPermissionCollection()    public PermissionCollection newPermissionCollection()
248    {    {
249      return new PermissionCollection()      return new PropertyPermissionCollection();
     {  
       Hashtable permissions = new Hashtable();  
       int allActions = 0;  
   
       public void add(Permission permission)  
       {  
         if (isReadOnly())  
           throw new IllegalStateException("readonly");  
   
         // also check that permission is of correct type.  
         PropertyPermission pp = (PropertyPermission) permission;  
         String name = pp.getName();  
         if (name.equals("*"))  
           allActions |= pp.actions;  
         permissions.put(name, pp);  
       }  
   
       public boolean implies(Permission permission)  
       {  
         if (!(permission instanceof PropertyPermission))  
           return false;  
   
         PropertyPermission toImply = (PropertyPermission) permission;  
         if ((toImply.actions & ~allActions) == 0)  
           return true;  
   
         String name = toImply.getName();  
         if (name.equals("*"))  
           return false;  
   
         int prefixLength = name.length();  
         if (name.endsWith("*"))  
           prefixLength -= 2;  
   
         while (true)  
           {  
             PropertyPermission forName =  
               (PropertyPermission) permissions.get(name);  
             if (forName != null && (toImply.actions & ~forName.actions) == 0)  
               return true;  
   
             prefixLength = name.lastIndexOf('.', prefixLength);  
             if (prefixLength < 0)  
               return false;  
             name = name.substring(0, prefixLength + 1) + '*';  
           }  
       }  
   
       public Enumeration elements()  
       {  
         return permissions.elements();  
       }  
     };  
250    }    }
251  }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26