View Javadoc
1   /**
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Intalio, Inc.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Intalio, Inc. Exolab is a registered
23   *    trademark of Intalio, Inc.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
42   *
43   * $Id$
44   */
45  
46  package org.exolab.castor.xml;
47  
48  /**
49   * A class used to indicate access rights
50   * @author <a href="kvisco@intalio.com">Keith Visco</a>
51   * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
52  **/
53  public class AccessRights {
54      
55      /**
56       * The type that indicates both read and write access
57      **/
58      public static final short BOTH  = 0;
59      
60      /**
61       * The type that indicates only read access
62      **/
63      public static final short READ = 1;
64      
65      /**
66       * The type that indicates only write access
67      **/
68      public static final short WRITE = 2;
69      
70      
71      /**
72       * A read and write AccessRights
73      **/
74      public static final AccessRights both 
75          = new AccessRights(AccessRights.BOTH);
76          
77      /**
78       * A read-only AccessRights
79      **/
80      public static final AccessRights read
81          = new AccessRights(AccessRights.READ);
82      
83      /**
84       * A write-only AccessRights
85      **/
86      public static final AccessRights write 
87          = new AccessRights(AccessRights.WRITE);
88      
89      /**
90       * The type of this AccessRights
91      **/
92      private short type = BOTH;
93      
94      /**
95       * Creates a default AccessRights with both read and write privileges
96      **/
97      private AccessRights() {
98          super();
99      } //-- AccessRights
100     
101     /**
102      * Creates a new AccessRights with the privilege set to the given type
103      * @param type the type of privilege to be granted
104     **/
105     private AccessRights(short type) {
106         this.type = type;
107     } //-- AccessRights
108     
109     /**
110      * Returns the type of this Access
111     **/
112     public short getType() {
113         return type;
114     } //-- getType
115     
116     
117     /**
118      * Returns true if this AccessRights allows reading
119      * @return true if this AccessRights allows reading,
120      * otherwise false.
121     **/
122     public boolean isReadable() {
123         return ((type == BOTH) || (type == READ));
124     } //-- isReadable
125     
126     /**
127      * Returns true if this AccessRights allows writing
128      * @return true if this AccessRights allows writing, 
129      * otherwise false.
130     **/
131     public boolean isWritable() {
132         return ((type == BOTH) || (type == WRITE));
133     } //-- isWritable
134 
135     
136 } //-- AccessRights