KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > mivisitor > VersionFieldAdder


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * 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  */

18 package org.objectweb.speedo.generation.mivisitor;
19
20 import org.objectweb.asm.Constants;
21 import org.objectweb.speedo.api.SpeedoException;
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 void visitClass(SpeedoClass sc) throws SpeedoException {
35         if(sc.version != null){
36             if(logger != null ){
37                 logger.log(BasicLevel.DEBUG, "VersionFieldAdder.visitClass(" + sc.getFQName() + ")");
38                 logger.log(BasicLevel.DEBUG, "Class " + sc.getFQName() + ": version: " + SpeedoVersion.toString(sc.version.strategy));
39             }
40             //if a version strategy has been defined
41
if (sc.version.strategy != SpeedoVersion.NO_VERSION) {
42                 //create a speedofield
43
SpeedoField sf = new SpeedoField();
44                 sf.access = Constants.ACC_PUBLIC;
45                 sf.name = "speedo" + SpeedoVersion.toString(sc.version.strategy);
46                 // equivalent for long in ASM
47
sf.desc = "J";
48                 //create a speedo extension for the sql name
49
SpeedoExtension se = new SpeedoExtension("speedo","sql-name", sf.name.toUpperCase(), sf);
50                 sf.addExtension(se);
51                 sc.add(sf, true, logger);
52             }
53         }
54         super.visitClass(sc);
55     }
56 }
Popular Tags