KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, 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.kernel.plugins.deployment.xml;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import javax.xml.namespace.NamespaceContext JavaDoc;
30 import javax.xml.namespace.QName JavaDoc;
31
32 import org.jboss.beans.metadata.plugins.*;
33 import org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData;
34 import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
35 import org.jboss.beans.metadata.spi.DemandMetaData;
36 import org.jboss.beans.metadata.spi.DependencyMetaData;
37 import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
38 import org.jboss.beans.metadata.spi.ParameterMetaData;
39 import org.jboss.beans.metadata.spi.PropertyMetaData;
40 import org.jboss.beans.metadata.spi.SupplyMetaData;
41 import org.jboss.beans.metadata.spi.ValueMetaData;
42 import org.jboss.beans.metadata.plugins.InjectionType;
43 import org.jboss.dependency.spi.ControllerMode;
44 import org.jboss.dependency.spi.ControllerState;
45 import org.jboss.kernel.plugins.deployment.AbstractKernelDeployment;
46 import org.jboss.logging.Logger;
47 import org.jboss.xb.binding.sunday.unmarshalling.CharactersHandler;
48 import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler;
49 import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementInterceptor;
50 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
51 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
52 import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
53 import org.xml.sax.Attributes JavaDoc;
54
55 /**
56  * The POJO schema binding.
57  *
58  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
59  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
60  * @version $Revision: 57306 $
61  */

62 public class BeanSchemaBinding
63 {
64    /** The log */
65    private static final Logger log = Logger.getLogger(BeanSchemaBinding.class);
66
67    /** The namespace */
68    private static final String JavaDoc BEAN_DEPLOYER_NS = "urn:jboss:bean-deployer";
69
70    /** The deployment binding */
71    private static final QName JavaDoc deploymentTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "deploymentType");
72
73    /** The bean binding */
74    private static final QName JavaDoc beanTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "beanType");
75
76    /** The bean element name */
77    private static final QName JavaDoc beanQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "bean");
78
79    /** The beanfactory binding */
80    private static final QName JavaDoc beanFactoryTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "beanfactoryType");
81
82    /** The beanfactory element name */
83    private static final QName JavaDoc beanFactoryQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "beanfactory");
84
85    /** The classloader binding */
86    private static final QName JavaDoc classloaderTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "classloaderType");
87
88    /** The classloader element name */
89    private static final QName JavaDoc classloaderQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "classloader");
90
91    /** The constructor binding */
92    private static final QName JavaDoc constructorTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "constructorType");
93
94    /** The constructor element name */
95    private static final QName JavaDoc constructorQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "constructor");
96
97    /** The factory element name */
98    private static final QName JavaDoc factoryQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "factory");
99
100    /** The parameter binding */
101    private static final QName JavaDoc parameterTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "parameterType");
102
103    /** The parameter element name */
104    private static final QName JavaDoc parameterQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "parameter");
105
106    /** The lifecycle binding */
107    private static final QName JavaDoc lifecycleTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "lifecycleType");
108
109    /** The create element name */
110    private static final QName JavaDoc createQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "create");
111
112    /** The start element name */
113    private static final QName JavaDoc startQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "start");
114
115    /** The stop element name */
116    private static final QName JavaDoc stopQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "stop");
117
118    /** The destroy element name */
119    private static final QName JavaDoc destroyQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "destroy");
120
121    /** The property binding */
122    private static final QName JavaDoc propertyTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "propertyType");
123
124    /** The property element name */
125    private static final QName JavaDoc propertyQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "property");
126
127    /** The depends binding */
128    private static final QName JavaDoc dependsTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "dependsType");
129
130    /** The depends element name */
131    private static final QName JavaDoc dependsQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "depends");
132
133    /** The demand binding */
134    private static final QName JavaDoc demandTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "demandType");
135
136    /** The demand element name */
137    private static final QName JavaDoc demandQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "demand");
138
139    /** The supply binding */
140    private static final QName JavaDoc supplyTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "supplyType");
141
142    /** The supply element name */
143    private static final QName JavaDoc supplyQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "supply");
144
145    /** The dependency binding */
146    private static final QName JavaDoc dependencyTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "dependencyType");
147
148    /** The injection binding */
149    private static final QName JavaDoc injectionTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "injectionType");
150
151    /** The inject element name */
152    private static final QName JavaDoc injectQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "inject");
153
154    /** The plain value binding */
155    private static final QName JavaDoc plainValueTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "plainValueType");
156
157    /** The value binding */
158    private static final QName JavaDoc valueTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "valueType");
159
160    /** The value element name */
161    private static final QName JavaDoc valueQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "value");
162
163    /** The null element name */
164    private static final QName JavaDoc nullQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "null");
165
166    /** The collection binding */
167    private static final QName JavaDoc collectionTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "collectionType");
168
169    /** The collection element name */
170    private static final QName JavaDoc collectionQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "collection");
171
172    /** The list binding */
173    private static final QName JavaDoc listTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "listType");
174
175    /** The list element name */
176    private static final QName JavaDoc listQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "list");
177
178    /** The set binding */
179    private static final QName JavaDoc setTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "setType");
180
181    /** The set element name */
182    private static final QName JavaDoc setQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "set");
183
184    /** The array binding */
185    private static final QName JavaDoc arrayTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "arrayType");
186
187    /** The array element name */
188    private static final QName JavaDoc arrayQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "array");
189
190    /** The map binding */
191    private static final QName JavaDoc mapTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "mapType");
192
193    /** The map element name */
194    private static final QName JavaDoc mapQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "map");
195
196    /** The entry binding */
197    private static final QName JavaDoc entryTypeQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "entryType");
198
199    /** The entry element name */
200    private static final QName JavaDoc entryQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "entry");
201
202    /** The key element name */
203    private static final QName JavaDoc keyQName = new QName JavaDoc(BEAN_DEPLOYER_NS, "key");
204
205    /** The schema binding */
206    private static SchemaBinding schemaBinding;
207    
208    /** The value handler */
209    public static ValueMetaDataElementInterceptor VALUES = new ValueMetaDataElementInterceptor();
210    
211    /** The null handler */
212    public static NullValueElementInterceptor NULLVALUES = new NullValueElementInterceptor();
213
214    /**
215     * Initialize the schema binding
216     *
217     * @param schemaBinding the schema binding
218     */

