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.asm.Constants;
20: import org.objectweb.speedo.api.SpeedoException;
21: import org.objectweb.speedo.lib.Personality;
22: import org.objectweb.speedo.metadata.SpeedoClass;
23: import org.objectweb.speedo.metadata.SpeedoExtension;
24: import org.objectweb.speedo.metadata.SpeedoField;
25: import org.objectweb.speedo.metadata.SpeedoVersion;
26: import org.objectweb.util.monolog.api.BasicLevel;
27:
28: /**
29: * This class adds the field version to the speedo class if the versioning strategy is not null.
30: * @author Y.Bersihand
31: */
32: public class VersionFieldAdder extends AbstractMetaInfoVisitor {
33:
34: public VersionFieldAdder(Personality p) {
35: super (p);
36: }
37:
38: public void visitClass(SpeedoClass sc) throws SpeedoException {
39: if (sc.version != null) {
40: if (logger != null) {
41: logger.log(BasicLevel.DEBUG,
42: "VersionFieldAdder.visitClass("
43: + sc.getFQName() + ")");
44: logger.log(BasicLevel.DEBUG, "Class " + sc.getFQName()
45: + ": version: "
46: + SpeedoVersion.toString(sc.version.strategy));
47: }
48: //if a version strategy has been defined
49: if (sc.version.strategy != SpeedoVersion.NO_VERSION) {
50: //create a speedofield
51: SpeedoField sf = new SpeedoField();
52: sf.visibility = Constants.ACC_PUBLIC;
53: sf.name = "speedo"
54: + SpeedoVersion.toString(sc.version.strategy);
55: // equivalent for long in ASM
56: sf.type = "J";
57: //create a speedo extension for the sql name
58: SpeedoExtension se = new SpeedoExtension("speedo",
59: "sql-name", sf.name.toUpperCase(), sf);
60: sf.addExtension(se);
61: sc.add(sf, true, logger);
62: }
63: }
64: super.visitClass(sc);
65: }
66: }
|