KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2003-2004 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 import java.util.Iterator JavaDoc;
24
25 /**
26  * rtti.acc generation plugin
27  */

28
29 public class RttiPlugin extends AbstractPlugin {
30
31     public void genConfig(Writer JavaDoc output, Project project)
32         throws IOException JavaDoc
33     {
34         // Generate "extended" types
35
Iterator JavaDoc enums = Projects.types.getExtendedTypes().iterator();
36         while (enums.hasNext()) {
37             ExtendedType extended = (ExtendedType)enums.next();
38             output.write("newVirtualClass "+extended.getName()+" "+
39                          extended.getRealType().getGenerationFullName()+";\n");
40         }
41
42         super.genConfig(output,project);
43     }
44
45     public void genFieldConfig(Writer JavaDoc output, Project project,
46                                Package JavaDoc pkg, Class JavaDoc cl, Field field)
47         throws IOException JavaDoc
48     {
49         if (field.isCalculated()) {
50             Getter getter = field.getGetter();
51             if (getter!=null) {
52                 state.openField(cl,field);
53                 output.write(" declareCalculatedField "+
54                              getter.getGenerationName()+";\n");
55             } else {
56                 System.err.println("Calculated field "+field.getFullName()+
57                                    " does not have a getter");
58             }
59             Setter setter = field.getSetter();
60             if (setter!=null) {
61                 state.openField(cl,field);
62                 output.write(" setSetter "+
63                              setter.getGenerationName()+";\n");
64             }
65         }
66         if (field.getType() instanceof ExtendedType) {
67             state.openField(cl,field);
68             output.write(" setFieldType "+
69                          field.getType().getName()+";\n");
70         }
71     }
72
73     public void genRoleConfig(Writer JavaDoc output, Project project,
74                               Package JavaDoc pkg, Class JavaDoc cl, RelationRole role)
75         throws IOException JavaDoc
76     {
77         // Repositories
78
String JavaDoc name = role.getGenerationName();
79         if (role.getEnd() instanceof Repository) {
80             Repository rep = (Repository)role.getEnd();
81             RelationRole itemsRole = (RelationRole)role.oppositeRole();
82             if (itemsRole!=null) {
83                 state.openClass(cl);
84                 output.write(
85                     " defineRepository \""+rep.getGenerationName().toLowerCase()+"#0\" "+
86                     itemsRole.getGenerationFullName()+";\n");
87             }
88             
89         }
90
91         // associations
92
if (role instanceof RelationRole) {
93             RelationRole relRole = (RelationRole)role;
94             if (((RelationLink)relRole.getLink()).getOrientation()
95                 == RelationLink.ORIENTATION_BOTH
96                 && relRole.getLink().getStartRole()==relRole)
97             {
98                 RelationRole opposite = (RelationRole)relRole.oppositeRole();
99                 state.openRole(cl,role);
100                 output.write(" declareAssociation "+
101                              opposite.getGenerationFullName()+";\n");
102             }
103         }
104
105         if (role.isNavigable()) {
106             RelationLink link = (RelationLink)role.getLink();
107             if (link.isCalculated()) {
108                 Method getter = role.getGetter();
109                 if (getter!=null) {
110                     state.openRole(cl,role);
111                     output.write(" declareCalculatedField "+
112                                  role.getGetter().getGenerationName()+";\n");
113                 } else {
114                     System.err.println("Calculated role "+role.getFullName()+
115                                        " does not have a getter");
116                 }
117                 state.openRole(cl,role);
118                 output.write(" setComponentType "+role.getEnd().getGenerationFullName()+";\n");
119             }
120             state.openRole(cl,role);
121             output.write(" setAggregation "+link.isAggregation()+";\n");
122             if (!role.isMultiple() && role.getCardinality().startsWith("0")) {
123                 state.openRole(cl,role);
124                 output.write(" setNullAllowed;\n");
125             }
126             Typed index = role.getPrimaryKey();
127             if (index!=null) {
128                 state.openRole(cl,role);
129                 output.write(" setIndexedField "+
130                              index.getGenerationFullName()+";\n");
131                 output.write(" setRemover "+role.getRemoverName()+";\n");
132             }
133         }
134     }
135
136 }
137
Popular Tags