1 17 18 package org.objectweb.jac.core.rtti; 19 20 import java.lang.reflect.*; 21 import java.util.*; 22 import org.objectweb.jac.core.ACManager; 23 import org.objectweb.jac.util.ExtArrays; 24 25 48 49 public abstract class MetaItem { 50 51 53 protected static HashMap attrACs = new HashMap(); 54 55 61 62 public static void unsetAttributesFor( String acName ) {} 63 64 65 private HashMap attributes = new HashMap(); 66 67 static ACManager acManager; 68 static Method acManagerGetObjectMethod; 69 static Method acManagerGetMethod; 70 71 static { 72 try { 73 acManagerGetMethod = 74 Class.forName("org.objectweb.jac.core.ACManager").getMethod("get",new Class [0]); 75 acManagerGetObjectMethod = 76 Class.forName("org.objectweb.jac.core.ACManager").getMethod( 77 "getObject",new Class []{String .class}); 78 } catch(Exception e) { 79 e.printStackTrace(); 80 } 81 } 82 83 Object getAC(String name) { 84 Object ac = null; 85 try { 86 if (acManager==null) { 87 acManager = 88 (ACManager)acManagerGetMethod.invoke(null,ExtArrays.emptyObjectArray); 89 } 90 ac = acManagerGetObjectMethod.invoke(acManager,new Object []{name}); 91 } catch (Exception e) { 92 e.printStackTrace(); 93 } 94 return ac; 95 } 96 97 boolean isRegisteredAC( String name ) { 98 return getAC(name)!=null; 99 } 100 101 static Method collabGetMethod = null; 102 static Method collabGetCurACMethod = null; 103 104 String getCurAC() { 105 123 return null; 124 } 125 126 static AttributeController accessController = null; 127 128 133 public static void registerAccessController(AttributeController controller) { 134 accessController = controller; 135 } 136 137 Object controlledAccess(Object substance, String name, Object value) { 138 if ( accessController==null || 139 ! (name.equals("GuiAC.VISIBLE") || 140 name.equals("GuiAC.EDITABLE") || 141 name.equals("GuiAC.ADDABLE") || 142 name.equals("GuiAC.CREATABLE") || 143 name.equals("GuiAC.REMOVABLE")) ) 144 return value; 145 146 Object result = null; 147 try { 148 result = accessController.controlAttribute(substance,this,name,value); 149 } catch(Exception e) { 150 e.printStackTrace(); 151 return value; 152 } 153 return result; 154 } 155 156 157 163 164 public Object getAttribute(String name) { 165 return getAttribute(name,false); 166 } 167 168 175 public Object getAttributeAlways(String name) { 176 return getAttribute(name,true); 177 } 178 179 187 public Object getAttribute(String name, boolean always) { 188 String acName = (String )attrACs.get(name); 189 if (!always && (acName!=null && (!isRegisteredAC(acName))) ) { 190 return null; 191 } 192 Object value=attributes.get(name); 193 if (value==null && itemClass!=null) { 194 value = itemClass.getAttribute(name); 195 } 196 return controlledAccess(null,name,value); 197 } 198 199 206 public boolean getBoolean(String name, boolean defValue) { 207 Boolean value = (Boolean )getAttribute(name); 208 if (value==null) 209 return defValue; 210 else 211 return value.booleanValue(); 212 } 213 214 221 222 public Object getAttribute(Object substance, String name) { 223 String acName = (String )attrACs.get(name); 224 if( acName!=null && (!isRegisteredAC(acName)) ) { 225 return null; 226 } 227 Object value=attributes.get(name); 228 if (value==null && itemClass!=null) { 229 value = itemClass.getAttribute(name); 230 } 231 return controlledAccess(substance,name,value); 232 } 233 234 240 241 public final void setAttribute(String name, Object value) { 242 if (name == null) 243 return; 244 String acName = (String )getCurAC(); 245 if (acName != null) { 246 if ( !attrACs.containsKey(name) ) { 247 attrACs.put(name,acName); 248 } 249 } 250 attributes.put(name,value); 251 } 252 253 258 259 public void unsetAttribute(String name) { 260 attributes.remove(name); 261 } 262 263 268 269 public abstract String getName(); 270 271 MetaItem itemClass; 272 public void setItemClass(MetaItem itemClass) { 273 this.itemClass = itemClass; 274 } 275 public MetaItem getItemClass() { 276 return itemClass; 277 } 278 } 279 | Popular Tags |