KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > tools > OPP > srcgen > ClassBuilder


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: ClassBuilder.java,v 1.2 2003/11/07 21:34:22 per_nyfelt Exp $
8
package org.ozoneDB.tools.OPP.srcgen;
9
10 import org.ozoneDB.tools.OPP.srcgen.BuilderException;
11 import org.ozoneDB.tools.OPP.message.MessageWriter;
12
13 import java.lang.reflect.Modifier JavaDoc;
14
15 /**
16  * The builder part of the builder director pattern.
17  *
18  * Provides a common interface for building class related structures.
19  * ClassBuilders are commonly used together with a ClassDirector. <br>
20  * This nicely separates the concerns of what is being built and what
21  * the source of directions is.
22  * @see ClassDirector
23  * @author Joakim Ohlrogge
24  */

25 public interface ClassBuilder {
26     /**
27      * Represents a parameter. Contains information about the type, the name and
28      * the modifiers for the parameter. There is no control wheather the modifiers
29      * given are valid for a parameter.
30      *
31      * @see java.lang.reflect.Modifier
32      */

33     public class Parameter {
34         private String JavaDoc type;
35         private String JavaDoc name;
36         private String JavaDoc origName;
37         private int modifier;
38
39         public String JavaDoc getType() {
40             return type;
41         }
42
43         public String JavaDoc getName() {
44             return name;
45         }
46
47         /**
48          * @see java.lang.reflect.Modifier
49          * @return the integer value representing the modifiers
50          */

51         public int getModifier() {
52             return modifier;
53         }
54
55         /**
56          * The original string representation of the parameter.
57          * Dirty hack, will have to reconsider some design descisions...
58          */

59         public String JavaDoc getOrigTypeName() {
60             return origName;
61         }
62
63         /**
64          *
65          * @param type The type of the parameter
66          * @param name The parameter name
67          * @param modifier The integer value representing the parameters modifiers
68          * @see java.lang.reflect.Modifier
69          */

70         public Parameter(String JavaDoc type, String JavaDoc name, String JavaDoc origName, int modifier) {
71             this.type = type;
72             this.name = name;
73             this.modifier = modifier;
74             this.origName = origName;
75         }
76
77         public String JavaDoc toString() {
78             return (Modifier.toString(modifier) + " " + type + " " + name);
79         }
80     }
81
82     /**
83      * Initializes the builder for each new build. This method may be called several times during the lifetime of the
84      * builder but only once for each build. This method may be used reset any internal state that the builder may have.
85      *
86      * @param msgWriter The writer the builder should use to report messages.
87      */

88     void init(MessageWriter msgWriter);
89
90     /**
91      * Called for each new class. May be called moore than once if the class has inner classes.
92      *
93      * @param modifier The modifiers for this class
94      * @param fullName The full name including package path of this class
95      * @param superClass The full name including package pathh for this class
96      * @param interfaces The interfaces implemented by this class
97      */

98     void beginClass(int modifier, final String JavaDoc fullName, String JavaDoc superClass, String JavaDoc interfaces[]) throws BuilderException;
99
100     /**
101      * Called for each constructor in the current class
102      * @param modifier The modifier for this constructor
103      * @param parameters The parameters for this constructor
104      * @param exceptions The exceptions thrown by this constructor
105      */

106     void makeConstructor(int modifier, Parameter parameters[], String JavaDoc exceptions[]) throws BuilderException;
107
108     /**
109      * Called for each method in the current class
110      * @param modifier The modifiers for the method
111      * @param name The name of the method
112      * @param parameters The parameter list for the method
113      * @param returnType The return type of the method, use null for void
114      * @param exceptions The exceptions thrown by the method
115      * @param lockLevel The lock level for this method
116      */

117     void makeMethod(int modifier, String JavaDoc name, Parameter parameters[], String JavaDoc returnType, String JavaDoc exceptions[], int lockLevel) throws BuilderException;
118
119     /**
120      * Called at the end of each generated class.
121      * Must be called once and once only for each beginClass.
122      */

123     void endClass() throws BuilderException;
124 }
125
Popular Tags