001 package com.hammurapi.config.runtime;
002
003 import java.util.Iterator;
004 import java.util.LinkedList;
005
006 import com.hammurapi.config.bootstrap.ConfigurationException;
007 import com.hammurapi.config.bootstrap.Destroyable;
008
009 public class CompositeDestroyable implements Destroyable, DestroyableSink {
010
011 private LinkedList<Destroyable> children = new LinkedList<Destroyable>();
012
013 public synchronized void destroy() throws ConfigurationException {
014 Iterator<Destroyable> dit = children.iterator();
015 while (dit.hasNext()) {
016 Destroyable d = dit.next();
017 d.destroy();
018 if (!(d instanceof CompositeDestroyable)) {
019 dit.remove();
020 }
021 }
022 }
023
024 public synchronized void addDestroyable(Destroyable child) {
025 if (child!=null) {
026 children.addFirst(child);
027 }
028 }
029
030 public synchronized boolean isEmpty() {
031 for (Destroyable child: children) {
032 if (child instanceof CompositeDestroyable) {
033 if (!((CompositeDestroyable) child).isEmpty()) {
034 return false;
035 }
036 } else {
037 return false;
038 }
039 }
040 return true;
041 }
042
043 }