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.factory.GenericBeanFactoryMetaData; 28 import org.jboss.beans.metadata.spi.ConstructorMetaData; 29 import org.jboss.beans.metadata.spi.PropertyMetaData; 30 import org.jboss.beans.metadata.spi.ValueMetaData; 31 import org.jboss.dependency.spi.ControllerMode; 32 import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler; 33 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding; 34 import org.xml.sax.Attributes ; 35 36 42 public class BeanFactoryHandler extends DefaultElementHandler 43 { 44 45 public static final BeanFactoryHandler HANDLER = new BeanFactoryHandler(); 46 47 public Object startElement(Object parent, QName name, ElementBinding element) 48 { 49 return new GenericBeanFactoryMetaData(); 50 } 51 52 public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx) 53 { 54 GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) o; 55 for (int i = 0; i < attrs.getLength(); ++i) 56 { 57 String localName = attrs.getLocalName(i); 58 if ("name".equals(localName)) 59 bean.setName(attrs.getValue(i)); 60 else if ("class".equals(localName)) 61 bean.setBeanClass(attrs.getValue(i)); 62 else if ("mode".equals(localName)) 63 bean.setMode(new ControllerMode(attrs.getValue(i))); 64 } 65 } 66 67 public Object endElement(Object o, QName qName, ElementBinding element) 68 { 69 GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) o; 70 if (bean.getBeanClass() == null) 71 { 72 PropertyMetaData property = bean.getProperty("constructor"); 73 if (property == null) 74 throw new IllegalArgumentException ("BeanFactory should have a class attribute or a constructor element."); 75 ValueMetaData value = property.getValue(); 76 if (value == null) 77 throw new IllegalArgumentException ("BeanFactory should have a class attribute or a constructor element."); 78 ConstructorMetaData constructor = (ConstructorMetaData) value.getUnderlyingValue(); 79 if (constructor == null) 80 throw new IllegalArgumentException ("BeanFactory should have a class attribute or a constructor element."); 81 if (constructor.getFactoryMethod() == null) 82 throw new IllegalArgumentException ("BeanFactory should have a class attribute or the constructor element should have a factoryMethod attribute."); 83 if (constructor.getFactory() == null && constructor.getFactoryClass() == null) 84 throw new IllegalArgumentException ("BeanFactory should have a class attribute or the constructor element should have a either a factoryClass attribute or a factory element."); 85 } 86 return bean; 87 } 88 } 89 | Popular Tags |