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;
18:
19: import org.objectweb.speedo.api.SpeedoException;
20: import org.objectweb.speedo.api.SpeedoProperties;
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.util.monolog.api.BasicLevel;
25:
26: /**
27: * Manage the cascade-delete option.
28: *
29: * @author Y. Bersihand
30: */
31: public class CascadeDeleteSetter extends AbstractMetaInfoVisitor {
32:
33: public String getTitle() {
34: return "Manage cascade-delete option...";
35: }
36:
37: public CascadeDeleteSetter(Personality p) {
38: super (p);
39: }
40:
41: public CascadeDeleteSetter(MetaInfoVisitor mim, Personality p) {
42: super (mim, p);
43: }
44:
45: protected String getLoggerName() {
46: return LOGGER_NAME + ".cascadeDelete";
47: }
48:
49: public void visitField(SpeedoField sf) throws SpeedoException {
50: super .visitField(sf);
51: //Cascade delete
52: SpeedoExtension se = sf.getExtension(
53: SpeedoProperties.VENDOR_NAME,
54: SpeedoProperties.CASCADE_DELETE);
55: //set the isCascadeDelete attribute
56: sf.isCascadeDelete = se != null
57: && ("true".equalsIgnoreCase(se.value)
58: || "yes".equalsIgnoreCase(se.value) || "on"
59: .equalsIgnoreCase(se.value));
60: //remove the cascade-delete option for collection, map, etc...
61: //of non persistent objects.
62: if (sf.jdoTuple != null && sf.getReferencedClass() == null
63: && sf.isCascadeDelete) {
64: sf.isCascadeDelete = false;
65: if (logger != null) {
66: logger
67: .log(
68: BasicLevel.WARN,
69: "Field "
70: + sf.name
71: + " of class "
72: + sf.moClass.name
73: + ":"
74: + "Cascade-delete option for collection, map, etc.. of non persistent objects is not needed.");
75: }
76: }
77: }
78: }
|