KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > AccGenState


1 /*
2   Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.ide;
20
21 import java.io.IOException JavaDoc;
22 import java.io.Writer JavaDoc;
23
24 /**
25  * Generation state for acc configuration code genaration. It
26  * memorizes if a class or attribute block is opened or not.
27  */

28 public class AccGenState {
29    /** Is a "class" block opened ? */
30    boolean classOpened = false;
31    /** Is an "attribute" block opened ? */
32    boolean fieldOpened = false;
33    Writer JavaDoc output;
34
35    public AccGenState(Writer JavaDoc output) {
36       this.output = output;
37    }
38
39    /**
40     * Start a "class" block
41     */

42    void openClass(Class JavaDoc cl)
43       throws IOException JavaDoc
44    {
45       if (!classOpened) {
46          output.write("class "+cl.getGenerationFullName()+" {\n");
47          classOpened = true;
48       }
49    }
50    /**
51     * End a "class" block if any
52     */

53    void closeClass()
54       throws IOException JavaDoc
55    {
56       if (classOpened) {
57          classOpened = false;
58          write("}\n");
59       }
60    }
61
62    /**
63     * Start a "attribute" block
64     */

65    void openField(Class JavaDoc cl, Field field)
66       throws IOException JavaDoc
67    {
68       openClass(cl);
69       if (!fieldOpened) {
70          write("attribute "+field.getGenerationName()+" {\n");
71          fieldOpened = true;
72       }
73    }
74
75    /**
76     * Start a "attribute" block
77     */

78    void openRole(Class JavaDoc cl, RelationRole role)
79       throws IOException JavaDoc
80    {
81       openClass(cl);
82       if (!fieldOpened) {
83          write("attribute "+role.getGenerationName()+" {\n");
84          fieldOpened = true;
85       }
86    }
87
88    /**
89     * Start a "attribute" block
90     */

91    void openMethod(Class JavaDoc cl, Method method)
92       throws IOException JavaDoc
93    {
94       openClass(cl);
95       if (!fieldOpened) {
96          write("method \""+method.getUniqueName()+"\" {\n");
97          fieldOpened = true;
98       }
99    }
100    /**
101     * End a "attribute" block if any
102     */

103    void closeMember()
104       throws IOException JavaDoc
105    {
106       if (fieldOpened) {
107          fieldOpened = false;
108          write("}\n");
109       }
110    }
111
112    /**
113     * Write some text to output with correct indentation
114     * @param text text to write to output
115     */

116    void write(String JavaDoc text) throws IOException JavaDoc {
117       if (classOpened)
118          output.write(" ");
119       if (fieldOpened)
120          output.write(" ");
121       output.write(text);
122    }
123 }
124
Popular Tags