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.jdo;
18:
19: import org.objectweb.speedo.generation.mivisitor.AbstractMetaInfoVisitor;
20: import org.objectweb.speedo.generation.mivisitor.MetaInfoVisitor;
21: import org.objectweb.speedo.lib.Personality;
22: import org.objectweb.speedo.metadata.SpeedoExtension;
23: import org.objectweb.speedo.metadata.SpeedoField;
24: import org.objectweb.speedo.metadata.SpeedoTuple;
25: import org.objectweb.speedo.api.SpeedoException;
26: import org.objectweb.util.monolog.api.BasicLevel;
27:
28: /**
29: * Copies all extensions defined on tuple node, into the field node.
30: *
31: * @author S.Chassande-Barrioz
32: */
33: public class TupleExtensionCopier extends AbstractMetaInfoVisitor {
34:
35: public TupleExtensionCopier(Personality p) {
36: super (p);
37: }
38:
39: public TupleExtensionCopier(MetaInfoVisitor mim, Personality p) {
40: super (mim, p);
41: }
42:
43: protected String getLoggerName() {
44: return LOGGER_NAME + ".tupleExtensionCopier";
45: }
46:
47: public void visitExtension(SpeedoExtension se)
48: throws SpeedoException {
49: debug = logger.isLoggable(BasicLevel.DEBUG);
50: if (se.owner instanceof SpeedoTuple) {
51: SpeedoField sf = ((SpeedoTuple) se.owner).moField;
52: SpeedoExtension oldse = sf.getExtensionByKey(se.key);
53: if (oldse != null) {
54: //The extension already exist on the SpeedoField
55: if ((se.value == null && oldse.value != null)
56: || se.value != null
57: && !se.value.equals(oldse.value)) {
58: //different value ==> exception
59: throw new SpeedoException(
60: "Duplicate extension declaration without the same value: extension name='"
61: + se.key + "', field name='"
62: + sf.name + "' in the class '"
63: + sf.moClass.getFQName()
64: + "' in the jdo file "
65: + sf.moClass.getXMLFileName() + "'");
66: }
67: } else { //The extension does not exist on the field
68: se.owner.addExtension(se);
69: }
70: }
71: super.visitExtension(se);
72: }
73: }
|