001    /*
002    @license.text@
003     */
004    package biz.hammurapi.config;
005    
006    
007    import org.w3c.dom.Element;
008    import org.w3c.dom.Node;
009    import org.w3c.dom.NodeList;
010    
011    /**
012     * Simple container
013     * @author Pavel Vlasov
014     * @revision $Revision$
015     */
016    public abstract class DomConfigurableContainer extends GenericContainer implements DomConfigurable {
017            public DomConfigurableContainer() {
018                    // Default constructor
019            }
020            
021            protected abstract String getComponentName(Node node);
022    
023            public void configure(Node configNode, final Context context) throws ConfigurationException {
024                    DomConfigFactory factory=new DomConfigFactory(new Context() {
025    
026                            public Object get(String name) {
027                                    Object ret=DomConfigurableContainer.this.get(name);
028                                    if (ret!=null) {
029                                            return ret;
030                                    }
031                                    return context==null ? null : context.get(name);
032                            }
033                            
034                    });
035                    
036                    NodeList children=configNode.getChildNodes();
037                    for (int i=0, length=children.getLength(); i<length; i++) {
038                            Node child=children.item(i);
039                            if (child instanceof Element) {
040                                    addComponent(getComponentName(child), factory.create(child));
041                            }
042                    }
043            }
044    }