1 26 27 package org.objectweb.util.browser.core.common; 28 29 30 import org.objectweb.util.browser.api.Entry; 31 import org.objectweb.util.browser.core.api.BrowserProperty; 32 import org.objectweb.util.browser.core.api.PropertyContainer; 33 import org.objectweb.util.browser.core.api.Role; 34 import org.objectweb.util.browser.core.api.RoleManagement; 35 import org.objectweb.util.browser.core.api.TypeKey; 36 import org.objectweb.util.browser.core.naming.DefaultContextContainer; 37 38 39 import java.util.List ; 40 import java.util.Iterator ; 41 import java.util.Map ; 42 import java.util.HashMap ; 43 44 50 public abstract class DefaultPropertyContainer 51 extends DefaultContextContainer 52 implements PropertyContainer { 53 54 60 63 protected BrowserProperty loader_; 64 65 71 protected Map cache_; 72 73 79 83 public DefaultPropertyContainer(BrowserProperty loader) { 84 super(); 85 loader_ = loader; 86 cache_ = new HashMap (); 87 } 88 89 95 100 protected Entry tryToLoad(String className) { 101 Role[] roles = loader_.getInheritedRoles(); 102 ExtendedBoolean nodeFound = new ExtendedBoolean(false); 104 boolean atLeastOneNodeFound = false; 105 for(int i = 0 ; i < roles.length ; i++){ 106 Entry entry = getElement(className, roles[i], nodeFound); 107 if (entry != null) { 108 if(!(roles[i].getId().equals(RoleManagement.DEFAULT_ROLE) && atLeastOneNodeFound)){ 109 addEntry(entry.getName().toString(), entry.getValue()); 110 return entry; 111 } 112 if(nodeFound.getValue()) 113 atLeastOneNodeFound = true; 114 } 115 } 116 return null; 117 } 118 119 123 protected String getKey(Class c) { 124 String key = ""; 125 if(c!=null){ 126 TypeKey typeKey = loader_.getTypeSystem().getTypeKey(c); 127 key = typeKey.getTypeSystem() + "." + typeKey.getTypeName(); 128 } 129 return key; 130 } 131 132 137 protected abstract Entry getElement(String className, Role role, ExtendedBoolean nodeFound); 138 139 145 154 public Entry getRecursiveProperty(Object object) { 155 String cKey = getKey(object.getClass()); 156 if (cache_.containsKey(cKey)) { 158 return getLocalEntry((String ) cache_.get(cKey)); 159 } 160 ClassesInheritance ci = new ClassesInheritance(object.getClass()); 161 List list = ci.getInheritClasses(); 162 Iterator it = list.iterator(); 163 while (it.hasNext()) { 164 String key = getKey((Class ) it.next());; 165 Entry entry = getLocalEntry(key); 166 if (entry == null) { 167 entry = tryToLoad(key); 168 } 169 if (entry != null) { 170 cache_.put(cKey, key); 171 return entry; 172 } 173 } 174 return null; 175 } 176 177 180 public void clear(){ 181 super.clear(); 182 cache_.clear(); 183 } 184 } 185 | Popular Tags |