KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > datatypes > processors > IgnoreIfChangedProcessor


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.datatypes.processors;
11
12 import org.mmbase.bridge.*;
13 import org.mmbase.util.logging.Logger;
14 import org.mmbase.util.logging.Logging;
15
16 /**
17  * If this processor is used on a certain field, that you can effectively set the value only once
18  * (until the commit of the node). This is based on {@link
19  * org.mmbase.bridge.Node#isChanged(String)}. It that returns true (and the node is not new), the old value is used.
20  *
21  * @author Michiel Meeuwissen
22  * @version $Id: IgnoreIfChangedProcessor.java,v 1.2 2006/07/06 15:14:59 michiel Exp $
23  * @since MMBase-1.8.1
24  */

25
26 public class IgnoreIfChangedProcessor implements Processor {
27     private static final Logger log = Logging.getLoggerInstance(IgnoreEmptyProcessor.class);
28     private static final long serialVersionUID = 1L;
29
30     public final Object JavaDoc process(Node node, Field field, Object JavaDoc value) {
31         Object JavaDoc prevValue = node.getValue(field.getName());
32         if (! node.isNew()) {
33             if (node.isChanged(field.getName())) {
34                 return prevValue;
35             }
36         }
37         return value;
38     }
39
40     public String JavaDoc toString() {
41         return "IGNOREIFCHANGED";
42     }
43 }
44
45
46
Popular Tags