KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > services > compiler > ClassBuilder


1 /*
2
3    Derby - Class org.apache.derby.iapi.services.compiler.ClassBuilder
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.services.compiler;
23
24 import org.apache.derby.iapi.services.loader.GeneratedClass;
25 import org.apache.derby.iapi.error.StandardException;
26 import org.apache.derby.iapi.util.ByteArray;
27
28 /**
29  * ClassBuilder is used to construct a java class's byte array
30  * representation.
31  *
32  * Limitations:
33  * No checking for language use violations such as invalid modifiers
34  * or duplicate field names.
35  * All classes must have a superclass; java.lang.Object must be
36  * supplied if there is no superclass.
37  *
38  * <p>
39  * When a class is first created, it has:
40  * <ul>
41  * <li> a superclass
42  * <li> modifiers
43  * <li> a name
44  * <li> a package
45  * <li> no superinterfaces, methods, fields, or constructors
46  * <li> an empty static initializer
47  * </ul>
48  * <p>
49  * MethodBuilder implementations are required to get code out of the
50  * constructs within their bodies in some manner.
51  * Most typically, they may have a stream to which the statement and
52  * expression constructs write the code that they represent,
53  * and they walk over the statements and expressions in the appropriate order.
54  *
55  * @author ames
56  */

57 public interface ClassBuilder {
58
59     /**
60      * add a field to this class. Fields cannot
61      * be initialized here, they must be initialized
62      * in the static initializer code (static fields)
63      * or in the constructors.
64      * <p>
65      * Methods are added when they are created with the JavaFactory.
66      * @param type The type of the field in java language.
67      * @param name The name of the field.
68      * @param modifiers The | of the modifier values such as
69      * public, static, etc.
70      * @see ClassBuilder#newMethodBuilder
71      * @see #newConstructorBuilder
72      */

73     LocalField addField(String JavaDoc type, String JavaDoc name, int modifiers);
74
75     /**
76         Fully create the bytecode and load the
77         class using the ClassBuilder's ClassFactory.
78
79         @exception StandardException Standard Cloudscape policy
80     */

81     GeneratedClass getGeneratedClass() throws StandardException;
82
83     /**
84      * At the time the class is completed and bytecode
85      * generated, if there are no constructors then
86      * the default no-arg constructor will be defined.
87      */

88     ByteArray getClassBytecode() throws StandardException;
89
90     /**
91      * the class's unqualified name
92      */

93     String JavaDoc getName();
94
95     /**
96      * the class's qualified name
97      */

98     String JavaDoc getFullName();
99
100     /**
101      * a method. Once it is created, parameters, thrown
102      * exceptions, statements, and local variable declarations
103      * must be added to it. It is put into its defining class
104      * when it is created.
105      * <verbatim>
106        Java: #modifiers #returnType #methodName() {}
107             // modifiers is the | of the JVM constants for
108             // the modifiers such as static, public, etc.
109        </verbatim>
110        <p>
111      * This is used to start a constructor as well; pass in
112      * null for the returnType when used in that manner.
113      *
114      * @param modifiers the | of the Modifier
115      * constants representing the visibility and control of this
116      * method.
117      * @param returnType the return type of the method as its
118      * Java language type name.
119      * @param methodName the name of the method.
120      *
121      * @return the method builder.
122      * @see java.lang.reflect.Modifier
123      */

124     MethodBuilder newMethodBuilder(int modifiers, String JavaDoc returnType,
125         String JavaDoc methodName);
126     
127     /**
128      * a method with parameters. Once it is created, thrown
129      * exceptions, statements, and local variable declarations
130      * must be added to it. It is put into its defining class
131      * when it is created.
132      * <verbatim>
133        Java: #modifiers #returnType #methodName() {}
134             // modifiers is the | of the JVM constants for
135             // the modifiers such as static, public, etc.
136        </verbatim>
137        <p>
138      * This is used to start a constructor as well; pass in
139      * null for the returnType when used in that manner.
140      *
141      * @param modifiers the | of the Modifier
142      * constants representing the visibility and control of this
143      * method.
144      * @param returnType the return type of the method as its
145      * Java language type name.
146      * @param methodName the name of the method.
147      * @param parms an array of String representing the
148      * method's parameter types
149      *
150      * @return the method builder.
151      * @see java.lang.reflect.Modifier
152      */

153     MethodBuilder newMethodBuilder(int modifiers, String JavaDoc returnType,
154         String JavaDoc methodName, String JavaDoc[] parms);
155
156     /**
157      * a constructor. Once it is created, parameters, thrown
158      * exceptions, statements, and local variable declarations
159      * must be added to it. It is put into its defining class
160      * when it is created.
161      * <verbatim>
162        Java: #modifiers #className() {}
163             // modifiers is the | of the JVM constants for
164             // the modifiers such as static, public, etc.
165             // className is taken from definingClass.name()
166        </verbatim>
167      * <p>
168      * This is used to start a constructor as well; pass in
169      * null for the returnType when used in that manner.
170      *
171      * @param modifiers the | of the Modifier
172      * constants representing the visibility and control of this
173      * method.
174      *
175      * @return the method builder for the constructor.
176      * @see java.lang.reflect.Modifier
177      */

178     MethodBuilder newConstructorBuilder(int modifiers);
179
180     /**
181         Create a new private field and its getter and setter methods.
182
183         @param getter getter for field
184         @param setter setter for field
185         @param methodModifier modifier for method
186         @param staticField true if the field is static
187         @param type type of the field, return type of the get method and
188         parameter type of the set method.
189
190     */

191     void newFieldWithAccessors(String JavaDoc getter, String JavaDoc setter, int methodModifier,
192         boolean staticField, String JavaDoc type);
193 }
194
Popular Tags