/**
* 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.SpeedoExtension;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.speedo.api.SpeedoProperties;
import org.objectweb.util.monolog.api.BasicLevel;
/**
* Add extensions FIELD_CONVERTER for various type:
* - java.sql.*
* - java.util.Locale
*
* @author S.Chassande-Barrioz
*/
public class FieldConverterVisitor extends AbstractMetaInfoVisitor {
public FieldConverterVisitor(Personality p) {
super(p);
}
protected String getLoggerName() {
return super.getLoggerName() + ".fieldconverter";
}
public void visitField(SpeedoField sf) throws SpeedoException {
super.visitField(sf);
if (sf.type.startsWith("Ljava/sql/")) {
SpeedoExtension se = new SpeedoExtension();
se.vendorName = SpeedoProperties.VENDOR_NAME;
se.key = SpeedoProperties.FIELD_CONVERTER;
se.value = "org.objectweb.speedo.lib.Sql";
se.value += sf.type.substring(10, sf.type.length()-1);
se.value += "FieldMapping";
logger.log(BasicLevel.DEBUG, "Use the converter '" + se.value
+ "' for the field '" + sf.name + "'");
sf.addExtension(se);
} else if (sf.type.startsWith("Ljava/util/Locale")) {
SpeedoExtension se = new SpeedoExtension();
se.vendorName = SpeedoProperties.VENDOR_NAME;
se.key = SpeedoProperties.FIELD_CONVERTER;
se.value = "org.objectweb.speedo.lib.LocaleFieldMapping";
logger.log(BasicLevel.DEBUG, "Use the converter '" + se.value
+ "' for the field '" + sf.name + "'");
sf.addExtension(se);
}
}
}