KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > xb > binding > Marshaller


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.xb.binding;
23
24 import org.xml.sax.SAXException JavaDoc;
25
26 import javax.xml.parsers.ParserConfigurationException JavaDoc;
27 import java.io.Reader JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.Writer JavaDoc;
30
31 /**
32  * An interface for marshaller implementations, e.g. DTD and XML schema marshallers.
33  *
34  * @version <tt>$Revision: 1958 $</tt>
35  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
36  */

37 public interface Marshaller
38 {
39    /**
40     * Allowed values are true and false. If not set, true is assumed.
41     * If true, xml version and encoding will be included into the marshalled XML content.
42     */

43    String JavaDoc PROP_OUTPUT_XML_VERSION = "org.jboss.xml.binding.marshalling.version";
44
45    /**
46     * The value should be a fully qualified class name of the Marshaller implementation.
47     * Used by the FACTORY.getInstance().
48     */

49    String JavaDoc PROP_MARSHALLER = "org.jboss.xml.binding.Marshaller";
50
51    /**
52     * Allowed values are true and false. If not set, true is assumed.
53     * If true, XML content will be written with indentations, otherwise in one string.
54     */

55    String JavaDoc PROP_OUTPUT_INDENTATION = "org.jboss.xml.binding.marshalling.indent";
56
57    class FACTORY
58    {
59       public static Marshaller getInstance()
60       {
61          String JavaDoc impl = System.getProperty(PROP_MARSHALLER);
62          if(impl == null)
63          {
64             throw new IllegalStateException JavaDoc("Required system property is not set: " + PROP_MARSHALLER);
65          }
66
67          Class JavaDoc implCls;
68          try
69          {
70             implCls = Thread.currentThread().getContextClassLoader().loadClass(impl);
71          }
72          catch(ClassNotFoundException JavaDoc e)
73          {
74             throw new IllegalStateException JavaDoc("Failed to load marshaller implementation class: " + impl);
75          }
76
77          try
78          {
79             return (Marshaller)implCls.newInstance();
80          }
81          catch(Exception JavaDoc e)
82          {
83             throw new IllegalStateException JavaDoc("Failed to instantiate a marshaller: " + implCls);
84          }
85       }
86    }
87
88    String JavaDoc VERSION = "1.0";
89    String JavaDoc ENCODING = "UTF-8";
90
91    void setVersion(String JavaDoc version);
92    void setEncoding(String JavaDoc encoding);
93
94    void mapPublicIdToSystemId(String JavaDoc publicId, String JavaDoc systemId);
95
96    void mapClassToGlobalElement(Class JavaDoc cls, String JavaDoc localName, String JavaDoc nsUri, String JavaDoc schemaUrl, ObjectModelProvider provider);
97
98    void mapClassToGlobalType(Class JavaDoc cls, String JavaDoc localName, String JavaDoc nsUri, String JavaDoc schemaUrl, ObjectModelProvider provider);
99
100    void addRootElement(String JavaDoc namespaceUri, String JavaDoc prefix, String JavaDoc name);
101
102    void marshal(String JavaDoc schemaUri, ObjectModelProvider provider, Object JavaDoc root, Writer JavaDoc writer) throws IOException JavaDoc,
103       ParserConfigurationException JavaDoc,
104       SAXException JavaDoc;
105
106    void marshal(Reader JavaDoc schema, ObjectModelProvider provider, Object JavaDoc document, Writer JavaDoc writer)
107       throws IOException JavaDoc, SAXException JavaDoc, ParserConfigurationException JavaDoc;
108
109    void setProperty(String JavaDoc name, String JavaDoc value);
110
111    String JavaDoc getProperty(String JavaDoc name);
112 }
113
Popular Tags