KickJava   Java API By Example, From Geeks To Geeks.

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


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.speedo.metadata.SpeedoExtension;
21 import org.objectweb.speedo.metadata.SpeedoField;
22 import org.objectweb.speedo.metadata.SpeedoTuple;
23 import org.objectweb.speedo.api.SpeedoException;
24 import org.objectweb.util.monolog.api.BasicLevel;
25
26 /**
27  * Copies all extensions defined on tuple node, into the field node.
28  *
29  * @author S.Chassande-Barrioz
30  */

31 public class TupleExtensionCopier extends AbstractMetaInfoVisitor {
32
33     public TupleExtensionCopier() {
34     }
35
36     public TupleExtensionCopier(MetaInfoVisitor mim) {
37         super(mim);
38     }
39
40     protected String JavaDoc getLoggerName() {
41         return LOGGER_NAME + ".tupleExtensionCopier";
42     }
43
44     public void visitExtension(SpeedoExtension se) throws SpeedoException {
45         debug = logger.isLoggable(BasicLevel.DEBUG);
46         if (se.jdoElement instanceof SpeedoTuple) {
47             SpeedoField sf = ((SpeedoTuple) se.jdoElement).jdoField;
48             SpeedoExtension oldse = sf.getExtensionByKey(se.key);
49             if (oldse != null) {
50                 //The extension already exist on the SpeedoField
51
if ((se.value == null && oldse.value!= null)
52                     || se.value != null && !se.value.equals(oldse.value)) {
53                     //different value ==> exception
54
throw new SpeedoException(
55                         "Duplicate extension declaration without the same value: extension name='"
56                         + se.key + "', field name='" + sf.name
57                         + "' in the class '" + sf.jdoClass.getFQName()
58                         + "' in the jdo file " + sf.jdoClass.getJDOFileName()
59                         + "'");
60                 }
61             } else { //The extension does not exist on the field
62
se.jdoElement.addExtension(se);
63             }
64         }
65         super.visitExtension(se);
66     }
67 }
68
Popular Tags