1 22 package org.jboss.aop.microcontainer.beans.xml; 23 24 import javax.xml.namespace.NamespaceContext ; 25 import javax.xml.namespace.QName ; 26 27 import org.jboss.aop.microcontainer.beans.AspectBeanMetaDataFactory; 28 import org.jboss.aop.microcontainer.beans.LifecycleBeanMetaDataFactory; 29 import org.jboss.kernel.plugins.deployment.xml.BeanFactoryHandler; 30 import org.jboss.kernel.plugins.deployment.xml.BeanSchemaBinding20; 31 import org.jboss.kernel.plugins.deployment.xml.BeanSchemaBindingHelper; 32 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding; 33 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding; 34 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingInitializer; 35 import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding; 36 import org.xml.sax.Attributes ; 37 38 44 public class AOPBeansSchemaInitializer implements SchemaBindingInitializer 45 { 46 47 private static final String AOP_BEANS_NS = "urn:jboss:aop-beans:1.0"; 48 49 50 private static final QName aspectTypeQName = new QName (AOP_BEANS_NS, "aspectType"); 51 52 53 private static final QName lifecycleTypeQName = new QName (AOP_BEANS_NS, "lifecycleType"); 54 55 public SchemaBinding init(SchemaBinding schema) 56 { 57 TypeBinding aspectType = schema.getType(aspectTypeQName); 59 BeanSchemaBindingHelper.initBeanFactoryHandlers(aspectType); 60 aspectType.setHandler(new BeanFactoryHandler() 61 { 62 public Object startElement(Object parent, QName name, ElementBinding element) 63 { 64 return new AspectBeanMetaDataFactory(); 65 } 66 67 public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx) 68 { 69 super.attributes(o, elementName, element, attrs, nsCtx); 70 71 AspectBeanMetaDataFactory factory = (AspectBeanMetaDataFactory) o; 72 for (int i = 0; i < attrs.getLength(); ++i) 73 { 74 String localName = attrs.getLocalName(i); 75 if ("pointcut".equals(localName)) 76 factory.setPointcut(attrs.getValue(i)); 77 else if ("manager-bean".equals(localName)) 78 factory.setManagerBean(attrs.getValue(i)); 79 else if ("manager-property".equals(localName)) 80 factory.setManagerProperty(attrs.getValue(i)); 81 } 82 } 83 }); 84 85 TypeBinding lifecycleType = schema.getType(lifecycleTypeQName); 87 BeanSchemaBindingHelper.initBeanFactoryHandlers(lifecycleType); 88 lifecycleType.setHandler(new BeanFactoryHandler() 89 { 90 public Object startElement(Object parent, QName name, ElementBinding element) 91 { 92 return new LifecycleBeanMetaDataFactory(); 93 } 94 95 public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx) 96 { 97 super.attributes(o, elementName, element, attrs, nsCtx); 98 99 LifecycleBeanMetaDataFactory factory = (LifecycleBeanMetaDataFactory) o; 100 for (int i = 0; i < attrs.getLength(); ++i) 101 { 102 String localName = attrs.getLocalName(i); 103 if ("pointcut".equals(localName)) 104 factory.setPointcut(attrs.getValue(i)); 105 else if ("manager-bean".equals(localName)) 106 factory.setManagerBean(attrs.getValue(i)); 107 else if ("manager-property".equals(localName)) 108 factory.setManagerProperty(attrs.getValue(i)); 109 else if ("classes".equals(localName)) 110 factory.setClasses(attrs.getValue(i)); 111 } 112 } 113 }); 114 115 BeanSchemaBinding20.initArtifacts(schema); 117 118 return schema; 119 } 120 } 121 | Popular Tags |