KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xml > multispaced > XMBeanMetaDataFactory


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.xml.multispaced;
8
9 import org.jboss.xb.binding.ObjectModelFactory;
10 import org.jboss.xb.binding.UnmarshallingContext;
11 import org.xml.sax.Attributes JavaDoc;
12
13 /**
14  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
15  * @version <tt>$Revision: 1.3.2.3 $</tt>
16  */

17 public class XMBeanMetaDataFactory
18    implements ObjectModelFactory
19 {
20    public static final XMBeanMetaDataFactory INSTANCE = new XMBeanMetaDataFactory();
21
22    private XMBeanMetaDataFactory()
23    {
24    }
25
26    public Object JavaDoc completeRoot(Object JavaDoc root, UnmarshallingContext ctx,
27          String JavaDoc uri, String JavaDoc name)
28    {
29       return root;
30    }
31
32    public Object JavaDoc newRoot(Object JavaDoc root,
33                                UnmarshallingContext navigator,
34                                String JavaDoc namespaceURI,
35                                String JavaDoc localName,
36                                Attributes JavaDoc attrs)
37    {
38       return root == null ? new XMBeanMetaData() : root;
39    }
40
41    public void setValue(XMBeanMetaData xmbean,
42                         UnmarshallingContext navigator,
43                         String JavaDoc namespaceUri,
44                         String JavaDoc localName,
45                         String JavaDoc value)
46    {
47       if("description".equals(localName))
48       {
49          xmbean.setDescription(value);
50       }
51       else if("class".equals(localName))
52       {
53          xmbean.setMbeanClass(value);
54       }
55    }
56
57    public Object JavaDoc newChild(XMBeanMetaData xmbean,
58                           UnmarshallingContext navigator,
59                           String JavaDoc namespaceUri,
60                           String JavaDoc localName,
61                           Attributes JavaDoc attrs)
62    {
63       Object JavaDoc child;
64       if("constructor".equals(localName))
65       {
66          child = new XMBeanConstructorMetaData();
67       }
68       else if("attribute".equals(localName))
69       {
70          final XMBeanAttributeMetaData attribute = new XMBeanAttributeMetaData();
71          for(int i = 0; i < attrs.getLength(); ++i)
72          {
73             final String JavaDoc attrName = attrs.getLocalName(i);
74             if("access".equals(attrName))
75             {
76                attribute.setAccess(attrs.getValue(i));
77             }
78             else if("getMethod".equals(attrName))
79             {
80                attribute.setGetMethod(attrs.getValue(i));
81             }
82             else if("setMethod".equals(attrName))
83             {
84                attribute.setSetMethod(attrs.getValue(i));
85             }
86          }
87          child = attribute;
88       }
89       else if("operation".equals(localName))
90       {
91          child = new XMBeanOperationMetaData();
92       }
93       else if("notification".equals(localName))
94       {
95          child = new XMBeanNotificationMetaData();
96       }
97       else
98       {
99          child = null;
100       }
101
102       return child;
103    }
104
105    public void addChild(XMBeanMetaData xmbean, XMBeanConstructorMetaData constructor, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
106    {
107       xmbean.addConstructor(constructor);
108    }
109
110    public void addChild(XMBeanMetaData xmbean, XMBeanAttributeMetaData attribute, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
111    {
112       xmbean.addAttribute(attribute);
113    }
114
115    public void addChild(XMBeanMetaData xmbean, XMBeanOperationMetaData operation, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
116    {
117       xmbean.addOperation(operation);
118    }
119
120    public void addChild(XMBeanMetaData xmbean, XMBeanNotificationMetaData notification, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
121    {
122       xmbean.addNotification(notification);
123    }
124
125    public void addChild(XMBeanMetaData xmbean,
126                         Object JavaDoc pm,
127                         UnmarshallingContext navigator,
128                         String JavaDoc namespaceURI,
129                         String JavaDoc localName)
130    {
131       xmbean.setPersistenceManager(pm);
132    }
133
134    public void setValue(XMBeanConstructorMetaData constructor,
135                         UnmarshallingContext navigator,
136                         String JavaDoc namespaceUri,
137                         String JavaDoc localName,
138                         String JavaDoc value)
139    {
140       if("description".equals(localName))
141       {
142          constructor.setDescription(value);
143       }
144       else if("name".equals(localName))
145       {
146          constructor.setName(value);
147       }
148    }
149
150    public void setValue(XMBeanAttributeMetaData attribute,
151                         UnmarshallingContext navigator,
152                         String JavaDoc namespaceUri,
153                         String JavaDoc localName,
154                         String JavaDoc value)
155    {
156       if("description".equals(localName))
157       {
158          attribute.setDescription(value);
159       }
160       else if("name".equals(localName))
161       {
162          attribute.setName(value);
163       }
164       else if("type".equals(localName))
165       {
166          attribute.setType(value);
167       }
168    }
169
170    public void setValue(XMBeanOperationMetaData operation,
171                         UnmarshallingContext navigator,
172                         String JavaDoc namespaceUri,
173                         String JavaDoc localName,
174                         String JavaDoc value)
175    {
176       if("description".equals(localName))
177       {
178          operation.setDescription(value);
179       }
180       else if("name".equals(localName))
181       {
182          operation.setName(value);
183       }
184       else if("return-type".equals(localName))
185       {
186          operation.setReturnType(value);
187       }
188    }
189
190    public void setValue(XMBeanNotificationMetaData notification,
191                         UnmarshallingContext navigator,
192                         String JavaDoc namespaceUri,
193                         String JavaDoc localName,
194                         String JavaDoc value)
195    {
196       if("description".equals(localName))
197       {
198          notification.setDescription(value);
199       }
200       else if("name".equals(localName))
201       {
202          notification.setName(value);
203       }
204       else if("notification-type".equals(localName))
205       {
206          notification.setNotificationType(value);
207       }
208    }
209 }
210
Popular Tags