/**
* 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.jdo;
import org.objectweb.speedo.generation.mivisitor.AbstractMetaInfoVisitor;
import org.objectweb.speedo.generation.mivisitor.MetaInfoVisitor;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.metadata.SpeedoExtension;
import org.objectweb.speedo.metadata.SpeedoField;
import org.objectweb.speedo.metadata.SpeedoTuple;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.util.monolog.api.BasicLevel;
/**
* Copies all extensions defined on tuple node, into the field node.
*
* @author S.Chassande-Barrioz
*/
public class TupleExtensionCopier extends AbstractMetaInfoVisitor {
public TupleExtensionCopier(Personality p) {
super(p);
}
public TupleExtensionCopier(MetaInfoVisitor mim, Personality p) {
super(mim, p);
}
protected String getLoggerName() {
return LOGGER_NAME + ".tupleExtensionCopier";
}
public void visitExtension(SpeedoExtension se) throws SpeedoException {
debug = logger.isLoggable(BasicLevel.DEBUG);
if (se.owner instanceof SpeedoTuple) {
SpeedoField sf = ((SpeedoTuple) se.owner).moField;
SpeedoExtension oldse = sf.getExtensionByKey(se.key);
if (oldse != null) {
//The extension already exist on the SpeedoField
if ((se.value == null && oldse.value!= null)
|| se.value != null && !se.value.equals(oldse.value)) {
//different value ==> exception
throw new SpeedoException(
"Duplicate extension declaration without the same value: extension name='"
+ se.key + "', field name='" + sf.name
+ "' in the class '" + sf.moClass.getFQName()
+ "' in the jdo file " + sf.moClass.getXMLFileName()
+ "'");
}
} else { //The extension does not exist on the field
se.owner.addExtension(se);
}
}
super.visitExtension(se);
}
}