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.AbstractConstructorMetaData; 28 import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler; 29 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding; 30 import org.xml.sax.Attributes ; 31 32 38 public class ConstructorHandler extends DefaultElementHandler 39 { 40 41 public static final ConstructorHandler HANDLER = new ConstructorHandler(); 42 43 public Object startElement(Object parent, QName name, ElementBinding element) 44 { 45 return new AbstractConstructorMetaData(); 46 } 47 48 public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx) 49 { 50 AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) o; 51 for (int i = 0; i < attrs.getLength(); ++i) 52 { 53 String localName = attrs.getLocalName(i); 54 if ("factoryClass".equals(localName)) 55 constructor.setFactoryClass(attrs.getValue(i)); 56 else if ("factoryMethod".equals(localName)) 57 constructor.setFactoryMethod(attrs.getValue(i)); 58 } 59 } 60 61 public Object endElement(Object o, QName qName, ElementBinding element) 62 { 63 AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) o; 64 if (constructor.getFactory() != null || constructor.getFactoryClass() != null) 65 if (constructor.getFactoryMethod() == null) 66 throw new IllegalArgumentException ("Constructor needs a factoryMethod attribute when there is a factoryClass attribute or factory element."); 67 return constructor; 68 } 69 } 70 | Popular Tags |