KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > go > trove > classfile > AccessFlags


1 /* ====================================================================
2  * Trove - Copyright (c) 1997-2000 Walt Disney Internet Group
3  * ====================================================================
4  * The Tea Software License, Version 1.1
5  *
6  * Copyright (c) 2000 Walt Disney Internet Group. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Walt Disney Internet Group (http://opensource.go.com/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Tea", "TeaServlet", "Kettle", "Trove" and "BeanDoc" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact opensource@dig.com.
31  *
32  * 5. Products derived from this software may not be called "Tea",
33  * "TeaServlet", "Kettle" or "Trove", nor may "Tea", "TeaServlet",
34  * "Kettle", "Trove" or "BeanDoc" appear in their name, without prior
35  * written permission of the Walt Disney Internet Group.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE WALT DISNEY INTERNET GROUP OR ITS
41  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
42  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
43  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
44  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * For more information about Tea, please see http://opensource.go.com/.
51  */

52
53 package com.go.trove.classfile;
54
55 import java.lang.reflect.Modifier JavaDoc;
56
57 /******************************************************************************
58  * The AccessFlags class is a wrapper around a Modifier bit mask. The
59  * methods provided to manipulate the Modifier ensure that it is always
60  * legal. i.e. setting it public automatically clears it from being
61  * private or protected.
62  *
63  * @author Brian S O'Neill
64  * @version
65  * <!--$$Revision:--> 18 <!-- $-->, <!--$$JustDate:--> 9/07/00 <!-- $-->
66  */

67 public class AccessFlags extends Modifier JavaDoc implements Cloneable JavaDoc {
68     private int mFlags;
69     
70     /** Construct with a modifier of 0. */
71     public AccessFlags() {
72         mFlags = 0;
73     }
74
75     public AccessFlags(int modifier) {
76         mFlags = modifier;
77     }
78     
79     public final int getModifier() {
80         return mFlags;
81     }
82     
83     public void setModifier(int flags) {
84         mFlags = flags;
85     }
86     
87     public boolean isPublic() {
88         return isPublic(mFlags);
89     }
90
91     /**
92      * When set public, it is cleared from being private or protected.
93      */

94     public void setPublic(boolean value) {
95         if (value) {
96             mFlags |= PUBLIC;
97             mFlags &= ~PROTECTED & ~PRIVATE;
98         }
99         else {
100             mFlags &= ~PUBLIC;
101         }
102     }
103     
104     public boolean isPrivate() {
105         return isPrivate(mFlags);
106     }
107
108     /**
109      * When set private, it is cleared from being public or protected.
110      */

111     public void setPrivate(boolean value) {
112         if (value) {
113             mFlags |= PRIVATE;
114             mFlags &= ~PUBLIC & ~PROTECTED;
115         }
116         else {
117             mFlags &= ~PRIVATE;
118         }
119     }
120
121     public boolean isProtected() {
122         return isProtected(mFlags);
123     }
124     
125     /**
126      * When set protected, it is cleared from being public or private.
127      */

128     public void setProtected(boolean value) {
129         if (value) {
130             mFlags |= PROTECTED;
131             mFlags &= ~PUBLIC & ~PRIVATE;
132         }
133         else {
134             mFlags &= ~PROTECTED;
135         }
136     }
137     
138     public boolean isStatic() {
139         return isStatic(mFlags);
140     }
141
142     public void setStatic(boolean value) {
143         if (value) {
144             mFlags |= STATIC;
145         }
146         else {
147             mFlags &= ~STATIC;
148         }
149     }
150
151     public boolean isFinal() {
152         return isFinal(mFlags);
153     }
154
155     /**
156      * When set final, it is cleared from being an interface or abstract.
157      */

158     public void setFinal(boolean value) {
159         if (value) {
160             mFlags |= FINAL;
161             mFlags &= ~INTERFACE & ~ABSTRACT;
162         }
163         else {
164             mFlags &= ~FINAL;
165         }
166     }
167     
168     public boolean isSynchronized() {
169         return isSynchronized(mFlags);
170     }
171
172     public void setSynchronized(boolean value) {
173         if (value) {
174             mFlags |= SYNCHRONIZED;
175         }
176         else {
177             mFlags &= ~SYNCHRONIZED;
178         }
179     }
180     
181     public boolean isVolatile() {
182         return isVolatile(mFlags);
183     }
184
185     public void setVolatile(boolean value) {
186         if (value) {
187             mFlags |= VOLATILE;
188         }
189         else {
190             mFlags &= ~VOLATILE;
191         }
192     }
193     
194     public boolean isTransient() {
195         return isTransient(mFlags);
196     }
197
198     public void setTransient(boolean value) {
199         if (value) {
200             mFlags |= TRANSIENT;
201         }
202         else {
203             mFlags &= ~TRANSIENT;
204         }
205     }
206     
207     public boolean isNative() {
208         return isNative(mFlags);
209     }
210
211     public void setNative(boolean value) {
212         if (value) {
213             mFlags |= NATIVE;
214         }
215         else {
216             mFlags &= ~NATIVE;
217         }
218     }
219     
220     public boolean isInterface() {
221         return isInterface(mFlags);
222     }
223
224     /**
225      * When set as an interface, it is cleared from being final and set as
226      * being abstract.
227      */

228     public void setInterface(boolean value) {
229         if (value) {
230             mFlags |= INTERFACE | ABSTRACT;
231             mFlags &= ~FINAL;
232         }
233         else {
234             mFlags &= ~INTERFACE;
235         }
236     }
237     
238     public boolean isAbstract() {
239         return isAbstract(mFlags);
240     }
241
242     /**
243      * When set abstract, it is cleared from being final. When cleared from
244      * being abstract, it is also cleared from being an interface.
245      */

246     public void setAbstract(boolean value) {
247         if (value) {
248             mFlags |= ABSTRACT;
249             mFlags &= ~FINAL;
250         }
251         else {
252             mFlags &= ~ABSTRACT & ~INTERFACE;
253         }
254     }
255
256     public Object JavaDoc clone() {
257         try {
258             return super.clone();
259         }
260         catch (CloneNotSupportedException JavaDoc e) {
261             throw new InternalError JavaDoc(e.toString());
262         }
263     }
264     
265     /**
266      * Returns the string value generated by the Modifier class.
267      * @see java.lang.reflect.Modifier#toString()
268      */

269     public String JavaDoc toString() {
270         return toString(mFlags);
271     }
272 }
273
Popular Tags