pier        01/07/26 12:30:28

  Modified:    java/org/apache/service ServicePermission.java
  Log:
  - Updated JavaDOC descriptions for those methods which didn't have one.
  - Modified how the toString() and hashCode() methods work, by storing a
    copy of the description of this permission instance in a local private
    variable.
  
  Revision  Changes    Path
  1.2       +64 -14    
jakarta-tomcat-service/java/org/apache/service/ServicePermission.java
  
  Index: ServicePermission.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-service/java/org/apache/service/ServicePermission.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServicePermission.java    2001/07/26 18:09:44     1.1
  +++ ServicePermission.java    2001/07/26 19:30:28     1.2
  @@ -124,7 +124,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Pier Fumagalli</a>
    * @author Copyright &copy; 2000-2001 <a href="http://www.apache.org/";>The
    *         Apache Software Foundation</a>. All rights reserved.
  - * @version 1.0 <i>(CVS $Revision: 1.1 $)</i>
  + * @version 1.0 <i>(CVS $Revision: 1.2 $)</i>
    */
   public final class ServicePermission extends Permission {
   
  @@ -195,7 +195,7 @@
        * target name.
        */
       protected static final String WILDCARD = "*";
  -    
  +
       /* ==================================================================== */
       /* Instance variables */
   
  @@ -203,6 +203,8 @@
       private transient int type = 0;
       /** The permission mask associated with this permission object. */
       private transient int mask = 0;
  +    /** The String representation of this permission object. */
  +    private transient String desc = null;
   
       /* ==================================================================== */
       /* Constructors */
  @@ -220,16 +222,20 @@
        */
       public ServicePermission (String target)
       throws IllegalArgumentException {
  +        // Setup the target name of this permission object.
           super(target);
   
  +        // Check if the permission target name was specified
           if (target==null)
               throw new IllegalArgumentException("Null permission name");
   
  +        // Check if this is a "control" permission and set up accordingly.
           if (CONTROL.equalsIgnoreCase(target)) {
               type=TYPE_CONTROL;
               return;
           }
  -        
  +
  +        // If we got here, we have an invalid permission name.
           throw new IllegalArgumentException("Invalid permission name \""+
                                              target+"\" specified");
       }
  @@ -239,7 +245,7 @@
        * permission name and a specified list of actions.
        * <p>
        * </p>
  -     * 
  +     *
        * @param target The target name of this permission.
        * @param actions The list of actions permitted by this permission.
        * @exception IllegalArgumentException If the specified target name is not
  @@ -248,50 +254,96 @@
        */
       public ServicePermission(String target, String actions)
       throws IllegalArgumentException {
  +        // Setup this instance's target name.
           this(target);
   
  +        // Create the appropriate mask if this is a control permission.
           if (this.type==TYPE_CONTROL) {
               this.mask=this.createControlMask(actions);
  +            return();
           }
       }
   
       /* ==================================================================== */
       /* Public methods */
   
  +    /**
  +     * Return the list of actions permitted by this instance of
  +     * <code>ServicePermission</code> in its canonical form.
  +     *
  +     * @return The canonicalized list of actions.
  +     */
       public String getActions() {
  -        if (this.type==TYPE_CONTROL)
  +        if (this.type==TYPE_CONTROL) {
               return(this.createControlActions(this.mask));
  -
  +        }
           return("");
       }
   
  +    /**
  +     * Return the hash code for this <code>ServicePermission</code> instance.
  +     *
  +     * @return An hash code value.
  +     */
       public int hashCode() {
  -        return(this.toString().hashCode());
  +        this.setupDescription();
  +        return(this.dest.hashCode());
       }
   
  +    /**
  +     * Check if a specified object equals <code>ServicePermission</code>.
  +     *
  +     * @return <b>true</b> or <b>false</b> wether the specified object equals
  +     *         this <code>ServicePermission</code> instance or not.
  +     */
       public boolean equals(Object object) {
           if (object == this) return(true);
   
           if (!(object instanceof ServicePermission)) return false;
   
           ServicePermission that = (ServicePermission)object;
  -        
  +
           if (this.type!=that.type) return(false);
           return(this.mask==that.mask);
       }
   
  +    /**
  +     * Check if this <code>ServicePermission</code> implies another
  +     * <code>Permission</code>.
  +     *
  +     * @return <b>true</b> or <b>false</b> wether the specified permission
  +     *         is implied by this <code>ServicePermission</code> instance or
  +     *         not.
  +     */
       public boolean implies(Permission permission) {
           if (permission == this) return(true);
   
           if (!(permission instanceof ServicePermission)) return false;
   
           ServicePermission that = (ServicePermission)permission;
  -        
  +
           if (this.type!=that.type) return(false);
           return((this.mask&that.mask)==that.mask);
       }
   
  +    /**
  +     * Return a <code>String</code> representation of this instance.
  +     *
  +     * @return A <code>String</code> representing this
  +     *         <code>ServicePermission</code> instance.
  +     */
       public String toString() {
  +        this.setupDescription();
  +        return(new String(this.desc));
  +    }
  +
  +    /* ==================================================================== */
  +    /* Private methods */
  +
  +    /** Create a String description for this permission instance. */
  +    private void setupDescription() {
  +        if (this.desc!=null) return;
  +
           StringBuffer buf=new StringBuffer();
           buf.append(this.getClass().getName());
           buf.append('[');
  @@ -308,11 +360,9 @@
           buf.append(':');
           buf.append(this.getActions());
           buf.append(']');
  -        return(buf.toString());
  -    }
   
  -    /* ==================================================================== */
  -    /* Private methods */
  +        this.desc=buf.toString();
  +    }
   
       /** Create a permission mask for a given control actions string. */
       private int createControlMask(String actions)
  @@ -342,7 +392,7 @@
           }
           return(mask);
       }
  -    
  +
       /** Create a actions list for a given control permission mask. */
       private String createControlActions(int mask) {
           StringBuffer buf=new StringBuffer();
  
  
  

Reply via email to