1 26 27 package org.objectweb.util.browser.core.popup; 28 29 30 import org.objectweb.util.browser.api.Context; 31 import org.objectweb.util.browser.api.Entry; 32 import org.objectweb.util.browser.core.api.BrowserProperty; 33 import org.objectweb.util.browser.core.api.MenuFactory; 34 import org.objectweb.util.browser.core.api.MenuFactoryConfiguration; 35 import org.objectweb.util.browser.core.api.Role; 36 import org.objectweb.util.browser.core.api.RoleManagement; 37 import org.objectweb.util.browser.core.api.TypeKey; 38 import org.objectweb.util.browser.core.common.*; 39 import org.objectweb.util.browser.core.common.DefaultPropertyContainer; 40 import org.objectweb.util.browser.core.common.ClassesInheritance; 41 import org.objectweb.util.browser.core.naming.DefaultEntry; 42 import org.objectweb.util.browser.core.naming.DefaultName; 43 44 45 import java.util.HashMap ; 46 import java.util.Map ; 47 import java.util.Vector ; 48 import java.util.List ; 49 import java.util.Iterator ; 50 51 58 public class MenuPropertyContainer 59 extends DefaultPropertyContainer { 60 61 protected Map menuCache_; 62 63 69 73 public MenuPropertyContainer(BrowserProperty loader) { 74 super(loader); 75 menuCache_ = new HashMap (); 76 } 77 78 84 89 protected Entry getElement(String className, Role role, ExtendedBoolean nodeFound) { 90 return loader_.getMenu(className, role, nodeFound); 91 } 92 93 100 protected void addEntry(String id, MenuFactory object) { 101 super.addEntry(id, object); 102 } 103 104 110 116 protected Entry tryToLoad(String className) { 117 Vector entryList = new Vector (); 118 Role[] roles = loader_.getInheritedRoles(); 119 ExtendedBoolean nodeFound = new ExtendedBoolean(false); 120 boolean atLeastOneNodeFound = false; 121 for(int i = 0 ; i < roles.length ; i++){ 122 Entry entry = getElement(className, roles[i], nodeFound); 123 if (entry != null) { 124 if(!(roles[i].getId().equals(RoleManagement.DEFAULT_ROLE) && atLeastOneNodeFound)) 125 entryList.add(entry); 126 if(nodeFound.getValue()) 127 atLeastOneNodeFound = true; 128 } 129 } 130 if(!entryList.isEmpty()){ 131 return new DefaultEntry((Entry[])entryList.toArray(new Entry[0]),new DefaultName(className)); 132 } 133 return null; 134 } 135 136 145 public Entry getRecursiveProperty(Object object) { 146 Class c = object.getClass(); 147 TypeKey typeKey = loader_.getTypeSystem().getTypeKey(c); 148 String cKey = typeKey.getTypeSystem() + "." + typeKey.getTypeName(); 149 if (cache_.containsKey(cKey)) { 151 return (Entry)menuCache_.get((String ) cache_.get(cKey)); 152 } 153 ClassesInheritance ci = new ClassesInheritance(c); 155 List list = ci.getInheritClasses(); 156 Iterator it = list.iterator(); 157 Vector inheritTypeMenu = new ContextVector(); 159 Vector inheritTreeMenu = new ContextVector(); 160 boolean isFirst = true; 161 MenuFactoryConfiguration menuFactory = null; 162 Entry currentMenuEntry = null; 163 Entry entry = null; 164 while (it.hasNext()) { 165 Class class_ = (Class ) it.next(); 166 typeKey = loader_.getTypeSystem().getTypeKey(class_); 167 String key = typeKey.getTypeSystem() + "." + typeKey.getTypeName(); 168 entry = getLocalEntry(key); 169 if (entry == null) { 170 entry = tryToLoad(key); 171 } 172 if (entry != null) { 173 Entry[] entryList = (Entry[]) entry.getValue(); 174 for(int i=0; i < entryList.length ; i++){ 175 if(isFirst) { 176 isFirst = false; 178 cache_.put(cKey, key); 179 menuFactory = (MenuFactoryConfiguration) entryList[i].getValue(); 180 menuFactory.setClassName(class_.getName()); 181 currentMenuEntry = entryList[i]; 182 menuCache_.put(key,currentMenuEntry); 183 } else { 184 MenuFactoryConfiguration mfc = (MenuFactoryConfiguration) entryList[i].getValue(); 185 inheritTypeMenu.add(mfc.getItems()); 186 inheritTreeMenu.add(mfc.getChildItems()); 187 } 188 } 189 } 190 } 191 if (menuFactory != null) { 192 menuFactory.setInheritTypeMenu((Context[]) inheritTypeMenu.toArray(new Context[0])); 193 menuFactory.setInheritTreeMenu((Context[]) inheritTreeMenu.toArray(new Context[0])); 194 } 195 return currentMenuEntry; 196 } 197 198 207 213 214 217 protected class ContextVector extends Vector { 218 219 223 protected boolean isEmpty(Context context) { 224 if (context != null) { 225 Entry[] entries = context.getEntries(); 226 return entries.length == 0; 227 } 228 return true; 229 } 230 231 234 public boolean add(Context c) { 235 if (!isEmpty(c)) 236 return super.add(c); 237 return false; 238 } 239 240 243 public boolean add(Object o) { 244 if (o != null) 245 return add((Context) o); 246 return false; 247 } 248 249 } 250 251 } 252 | Popular Tags |