1 10 package org.mmbase.datatypes.processors; 11 12 import org.mmbase.bridge.*; 13 import org.mmbase.util.logging.*; 14 import java.util.Date ; 15 16 23 24 public class CreationTimeGuesser implements Processor { 25 26 private static final Logger log = Logging.getLoggerInstance(CreationTimeGuesser.class); 27 28 private static final long serialVersionUID = 1L; 29 30 31 public final Object process(Node node, Field field, Object value) { 32 Object v = node.getValueWithoutProcess(field.getName()); 33 if (v == null) { 34 int age = node.getFunctionValue("age", null).toInt(); 35 Date creationTime = new Date (System.currentTimeMillis() - 24L * 60 * 60 * 1000 * age); 36 if (node.mayWrite() && ! field.isVirtual()) { 38 boolean c = node.isChanged(); 39 node.setValueWithoutProcess(field.getName(), creationTime); 40 if (! c) { 41 node.commit(); 42 } 43 } 44 value = 45 value == null ? 46 creationTime : 47 org.mmbase.util.Casting.toType(value.getClass(), node.getCloud(), creationTime); 49 log.debug("Guessing creation time : " + age + " days --> " + value); 50 } 51 return value; 52 } 53 54 public String toString() { 55 return "CreationTime"; 56 } 57 } 58 59 60 | Popular Tags |