KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > mivisitor > JavaLangShorcutVisitor


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * 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 library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.generation.mivisitor;
19
20 import org.objectweb.speedo.metadata.SpeedoField;
21 import org.objectweb.speedo.metadata.SpeedoMap;
22 import org.objectweb.speedo.metadata.SpeedoCollection;
23 import org.objectweb.speedo.metadata.SpeedoClass;
24 import org.objectweb.speedo.api.SpeedoException;
25 import org.objectweb.jorm.type.api.PTypeSpace;
26 import org.objectweb.jorm.type.api.PType;
27
28 /**
29  * When the user specifies short names of java.lang.* classes, the values are
30  * replaced with the fully qualified name.
31  * String ==> java.lang.String
32  *
33  * @author S.Chassande-Barrioz
34  */

35 public class JavaLangShorcutVisitor extends AbstractMetaInfoVisitor {
36
37     private final static String JavaDoc[][] STN2FQTN = {
38         {"Object", "java.lang.Object"},
39         {"Date", "java.util.Date"},
40         {"Locale", "java.util.Locale"},
41         {"String", "java.lang.String"},
42         {"Integer", "java.lang.Integer"}
43     };
44
45     protected String JavaDoc getLoggerName() {
46         return super.getLoggerName() +".javalang";
47     }
48
49     public void visitClass(SpeedoClass sc) throws SpeedoException {
50         super.visitClass(sc);
51         if (sc.objectidClass != null) {
52             int idx = sc.objectidClass.indexOf('.');
53             if (idx == -1) {
54                 sc.objectidClass = sc.jdoPackage.name + '.' + sc.objectidClass;
55             }
56         }
57     }
58
59     public void visitField(SpeedoField sf) throws SpeedoException {
60         super.visitField(sf);
61
62         if (sf.jdoTuple instanceof SpeedoMap) {
63             SpeedoMap sm = (SpeedoMap) sf.jdoTuple;
64             sm.keyType = toJavaFQN((String JavaDoc) sm.keyType);
65             sm.valueType = toJavaFQN((String JavaDoc) sm.valueType);
66         } else if (sf.jdoTuple instanceof SpeedoCollection) {
67             SpeedoCollection sc = (SpeedoCollection) sf.jdoTuple;
68             sc.elementType = toJavaFQN((String JavaDoc) sc.elementType);
69         }
70     }
71
72     private static String JavaDoc toJavaFQN(String JavaDoc name) {
73         for(int i=0; i<STN2FQTN.length; i++) {
74             if (STN2FQTN[i][0].equals(name)) {
75                 return STN2FQTN[i][1];
76             }
77         }
78         for (int i = 0; i < PTypeSpace.PREDEFINEDPTYPES.length; i++) {
79             PType ptype = PTypeSpace.PREDEFINEDPTYPES[i];
80             if (ptype.getJavaName().equals(name)
81                 || ptype.getJormName().equals(name)) {
82                 return ptype.getJavaName();
83             }
84         }
85         return name;
86     }
87 }
88
Popular Tags