KickJava   Java API By Example, From Geeks To Geeks.

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


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.xml.binding;
8
9 import org.xml.sax.SAXException JavaDoc;
10
11 import javax.xml.parsers.ParserConfigurationException JavaDoc;
12 import java.io.Reader JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.Writer JavaDoc;
15
16 /**
17  * An interface for marshaller implementations, e.g. DTD and XML schema marshallers.
18  *
19  * @version <tt>$Revision: 1.4.2.5 $</tt>
20  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
21  */

22 public interface Marshaller
23 {
24    /**
25     * Allowed values are true and false. If not set, true is assumed.
26     * If true, xml version and encoding will be included into the marshalled XML content.
27     */

28    String JavaDoc PROP_OUTPUT_XML_VERSION = "org.jboss.xml.binding.marshalling.version";
29
30    /**
31     * The value should be a fully qualified class name of the Marshaller implementation.
32     * Used by the FACTORY.getInstance().
33     */

34    String JavaDoc PROP_MARSHALLER = "org.jboss.xml.binding.Marshaller";
35
36    /**
37     * Allowed values are true and false. If not set, true is assumed.
38     * If true, XML content will be written with indentations, otherwise in one string.
39     */

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