01: /**
02: * Copyright (C) 2001-2004 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * 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: */package org.objectweb.speedo.generation.mivisitor;
18:
19: import org.objectweb.speedo.lib.Personality;
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: private final static String[][] STN2FQTN = {
37: { "Object", "java.lang.Object" },
38: { "Date", "java.util.Date" },
39: { "Locale", "java.util.Locale" },
40: { "String", "java.lang.String" },
41: { "Integer", "java.lang.Integer" } };
42:
43: public JavaLangShorcutVisitor(Personality p) {
44: super (p);
45: }
46:
47: protected String getLoggerName() {
48: return super .getLoggerName() + ".javalang";
49: }
50:
51: public void visitClass(SpeedoClass sc) throws SpeedoException {
52: super .visitClass(sc);
53: if (sc.identity.objectidClass != null) {
54: int idx = sc.identity.objectidClass.indexOf('.');
55: if (idx == -1) {
56: sc.identity.objectidClass = sc.moPackage.name + '.'
57: + sc.identity.objectidClass;
58: }
59: }
60: }
61:
62: public void visitField(SpeedoField sf) throws SpeedoException {
63: super .visitField(sf);
64:
65: if (sf.jdoTuple instanceof SpeedoMap) {
66: SpeedoMap sm = (SpeedoMap) sf.jdoTuple;
67: sm.keyType = toJavaFQN((String) sm.keyType);
68: sm.valueType = toJavaFQN((String) sm.valueType);
69: } else if (sf.jdoTuple instanceof SpeedoCollection) {
70: SpeedoCollection sc = (SpeedoCollection) sf.jdoTuple;
71: sc.elementType = toJavaFQN((String) sc.elementType);
72: }
73: }
74:
75: private static String toJavaFQN(String name) {
76: for (int i = 0; i < STN2FQTN.length; i++) {
77: if (STN2FQTN[i][0].equals(name)) {
78: return STN2FQTN[i][1];
79: }
80: }
81: for (int i = 0; i < PTypeSpace.PREDEFINEDPTYPES.length; i++) {
82: PType ptype = PTypeSpace.PREDEFINEDPTYPES[i];
83: if (ptype.getJavaName().equals(name)
84: || ptype.getJormName().equals(name)) {
85: return ptype.getJavaName();
86: }
87: }
88: return name;
89: }
90: }
|