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.AbstractDependencyValueMetaData; 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 DependencyHandler extends DefaultElementHandler 40 { 41 42 public static final DependencyHandler HANDLER = new DependencyHandler(); 43 44 public Object startElement(Object parent, QName name, ElementBinding element) 45 { 46 return new AbstractDependencyValueMetaData(); 47 } 48 49 public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx) 50 { 51 AbstractDependencyValueMetaData dependency = (AbstractDependencyValueMetaData) o; 52 for (int i = 0; i < attrs.getLength(); ++i) 53 { 54 String localName = attrs.getLocalName(i); 55 if ("bean".equals(localName)) 56 dependency.setValue(attrs.getValue(i)); 57 else if ("property".equals(localName)) 58 dependency.setProperty(attrs.getValue(i)); 59 else if ("state".equals(localName)) 60 dependency.setDependentState(new ControllerState(attrs.getValue(i))); 61 else if ("whenRequired".equals(localName)) 62 dependency.setWhenRequiredState(new ControllerState(attrs.getValue(i))); 63 } 64 } 65 66 public Object endElement(Object o, QName qName, ElementBinding element) 67 { 68 AbstractDependencyValueMetaData x = (AbstractDependencyValueMetaData) o; 69 String name = (String ) x.getUnderlyingValue(); 70 if (name == null || name.trim().length() == 0) 71 throw new IllegalArgumentException ("Null or empty bean in injection."); 72 return o; 73 } 74 } 75 | Popular Tags |