KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > codegen > JavaModifiers


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: JavaModifiers.java,v 1.1.1.1 2003/03/10 16:36:19 taweili Exp $
22  */

23
24 package org.enhydra.xml.xmlc.codegen;
25
26 /**
27  * Definitions of Java modifiers for methods, fields and classes.
28  */

29 public class JavaModifiers {
30     /**
31      * Public access modifier flag.
32      */

33     public static int PUBLIC = 0x01;
34
35     /**
36      * Protected access modifier flag.
37      */

38     public static int PROTECTED = 0x02;
39
40     /**
41      * Private access modifier flag.
42      */

43     public static int PRIVATE = 0x04;
44
45     /**
46      * Class scope modifier flag.
47      */

48     public static int STATIC = 0x08;
49
50     /**
51      * Unmodifiable scope modifier flag.
52      */

53     public static int FINAL = 0x10;
54
55     /**
56      * Abstract modifier flag.
57      */

58     public static int ABSTRACT = 0x20;
59
60     /**
61      * Don't include field or method in implementation if generating
62      * an interface and an implementation.
63      */

64     public static int OMIT_IMPLEMENTATION = 0x40;
65
66     /**
67      * Don't include field or method in interface if generating
68      * an interface and an implementation.
69      */

70     public static int OMIT_INTERFACE = 0x80;
71
72     /**
73      * Common modifiers for public constants. Shorthand for
74      * PUBLIC | STATIC | FINAL.
75      */

76     public static int PUBLIC_CONST = PUBLIC | STATIC | FINAL;
77
78     /**
79      * Common modifiers for private constants. Shorthand for
80      * PRIVATE | STATIC | FINAL.
81      */

82     public static int PRIVATE_CONST = PRIVATE | STATIC | FINAL;
83
84     /**
85      * Prevent instantiation.
86      */

87     private JavaModifiers() {
88     }
89
90     /**
91      * Convert a modifier set to a string prefix for a declaration.
92      * The result includes a trailing blank if modifier is included.
93      */

94     public static String JavaDoc toDecl(int modifiers) {
95         if (modifiers == 0) {
96             // Optimize for no modifiers.
97
return "";
98         }
99
100         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
101         if ((modifiers & PUBLIC) != 0) {
102             str.append("public");
103             str.append(' ');
104         }
105         if ((modifiers & PROTECTED) != 0) {
106             str.append("protected");
107             str.append(' ');
108         }
109         if ((modifiers & PRIVATE) != 0) {
110             str.append("private");
111             str.append(' ');
112         }
113         if ((modifiers & STATIC) != 0) {
114             str.append("static");
115             str.append(' ');
116         }
117         if ((modifiers & FINAL) != 0) {
118             str.append("final");
119             str.append(' ');
120         }
121         if ((modifiers & ABSTRACT) != 0) {
122             str.append("abstract");
123             str.append(' ');
124         }
125         return str.toString();
126     }
127 }
128
129
Popular Tags