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, ClassLoader classLoader) throws ConfigurationException { 024 DomConfigFactory factory=new DomConfigFactory( 025 classLoader, 026 new Context() { 027 028 public Object get(String name) { 029 Object ret=DomConfigurableContainer.this.get(name); 030 if (ret!=null) { 031 return ret; 032 } 033 return context==null ? null : context.get(name); 034 } 035 036 }); 037 038 NodeList children=configNode.getChildNodes(); 039 for (int i=0, length=children.getLength(); i<length; i++) { 040 Node child=children.item(i); 041 if (child instanceof Element) { 042 addComponent(getComponentName(child), factory.create(child)); 043 } 044 } 045 } 046 }