KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > xb > binding > sunday > unmarshalling > SingletonSchemaResolverFactory


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.xb.binding.sunday.unmarshalling;
23
24 import org.jboss.logging.Logger;
25 import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
26 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
27 import org.jboss.xb.binding.sunday.unmarshalling.SchemaResolverFactory;
28
29 /**
30  * SingletonSchemaResolverFactory.
31  *
32  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
33  * @version $Revision: 1958 $
34  */

35 public class SingletonSchemaResolverFactory implements SchemaResolverFactory
36 {
37    /** The log */
38    private static final Logger log = Logger.getLogger(SingletonSchemaResolverFactory.class);
39
40    /** The factory instance */
41    private static final SingletonSchemaResolverFactory singleton = new SingletonSchemaResolverFactory();
42
43    /** The resolver */
44    private final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
45
46    /**
47     * Get the factory instance
48     *
49     * @return the instance
50     */

51    public static SingletonSchemaResolverFactory getInstance()
52    {
53       return singleton;
54    }
55
56    /**
57     * Create a new SingletonSchemaResolverFactory.
58     */

59    private SingletonSchemaResolverFactory()
60    {
61       addSchema("urn:jboss:aop-beans:1.0", "org.jboss.aop.microcontainer.beans.xml.AOPBeansSchemaInitializer", Boolean.FALSE);
62       addSchema("urn:jboss:bean-deployer", "org.jboss.kernel.plugins.deployment.xml.BeanSchemaInitializer", Boolean.FALSE);
63       addSchema("urn:jboss:bean-deployer:2.0", "org.jboss.kernel.plugins.deployment.xml.BeanSchemaInitializer20", Boolean.FALSE);
64       addSchema("urn:jboss:javabean:1.0", "org.jboss.kernel.plugins.config.xml.JavaBeanSchemaInitializer", Boolean.FALSE);
65    }
66
67    public SchemaBindingResolver getSchemaBindingResolver()
68    {
69       return resolver;
70    }
71
72    /**
73     * Add a schema
74     *
75     * @param namespace the namespace
76     * @param initializer the initializer
77     * @return true when added
78     */

79    protected boolean addSchema(String JavaDoc namespace, String JavaDoc initializer)
80    {
81       try
82       {
83          resolver.addSchemaInitializer(namespace, initializer);
84          log.trace("Mapped initializer '" + namespace + "' to '" + initializer + "'");
85          return true;
86       }
87       catch (Exception JavaDoc ignored)
88       {
89          log.trace("Ignored: ", ignored);
90          return false;
91       }
92    }
93
94    /**
95     * Add a schema
96     *
97     * @param namespace the namespace
98     * @param initializer the initializer
99     * @param parseAnnotations whether to parse annotations
100     * @return true when added
101     */

102    protected boolean addSchema(String JavaDoc namespace, String JavaDoc initializer, Boolean JavaDoc parseAnnotations)
103    {
104       if (addSchema(namespace, initializer) == false)
105          return false;
106       setParseAnnotations(namespace, parseAnnotations);
107       return true;
108    }
109
110    /**
111     * Add a schema
112     *
113     * @param namespace the namespace
114     * @param initializer the initializer
115     * @param location the location
116     * @return true when added
117     */

118    protected boolean addSchema(String JavaDoc namespace, String JavaDoc initializer, String JavaDoc location)
119    {
120       if (addSchema(namespace, initializer) == false)
121          return false;
122       try
123       {
124          resolver.addSchemaLocation(namespace, location);
125          log.trace("Mapped location '" + namespace + "' to '" + location + "'");
126          return true;
127       }
128       catch (Exception JavaDoc ignored)
129       {
130          log.trace("Ignored: ", ignored);
131          return false;
132       }
133    }
134
135    /**
136     * Add a schema
137     *
138     * @param namespace the namespace
139     * @param initializer the initializer
140     * @param location the location
141     * @param parseAnnotations whether to parse annotations
142     * @return true when added
143     */

144    protected boolean addSchema(String JavaDoc namespace, String JavaDoc initializer, String JavaDoc location, Boolean JavaDoc parseAnnotations)
145    {
146       if (addSchema(namespace, initializer, location) == false)
147          return false;
148       setParseAnnotations(namespace, parseAnnotations);
149       return true;
150    }
151
152    /**
153     * Set the parse annotations for a schema
154     *
155     * @param namespace the namespace
156     * @param parseAnnotations whether to parse annotations
157     */

158    protected void setParseAnnotations(String JavaDoc namespace, Boolean JavaDoc parseAnnotations)
159    {
160       resolver.addSchemaParseAnnotations(namespace, parseAnnotations);
161       log.trace("Parse annotations '" + namespace + "' set to '" + parseAnnotations + "'");
162    }
163 }
164
Popular Tags