KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xml > initializer > ContainerInitializer


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.test.xml.initializer;
23
24 import javax.xml.namespace.QName JavaDoc;
25
26 import org.jboss.xb.binding.metadata.ClassMetaData;
27 import org.jboss.xb.binding.metadata.PropertyMetaData;
28 import org.jboss.xb.binding.sunday.unmarshalling.DefaultWildcardHandler;
29 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
30 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
31 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingInitializer;
32
33 /**
34  * ContainerInitializer.
35  *
36  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
37  * @version $Revision: 40741 $
38  */

39 public class ContainerInitializer implements SchemaBindingInitializer
40 {
41    public static final String JavaDoc NS = "dummy://www.jboss.org/container";
42
43    private static final QName JavaDoc containerStrictQName = new QName JavaDoc(NS, "containerStrict");
44    private static final QName JavaDoc containerLaxQName = new QName JavaDoc(NS, "containerLax");
45    private static final QName JavaDoc containerSkipQName = new QName JavaDoc(NS, "containerSkip");
46
47    private static final ContainerWildcardHandler wildcardHandler = new ContainerWildcardHandler();
48    
49    public SchemaBinding init(SchemaBinding schema)
50    {
51       ClassMetaData classMetaData = new ClassMetaData();
52       classMetaData.setImpl(Container.class.getName());
53
54       PropertyMetaData property = new PropertyMetaData();
55       property.setName("value");
56       
57       ElementBinding containerStrict = schema.getElement(containerStrictQName);
58       containerStrict.setClassMetaData(classMetaData);
59       containerStrict.getType().getWildcard().setWildcardHandler(wildcardHandler);
60       ElementBinding containerLax = schema.getElement(containerLaxQName);
61       containerLax.setClassMetaData(classMetaData);
62       containerStrict.getType().getWildcard().setWildcardHandler(wildcardHandler);
63       ElementBinding containerSkip = schema.getElement(containerSkipQName);
64       containerSkip.setClassMetaData(classMetaData);
65       containerStrict.getType().getWildcard().setWildcardHandler(wildcardHandler);
66
67       return schema;
68    }
69    
70    private static class ContainerWildcardHandler extends DefaultWildcardHandler
71    {
72       public void setParent(Object JavaDoc parent, Object JavaDoc o, QName JavaDoc elementName, ElementBinding element, ElementBinding parentElement)
73       {
74          Container container = (Container) parent;
75          container.setValue(o);
76       }
77    }
78 }
79
Popular Tags