1 22 package org.jboss.kernel.plugins.deployment.xml; 23 24 import javax.xml.namespace.NamespaceContext ; 25 import javax.xml.namespace.QName ; 26 27 import org.jboss.beans.metadata.plugins.AbstractDemandMetaData; 28 import org.jboss.dependency.spi.ControllerState; 29 import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler; 30 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding; 31 import org.xml.sax.Attributes ; 32 33 39 public class DemandHandler extends DefaultElementHandler 40 { 41 42 public static final DemandHandler HANDLER = new DemandHandler(); 43 44 public Object startElement(Object parent, QName name, ElementBinding element) 45 { 46 return new AbstractDemandMetaData(); 47 } 48 49 public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx) 50 { 51 AbstractDemandMetaData demand = (AbstractDemandMetaData) o; 52 for (int i = 0; i < attrs.getLength(); ++i) 53 { 54 String localName = attrs.getLocalName(i); 55 if ("state".equals(localName)) 56 demand.setWhenRequired(new ControllerState(attrs.getValue(i))); 57 } 58 } 59 60 public Object endElement(Object o, QName qName, ElementBinding element) 61 { 62 AbstractDemandMetaData x = (AbstractDemandMetaData) o; 63 String name = (String ) x.getDemand(); 64 if (name == null || name.trim().length() == 0) 65 throw new IllegalArgumentException ("Null or empty demand."); 66 return o; 67 } 68 } 69 | Popular Tags |