219    protected synchronized static void init(SchemaBinding schemaBinding)
220    {
221       // Encourage users to upgrade to the more complete 2.0 version of the schema
222
log.warn("You should use the 2.0 version of the Microcontainer xml. xmlns='urn:jboss:bean-deployer:2.0'");
223       
224       BeanSchemaBinding.schemaBinding = schemaBinding;
225
226       // deployment binding
227
TypeBinding deploymentType = schemaBinding.getType(deploymentTypeQName);
228       deploymentType.setHandler(new DefaultElementHandler()
229       {
230          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
231          {
232             return new AbstractKernelDeployment();
233          }
234       });
235
236       // deployment has a classloader
237
deploymentType.pushInterceptor(classloaderQName, new DefaultElementInterceptor()
238       {
239          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
240          {
241             AbstractKernelDeployment deployment = (AbstractKernelDeployment) parent;
242             AbstractClassLoaderMetaData classloader = (AbstractClassLoaderMetaData) child;
243             deployment.setClassLoader(classloader);
244             // add classloaders as value beans
245
List JavaDoc<BeanMetaDataFactory> beans = deployment.getBeanFactories();
246             if (beans == null)
247             {
248                beans = new ArrayList JavaDoc<BeanMetaDataFactory>();
249                deployment.setBeanFactories(beans);
250             }
251             beans.add(classloader);
252          }
253       });
254
255       // deployment has a list beans
256
deploymentType.pushInterceptor(beanQName, new DefaultElementInterceptor()
257       {
258          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
259          {
260             AbstractKernelDeployment deployment = (AbstractKernelDeployment) parent;
261             AbstractBeanMetaData bean = (AbstractBeanMetaData) child;
262             List JavaDoc<BeanMetaDataFactory> beans = deployment.getBeanFactories();
263             if (beans == null)
264             {
265                beans = new ArrayList JavaDoc<BeanMetaDataFactory>();
266                deployment.setBeanFactories(beans);
267             }
268             beans.add(bean);
269          }
270       });
271
272       // deployment has a list beanfactorys
273
deploymentType.pushInterceptor(beanFactoryQName, new DefaultElementInterceptor()
274       {
275          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
276          {
277             AbstractKernelDeployment deployment = (AbstractKernelDeployment) parent;
278             AbstractBeanMetaData bean = (AbstractBeanMetaData) child;
279             List JavaDoc<BeanMetaDataFactory> beans = deployment.getBeanFactories();
280             if (beans == null)
281             {
282                beans = new ArrayList JavaDoc<BeanMetaDataFactory>();
283                deployment.setBeanFactories(beans);
284             }
285             beans.add(bean);
286          }
287       });
288
289       // bean binding
290
TypeBinding beanType = schemaBinding.getType(beanTypeQName);
291
292       /*
293       ClassMetaData classMetaData = new ClassMetaData();
294       classMetaData.setImpl(AbstractBeanMetaData.class.getName());
295       beanType.setClassMetaData(classMetaData);
296       
297       QName CLASS = new QName("class");
298       AttributeBinding attribute = beanType.getAttribute(CLASS);
299       PropertyMetaData propertyMetaData = new PropertyMetaData();
300       propertyMetaData.setName("bean");
301       attribute.setPropertyMetaData(propertyMetaData);
302
303       QName MODE = new QName("mode");
304       attribute = beanType.getAttribute(MODE);
305       ValueAdapter modeAdapter = new ValueAdapter()
306       {
307          public Object cast(Object o, Class c)
308          {
309             String string = (String) o;
310             return new ControllerMode(string);
311          }
312       };
313       attribute.setValueAdapter(modeAdapter);
314       */

315       beanType.setHandler(new DefaultElementHandler()
316       {
317          
318          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
319          {
320             return new AbstractBeanMetaData();
321          }
322
323          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
324          {
325             AbstractBeanMetaData bean = (AbstractBeanMetaData) o;
326             for (int i = 0; i < attrs.getLength(); ++i)
327             {
328                String JavaDoc localName = attrs.getLocalName(i);
329                if ("name".equals(localName))
330                   bean.setName(attrs.getValue(i));
331                else if ("class".equals(localName))
332                   bean.setBean(attrs.getValue(i));
333                else if ("mode".equals(localName))
334                   bean.setMode(new ControllerMode(attrs.getValue(i)));
335             }
336          }
337       });
338
339       // beanfactory binding
340
TypeBinding beanFactoryType = schemaBinding.getType(beanFactoryTypeQName);
341       beanFactoryType.setHandler(new DefaultElementHandler()
342       {
343          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
344          {
345             return new GenericBeanFactoryMetaData();
346          }
347
348          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
349          {
350             GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) o;
351             for (int i = 0; i < attrs.getLength(); ++i)
352             {
353                String JavaDoc localName = attrs.getLocalName(i);
354                if ("name".equals(localName))
355                   bean.setName(attrs.getValue(i));
356                else if ("class".equals(localName))
357                   bean.setBeanClass(attrs.getValue(i));
358                else if ("mode".equals(localName))
359                   bean.setMode(new ControllerMode(attrs.getValue(i)));
360             }
361          }
362       });
363
364       // bean has a classloader
365
beanType.pushInterceptor(classloaderQName, new DefaultElementInterceptor()
366       {
367          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
368          {
369             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
370             AbstractClassLoaderMetaData classloader = (AbstractClassLoaderMetaData) child;
371             bean.setClassLoader(classloader);
372          }
373       });
374
375       // beanfactory has a classloader
376
beanFactoryType.pushInterceptor(classloaderQName, new DefaultElementInterceptor()
377       {
378          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
379          {
380             GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) parent;
381             AbstractClassLoaderMetaData classloader = (AbstractClassLoaderMetaData) child;
382             bean.setClassLoader(classloader);
383          }
384       });
385
386       // bean has a constructor
387
beanType.pushInterceptor(constructorQName, new DefaultElementInterceptor()
388       {
389          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
390          {
391             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
392             AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) child;
393             bean.setConstructor(constructor);
394          }
395       });
396
397       // beanfactory has a constructor
398
beanFactoryType.pushInterceptor(constructorQName, new DefaultElementInterceptor()
399       {
400          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
401          {
402             GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) parent;
403             AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) child;
404             bean.setBeanConstructor(constructor);
405          }
406       });
407
408       // classloader binding
409
TypeBinding classloaderType = schemaBinding.getType(classloaderTypeQName);
410       configureValueBindings(classloaderType);
411       classloaderType.setHandler(new DefaultElementHandler()
412       {
413          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
414          {
415             return new AbstractClassLoaderMetaData();
416          }
417
418          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
419          {
420          }
421       });
422
423       // constructor binding
424
TypeBinding constructorType = schemaBinding.getType(constructorTypeQName);
425       constructorType.setHandler(new DefaultElementHandler()
426       {
427          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
428          {
429             return new AbstractConstructorMetaData();
430          }
431
432          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
433          {
434             AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) o;
435             for (int i = 0; i < attrs.getLength(); ++i)
436             {
437                String JavaDoc localName = attrs.getLocalName(i);
438                if ("factoryClass".equals(localName))
439                   constructor.setFactoryClass(attrs.getValue(i));
440                else if ("factoryMethod".equals(localName))
441                   constructor.setFactoryMethod(attrs.getValue(i));
442             }
443          }
444       });
445
446       // constructor has a factory
447
constructorType.pushInterceptor(factoryQName, new DefaultElementInterceptor()
448       {
449          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
450          {
451             AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) parent;
452             AbstractDependencyValueMetaData factory = (AbstractDependencyValueMetaData) child;
453             constructor.setFactory(factory);
454          }
455       });
456
457       // constructor has a list parameters
458
constructorType.pushInterceptor(parameterQName, new DefaultElementInterceptor()
459       {
460          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
461          {
462             AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) parent;
463             AbstractParameterMetaData parameter = (AbstractParameterMetaData) child;
464             List JavaDoc<ParameterMetaData> parameters = constructor.getParameters();
465             if (parameters == null)
466             {
467                parameters = new ArrayList JavaDoc<ParameterMetaData>();
468                constructor.setParameters(parameters);
469             }
470             parameter.setIndex(parameters.size());
471             parameters.add(parameter);
472          }
473       });
474
475       // parameter binding
476
TypeBinding parameterType = schemaBinding.getType(parameterTypeQName);
477       configureValueBindings(parameterType);
478       parameterType.setHandler(new DefaultElementHandler()
479       {
480          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
481          {
482             return new AbstractParameterMetaData();
483          }
484
485          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
486          {
487             AbstractParameterMetaData parameter = (AbstractParameterMetaData) o;
488             for (int i = 0; i < attrs.getLength(); ++i)
489             {
490                String JavaDoc localName = attrs.getLocalName(i);
491                if ("class".equals(localName))
492                   parameter.setType(attrs.getValue(i));
493             }
494          }
495       });
496       
497       // parameter can take a value
498
parameterType.setSimpleType(new CharactersHandler()
499       {
500          public Object JavaDoc unmarshal(QName JavaDoc qName, TypeBinding typeBinding, NamespaceContext JavaDoc nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String JavaDoc value)
501          {
502             return new StringValueMetaData(value);
503          }
504
505          public void setValue(QName JavaDoc qName, ElementBinding element, Object JavaDoc owner, Object JavaDoc value)
506          {
507             AbstractParameterMetaData parameter = (AbstractParameterMetaData) owner;
508             parameter.setValue((StringValueMetaData) value);
509          }
510       });
511
512       // bean has a create
513
beanType.pushInterceptor(createQName, new DefaultElementInterceptor()
514       {
515          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
516          {
517             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
518             AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
519             lifecycle.setType("create");
520             bean.setCreate(lifecycle);
521          }
522       });
523
524       // beanfactory has a create
525
beanFactoryType.pushInterceptor(createQName, new DefaultElementInterceptor()
526       {
527          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
528          {
529             GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) parent;
530             AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
531             lifecycle.setType("create");
532             bean.setBeanCreate(lifecycle);
533          }
534       });
535
536       // bean has a start
537
beanType.pushInterceptor(startQName, new DefaultElementInterceptor()
538       {
539          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
540          {
541             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
542             AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
543             lifecycle.setType("start");
544             bean.setStart(lifecycle);
545          }
546       });
547
548       // beanfactory has a start
549
beanFactoryType.pushInterceptor(startQName, new DefaultElementInterceptor()
550       {
551          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
552          {
553             GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) parent;
554             AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
555             lifecycle.setType("start");
556             bean.setBeanStart(lifecycle);
557          }
558       });
559
560       // bean has a stop
561
beanType.pushInterceptor(stopQName, new DefaultElementInterceptor()
562       {
563          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
564          {
565             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
566             AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
567             lifecycle.setType("stop");
568             bean.setStop(lifecycle);
569          }
570       });
571
572       // bean has a destroy
573
beanType.pushInterceptor(destroyQName, new DefaultElementInterceptor()
574       {
575          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
576          {
577             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
578             AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
579             lifecycle.setType("destroy");
580             bean.setDestroy(lifecycle);
581          }
582       });
583
584       // lifecycle binding
585
TypeBinding lifecycleType = schemaBinding.getType(lifecycleTypeQName);
586       lifecycleType.setHandler(new DefaultElementHandler()
587       {
588          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
589          {
590             return new AbstractLifecycleMetaData();
591          }
592
593          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
594          {
595             AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) o;
596             for (int i = 0; i < attrs.getLength(); ++i)
597             {
598                String JavaDoc localName = attrs.getLocalName(i);
599                if ("method".equals(localName))
600                   lifecycle.setMethodName(attrs.getValue(i));
601             }
602          }
603       });
604
605       // lifecycle has a list parameters
606
lifecycleType.pushInterceptor(parameterQName, new DefaultElementInterceptor()
607       {
608          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
609          {
610             AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) parent;
611             AbstractParameterMetaData parameter = (AbstractParameterMetaData) child;
612             List JavaDoc<ParameterMetaData> parameters = lifecycle.getParameters();
613             if (parameters == null)
614             {
615                parameters = new ArrayList JavaDoc<ParameterMetaData>();
616                lifecycle.setParameters(parameters);
617             }
618             parameter.setIndex(parameters.size());
619             parameters.add(parameter);
620          }
621       });
622
623       // bean has a set of properties
624
beanType.pushInterceptor(propertyQName, new DefaultElementInterceptor()
625       {
626          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
627          {
628             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
629             AbstractPropertyMetaData property = (AbstractPropertyMetaData) child;
630             Set JavaDoc<PropertyMetaData> properties = bean.getProperties();
631             if (properties == null)
632             {
633                properties = new HashSet JavaDoc<PropertyMetaData>();
634                bean.setProperties(properties);
635             }
636             properties.add(property);
637          }
638       });
639
640       // beanfactory has a set of properties
641
beanFactoryType.pushInterceptor(propertyQName, new DefaultElementInterceptor()
642       {
643          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
644          {
645             GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) parent;
646             AbstractPropertyMetaData property = (AbstractPropertyMetaData) child;
647             bean.addBeanProperty(property);
648          }
649       });
650
651       // bean has a set of depends
652
beanType.pushInterceptor(dependsQName, new DefaultElementInterceptor()
653       {
654          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
655          {
656             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
657             AbstractDependencyMetaData dependency = (AbstractDependencyMetaData) child;
658             Set JavaDoc<DependencyMetaData> depends = bean.getDepends();
659             if (depends == null)
660             {
661                depends = new HashSet JavaDoc<DependencyMetaData>();
662                bean.setDepends(depends);
663             }
664             depends.add(dependency);
665          }
666       });
667
668       // beanfactory has a set of depends
669
beanFactoryType.pushInterceptor(dependsQName, new DefaultElementInterceptor()
670       {
671          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
672          {
673             GenericBeanFactoryMetaData bean = (GenericBeanFactoryMetaData) parent;
674             AbstractDependencyMetaData dependency = (AbstractDependencyMetaData) child;
675             Set JavaDoc<DependencyMetaData> depends = bean.getDepends();
676             if (depends == null)
677             {
678                depends = new HashSet JavaDoc<DependencyMetaData>();
679                bean.setDepends(depends);
680             }
681             depends.add(dependency);
682          }
683       });
684
685       // bean has a set of demands
686
beanType.pushInterceptor(demandQName, new DefaultElementInterceptor()
687       {
688          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
689          {
690             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
691             AbstractDemandMetaData demand = (AbstractDemandMetaData) child;
692             Set JavaDoc<DemandMetaData> demands = bean.getDemands();
693             if (demands == null)
694             {
695                demands = new HashSet JavaDoc<DemandMetaData>();
696                bean.setDemands(demands);
697             }
698             demands.add(demand);
699          }
700       });
701
702       // beanfactory has a set of demands
703
beanFactoryType.pushInterceptor(demandQName, new DefaultElementInterceptor()
704       {
705          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
706          {
707             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
708             AbstractDemandMetaData demand = (AbstractDemandMetaData) child;
709             Set JavaDoc<DemandMetaData> demands = bean.getDemands();
710             if (demands == null)
711             {
712                demands = new HashSet JavaDoc<DemandMetaData>();
713                bean.setDemands(demands);
714             }
715             demands.add(demand);
716          }
717       });
718
719       // bean has a set of supplies
720
beanType.pushInterceptor(supplyQName, new DefaultElementInterceptor()
721       {
722          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
723          {
724             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
725             AbstractSupplyMetaData supply = (AbstractSupplyMetaData) child;
726             Set JavaDoc<SupplyMetaData> supplies = bean.getSupplies();
727             if (supplies == null)
728             {
729                supplies = new HashSet JavaDoc<SupplyMetaData>();
730                bean.setSupplies(supplies);
731             }
732             supplies.add(supply);
733          }
734       });
735
736       // beanfactory has a set of supplies
737
beanFactoryType.pushInterceptor(supplyQName, new DefaultElementInterceptor()
738       {
739          public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
740          {
741             AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
742             AbstractSupplyMetaData supply = (AbstractSupplyMetaData) child;
743             Set JavaDoc<SupplyMetaData> supplies = bean.getSupplies();
744             if (supplies == null)
745             {
746                supplies = new HashSet JavaDoc<SupplyMetaData>();
747                bean.setSupplies(supplies);
748             }
749             supplies.add(supply);
750          }
751       });
752
753       // property binding
754
TypeBinding propertyType = schemaBinding.getType(propertyTypeQName);
755       configureValueBindings(propertyType);
756       propertyType.setHandler(new DefaultElementHandler()
757       {
758          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
759          {
760             return new AbstractPropertyMetaData();
761          }
762
763          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
764          {
765             AbstractPropertyMetaData property = (AbstractPropertyMetaData) o;
766             for (int i = 0; i < attrs.getLength(); ++i)
767             {
768                String JavaDoc localName = attrs.getLocalName(i);
769                if ("name".equals(localName))
770                   property.setName(attrs.getValue(i));
771                else if ("class".equals(localName))
772                {
773                   StringValueMetaData svmd = new StringValueMetaData();
774                   svmd.setType(attrs.getValue(i));
775                   property.setValue(svmd);
776                }
777             }
778          }
779          
780          public Object JavaDoc endElement(Object JavaDoc o, QName JavaDoc qName, ElementBinding element)
781          {
782             AbstractPropertyMetaData x = (AbstractPropertyMetaData) o;
783             String JavaDoc name = x.getName();
784             if (name == null || name.trim().length() == 0)
785                throw new IllegalArgumentException JavaDoc("Null or empty property name.");
786             return o;
787          }
788       });
789
790       // property can take a value
791
propertyType.setSimpleType(new CharactersHandler()
792       {
793          public Object JavaDoc unmarshal(QName JavaDoc qName, TypeBinding typeBinding, NamespaceContext JavaDoc nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String JavaDoc value)
794          {
795             return new StringValueMetaData(value);
796          }
797
798          public void setValue(QName JavaDoc qName, ElementBinding element, Object JavaDoc owner, Object JavaDoc value)
799          {
800             AbstractPropertyMetaData property = (AbstractPropertyMetaData) owner;
801             StringValueMetaData svmd = (StringValueMetaData) value;
802             ValueMetaData vmd = property.getValue();
803             if (vmd != null && vmd instanceof StringValueMetaData)
804             {
805                StringValueMetaData previous = (StringValueMetaData) vmd;
806                String JavaDoc type = previous.getType();
807                if (type != null)
808                   svmd.setType(type);
809             }
810             property.setValue(svmd);
811          }
812       });
813
814       // dependency binding
815
TypeBinding dependsType = schemaBinding.getType(dependsTypeQName);
816       dependsType.setHandler(new DefaultElementHandler()
817       {
818          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
819          {
820             return new AbstractDependencyMetaData();
821          }
822
823          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
824          {
825          }
826          
827          public Object JavaDoc endElement(Object JavaDoc o, QName JavaDoc qName, ElementBinding element)
828          {
829             AbstractDependencyMetaData x = (AbstractDependencyMetaData) o;
830             String JavaDoc name = (String JavaDoc) x.getDependency();
831             if (name == null || name.trim().length() == 0)
832                throw new IllegalArgumentException JavaDoc("Null or empty dependency.");
833             return o;
834          }
835       });
836
837       // depends can take a value
838
dependsType.setSimpleType(new CharactersHandler()
839       {
840          public Object JavaDoc unmarshal(QName JavaDoc qName, TypeBinding typeBinding, NamespaceContext JavaDoc nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String JavaDoc value)
841          {
842             return value;
843          }
844
845          public void setValue(QName JavaDoc qname, ElementBinding element, Object JavaDoc owner, Object JavaDoc value)
846          {
847             AbstractDependencyMetaData depends = (AbstractDependencyMetaData) owner;
848             depends.setDependency(value);
849          }
850       });
851
852       // demand binding
853
TypeBinding demandType = schemaBinding.getType(demandTypeQName);
854       demandType.setHandler(new DefaultElementHandler()
855       {
856          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
857          {
858             return new AbstractDemandMetaData();
859          }
860
861          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
862          {
863             AbstractDemandMetaData demand = (AbstractDemandMetaData) o;
864             for (int i = 0; i < attrs.getLength(); ++i)
865             {
866                String JavaDoc localName = attrs.getLocalName(i);
867                if ("state".equals(localName))
868                   demand.setWhenRequired(new ControllerState(attrs.getValue(i)));
869             }
870          }
871          
872          public Object JavaDoc endElement(Object JavaDoc o, QName JavaDoc qName, ElementBinding element)
873          {
874             AbstractDemandMetaData x = (AbstractDemandMetaData) o;
875             String JavaDoc name = (String JavaDoc) x.getDemand();
876             if (name == null || name.trim().length() == 0)
877                throw new IllegalArgumentException JavaDoc("Null or empty demand.");
878             return o;
879          }
880       });
881
882       // demand can take a value
883
demandType.setSimpleType(new CharactersHandler()
884       {
885          public Object JavaDoc unmarshal(QName JavaDoc qName, TypeBinding typeBinding, NamespaceContext JavaDoc nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String JavaDoc value)
886          {
887             return value;
888          }
889
890          public void setValue(QName JavaDoc qname, ElementBinding element, Object JavaDoc owner, Object JavaDoc value)
891          {
892             AbstractDemandMetaData demand = (AbstractDemandMetaData) owner;
893             demand.setDemand(value);
894          }
895       });
896
897       // supply binding
898
TypeBinding supplyType = schemaBinding.getType(supplyTypeQName);
899       supplyType.setHandler(new DefaultElementHandler()
900       {
901          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
902          {
903             return new AbstractSupplyMetaData();
904          }
905          
906          public Object JavaDoc endElement(Object JavaDoc o, QName JavaDoc qName, ElementBinding element)
907          {
908             AbstractSupplyMetaData x = (AbstractSupplyMetaData) o;
909             String JavaDoc name = (String JavaDoc) x.getSupply();
910             if (name == null || name.trim().length() == 0)
911                throw new IllegalArgumentException JavaDoc("Null or empty supply.");
912             return o;
913          }
914       });
915
916       // supply can take a value
917
supplyType.setSimpleType(new CharactersHandler()
918       {
919          public Object JavaDoc unmarshal(QName JavaDoc qName, TypeBinding typeBinding, NamespaceContext JavaDoc nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String JavaDoc value)
920          {
921             return value;
922          }
923
924          public void setValue(QName JavaDoc qName, ElementBinding element, Object JavaDoc owner, Object JavaDoc value)
925          {
926             AbstractSupplyMetaData supply = (AbstractSupplyMetaData) owner;
927             supply.setSupply(value);
928          }
929       });
930
931       // dependency binding
932
TypeBinding dependencyType = schemaBinding.getType(dependencyTypeQName);
933       dependencyType.setHandler(new DefaultElementHandler()
934       {
935          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
936          {
937             return new AbstractDependencyValueMetaData();
938          }
939
940          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
941          {
942             AbstractDependencyValueMetaData dependency = (AbstractDependencyValueMetaData) o;
943             for (int i = 0; i < attrs.getLength(); ++i)
944             {
945                String JavaDoc localName = attrs.getLocalName(i);
946                if ("bean".equals(localName))
947                   dependency.setValue(attrs.getValue(i));
948                else if ("property".equals(localName))
949                   dependency.setProperty(attrs.getValue(i));
950                else if ("state".equals(localName))
951                   dependency.setDependentState(new ControllerState(attrs.getValue(i)));
952                else if ("whenRequired".equals(localName))
953                   dependency.setWhenRequiredState(new ControllerState(attrs.getValue(i)));
954             }
955          }
956          
957          public Object JavaDoc endElement(Object JavaDoc o, QName JavaDoc qName, ElementBinding element)
958          {
959             AbstractDependencyValueMetaData x = (AbstractDependencyValueMetaData) o;
960             String JavaDoc name = (String JavaDoc) x.getUnderlyingValue();
961             if (name == null || name.trim().length() == 0)
962                throw new IllegalArgumentException JavaDoc("Null or empty bean in injection/factory.");
963             return o;
964          }
965       });
966
967       // injection binding
968
TypeBinding injectionType = schemaBinding.getType(injectionTypeQName);
969       injectionType.setHandler(new DefaultElementHandler()
970       {
971          public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
972          {
973             AbstractInjectionValueMetaData vmd = new AbstractInjectionValueMetaData();
974             if (parent instanceof AbstractPropertyMetaData)
975             {
976                AbstractPropertyMetaData x = (AbstractPropertyMetaData) parent;
977                vmd.setPropertyMetaData(x);
978             }
979             return vmd;
980          }
981
982          public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
983          {
984             AbstractInjectionValueMetaData injection = (AbstractInjectionValueMetaData) o;
985             for (int i = 0; i < attrs.getLength(); ++i)
986             {
987                String JavaDoc localName = attrs.getLocalName(i);
988                if ("bean".equals(localName))
989                   injection.setValue(attrs.getValue(i));
990                else if ("property".equals(localName))
991                   injection.setProperty(attrs.getValue(i));
992                else if ("state".equals(localName))
993                   injection.setDependentState(new ControllerState(attrs.getValue(i)));
994                else if ("whenRequired".equals(localName))
995                   injection.setWhenRequiredState(new ControllerState(attrs.getValue(i)));
996                else if ("type".equals(localName))
997                   injection.setInjectionType(new InjectionType(attrs.getValue(i)));
998             }
999          }
1000
1001      });
1002
1003      // value binding
1004
TypeBinding plainValueType = schemaBinding.getType(plainValueTypeQName);
1005      plainValueType.setHandler(new DefaultElementHandler()
1006      {
1007         public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
1008         {
1009            return new StringValueMetaData();
1010         }
1011
1012         public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
1013         {
1014            StringValueMetaData value = (StringValueMetaData) o;
1015            for (int i = 0; i < attrs.getLength(); ++i)
1016            {
1017               String JavaDoc localName = attrs.getLocalName(i);
1018               if ("class".equals(localName))
1019                  value.setType(attrs.getValue(i));
1020            }
1021         }
1022      });
1023
1024      // value can take a value
1025
plainValueType.setSimpleType(new CharactersHandler()
1026      {
1027         public Object JavaDoc unmarshal(QName JavaDoc qName, TypeBinding typeBinding, NamespaceContext JavaDoc nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String JavaDoc value)
1028         {
1029            return value;
1030         }
1031
1032         public void setValue(QName JavaDoc qName, ElementBinding element, Object JavaDoc owner, Object JavaDoc value)
1033         {
1034            StringValueMetaData valueMetaData = (StringValueMetaData) owner;
1035            valueMetaData.setValue(value);
1036         }
1037      });
1038
1039      // value binding
1040
TypeBinding valueType = schemaBinding.getType(valueTypeQName);
1041      configureValueBindings(valueType);
1042      valueType.setHandler(new DefaultElementHandler()
1043      {
1044         public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
1045         {
1046            return new AbstractValueMetaData(new StringValueMetaData());
1047         }
1048
1049         public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
1050         {
1051            AbstractValueMetaData value = (AbstractValueMetaData) o;
1052            StringValueMetaData string = (StringValueMetaData) value.getValue();
1053            for (int i = 0; i < attrs.getLength(); ++i)
1054            {
1055               String JavaDoc localName = attrs.getLocalName(i);
1056               if ("class".equals(localName))
1057                  string.setType(attrs.getValue(i));
1058            }
1059         }
1060      });
1061
1062      // value can take a value
1063
valueType.setSimpleType(new CharactersHandler()
1064      {
1065         public Object JavaDoc unmarshal(QName JavaDoc qName, TypeBinding typeBinding, NamespaceContext JavaDoc nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String JavaDoc value)
1066         {
1067            return value;
1068         }
1069
1070         public void setValue(QName JavaDoc qName, ElementBinding element, Object JavaDoc owner, Object JavaDoc value)
1071         {
1072            AbstractValueMetaData valueMetaData = (AbstractValueMetaData) owner;
1073            StringValueMetaData string = (StringValueMetaData) valueMetaData.getValue();
1074            string.setValue(value);
1075         }
1076      });
1077
1078      // collection binding
1079
configureCollection(collectionTypeQName);
1080
1081      // list binding
1082
configureCollection(listTypeQName);
1083
1084      // set binding
1085
configureCollection(setTypeQName);
1086
1087      // array binding
1088
configureCollection(arrayTypeQName);
1089
1090      // map binding
1091
TypeBinding mapType = schemaBinding.getType(mapTypeQName);
1092      mapType.setHandler(new DefaultElementHandler()
1093      {
1094         public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
1095         {
1096            return new AbstractMapMetaData();
1097         }
1098
1099         public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
1100         {
1101            AbstractMapMetaData collection = (AbstractMapMetaData) o;
1102            for (int i = 0; i < attrs.getLength(); ++i)
1103            {
1104               String JavaDoc localName = attrs.getLocalName(i);
1105               if ("class".equals(localName))
1106                  collection.setType(attrs.getValue(i));
1107               else if ("keyClass".equals(localName))
1108                  collection.setKeyType(attrs.getValue(i));
1109               else if ("valueClass".equals(localName))
1110                  collection.setValueType(attrs.getValue(i));
1111            }
1112         }
1113      });
1114
1115      // map has a map entries
1116
mapType.pushInterceptor(entryQName, new DefaultElementInterceptor()
1117      {
1118         public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
1119         {
1120            AbstractMapMetaData map = (AbstractMapMetaData) parent;
1121            MapEntry entry = (MapEntry) child;
1122            AbstractValueMetaData entryKey = (AbstractValueMetaData) entry.key;
1123            if (entryKey == null)
1124               throw new IllegalArgumentException JavaDoc("No key in map entry");
1125            AbstractValueMetaData entryValue = (AbstractValueMetaData) entry.value;
1126            if (entryValue == null)
1127               throw new IllegalArgumentException JavaDoc("No value in map entry");
1128            map.put((MetaDataVisitorNode) entryKey.getValue(), (MetaDataVisitorNode) entryValue.getValue());
1129         }
1130      });
1131
1132      // entry binding
1133
TypeBinding entryType = schemaBinding.getType(entryTypeQName);
1134      entryType.setHandler(new DefaultElementHandler()
1135      {
1136         public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
1137         {
1138            return new MapEntry();
1139         }
1140      });
1141
1142      // entry has a key
1143
entryType.pushInterceptor(keyQName, new DefaultElementInterceptor()
1144      {
1145         public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
1146         {
1147            MapEntry entry = (MapEntry) parent;
1148            entry.key = (ValueMetaData) child;
1149         }
1150      });
1151
1152      // entry has a value
1153
entryType.pushInterceptor(valueQName, new DefaultElementInterceptor()
1154      {
1155         public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
1156         {
1157            MapEntry entry = (MapEntry) parent;
1158            entry.value = (ValueMetaData) child;
1159         }
1160      });
1161   }
1162   
1163   /**
1164    * Configure a collection.
1165    */

