/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.speedo.generation.mivisitor;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.metadata.SpeedoField;
import org.objectweb.speedo.metadata.SpeedoMap;
import org.objectweb.speedo.metadata.SpeedoCollection;
import org.objectweb.speedo.metadata.SpeedoClass;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.jorm.type.api.PTypeSpace;
import org.objectweb.jorm.type.api.PType;
/**
* When the user specifies short names of java.lang.* classes, the values are
* replaced with the fully qualified name.
* String ==> java.lang.String
*
* @author S.Chassande-Barrioz
*/
public class JavaLangShorcutVisitor extends AbstractMetaInfoVisitor {
private final static String[][] STN2FQTN = {
{"Object", "java.lang.Object"},
{"Date", "java.util.Date"},
{"Locale", "java.util.Locale"},
{"String", "java.lang.String"},
{"Integer", "java.lang.Integer"}
};
public JavaLangShorcutVisitor(Personality p) {
super(p);
}
protected String getLoggerName() {
return super.getLoggerName() +".javalang";
}
public void visitClass(SpeedoClass sc) throws SpeedoException {
super.visitClass(sc);
if (sc.identity.objectidClass != null) {
int idx = sc.identity.objectidClass.indexOf('.');
if (idx == -1) {
sc.identity.objectidClass = sc.moPackage.name + '.' + sc.identity.objectidClass;
}
}
}
public void visitField(SpeedoField sf) throws SpeedoException {
super.visitField(sf);
if (sf.jdoTuple instanceof SpeedoMap) {
SpeedoMap sm = (SpeedoMap) sf.jdoTuple;
sm.keyType = toJavaFQN((String) sm.keyType);
sm.valueType = toJavaFQN((String) sm.valueType);
} else if (sf.jdoTuple instanceof SpeedoCollection) {
SpeedoCollection sc = (SpeedoCollection) sf.jdoTuple;
sc.elementType = toJavaFQN((String) sc.elementType);
}
}
private static String toJavaFQN(String name) {
for(int i=0; i<STN2FQTN.length; i++) {
if (STN2FQTN[i][0].equals(name)) {
return STN2FQTN[i][1];
}
}
for (int i = 0; i < PTypeSpace.PREDEFINEDPTYPES.length; i++) {
PType ptype = PTypeSpace.PREDEFINEDPTYPES[i];
if (ptype.getJavaName().equals(name)
|| ptype.getJormName().equals(name)) {
return ptype.getJavaName();
}
}
return name;
}
}