1 9 package org.jboss.portal.core.impl.preferences; 10 11 import java.util.HashMap ; 12 import java.util.Map ; 13 14 import org.apache.log4j.Logger; 15 import org.jboss.portal.common.FQN; 16 import org.jboss.portal.server.plugins.preferences.PreferenceSet; 17 import org.jboss.portal.server.plugins.preferences.PreferenceStore; 18 19 23 public abstract class MappedPreferenceStore implements PreferenceStore 24 { 25 26 27 private static final Logger log = Logger.getLogger(MappedPreferenceStore.class); 28 29 30 protected Map descendants; 31 32 public MappedPreferenceStore() 33 { 34 descendants = new HashMap (); 35 } 36 37 public PreferenceSet get(FQN fqn) 38 { 39 return getDescendant(fqn); 40 } 41 42 45 protected abstract MappedPreferenceSet getRoot(); 46 47 private MappedPreferenceSet getDescendant(FQN fqn) 48 { 49 boolean debug = log.isDebugEnabled(); 51 52 MappedPreferenceSet set = (MappedPreferenceSet)descendants.get(fqn); 54 55 if (debug) 57 { 58 if (set == null) 59 { 60 log.debug("Preference set not found for " + fqn); 61 } 62 else 63 { 64 log.debug("Got cached preference set for " + fqn); 65 } 66 } 67 68 if (set == null) 70 { 71 MappedPreferenceSet root = getRoot(); 73 set = root.getDescendant(fqn); 74 75 for (MappedPreferenceSet current = set;current != null;current = current.getParent()) 77 { 78 if (descendants.put(current.getFQN(), current) != null) 79 { 80 break; 82 } 83 } 84 } 85 86 return set; 88 } 89 } 90 | Popular Tags |