1166   private static void configureCollection(QName JavaDoc qname)
1167   {
1168      TypeBinding collectionType = schemaBinding.getType(qname);
1169      collectionType.setHandler(new DefaultElementHandler()
1170      {
1171         public Object JavaDoc startElement(Object JavaDoc parent, QName JavaDoc name, ElementBinding element)
1172         {
1173            if (collectionQName.equals(name))
1174               return new AbstractCollectionMetaData();
1175            else if (listQName.equals(name))
1176               return new AbstractListMetaData();
1177            else if (setQName.equals(name))
1178               return new AbstractSetMetaData();
1179            else if (arrayQName.equals(name))
1180               return new AbstractArrayMetaData();
1181            else
1182               throw new IllegalArgumentException JavaDoc("Unknown collection qname=" + name);
1183         }
1184
1185         public void attributes(Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, Attributes JavaDoc attrs, NamespaceContext JavaDoc nsCtx)
1186         {
1187            AbstractCollectionMetaData collection = (AbstractCollectionMetaData) o;
1188            for (int i = 0; i < attrs.getLength(); ++i)
1189            {
1190               String JavaDoc localName = attrs.getLocalName(i);
1191               if ("class".equals(localName))
1192                  collection.setType(attrs.getValue(i));
1193               else if ("elementClass".equals(localName))
1194                  collection.setElementType(attrs.getValue(i));
1195            }
1196         }
1197      });
1198
1199      configureValueBindings(collectionType);
1200   }
1201   
1202   private static void configureValueBindings(TypeBinding typeBinding)
1203   {
1204      // type has values
1205
typeBinding.pushInterceptor(valueQName, VALUES);
1206
1207      // type has injections
1208
typeBinding.pushInterceptor(injectQName, VALUES);
1209
1210      // type can take a collection
1211
typeBinding.pushInterceptor(collectionQName, VALUES);
1212
1213      // type can take a list
1214
typeBinding.pushInterceptor(listQName, VALUES);
1215
1216      // type can take a set
1217
typeBinding.pushInterceptor(setQName, VALUES);
1218
1219      // type can take an array
1220
typeBinding.pushInterceptor(arrayQName, VALUES);
1221
1222      // type can take a map
1223
typeBinding.pushInterceptor(mapQName, VALUES);
1224
1225      // type has a null
1226
typeBinding.pushInterceptor(nullQName, NULLVALUES);
1227   }
1228   
1229   private static class NullValueElementInterceptor extends DefaultElementInterceptor
1230   {
1231      public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
1232      {
1233         if (parent instanceof AbstractCollectionMetaData)
1234         {
1235            AbstractCollectionMetaData collection = (AbstractCollectionMetaData) parent;
1236            collection.add(new AbstractValueMetaData());
1237         }
1238         else if (parent instanceof AbstractParameterMetaData)
1239         {
1240            AbstractParameterMetaData valueMetaData = (AbstractParameterMetaData) parent;
1241            valueMetaData.setValue(new AbstractValueMetaData());
1242         }
1243         else if (parent instanceof AbstractPropertyMetaData)
1244         {
1245            AbstractPropertyMetaData valueMetaData = (AbstractPropertyMetaData) parent;
1246            valueMetaData.setValue(new AbstractValueMetaData());
1247         }
1248         else if (parent instanceof AbstractClassLoaderMetaData)
1249         {
1250            AbstractClassLoaderMetaData valueMetaData = (AbstractClassLoaderMetaData) parent;
1251            valueMetaData.setClassLoader(new AbstractValueMetaData());
1252         }
1253         else
1254         {
1255            AbstractValueMetaData valueMetaData = (AbstractValueMetaData) parent;
1256            valueMetaData.setValue(new AbstractValueMetaData());
1257         }
1258      }
1259   }
1260   
1261   private static class ValueMetaDataElementInterceptor extends DefaultElementInterceptor
1262   {
1263      public void add(Object JavaDoc parent, Object JavaDoc child, QName JavaDoc name)
1264      {
1265         if (parent instanceof AbstractCollectionMetaData)
1266         {
1267            AbstractCollectionMetaData collection = (AbstractCollectionMetaData) parent;
1268            ValueMetaData value = (ValueMetaData) child;
1269            collection.add(value);
1270         }
1271         else if (parent instanceof AbstractParameterMetaData)
1272         {
1273            AbstractParameterMetaData valueMetaData = (AbstractParameterMetaData) parent;
1274            ValueMetaData value = (ValueMetaData) child;
1275            valueMetaData.setValue(value);
1276         }
1277         else if (parent instanceof AbstractPropertyMetaData)
1278         {
1279            AbstractPropertyMetaData valueMetaData = (AbstractPropertyMetaData) parent;
1280            ValueMetaData value = (ValueMetaData) child;
1281            valueMetaData.setValue(value);
1282         }
1283         else if (parent instanceof AbstractClassLoaderMetaData)
1284         {
1285            AbstractClassLoaderMetaData valueMetaData = (AbstractClassLoaderMetaData) parent;
1286            ValueMetaData value = (ValueMetaData) child;
1287            valueMetaData.setClassLoader(value);
1288         }
1289         else
1290         {
1291            AbstractValueMetaData valueMetaData = (AbstractValueMetaData) parent;
1292            ValueMetaData value = (ValueMetaData) child;
1293            valueMetaData.setValue(value);
1294         }
1295      }
1296   }
1297   
1298   private static class MapEntry
1299   {
1300      public Object JavaDoc key;
1301      public Object JavaDoc value;
1302   }
1303}
1304
Popular Tags