1 26 package org.objectweb.util.explorer.resolver.lib; 27 28 import org.objectweb.util.explorer.api.Entry; 29 import org.objectweb.util.explorer.core.common.api.BadParamException; 30 import org.objectweb.util.explorer.core.common.api.Description; 31 import org.objectweb.util.explorer.core.common.api.ExplorerConstants; 32 import org.objectweb.util.explorer.core.common.lib.ClassesInheritance; 33 import org.objectweb.util.explorer.core.menu.api.MenuDescription; 34 import org.objectweb.util.explorer.core.menu.lib.BasicMenuSeparator; 35 36 44 public class MenuResolver 45 extends AbstractPropertyResolver 46 { 47 48 54 60 66 69 protected String getPropertyType() { 70 return ExplorerConstants.MENU_PROPERTY; 71 } 72 73 79 protected MenuDescription mergeMenuDescription(MenuDescription source, MenuDescription target) { 80 if(target!=null){ 81 source.addMenuElements(target.getAllMenuElements()); 82 } 83 return source; 84 } 85 86 91 protected MenuDescription getMenuDesc(Object key){ 92 return (MenuDescription)getPropertyProvider().getPropertyDescription(getPropertyType(), key); 93 } 94 95 100 protected MenuDescription getMenuDescription(Entry entry, boolean childrenMenuElement){ 101 ExtendedMenuDescription menuDesc = new ExtendedMenuDescription(); 102 if(entry!=null && entry.getValue()!=null){ 103 Class [] javaTypes = ClassesInheritance.getInheritedClasses(entry.getValue().getClass()); 104 String [] roleIds = getRoleProvider().getInheritedRoleIds(getRoleManager().getCurrentRoleIds()); 105 boolean isFirst = true; 106 for (int i = 0; i < javaTypes.length; i++) { 107 for (int j = 0; j < roleIds.length; j++) { 108 Object key = null; 109 try { 110 key = getKeyProvider().computeKey(new String []{getTypeSystemId(),javaTypes[i].getName(),roleIds[j]}); 111 } catch (BadParamException e) { 112 getTrace().warn("Bad key param: " + e.getMessage()); 113 } 114 if(key!=null){ 115 MenuDescription newMenuDesc = getMenuDesc(key); 116 if(newMenuDesc!=null && !newMenuDesc.isEmpty()){ 117 if(childrenMenuElement) { 118 menuDesc.addChildrenMenuElements(newMenuDesc); 119 } else { 120 if(isFirst){ 121 isFirst = false; 122 } else { 123 menuDesc.addMenuElement(new BasicMenuSeparator()); 124 } 125 menuDesc.addMenuElements(newMenuDesc,i==0); 126 } 127 } 128 } 129 } 130 } 131 } 132 return menuDesc; 133 } 134 135 141 protected MenuDescription getMenuDescription(Entry currentEntry, Entry parentEntry){ 142 MenuDescription currentMenu = getMenuDescription(currentEntry,false); 143 if(parentEntry!=null){ 144 return mergeMenuDescription(currentMenu, getMenuDescription(parentEntry,true)); 145 } else { 146 return currentMenu; 147 } 148 } 149 150 156 159 public Description resolve(String propertyType, Entry currentEntry, Entry parentEntry) { 160 return getMenuDescription(currentEntry, parentEntry); 161 } 162 163 } 164 | Popular Tags |