/** * Undeploy object from the given registry * * @param reg Registry instance * @param aspectObj Aspect object */ public void $undeployFrom(AspectRegistryIfc reg, Object aspectObj) { if (reg == null) { /* tolerate non crosscutting objects */ return; } AspectContainerIfc curCont = reg.$getAspectContainer(); AspectContainerIfc myCont = null; if (curCont == null) { return; // ignore } else if (curCont.$getContainerType() == getContId()) { myCont = curCont; undeployFromContainer(myCont, aspectObj, reg); if (myCont.isEmpty()) { reg.$setAspectContainer(null); reg.$setSingleAspect(null); } else { reg.$setSingleAspect(myCont.getSingleInstance()); } } else if (curCont.$getContainerType() == AspectContainerIfc.COMPOSITE_CONTAINER) { CompositeAspectContainer composite = (CompositeAspectContainer) curCont; myCont = composite.findContainer(getContId()); if (myCont != null) { undeployFromContainer(myCont, aspectObj, reg); if (myCont.isEmpty()) { composite.getList().remove(myCont); if (composite.getList().size() < 2) { reg.$setAspectContainer((AspectContainerIfc) composite.getList().get(0)); reg.$setSingleAspect(reg.$getAspectContainer().getSingleInstance()); } } } } }
/** * Deploy object on given registry * * @param reg Registry instance * @param aspectObj Aspect object */ public void $deployOn(AspectRegistryIfc reg, Object aspectObj) { if (reg == null) { /* tolerate non crosscutting objects */ return; } AspectContainerIfc curCont = reg.$getAspectContainer(); AspectContainerIfc myCont = null; /* setup appropriate aspect container in the registry */ if (curCont == null) { myCont = createContainer(reg); reg.$setAspectContainer(myCont); deployOnContainer(myCont, aspectObj, reg); reg.$setSingleAspect(myCont.getSingleInstance()); } else { if (curCont.$getContainerType() == getContId()) { myCont = curCont; reg.$setSingleAspect(null); } else if (curCont.$getContainerType() == AspectContainerIfc.COMPOSITE_CONTAINER) { CompositeAspectContainer composite = (CompositeAspectContainer) curCont; myCont = composite.findContainer(getContId()); if (myCont == null) { myCont = createContainer(reg); composite.getList().add(myCont); } } else { CompositeAspectContainer composite = new CompositeAspectContainer(); myCont = createContainer(reg); composite.getList().add(curCont); composite.getList().add(myCont); reg.$setAspectContainer(composite); reg.$setSingleAspect(null); } deployOnContainer(myCont, aspectObj, reg); } }