KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.jac.core.rtti.NamingConventions;
22 import java.io.IOException;
23 import java.io.Writer;
24 import java.util.Iterator;
25
26 /**
27  * gui.acc generation plugin
28  */

29
30 public class GuiPlugin extends AbstractPlugin {
31
32     public void genConfig(Writer output, Project project)
33         throws IOException
34     {
35         // Generate enumerated types
36
Iterator enums = Projects.types.getEnumeratedTypes().iterator();
37         while (enums.hasNext()) {
38             EnumeratedType enum = (EnumeratedType)enums.next();
39             output.write("defineEnum "+enum.getName()+" { ");
40             Iterator names = enum.getNames().iterator();
41             while (names.hasNext()) {
42                 String name = (String)names.next();
43                 output.write("\""+name+"\"");
44                 if (names.hasNext())
45                     output.write(", ");
46             }
47             output.write("} "+enum.getStartValue()+" "+enum.getStep()+";\n");
48         }
49         super.genConfig(output,project);
50     }
51
52     public void genPackageConfig(Writer output,
53                                  Project project, Package pkg)
54         throws IOException
55     {
56         // Generate askForParameters
57
output.write("askForParameters "+pkg.getPPath()+".*;\n\n");
58         super.genPackageConfig(output,project,pkg);
59     }
60
61     public void genClassConfig(Writer output,
62                                Project project, Package pkg, Class cl)
63         throws IOException
64     {
65         // Generate default attributes order
66
state.openClass(cl);
67         if (!cl.getName().equals(cl.getGenerationName()))
68             state.write("setLabel \""+NamingConventions.textForName(cl.getName())+"\";\n");
69         state.write("setAttributesOrder {");
70         int count = 0;
71         Iterator fields = cl.getAllFields().iterator();
72         while (fields.hasNext()) {
73             Field field = (Field)fields.next();
74             if(field.isStatic()) continue;
75             if (count>0) {
76                 output.write(",");
77             }
78             output.write(field.getGenerationName());
79             count++;
80         }
81
82         Iterator roles = cl.getAllNavigableRoles().iterator();
83         while (roles.hasNext()) {
84             RelationRole role = (RelationRole)roles.next();
85             if (count>0) {
86                 output.write(",");
87             }
88             output.write(role.getGenerationName());
89             count++;
90         }
91         output.write("};\n");
92
93         super.genClassConfig(output,project,pkg,cl);
94       
95     }
96
97     public void genRoleConfig(Writer output, Project project,
98                               Package pkg, Class cl, RelationRole role)
99         throws IOException
100     {
101         if (role.isNavigable()) {
102             Class targetClass = (Class)role.getEnd();
103             if (!role.getName().equals(role.getGenerationName())) {
104                 state.openRole(cl,role);
105                 state.write("setLabel \""+
106                             NamingConventions.textForName(role.getRoleName())+"\";\n");
107             }
108             // Generate autoCreate for aggregations
109
if (role.isAggregation()) {
110                 state.openRole(cl,role);
111                 state.write("setAutoCreate;\n");
112             }
113         }
114     }
115
116     public void genFieldConfig(Writer output, Project project,
117                                Package pkg, Class cl, Field field)
118         throws IOException
119     {
120         if (!field.getName().equals(field.getGenerationName())) {
121             state.openField(cl,field);
122             state.write("setLabel \""+
123                         NamingConventions.textForName(field.getName())+"\";\n");
124         }
125         if (field.getType() instanceof EnumeratedType) {
126             state.openField(cl,field);
127             state.write("setFieldEnum "+
128                         ((EnumeratedType)field.getType()).getName()+";\n");
129         }
130         state.closeMember();
131     }
132
133     public void genMethodConfig(Writer output, Project project,
134                                 Package pkg, Class cl, Method method)
135         throws IOException
136     {
137         if (method.getVisibility()!=Visibility.PUBLIC)
138             return;
139         if (!method.getName().equals(method.getGenerationName())) {
140             state.openMethod(cl,method);
141             state.write("setLabel \""+
142                         NamingConventions.textForName(method.getName())+"\";\n");
143         }
144         // Generate method parameters names
145
if (method.getParameters().size()>0) {
146             state.openMethod(cl,method);
147             state.write("setParameterNames {");
148             Iterator it = method.getParameters().iterator();
149             while (it.hasNext()) {
150                 Parameter param = (Parameter)it.next();
151                 output.write("\""+param.getName()+"\"");
152                 if (it.hasNext()) {
153                     output.write(",");
154                 }
155             }
156             output.write("};\n");
157         }
158         state.closeMember();
159     }
160
161 }
162
Popular Tags