1 26 package org.objectweb.util.explorer.resolver.lib; 27 28 import org.objectweb.fractal.api.NoSuchInterfaceException; 29 import org.objectweb.util.explorer.api.Entry; 30 import org.objectweb.util.explorer.core.common.api.BadParamException; 31 import org.objectweb.util.explorer.core.common.api.Description; 32 import org.objectweb.util.explorer.core.common.api.KeyProvider; 33 import org.objectweb.util.explorer.core.common.lib.BindingFeature; 34 import org.objectweb.util.explorer.core.common.lib.ClassesInheritance; 35 import org.objectweb.util.explorer.core.role.api.RoleManager; 36 import org.objectweb.util.explorer.core.role.api.RoleProvider; 37 import org.objectweb.util.explorer.property.api.PropertyProvider; 38 import org.objectweb.util.explorer.resolver.api.PropertyResolver; 39 40 48 public abstract class AbstractPropertyResolver 49 extends BindingFeature 50 implements PropertyResolver 51 { 52 53 59 65 71 75 protected String getTypeSystemId(){ 76 return "Java"; 77 } 78 79 82 protected KeyProvider getKeyProvider(){ 83 try { 84 return (KeyProvider)lookupFc(KeyProvider.KEY_PROVIDER); 85 } catch (NoSuchInterfaceException e) { 86 getTrace().warn(KeyProvider.KEY_PROVIDER + ": interface not found!"); 87 return null; 88 } 89 } 90 91 94 protected PropertyProvider getPropertyProvider(){ 95 try { 96 return (PropertyProvider)lookupFc(PropertyProvider.PROPERTY_PROVIDER); 97 } catch (NoSuchInterfaceException e) { 98 getTrace().warn(PropertyProvider.PROPERTY_PROVIDER + ": interface not found!"); 99 return null; 100 } 101 } 102 103 106 protected RoleManager getRoleManager(){ 107 try { 108 return (RoleManager)lookupFc(RoleManager.ROLE_MANAGER); 109 } catch (NoSuchInterfaceException e) { 110 getTrace().warn(RoleManager.ROLE_MANAGER + ": interface not found!"); 111 return null; 112 } 113 114 } 115 116 119 protected RoleProvider getRoleProvider(){ 120 try { 121 return (RoleProvider)lookupFc(RoleProvider.ROLE_PROVIDER); 122 } catch (NoSuchInterfaceException e) { 123 getTrace().warn(RoleProvider.ROLE_PROVIDER + ": interface not found!"); 124 return null; 125 } 126 127 } 128 129 151 protected Description getDescription(Entry entry){ 152 if(entry!=null && entry.getValue()!=null){ 153 Class [] javaTypes = ClassesInheritance.getInheritedClasses(entry.getValue().getClass()); 154 String [] roleIds = getRoleProvider().getInheritedRoleIds(getRoleManager().getCurrentRoleIds()); 155 for (int i = 0; i < javaTypes.length; i++) { 156 for (int j = 0; j < roleIds.length; j++) { 157 Object key = null; 158 try { 159 key = getKeyProvider().computeKey(new String []{getTypeSystemId(),javaTypes[i].getName(),roleIds[j]}); 160 } catch (BadParamException e) { 161 getTrace().warn("Bad key param: " + e.getMessage()); 162 } 163 if(key!=null){ 164 Description desc = (Description)getPropertyProvider().getPropertyDescription(getPropertyType(),key); 165 if(desc!=null){ 166 return desc; 167 } 168 } 169 } 170 } 171 } 172 return null; 173 } 174 175 180 protected abstract String getPropertyType(); 181 182 185 public Description resolve(String propertyType, Entry currentEntry) { 186 return resolve(getPropertyType(), currentEntry, null); 187 } 188 189 195 198 public String [] clientFc() { 199 return new String []{PropertyProvider.PROPERTY_PROVIDER, 200 KeyProvider.KEY_PROVIDER, 201 RoleManager.ROLE_MANAGER, 202 RoleProvider.ROLE_PROVIDER}; 203 } 204 205 } 206 207 208 | Popular Tags |