1 package org.apache.beehive.controls.api.properties; 2 19 20 import java.lang.annotation.Annotation ; 21 22 import org.apache.beehive.controls.api.bean.ControlBean; 23 import org.apache.beehive.controls.api.bean.ControlExtension; 24 import org.apache.beehive.controls.api.bean.ControlInterface; 25 import org.apache.beehive.controls.api.bean.ExternalPropertySets; 26 27 33 abstract public class BaseMap implements PropertyMap, java.io.Serializable 34 { 35 40 protected void setMapClass(Class mapClass) 41 { 42 if (ControlBean.class.isAssignableFrom(mapClass)) 47 { 48 Class [] intfs = mapClass.getInterfaces(); 49 for (int i = 0; i < intfs.length; i++) 50 { 51 if (intfs[i].isAnnotationPresent(ControlInterface.class) || 52 intfs[i].isAnnotationPresent(ControlExtension.class)) 53 { 54 mapClass = intfs[i]; 55 break; 56 } 57 } 58 } 59 else 60 { 61 if (!mapClass.isAnnotation() && 62 !mapClass.isAnnotationPresent(ControlInterface.class) && 63 !mapClass.isAnnotationPresent(ControlExtension.class)) 64 throw new IllegalArgumentException (mapClass+" must be Control or annotation type"); 65 } 66 67 _mapClass = mapClass; 68 } 69 70 73 public Class getMapClass() { return _mapClass; } 74 75 79 private boolean isCompatibleClass(Class checkClass) 80 { 81 if (_mapClass.isAssignableFrom(checkClass)) 86 return true; 87 88 if (checkClass.isAnnotationPresent(PropertySet.class)) 93 { 94 Class declaringClass = checkClass.getDeclaringClass(); 95 96 if (declaringClass == null) 99 return true; 100 101 if (declaringClass.isAssignableFrom(_mapClass)) 102 return true; 103 } 104 105 if (_mapClass.isAnnotationPresent(PropertySet.class)) 112 { 113 Class declaringClass = _mapClass.getDeclaringClass(); 114 if (declaringClass != null && 115 declaringClass.isAssignableFrom(checkClass)) 116 return true; 117 118 if (declaringClass == null) 120 { 121 ExternalPropertySets eps = (ExternalPropertySets) checkClass.getAnnotation(ExternalPropertySets.class); 122 if (eps != null) 123 { 124 Class [] propSets = eps.value(); 125 if (propSets != null) 126 { 127 for (Class ps : propSets) 128 { 129 if (_mapClass.equals(ps)) 130 return true; 131 } 132 } 133 } 134 } 135 } 136 137 return false; 138 } 139 140 143 protected boolean isValidKey(PropertyKey key) 144 { 145 return isCompatibleClass(key.getPropertySet()); 146 } 147 148 152 public synchronized void setDelegateMap(PropertyMap delegateMap) 153 { 154 if (!isCompatibleClass(delegateMap.getMapClass())) 155 throw new IllegalArgumentException ("The delegate map type (" + delegateMap.getMapClass() + " is an incompatible type with " + _mapClass); 156 157 _delegateMap = delegateMap; 158 } 159 160 164 public PropertyMap getDelegateMap() 165 { 166 return _delegateMap; 167 } 168 169 172 public Object getProperty(PropertyKey key) 173 { 174 if (_delegateMap != null) 178 return _delegateMap.getProperty(key); 179 180 return key.getDefaultValue(); 184 } 185 186 190 public boolean containsPropertySet(Class <? extends Annotation > propertySet) 191 { 192 if (_delegateMap != null) 196 return _delegateMap.containsPropertySet(propertySet); 197 198 return false; 199 } 200 201 206 public <T extends Annotation > T getPropertySet(Class <T> propertySet) 207 { 208 if (!containsPropertySet(propertySet)) 209 return null; 210 211 return PropertySetProxy.getProxy(propertySet, this); 212 } 213 214 Class _mapClass; PropertyMap _delegateMap; } 217 | Popular Tags |