1 18 19 package org.objectweb.jac.core; 20 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import org.apache.log4j.Logger; 25 import org.objectweb.jac.core.ACManager; 26 27 38 39 public class CompositeAspectComponent extends AspectComponent { 40 static Logger logger = Logger.getLogger("aspects.composite"); 41 42 Map childClasses=new HashMap (); 43 Map children=new HashMap (); 44 Map defaultConfigs=new HashMap (); 45 46 52 public CompositeAspectComponent () { 53 super(); 54 } 55 56 64 protected void disableDefaultConfigs(String childName) { 65 defaultConfigs.put(childName,Boolean.FALSE); 66 } 67 68 74 protected void addChild(String name,Class acClass) { 75 logger.debug("addChild("+name+ 76 ","+acClass+")"+" to composite "+getName()); 77 childClasses.put(name,acClass); 78 } 79 80 86 protected void removeChild(String name) { 87 logger.debug("removeChild("+name+ 88 ") from composite "+getName()+")"); 89 childClasses.remove(name); } 90 91 97 protected AspectComponent getChild(String name) { 98 logger.debug("getChild("+name+ 99 ") in composite "+getName()); 100 return (AspectComponent)children.get(name); 101 } 102 103 107 protected String getChildActualName(String name) { 108 logger.debug("getChildActualName("+name+ 109 ") in composite "+getName()); 110 return getChild(name).getApplication()+"."+name; 111 } 112 113 123 protected String getChildRegisteredName(String name) { 124 logger.debug("getChildActualName("+name+ 125 ") in composite "+getName()); 126 return ACManager.getACM().getName(getChild(name)); 127 } 128 129 135 public void beforeConfiguration() throws Exception { 136 logger.debug("beforeConfiguration()"+ 137 " for composite "+getName()); 138 Iterator it=childClasses.entrySet().iterator(); 139 while(it.hasNext()) { 140 Map.Entry entry=(Map.Entry )it.next(); 141 Class acClass=(Class )entry.getValue(); 142 AspectComponent instance = (AspectComponent) acClass.newInstance(); 143 instance.setApplication(getApplication()); 144 children.put(entry.getKey(),instance); 145 String [] defaults = instance.getDefaultConfigs(); 147 for (int i=0; i<defaults.length; i++) { 148 instance.configure((String )entry.getKey(),defaults[i]); 149 } 150 } 151 152 } 153 154 160 public final void doRegister() { 161 logger.debug("registerChildren()"+ 162 " for composite "+getName()); 163 Iterator it=children.entrySet().iterator(); 164 while(it.hasNext()) { 165 Map.Entry entry=(Map.Entry )it.next(); 166 AspectComponent ac=(AspectComponent)entry.getValue(); 167 ACManager.get().register( ac.getApplication() + 168 "." + entry.getKey(), ac ); 169 } 170 logger.debug("end registerChildren() => ACM dump: "+ 171 ACManager.get().getPrintableString()); 172 173 } 174 175 176 181 public final void doUnregister() { 182 logger.debug("unregisterChildren()"+ 183 " for composite "+getName()); 184 Iterator it=children.entrySet().iterator(); 185 while(it.hasNext()) { 186 Map.Entry entry=(Map.Entry )it.next(); 187 AspectComponent ac=(AspectComponent)entry.getValue(); 188 ACManager.get().unregister( ac.getApplication() + 189 "." + entry.getKey() ); 190 } 191 } 192 193 } 194 | Popular Tags |