KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > business > xml > SummaryUnmarshaller


1 /**
2  * This class was generated from a set of XML constraints
3  * by the Enhydra Zeus XML Data Binding Framework. All
4  * source code in this file is constructed specifically
5  * to work with other Zeus-generated classes. If you
6  * modify this file by hand, you run the risk of breaking
7  * this interoperation, as well as introducing errors in
8  * source code compilation.
9  *
10  * * * * * MODIFY THIS FILE AT YOUR OWN RISK * * * * *
11  *
12  * To find out more about the Enhydra Zeus framework, you
13  * can point your browser at <http://zeus.enhydra.org>
14  * where you can download releases, join and discuss Zeus
15  * on user and developer mailing lists, and access source
16  * code. Please report any bugs through that website.
17  */

18 package org.enhydra.snapper.business.xml;
19
20 // Global Unmarshaller Import Statements
21
import java.io.File JavaDoc;
22 import java.io.FileReader JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.io.InputStreamReader JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.Reader JavaDoc;
27 import org.xml.sax.EntityResolver JavaDoc;
28 import org.xml.sax.ErrorHandler JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30 import org.xml.sax.SAXParseException JavaDoc;
31
32 public class SummaryUnmarshaller {
33
34     /** The EntityResolver for parser resolution. */
35     private static EntityResolver JavaDoc entityResolver;
36
37     /** The ErrorHandler for parser resolution. */
38     private static ErrorHandler JavaDoc errorHandler;
39
40     /**
41      * <p>
42      * This sets a SAX <code>EntityResolver</code> for this unmarshalling process.
43      * </p>
44      *
45      * @param resolver the entity resolver to use.
46      */

47     public static void setEntityResolver(EntityResolver JavaDoc resolver) {
48         entityResolver = resolver;
49     }
50
51     /**
52      * <p>
53      * This sets a SAX <code>ErrorHandler</code> for this unmarshalling process.
54      * </p>
55      *
56      * @param handler the error handler to use.
57      */

58     public static void setErrorHandler(ErrorHandler JavaDoc handler) {
59         errorHandler = handler;
60     }
61
62     public static Summary unmarshal(File JavaDoc file) throws IOException JavaDoc {
63         // Delegate to the unmarshal(Reader) method
64
return unmarshal(new FileReader JavaDoc(file));
65     }
66
67     public static Summary unmarshal(File JavaDoc file, boolean validate) throws IOException JavaDoc {
68         // Delegate to the unmarshal(Reader) method
69
return unmarshal(new FileReader JavaDoc(file), validate);
70     }
71
72     public static Summary unmarshal(InputStream JavaDoc inputStream) throws IOException JavaDoc {
73         // Delegate to the unmarshal(Reader) method
74
return unmarshal(new InputStreamReader JavaDoc(inputStream));
75     }
76
77     public static Summary unmarshal(InputStream JavaDoc inputStream, boolean validate) throws IOException JavaDoc {
78         // Delegate to the unmarshal(Reader) method
79
return unmarshal(new InputStreamReader JavaDoc(inputStream), validate);
80     }
81
82     public static Summary unmarshal(Reader JavaDoc reader) throws IOException JavaDoc {
83         // See if validation set as system property
84
String JavaDoc property = System.getProperty("org.enhydra.zeus.validation", "false");
85         boolean validationState = false;
86         if (property.equalsIgnoreCase("true")) {
87             validationState = true;
88         }
89
90         // Delegate with validation state
91
return unmarshal(reader, validationState);
92     }
93
94     public static Summary unmarshal(Reader JavaDoc reader, boolean validate) throws IOException JavaDoc {
95         // Set the entity resolver, if needed
96
if (entityResolver != null) {
97             SummaryImpl.setEntityResolver(entityResolver);
98         }
99
100         // Set the error handler, if needed
101
if (errorHandler != null) {
102             SummaryImpl.setErrorHandler(errorHandler);
103         } else {
104             if (validate) {
105                 SummaryImpl.setErrorHandler(new SummaryDefaultErrorHandler());
106             }
107         }
108
109         // Unmarshal using the implementation class
110
return SummaryImpl.unmarshal(reader, validate);
111     }
112
113 }
114
115
116 class SummaryDefaultErrorHandler implements ErrorHandler JavaDoc {
117
118     public void warning(SAXParseException JavaDoc e) throws SAXException JavaDoc {
119         System.err.println("Parsing Warning: " + e.getMessage());
120     }
121
122     public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc {
123         System.err.println("Parsing Error: " + e.getMessage());
124         throw e;
125     }
126
127     public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc {
128         System.err.println("Fatal Parsing Error: " + e.getMessage());
129         throw e;
130     }
131
132 }
133
Popular Tags