1 10 package org.mmbase.applications.xmlimporter; 11 12 import java.util.List ; 13 import org.mmbase.util.logging.Logger; 14 import org.mmbase.util.logging.Logging; 15 16 34 public class Consultant { 35 36 37 private static Logger log 38 = Logging.getLoggerInstance(Consultant.class.getName()); 39 40 42 public final static int IMPORT_STARTING = 0; 43 44 46 public final static int IMPORT_RUNNING = 1; 47 48 50 public final static int IMPORT_FINISHED = 2; 51 52 54 public final static int IMPORT_TIMED_OUT = 3; 55 56 58 public final static int IMPORT_EXCEPTION = 4; 59 60 61 private TmpObject originalObject; 62 63 64 private List mergeResults; 65 66 67 private int choice; 68 69 70 private int importStatus; 71 72 75 private boolean interactive; 76 77 78 private boolean duplicatesFound; 79 80 81 public Consultant() { 82 init(); 83 } 84 85 86 public void init() { 87 originalObject = null; 88 mergeResults = null; 89 choice = 0; 90 importStatus = 0; 91 interactive = false; 92 duplicatesFound = false; 93 } 94 95 101 public synchronized void consultUser(TmpObject originalObject, 102 List mergeResults) { 103 104 this.originalObject = originalObject; 105 this.mergeResults = mergeResults; 106 try { 107 while(!Thread.interrupted() && !duplicatesResolved()) { 108 wait(); 109 } 110 } catch (InterruptedException e) {} 111 } 112 113 117 public synchronized void setDuplicatesFound(boolean duplicatesFound) { 118 this.duplicatesFound = duplicatesFound; 119 } 120 121 124 public synchronized boolean duplicatesFound() { 125 if (interactive) { 126 return mergeResults != null; 127 } else { 128 return duplicatesFound; 129 } 130 } 131 132 135 public synchronized boolean duplicatesResolved() { 136 return mergeResults == null; 137 } 138 139 144 public synchronized int getChoice() { 145 return choice; 146 } 147 148 153 public synchronized void setChoice(int choice) { 154 this.choice = choice; 155 mergeResults = null; 157 originalObject = null; 158 notifyAll(); 160 } 161 162 167 public synchronized TmpObject getOriginalObject() { 168 return originalObject; 169 } 170 171 176 public synchronized List getMergeResults() { 177 return mergeResults; 178 } 179 180 193 public synchronized void setImportStatus(int importStatus) { 194 this.importStatus = importStatus; 195 } 196 197 201 public synchronized int getImportStatus() { 202 return importStatus; 203 } 204 205 210 public synchronized void setInteractive(boolean interactive) { 211 this.interactive = interactive; 212 } 213 214 218 public synchronized boolean interactive() { 219 return interactive; 220 } 221 222 227 public static void logInfo(String source, String message) { 228 log.info("source: " + source + "message: " + message); 229 } 230 231 236 public static void logError(String source, String message) { 237 log.error("source: " + source + "message: " + message); 238 } 239 240 245 public static void logDebug(String source, String message) { 246 if (log.isDebugEnabled()) { 247 log.debug("source: " + source + "message: " + message); 248 } 249 } 250 251 256 public static void logTrace(String source, String message) { 257 if (log.isDebugEnabled()) { 258 log.trace("source: " + source + "message: " + message); 259 } 260 } 261 } | Popular Tags |