/**
* 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.asm.Constants;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.metadata.SpeedoClass;
import org.objectweb.speedo.metadata.SpeedoExtension;
import org.objectweb.speedo.metadata.SpeedoField;
import org.objectweb.speedo.metadata.SpeedoVersion;
import org.objectweb.util.monolog.api.BasicLevel;
/**
* This class adds the field version to the speedo class if the versioning strategy is not null.
* @author Y.Bersihand
*/
public class VersionFieldAdder extends AbstractMetaInfoVisitor {
public VersionFieldAdder(Personality p) {
super(p);
}
public void visitClass(SpeedoClass sc) throws SpeedoException {
if(sc.version != null){
if(logger != null ){
logger.log(BasicLevel.DEBUG, "VersionFieldAdder.visitClass(" + sc.getFQName() + ")");
logger.log(BasicLevel.DEBUG, "Class " + sc.getFQName() + ": version: " + SpeedoVersion.toString(sc.version.strategy));
}
//if a version strategy has been defined
if (sc.version.strategy != SpeedoVersion.NO_VERSION) {
//create a speedofield
SpeedoField sf = new SpeedoField();
sf.visibility = Constants.ACC_PUBLIC;
sf.name = "speedo" + SpeedoVersion.toString(sc.version.strategy);
// equivalent for long in ASM
sf.type = "J";
//create a speedo extension for the sql name
SpeedoExtension se = new SpeedoExtension("speedo","sql-name", sf.name.toUpperCase(), sf);
sf.addExtension(se);
sc.add(sf, true, logger);
}
}
super.visitClass(sc);
}
}