/**
* 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;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.speedo.api.SpeedoProperties;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.metadata.SpeedoExtension;
import org.objectweb.speedo.metadata.SpeedoField;
import org.objectweb.util.monolog.api.BasicLevel;
/**
* Manage the cascade-delete option.
*
* @author Y. Bersihand
*/
public class CascadeDeleteSetter extends AbstractMetaInfoVisitor {
public String getTitle() {
return "Manage cascade-delete option...";
}
public CascadeDeleteSetter(Personality p) {
super(p);
}
public CascadeDeleteSetter(MetaInfoVisitor mim, Personality p) {
super(mim, p);
}
protected String getLoggerName() {
return LOGGER_NAME + ".cascadeDelete";
}
public void visitField(SpeedoField sf) throws SpeedoException {
super.visitField(sf);
//Cascade delete
SpeedoExtension se = sf.getExtension(
SpeedoProperties.VENDOR_NAME,
SpeedoProperties.CASCADE_DELETE);
//set the isCascadeDelete attribute
sf.isCascadeDelete = se != null
&& ("true".equalsIgnoreCase(se.value)
|| "yes".equalsIgnoreCase(se.value)
|| "on".equalsIgnoreCase(se.value));
//remove the cascade-delete option for collection, map, etc...
//of non persistent objects.
if (sf.jdoTuple != null && sf.getReferencedClass() == null
&& sf.isCascadeDelete) {
sf.isCascadeDelete = false;
if (logger != null) {
logger.log(BasicLevel.WARN,
"Field " + sf.name + " of class " + sf.moClass.name + ":" +
"Cascade-delete option for collection, map, etc.. of non persistent objects is not needed.");
}
}
}
}