KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > deployment > xml > InjectionHandler


1 /*
2  *
3  */

4
5 package org.jboss.kernel.plugins.deployment.xml;
6
7 import javax.xml.namespace.NamespaceContext JavaDoc;
8 import javax.xml.namespace.QName JavaDoc;
9
10 import org.jboss.beans.metadata.plugins.InjectionType;
11 import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
12 import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
13 import org.jboss.dependency.spi.ControllerState;
14 import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler;
15 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
16 import org.xml.sax.Attributes JavaDoc;
17
18 /**
19  * DependencyHandler.
20  *
21  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
22  * @version $Revision: 43106 $
23  */

24 public class InjectionHandler extends DefaultElementHandler
25 {
26    /** The handler */
27    public static final InjectionHandler HANDLER = new InjectionHandler();
28
29    public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
30    {
31       AbstractInjectionValueMetaData vmd = new AbstractInjectionValueMetaData();
32       if (parent instanceof AbstractPropertyMetaData)
33       {
34          AbstractPropertyMetaData x = (AbstractPropertyMetaData) parent;
35          vmd.setPropertyMetaData(x);
36       }
37       return vmd;
38    }
39
40    public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
41    {
42       AbstractInjectionValueMetaData injection = (AbstractInjectionValueMetaData) o;
43       for (int i = 0; i < attrs.getLength(); ++i)
44       {
45          String JavaDoc localName = attrs.getLocalName(i);
46          if ("bean".equals(localName))
47             injection.setValue(attrs.getValue(i));
48          else if ("property".equals(localName))
49             injection.setProperty(attrs.getValue(i));
50          else if ("state".equals(localName))
51             injection.setDependentState(new ControllerState(attrs.getValue(i)));
52          else if ("whenRequired".equals(localName))
53             injection.setWhenRequiredState(new ControllerState(attrs.getValue(i)));
54          else if ("type".equals(localName))
55             injection.setInjectionType(new InjectionType(attrs.getValue(i)));
56       }
57    }
58
59 }
60
Popular Tags