KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > microcontainer > beans > xml > AOPBeansSchemaInitializer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.aop.microcontainer.beans.xml;
23
24 import javax.xml.namespace.NamespaceContext JavaDoc;
25 import javax.xml.namespace.QName JavaDoc;
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 JavaDoc;
37
38 /**
39  * AOPBeansSchemaInitializer.
40  *
41  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
42  * @version $Revision: 58260 $
43  */

44 public class AOPBeansSchemaInitializer implements SchemaBindingInitializer
45 {
46    /** The namespace */
47    private static final String JavaDoc AOP_BEANS_NS = "urn:jboss:aop-beans:1.0";
48
49    /** The aspect binding */
50    private static final QName JavaDoc aspectTypeQName = new QName JavaDoc(AOP_BEANS_NS, "aspectType");
51    
52    /** The lifecycle aspect binding */
53    private static final QName JavaDoc lifecycleTypeQName = new QName JavaDoc(AOP_BEANS_NS, "lifecycleType");
54    
55    public SchemaBinding init(SchemaBinding schema)
56    {
57       // aspect binding
58
TypeBinding aspectType = schema.getType(aspectTypeQName);
59       BeanSchemaBindingHelper.initBeanFactoryHandlers(aspectType);
60       aspectType.setHandler(new BeanFactoryHandler()
61       {
62          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
63          {
64             return new AspectBeanMetaDataFactory();
65          }
66
67          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc 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 JavaDoc 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       //lifecycle binding
86
TypeBinding lifecycleType = schema.getType(lifecycleTypeQName);
87       BeanSchemaBindingHelper.initBeanFactoryHandlers(lifecycleType);
88       lifecycleType.setHandler(new BeanFactoryHandler()
89       {
90          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
91          {
92             return new LifecycleBeanMetaDataFactory();
93          }
94
95          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc 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 JavaDoc 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       // TODO FIXME???
116
BeanSchemaBinding20.initArtifacts(schema);
117       
118       return schema;
119    }
120 }
121
Popular Tags