KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > convert > xml > WebAppImpl


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.convert.xml;
19
20 // Global Implementation Import Statements
21
import java.io.File JavaDoc;
22 import java.io.FileReader JavaDoc;
23 import java.io.FileWriter JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.InputStreamReader JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.io.OutputStreamWriter JavaDoc;
29 import java.io.Reader JavaDoc;
30 import java.io.Writer JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34 import org.xml.sax.EntityResolver JavaDoc;
35 import org.xml.sax.ErrorHandler JavaDoc;
36 import org.xml.sax.InputSource JavaDoc;
37 import org.xml.sax.Locator JavaDoc;
38 import org.xml.sax.SAXException JavaDoc;
39 import org.xml.sax.SAXParseException JavaDoc;
40 import org.xml.sax.XMLReader JavaDoc;
41 import org.xml.sax.ext.LexicalHandler JavaDoc;
42 import org.xml.sax.helpers.DefaultHandler JavaDoc;
43 import org.xml.sax.helpers.XMLReaderFactory JavaDoc;
44
45 // Local Implementation Import Statements
46
import java.util.Iterator JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.LinkedList JavaDoc;
49
50 public class WebAppImpl extends DefaultHandler JavaDoc implements Cloneable JavaDoc, Unmarshallable, LexicalHandler JavaDoc, WebApp {
51
52     private Icon icon;
53     private DisplayName displayName;
54     private Description description;
55     private Distributable distributable;
56     private List JavaDoc contextParamList;
57     private List JavaDoc filterList;
58     private List JavaDoc filterMappingList;
59     private List JavaDoc listenerList;
60     private List JavaDoc servletList;
61     private List JavaDoc servletMappingList;
62     private SessionConfig sessionConfig;
63     private List JavaDoc mimeMappingList;
64     private WelcomeFileList welcomeFileList;
65     private List JavaDoc errorPageList;
66     private List JavaDoc taglibList;
67     private List JavaDoc resourceEnvRefList;
68     private List JavaDoc resourceRefList;
69     private List JavaDoc securityConstraintList;
70     private LoginConfig loginConfig;
71     private List JavaDoc securityRoleList;
72     private List JavaDoc envEntryList;
73     private List JavaDoc ejbRefList;
74     private List JavaDoc ejbLocalRefList;
75     private String JavaDoc id;
76     private boolean zeus_IdSet;
77
78     /** Any DOCTYPE reference/statements. */
79     private String JavaDoc docTypeString;
80
81     /** The encoding for the output document */
82     private String JavaDoc outputEncoding;
83
84     /** The current node in unmarshalling */
85     private Unmarshallable zeus_currentUNode;
86
87     /** The parent node in unmarshalling */
88     private Unmarshallable zeus_parentUNode;
89
90     /** Whether this node has been handled */
91     private boolean zeus_thisNodeHandled = false;
92
93     /** Whether a DTD exists for an unmarshal call */
94     private boolean hasDTD;
95
96     /** Whether validation is occurring */
97     private boolean validate;
98
99     /** The namespace mappings on this element */
100     private Map JavaDoc namespaceMappings;
101
102     /** The EntityResolver for SAX parsing to use */
103     private static EntityResolver JavaDoc entityResolver;
104
105     /** The ErrorHandler for SAX parsing to use */
106     private static ErrorHandler JavaDoc errorHandler;
107
108     private static WebAppImpl prototype = null;
109
110     public static void setPrototype(WebAppImpl prototype) {
111         WebAppImpl.prototype = prototype;
112     }
113     public static WebAppImpl newInstance() {
114         try {
115             return (prototype!=null)?(WebAppImpl)prototype.clone(): new WebAppImpl();
116         } catch (CloneNotSupportedException JavaDoc e) {
117             return null; // never
118
}
119     }
120     public WebAppImpl() {
121         contextParamList = new LinkedList JavaDoc();
122         filterList = new LinkedList JavaDoc();
123         filterMappingList = new LinkedList JavaDoc();
124         listenerList = new LinkedList JavaDoc();
125         servletList = new LinkedList JavaDoc();
126         servletMappingList = new LinkedList JavaDoc();
127         mimeMappingList = new LinkedList JavaDoc();
128         errorPageList = new LinkedList JavaDoc();
129         taglibList = new LinkedList JavaDoc();
130         resourceEnvRefList = new LinkedList JavaDoc();
131         resourceRefList = new LinkedList JavaDoc();
132         securityConstraintList = new LinkedList JavaDoc();
133         securityRoleList = new LinkedList JavaDoc();
134         envEntryList = new LinkedList JavaDoc();
135         ejbRefList = new LinkedList JavaDoc();
136         ejbLocalRefList = new LinkedList JavaDoc();
137         zeus_IdSet = false;
138         docTypeString = "";
139         hasDTD = false;
140         validate = false;
141         namespaceMappings = new HashMap JavaDoc();
142     }
143
144     public Icon getIcon() {
145         return icon;
146     }
147
148     public void setIcon(Icon icon) {
149         this.icon = icon;
150     }
151
152     public DisplayName getDisplayName() {
153         return displayName;
154     }
155
156     public void setDisplayName(DisplayName displayName) {
157         this.displayName = displayName;
158     }
159
160     public Description getDescription() {
161         return description;
162     }
163
164     public void setDescription(Description description) {
165         this.description = description;
166     }
167
168     public Distributable getDistributable() {
169         return distributable;
170     }
171
172     public void setDistributable(Distributable distributable) {
173         this.distributable = distributable;
174     }
175
176     public List JavaDoc getContextParamList() {
177         return contextParamList;
178     }
179
180     public void setContextParamList(List JavaDoc contextParamList) {
181         this.contextParamList = contextParamList;
182     }
183
184     public void addContextParam(ContextParam contextParam) {
185         contextParamList.add(contextParam);
186     }
187
188     public void removeContextParam(ContextParam contextParam) {
189         contextParamList.remove(contextParam);
190     }
191
192     public List JavaDoc getFilterList() {
193         return filterList;
194     }
195
196     public void setFilterList(List JavaDoc filterList) {
197         this.filterList = filterList;
198     }
199
200     public void addFilter(Filter filter) {
201         filterList.add(filter);
202     }
203
204     public void removeFilter(Filter filter) {
205         filterList.remove(filter);
206     }
207
208     public List JavaDoc getFilterMappingList() {
209         return filterMappingList;
210     }
211
212     public void setFilterMappingList(List JavaDoc filterMappingList) {
213         this.filterMappingList = filterMappingList;
214     }
215
216     public void addFilterMapping(FilterMapping filterMapping) {
217         filterMappingList.add(filterMapping);
218     }
219
220     public void removeFilterMapping(FilterMapping filterMapping) {
221         filterMappingList.remove(filterMapping);
222     }
223
224     public List JavaDoc getListenerList() {
225         return listenerList;
226     }
227
228     public void setListenerList(List JavaDoc listenerList) {
229         this.listenerList = listenerList;
230     }
231
232     public void addListener(Listener listener) {
233         listenerList.add(listener);
234     }
235
236     public void removeListener(Listener listener) {
237         listenerList.remove(listener);
238     }
239
240     public List JavaDoc getServletList() {
241         return servletList;
242     }
243
244     public void setServletList(List JavaDoc servletList) {
245         this.servletList = servletList;
246     }
247
248     public void addServlet(Servlet servlet) {
249         servletList.add(servlet);
250     }
251
252     public void removeServlet(Servlet servlet) {
253         servletList.remove(servlet);
254     }
255
256     public List JavaDoc getServletMappingList() {
257         return servletMappingList;
258     }
259
260     public void setServletMappingList(List JavaDoc servletMappingList) {
261         this.servletMappingList = servletMappingList;
262     }
263
264     public void addServletMapping(ServletMapping servletMapping) {
265         servletMappingList.add(servletMapping);
266     }
267
268     public void removeServletMapping(ServletMapping servletMapping) {
269         servletMappingList.remove(servletMapping);
270     }
271
272     public SessionConfig getSessionConfig() {
273         return sessionConfig;
274     }
275
276     public void setSessionConfig(SessionConfig sessionConfig) {
277         this.sessionConfig = sessionConfig;
278     }
279
280     public List JavaDoc getMimeMappingList() {
281         return mimeMappingList;
282     }
283
284     public void setMimeMappingList(List JavaDoc mimeMappingList) {
285         this.mimeMappingList = mimeMappingList;
286     }
287
288     public void addMimeMapping(MimeMapping mimeMapping) {
289         mimeMappingList.add(mimeMapping);
290     }
291
292     public void removeMimeMapping(MimeMapping mimeMapping) {
293         mimeMappingList.remove(mimeMapping);
294     }
295
296     public WelcomeFileList getWelcomeFileList() {
297         return welcomeFileList;
298     }
299
300     public void setWelcomeFileList(WelcomeFileList welcomeFileList) {
301         this.welcomeFileList = welcomeFileList;
302     }
303
304     public List JavaDoc getErrorPageList() {
305         return errorPageList;
306     }
307
308     public void setErrorPageList(List JavaDoc errorPageList) {
309         this.errorPageList = errorPageList;
310     }
311
312     public void addErrorPage(ErrorPage errorPage) {
313         errorPageList.add(errorPage);
314     }
315
316     public void removeErrorPage(ErrorPage errorPage) {
317         errorPageList.remove(errorPage);
318     }
319
320     public List JavaDoc getTaglibList() {
321         return taglibList;
322     }
323
324     public void setTaglibList(List JavaDoc taglibList) {
325         this.taglibList = taglibList;
326     }
327
328     public void addTaglib(Taglib taglib) {
329         taglibList.add(taglib);
330     }
331
332     public void removeTaglib(Taglib taglib) {
333         taglibList.remove(taglib);
334     }
335
336     public List JavaDoc getResourceEnvRefList() {
337         return resourceEnvRefList;
338     }
339
340     public void setResourceEnvRefList(List JavaDoc resourceEnvRefList) {
341         this.resourceEnvRefList = resourceEnvRefList;
342     }
343
344     public void addResourceEnvRef(ResourceEnvRef resourceEnvRef) {
345         resourceEnvRefList.add(resourceEnvRef);
346     }
347
348     public void removeResourceEnvRef(ResourceEnvRef resourceEnvRef) {
349         resourceEnvRefList.remove(resourceEnvRef);
350     }
351
352     public List JavaDoc getResourceRefList() {
353         return resourceRefList;
354     }
355
356     public void setResourceRefList(List JavaDoc resourceRefList) {
357         this.resourceRefList = resourceRefList;
358     }
359
360     public void addResourceRef(ResourceRef resourceRef) {
361         resourceRefList.add(resourceRef);
362     }
363
364     public void removeResourceRef(ResourceRef resourceRef) {
365         resourceRefList.remove(resourceRef);
366     }
367
368     public List JavaDoc getSecurityConstraintList() {
369         return securityConstraintList;
370     }
371
372     public void setSecurityConstraintList(List JavaDoc securityConstraintList) {
373         this.securityConstraintList = securityConstraintList;
374     }
375
376     public void addSecurityConstraint(SecurityConstraint securityConstraint) {
377         securityConstraintList.add(securityConstraint);
378     }
379
380     public void removeSecurityConstraint(SecurityConstraint securityConstraint) {
381         securityConstraintList.remove(securityConstraint);
382     }
383
384     public LoginConfig getLoginConfig() {
385         return loginConfig;
386     }
387
388     public void setLoginConfig(LoginConfig loginConfig) {
389         this.loginConfig = loginConfig;
390     }
391
392     public List JavaDoc getSecurityRoleList() {
393         return securityRoleList;
394     }
395
396     public void setSecurityRoleList(List JavaDoc securityRoleList) {
397         this.securityRoleList = securityRoleList;
398     }
399
400     public void addSecurityRole(SecurityRole securityRole) {
401         securityRoleList.add(securityRole);
402     }
403
404     public void removeSecurityRole(SecurityRole securityRole) {
405         securityRoleList.remove(securityRole);
406     }
407
408     public List JavaDoc getEnvEntryList() {
409         return envEntryList;
410     }
411
412     public void setEnvEntryList(List JavaDoc envEntryList) {
413         this.envEntryList = envEntryList;
414     }
415
416     public void addEnvEntry(EnvEntry envEntry) {
417         envEntryList.add(envEntry);
418     }
419
420     public void removeEnvEntry(EnvEntry envEntry) {
421         envEntryList.remove(envEntry);
422     }
423
424     public List JavaDoc getEjbRefList() {
425         return ejbRefList;
426     }
427
428     public void setEjbRefList(List JavaDoc ejbRefList) {
429         this.ejbRefList = ejbRefList;
430     }
431
432     public void addEjbRef(EjbRef ejbRef) {
433         ejbRefList.add(ejbRef);
434     }
435
436     public void removeEjbRef(EjbRef ejbRef) {
437         ejbRefList.remove(ejbRef);
438     }
439
440     public List JavaDoc getEjbLocalRefList() {
441         return ejbLocalRefList;
442     }
443
444     public void setEjbLocalRefList(List JavaDoc ejbLocalRefList) {
445         this.ejbLocalRefList = ejbLocalRefList;
446     }
447
448     public void addEjbLocalRef(EjbLocalRef ejbLocalRef) {
449         ejbLocalRefList.add(ejbLocalRef);
450     }
451
452     public void removeEjbLocalRef(EjbLocalRef ejbLocalRef) {
453         ejbLocalRefList.remove(ejbLocalRef);
454     }
455
456     public String JavaDoc getId() {
457         return id;
458     }
459
460     public void setId(String JavaDoc id) {
461         this.id = id;
462         zeus_IdSet = true;
463     }
464
465     public void setDocType(String JavaDoc name, String JavaDoc publicID, String JavaDoc systemID) {
466         try {
467             startDTD(name, publicID, systemID);
468         } catch (SAXException JavaDoc neverHappens) { }
469     }
470
471     public void setOutputEncoding(String JavaDoc outputEncoding) {
472         this.outputEncoding = outputEncoding;
473     }
474
475     public void marshal(File JavaDoc file) throws IOException JavaDoc {
476         // Delegate to the marshal(Writer) method
477
marshal(new FileWriter JavaDoc(file));
478     }
479
480     public void marshal(OutputStream JavaDoc outputStream) throws IOException JavaDoc {
481         // Delegate to the marshal(Writer) method
482
marshal(new OutputStreamWriter JavaDoc(outputStream));
483     }
484
485     public void marshal(Writer JavaDoc writer) throws IOException JavaDoc {
486         // Write out the XML declaration
487
writer.write("<?xml version=\"1.0\" ");
488         if (outputEncoding != null) {
489             writer.write("encoding=\"");
490             writer.write(outputEncoding);
491             writer.write("\"?>\n\n");
492
493         } else {
494             writer.write("encoding=\"UTF-8\"?>\n\n");
495
496         }
497         // Handle DOCTYPE declaration
498
writer.write(docTypeString);
499         writer.write("\n");
500         // Now start the recursive writing
501
writeXMLRepresentation(writer, "");
502
503         // Close up
504
writer.flush();
505         writer.close();
506     }
507
508     protected void writeXMLRepresentation(Writer JavaDoc writer,
509                                           String JavaDoc indent)
510         throws IOException JavaDoc {
511
512         writer.write(indent);
513         writer.write("<web-app");
514
515         // Handle namespace mappings (if needed)
516
for (Iterator JavaDoc i = namespaceMappings.keySet().iterator(); i.hasNext(); ) {
517             String JavaDoc prefix = (String JavaDoc)i.next();
518             String JavaDoc uri = (String JavaDoc)namespaceMappings.get(prefix);
519             writer.write(" xmlns");
520             if (!prefix.trim().equals("")) {
521                 writer.write(":");
522                 writer.write(prefix);
523             }
524             writer.write("=\"");
525             writer.write(uri);
526             writer.write("\"\n ");
527         }
528
529         // Handle attributes (if needed)
530
if (zeus_IdSet) {
531             writer.write(" id=\"");
532             writer.write(escapeAttributeValue(id));
533             writer.write("\"");
534         }
535         writer.write(">");
536         writer.write("\n");
537
538         // Handle child elements
539
if (icon != null) {
540             ((IconImpl)icon).writeXMLRepresentation(writer,
541                 new StringBuffer JavaDoc(indent).append(" ").toString());
542         }
543
544         if (displayName != null) {
545             ((DisplayNameImpl)displayName).writeXMLRepresentation(writer,
546                 new StringBuffer JavaDoc(indent).append(" ").toString());
547         }
548
549         if (description != null) {
550             ((DescriptionImpl)description).writeXMLRepresentation(writer,
551                 new StringBuffer JavaDoc(indent).append(" ").toString());
552         }
553
554         if (distributable != null) {
555             ((DistributableImpl)distributable).writeXMLRepresentation(writer,
556                 new StringBuffer JavaDoc(indent).append(" ").toString());
557         }
558
559         for (Iterator JavaDoc i=contextParamList.iterator(); i.hasNext(); ) {
560             ContextParamImpl contextParam = (ContextParamImpl)i.next();
561             contextParam.writeXMLRepresentation(writer,
562                 new StringBuffer JavaDoc(indent).append(" ").toString());
563         }
564         for (Iterator JavaDoc i=filterList.iterator(); i.hasNext(); ) {
565             FilterImpl filter = (FilterImpl)i.next();
566             filter.writeXMLRepresentation(writer,
567                 new StringBuffer JavaDoc(indent).append(" ").toString());
568         }
569         for (Iterator JavaDoc i=filterMappingList.iterator(); i.hasNext(); ) {
570             FilterMappingImpl filterMapping = (FilterMappingImpl)i.next();
571             filterMapping.writeXMLRepresentation(writer,
572                 new StringBuffer JavaDoc(indent).append(" ").toString());
573         }
574         for (Iterator JavaDoc i=listenerList.iterator(); i.hasNext(); ) {
575             ListenerImpl listener = (ListenerImpl)i.next();
576             listener.writeXMLRepresentation(writer,
577                 new StringBuffer JavaDoc(indent).append(" ").toString());
578         }
579         for (Iterator JavaDoc i=servletList.iterator(); i.hasNext(); ) {
580             ServletImpl servlet = (ServletImpl)i.next();
581             servlet.writeXMLRepresentation(writer,
582                 new StringBuffer JavaDoc(indent).append(" ").toString());
583         }
584         for (Iterator JavaDoc i=servletMappingList.iterator(); i.hasNext(); ) {
585             ServletMappingImpl servletMapping = (ServletMappingImpl)i.next();
586             servletMapping.writeXMLRepresentation(writer,
587                 new StringBuffer JavaDoc(indent).append(" ").toString());
588         }
589         if (sessionConfig != null) {
590             ((SessionConfigImpl)sessionConfig).writeXMLRepresentation(writer,
591                 new StringBuffer JavaDoc(indent).append(" ").toString());
592         }
593
594         for (Iterator JavaDoc i=mimeMappingList.iterator(); i.hasNext(); ) {
595             MimeMappingImpl mimeMapping = (MimeMappingImpl)i.next();
596             mimeMapping.writeXMLRepresentation(writer,
597                 new StringBuffer JavaDoc(indent).append(" ").toString());
598         }
599         if (welcomeFileList != null) {
600             ((WelcomeFileListImpl)welcomeFileList).writeXMLRepresentation(writer,
601                 new StringBuffer JavaDoc(indent).append(" ").toString());
602         }
603
604         for (Iterator JavaDoc i=errorPageList.iterator(); i.hasNext(); ) {
605             ErrorPageImpl errorPage = (ErrorPageImpl)i.next();
606             errorPage.writeXMLRepresentation(writer,
607                 new StringBuffer JavaDoc(indent).append(" ").toString());
608         }
609         for (Iterator JavaDoc i=taglibList.iterator(); i.hasNext(); ) {
610             TaglibImpl taglib = (TaglibImpl)i.next();
611             taglib.writeXMLRepresentation(writer,
612                 new StringBuffer JavaDoc(indent).append(" ").toString());
613         }
614         for (Iterator JavaDoc i=resourceEnvRefList.iterator(); i.hasNext(); ) {
615             ResourceEnvRefImpl resourceEnvRef = (ResourceEnvRefImpl)i.next();
616             resourceEnvRef.writeXMLRepresentation(writer,
617                 new StringBuffer JavaDoc(indent).append(" ").toString());
618         }
619         for (Iterator JavaDoc i=resourceRefList.iterator(); i.hasNext(); ) {
620             ResourceRefImpl resourceRef = (ResourceRefImpl)i.next();
621             resourceRef.writeXMLRepresentation(writer,
622                 new StringBuffer JavaDoc(indent).append(" ").toString());
623         }
624         for (Iterator JavaDoc i=securityConstraintList.iterator(); i.hasNext(); ) {
625             SecurityConstraintImpl securityConstraint = (SecurityConstraintImpl)i.next();
626             securityConstraint.writeXMLRepresentation(writer,
627                 new StringBuffer JavaDoc(indent).append(" ").toString());
628         }
629         if (loginConfig != null) {
630             ((LoginConfigImpl)loginConfig).writeXMLRepresentation(writer,
631                 new StringBuffer JavaDoc(indent).append(" ").toString());
632         }
633
634         for (Iterator JavaDoc i=securityRoleList.iterator(); i.hasNext(); ) {
635             SecurityRoleImpl securityRole = (SecurityRoleImpl)i.next();
636             securityRole.writeXMLRepresentation(writer,
637                 new StringBuffer JavaDoc(indent).append(" ").toString());
638         }
639         for (Iterator JavaDoc i=envEntryList.iterator(); i.hasNext(); ) {
640             EnvEntryImpl envEntry = (EnvEntryImpl)i.next();
641             envEntry.writeXMLRepresentation(writer,
642                 new StringBuffer JavaDoc(indent).append(" ").toString());
643         }
644         for (Iterator JavaDoc i=ejbRefList.iterator(); i.hasNext(); ) {
645             EjbRefImpl ejbRef = (EjbRefImpl)i.next();
646             ejbRef.writeXMLRepresentation(writer,
647                 new StringBuffer JavaDoc(indent).append(" ").toString());
648         }
649         for (Iterator JavaDoc i=ejbLocalRefList.iterator(); i.hasNext(); ) {
650             EjbLocalRefImpl ejbLocalRef = (EjbLocalRefImpl)i.next();
651             ejbLocalRef.writeXMLRepresentation(writer,
652                 new StringBuffer JavaDoc(indent).append(" ").toString());
653         }
654         writer.write(indent);
655         writer.write("</web-app>\n");
656     }
657
658     private String JavaDoc escapeAttributeValue(String JavaDoc attributeValue) {
659         String JavaDoc returnValue = attributeValue;
660         for (int i = 0; i < returnValue.length(); i++) {
661             char ch = returnValue.charAt(i);
662             if (ch == '"') {
663                 returnValue = new StringBuffer JavaDoc()
664                     .append(returnValue.substring(0, i))
665                     .append("&quot;")
666                     .append(returnValue.substring(i+1))
667                     .toString();
668             }
669         }
670         return returnValue;
671     }
672
673     private String JavaDoc escapeTextValue(String JavaDoc textValue) {
674         String JavaDoc returnValue = textValue;
675         for (int i = 0; i < returnValue.length(); i++) {
676             char ch = returnValue.charAt(i);
677             if (ch == '<') {
678                 returnValue = new StringBuffer JavaDoc()
679                     .append(returnValue.substring(0, i))
680                     .append("&lt;")
681                     .append(returnValue.substring(i+1))
682                     .toString();
683             } else if (ch == '>') {
684                 returnValue = new StringBuffer JavaDoc()
685                     .append(returnValue.substring(0, i))
686                     .append("&gt;")
687                     .append(returnValue.substring(i+1))
688                     .toString();
689             }
690         }
691         return returnValue;
692     }
693
694     /**
695      * <p>
696      * This sets a SAX <code>EntityResolver</code> for this unmarshalling process.
697      * </p>
698      *
699      * @param resolver the entity resolver to use.
700      */

701     public static void setEntityResolver(EntityResolver JavaDoc resolver) {
702         entityResolver = resolver;
703     }
704
705     /**
706      * <p>
707      * This sets a SAX <code>ErrorHandler</code> for this unmarshalling process.
708      * </p>
709      *
710      * @param handler the entity resolver to use.
711      */

712     public static void setErrorHandler(ErrorHandler JavaDoc handler) {
713         errorHandler = handler;
714     }
715
716     public static WebApp unmarshal(File JavaDoc file) throws IOException JavaDoc {
717         // Delegate to the unmarshal(Reader) method
718
return unmarshal(new FileReader JavaDoc(file));
719     }
720
721     public static WebApp unmarshal(File JavaDoc file, boolean validate) throws IOException JavaDoc {
722         // Delegate to the unmarshal(Reader) method
723
return unmarshal(new FileReader JavaDoc(file), validate);
724     }
725
726     public static WebApp unmarshal(InputStream JavaDoc inputStream) throws IOException JavaDoc {
727         // Delegate to the unmarshal(Reader) method
728
return unmarshal(new InputStreamReader JavaDoc(inputStream));
729     }
730
731     public static WebApp unmarshal(InputStream JavaDoc inputStream, boolean validate) throws IOException JavaDoc {
732         // Delegate to the unmarshal(Reader) method
733
return unmarshal(new InputStreamReader JavaDoc(inputStream), validate);
734     }
735
736     public static WebApp unmarshal(Reader JavaDoc reader) throws IOException JavaDoc {
737         // Delegate with default validation value
738
return unmarshal(reader, false);
739     }
740
741     public static WebApp unmarshal(Reader JavaDoc reader, boolean validate) throws IOException JavaDoc {
742         WebAppImpl webApp = WebAppImpl.newInstance();
743         webApp.setValidating(validate);
744         webApp.setCurrentUNode(webApp);
745         webApp.setParentUNode(null);
746         // Load the XML parser
747
XMLReader JavaDoc parser = null;
748         String JavaDoc parserClass = System.getProperty("org.xml.sax.driver",
749             "org.apache.xerces.parsers.SAXParser");
750         try {
751             parser = XMLReaderFactory.createXMLReader(parserClass);
752
753             // Set entity resolver, if needed
754
if (entityResolver != null) {
755                 parser.setEntityResolver(entityResolver);
756             }
757
758             // Set error handler
759
parser.setErrorHandler(webApp);
760
761             // Register lexical handler
762
parser.setProperty("http://xml.org/sax/properties/lexical-handler", webApp);
763
764             // Register content handler
765
parser.setContentHandler(webApp);
766         } catch (SAXException JavaDoc e) {
767             throw new IOException JavaDoc("Could not load XML parser: " +
768                 e.getMessage());
769         }
770
771         InputSource JavaDoc inputSource = new InputSource JavaDoc(reader);
772         try {
773             parser.setFeature("http://xml.org/sax/features/validation", new Boolean JavaDoc(validate).booleanValue());
774             parser.setFeature("http://xml.org/sax/features/namespaces", true);
775             parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
776             parser.parse(inputSource);
777         } catch (SAXException JavaDoc e) {
778             throw new IOException JavaDoc("Error parsing XML document: " +
779                 e.getMessage());
780         }
781
782         // Return the resultant object
783
return webApp;
784     }
785
786     public Unmarshallable getParentUNode() {
787         return zeus_parentUNode;
788     }
789
790     public void setParentUNode(Unmarshallable parentUNode) {
791         this.zeus_parentUNode = parentUNode;
792     }
793
794     public Unmarshallable getCurrentUNode() {
795         return zeus_currentUNode;
796     }
797
798     public void setCurrentUNode(Unmarshallable currentUNode) {
799         this.zeus_currentUNode = currentUNode;
800     }
801
802     public void setValidating(boolean validate) {
803         this.validate = validate;
804     }
805
806     public void startDocument() throws SAXException JavaDoc {
807         // no-op
808
}
809
810     public void setDocumentLocator(Locator JavaDoc locator) {
811         // no-op
812
}
813
814     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri)
815         throws SAXException JavaDoc {
816         namespaceMappings.put(prefix, uri);
817     }
818
819     public void startElement(String JavaDoc namespaceURI, String JavaDoc localName,
820                              String JavaDoc qName, org.xml.sax.Attributes JavaDoc atts)
821         throws SAXException JavaDoc {
822
823         // Feed this to the correct ContentHandler
824
Unmarshallable current = getCurrentUNode();
825         if (current != this) {
826             current.startElement(namespaceURI, localName, qName, atts);
827             return;
828         }
829
830         // See if we handle, or we delegate
831
if ((localName.equals("web-app")) && (!zeus_thisNodeHandled)) {
832             // Handle ourselves
833
for (int i=0, len=atts.getLength(); i<len; i++) {
834                 String JavaDoc attName= atts.getLocalName(i);
835                 String JavaDoc attValue = atts.getValue(i);
836                 if (attName.equals("id")) {
837                     setId(attValue);
838                 }
839             }
840             zeus_thisNodeHandled = true;
841             return;
842         } else {
843             // Delegate handling
844
if (localName.equals("icon") && (icon==null)) {
845                 IconImpl icon = IconImpl.newInstance();
846                 current = getCurrentUNode();
847                 icon.setParentUNode(current);
848                 icon.setCurrentUNode(icon);
849                 this.setCurrentUNode(icon);
850                 icon.startElement(namespaceURI, localName, qName, atts);
851                 // Add this value in
852
this.icon = icon;
853                 return;
854             }
855             if (localName.equals("display-name") && (displayName==null)) {
856                 DisplayNameImpl displayName = DisplayNameImpl.newInstance();
857                 current = getCurrentUNode();
858                 displayName.setParentUNode(current);
859                 displayName.setCurrentUNode(displayName);
860                 this.setCurrentUNode(displayName);
861                 displayName.startElement(namespaceURI, localName, qName, atts);
862                 // Add this value in
863
this.displayName = displayName;
864                 return;
865             }
866             if (localName.equals("description") && (description==null)) {
867                 DescriptionImpl description = DescriptionImpl.newInstance();
868                 current = getCurrentUNode();
869                 description.setParentUNode(current);
870                 description.setCurrentUNode(description);
871                 this.setCurrentUNode(description);
872                 description.startElement(namespaceURI, localName, qName, atts);
873                 // Add this value in
874
this.description = description;
875                 return;
876             }
877             if (localName.equals("distributable") && (distributable==null)) {
878                 DistributableImpl distributable = DistributableImpl.newInstance();
879                 current = getCurrentUNode();
880                 distributable.setParentUNode(current);
881                 distributable.setCurrentUNode(distributable);
882                 this.setCurrentUNode(distributable);
883                 distributable.startElement(namespaceURI, localName, qName, atts);
884                 // Add this value in
885
this.distributable = distributable;
886                 return;
887             }
888             if (localName.equals("context-param")) {
889                 ContextParamImpl contextParam = ContextParamImpl.newInstance();
890                 current = getCurrentUNode();
891                 contextParam.setParentUNode(current);
892                 contextParam.setCurrentUNode(contextParam);
893                 this.setCurrentUNode(contextParam);
894                 contextParam.startElement(namespaceURI, localName, qName, atts);
895                 // Add this value in
896
contextParamList.add(contextParam);
897                 return;
898             }
899             if (localName.equals("filter")) {
900                 FilterImpl filter = FilterImpl.newInstance();
901                 current = getCurrentUNode();
902                 filter.setParentUNode(current);
903                 filter.setCurrentUNode(filter);
904                 this.setCurrentUNode(filter);
905                 filter.startElement(namespaceURI, localName, qName, atts);
906                 // Add this value in
907
filterList.add(filter);
908                 return;
909             }
910             if (localName.equals("filter-mapping")) {
911                 FilterMappingImpl filterMapping = FilterMappingImpl.newInstance();
912                 current = getCurrentUNode();
913                 filterMapping.setParentUNode(current);
914                 filterMapping.setCurrentUNode(filterMapping);
915                 this.setCurrentUNode(filterMapping);
916                 filterMapping.startElement(namespaceURI, localName, qName, atts);
917                 // Add this value in
918
filterMappingList.add(filterMapping);
919                 return;
920             }
921             if (localName.equals("listener")) {
922                 ListenerImpl listener = ListenerImpl.newInstance();
923                 current = getCurrentUNode();
924                 listener.setParentUNode(current);
925                 listener.setCurrentUNode(listener);
926                 this.setCurrentUNode(listener);
927                 listener.startElement(namespaceURI, localName, qName, atts);
928                 // Add this value in
929
listenerList.add(listener);
930                 return;
931             }
932             if (localName.equals("servlet")) {
933                 ServletImpl servlet = ServletImpl.newInstance();
934                 current = getCurrentUNode();
935                 servlet.setParentUNode(current);
936                 servlet.setCurrentUNode(servlet);
937                 this.setCurrentUNode(servlet);
938                 servlet.startElement(namespaceURI, localName, qName, atts);
939                 // Add this value in
940
servletList.add(servlet);
941                 return;
942             }
943             if (localName.equals("servlet-mapping")) {
944                 ServletMappingImpl servletMapping = ServletMappingImpl.newInstance();
945                 current = getCurrentUNode();
946                 servletMapping.setParentUNode(current);
947                 servletMapping.setCurrentUNode(servletMapping);
948                 this.setCurrentUNode(servletMapping);
949                 servletMapping.startElement(namespaceURI, localName, qName, atts);
950                 // Add this value in
951
servletMappingList.add(servletMapping);
952                 return;
953             }
954             if (localName.equals("session-config") && (sessionConfig==null)) {
955                 SessionConfigImpl sessionConfig = SessionConfigImpl.newInstance();
956                 current = getCurrentUNode();
957                 sessionConfig.setParentUNode(current);
958                 sessionConfig.setCurrentUNode(sessionConfig);
959                 this.setCurrentUNode(sessionConfig);
960                 sessionConfig.startElement(namespaceURI, localName, qName, atts);
961                 // Add this value in
962
this.sessionConfig = sessionConfig;
963                 return;
964             }
965             if (localName.equals("mime-mapping")) {
966                 MimeMappingImpl mimeMapping = MimeMappingImpl.newInstance();
967                 current = getCurrentUNode();
968                 mimeMapping.setParentUNode(current);
969                 mimeMapping.setCurrentUNode(mimeMapping);
970                 this.setCurrentUNode(mimeMapping);
971                 mimeMapping.startElement(namespaceURI, localName, qName, atts);
972                 // Add this value in
973
mimeMappingList.add(mimeMapping);
974                 return;
975             }
976             if (localName.equals("welcome-file-list") && (welcomeFileList==null)) {
977                 WelcomeFileListImpl welcomeFileList = WelcomeFileListImpl.newInstance();
978                 current = getCurrentUNode();
979                 welcomeFileList.setParentUNode(current);
980                 welcomeFileList.setCurrentUNode(welcomeFileList);
981                 this.setCurrentUNode(welcomeFileList);
982                 welcomeFileList.startElement(namespaceURI, localName, qName, atts);
983                 // Add this value in
984
this.welcomeFileList = welcomeFileList;
985                 return;
986             }
987             if (localName.equals("error-page")) {
988                 ErrorPageImpl errorPage = ErrorPageImpl.newInstance();
989                 current = getCurrentUNode();
990                 errorPage.setParentUNode(current);
991                 errorPage.setCurrentUNode(errorPage);
992                 this.setCurrentUNode(errorPage);
993                 errorPage.startElement(namespaceURI, localName, qName, atts);
994                 // Add this value in
995
errorPageList.add(errorPage);
996                 return;
997             }
998             if (localName.equals("taglib")) {
999                 TaglibImpl taglib = TaglibImpl.newInstance();
1000                current = getCurrentUNode();
1001                taglib.setParentUNode(current);
1002                taglib.setCurrentUNode(taglib);
1003                this.setCurrentUNode(taglib);
1004                taglib.startElement(namespaceURI, localName, qName, atts);
1005                // Add this value in
1006
taglibList.add(taglib);
1007                return;
1008            }
1009            if (localName.equals("resource-env-ref")) {
1010                ResourceEnvRefImpl resourceEnvRef = ResourceEnvRefImpl.newInstance();
1011                current = getCurrentUNode();
1012                resourceEnvRef.setParentUNode(current);
1013                resourceEnvRef.setCurrentUNode(resourceEnvRef);
1014                this.setCurrentUNode(resourceEnvRef);
1015                resourceEnvRef.startElement(namespaceURI, localName, qName, atts);
1016                // Add this value in
1017
resourceEnvRefList.add(resourceEnvRef);
1018                return;
1019            }
1020            if (localName.equals("resource-ref")) {
1021                ResourceRefImpl resourceRef = ResourceRefImpl.newInstance();
1022                current = getCurrentUNode();
1023                resourceRef.setParentUNode(current);
1024                resourceRef.setCurrentUNode(resourceRef);
1025                this.setCurrentUNode(resourceRef);
1026                resourceRef.startElement(namespaceURI, localName, qName, atts);
1027                // Add this value in
1028
resourceRefList.add(resourceRef);
1029                return;
1030            }
1031            if (localName.equals("security-constraint")) {
1032                SecurityConstraintImpl securityConstraint = SecurityConstraintImpl.newInstance();
1033                current = getCurrentUNode();
1034                securityConstraint.setParentUNode(current);
1035                securityConstraint.setCurrentUNode(securityConstraint);
1036                this.setCurrentUNode(securityConstraint);
1037                securityConstraint.startElement(namespaceURI, localName, qName, atts);
1038                // Add this value in
1039
securityConstraintList.add(securityConstraint);
1040                return;
1041            }
1042            if (localName.equals("login-config") && (loginConfig==null)) {
1043                LoginConfigImpl loginConfig = LoginConfigImpl.newInstance();
1044                current = getCurrentUNode();
1045                loginConfig.setParentUNode(current);
1046                loginConfig.setCurrentUNode(loginConfig);
1047                this.setCurrentUNode(loginConfig);
1048                loginConfig.startElement(namespaceURI, localName, qName, atts);
1049                // Add this value in
1050
this.loginConfig = loginConfig;
1051                return;
1052            }
1053            if (localName.equals("security-role")) {
1054                SecurityRoleImpl securityRole = SecurityRoleImpl.newInstance();
1055                current = getCurrentUNode();
1056                securityRole.setParentUNode(current);
1057                securityRole.setCurrentUNode(securityRole);
1058                this.setCurrentUNode(securityRole);
1059                securityRole.startElement(namespaceURI, localName, qName, atts);
1060                // Add this value in
1061
securityRoleList.add(securityRole);
1062                return;
1063            }
1064            if (localName.equals("env-entry")) {
1065                EnvEntryImpl envEntry = EnvEntryImpl.newInstance();
1066                current = getCurrentUNode();
1067                envEntry.setParentUNode(current);
1068                envEntry.setCurrentUNode(envEntry);
1069                this.setCurrentUNode(envEntry);
1070                envEntry.startElement(namespaceURI, localName, qName, atts);
1071                // Add this value in
1072
envEntryList.add(envEntry);
1073                return;
1074            }
1075            if (localName.equals("ejb-ref")) {
1076                EjbRefImpl ejbRef = EjbRefImpl.newInstance();
1077                current = getCurrentUNode();
1078                ejbRef.setParentUNode(current);
1079                ejbRef.setCurrentUNode(ejbRef);
1080                this.setCurrentUNode(ejbRef);
1081                ejbRef.startElement(namespaceURI, localName, qName, atts);
1082                // Add this value in
1083
ejbRefList.add(ejbRef);
1084                return;
1085            }
1086            if (localName.equals("ejb-local-ref")) {
1087                EjbLocalRefImpl ejbLocalRef = EjbLocalRefImpl.newInstance();
1088                current = getCurrentUNode();
1089                ejbLocalRef.setParentUNode(current);
1090                ejbLocalRef.setCurrentUNode(ejbLocalRef);
1091                this.setCurrentUNode(ejbLocalRef);
1092                ejbLocalRef.startElement(namespaceURI, localName, qName, atts);
1093                // Add this value in
1094
ejbLocalRefList.add(ejbLocalRef);
1095                return;
1096            }
1097        }
1098    }
1099
1100    public void endElement(String JavaDoc namespaceURI, String JavaDoc localName,
1101                           String JavaDoc qName)
1102        throws SAXException JavaDoc {
1103
1104        Unmarshallable current = getCurrentUNode();
1105        if (current != this) {
1106            current.endElement(namespaceURI, localName, qName);
1107            return;
1108        }
1109
1110        Unmarshallable parent = getCurrentUNode().getParentUNode();
1111        if (parent != null) {
1112            parent.setCurrentUNode(parent);
1113        }
1114    }
1115
1116    public void characters(char[] ch, int start, int len)
1117        throws SAXException JavaDoc {
1118
1119        // Feed this to the correct ContentHandler
1120
Unmarshallable current = getCurrentUNode();
1121        if (current != this) {
1122            current.characters(ch, start, len);
1123            return;
1124        }
1125
1126        String JavaDoc text = new String JavaDoc(ch, start, len);
1127    }
1128
1129    public void comment(char ch[], int start, int len) throws SAXException JavaDoc {
1130        // Currently no-op
1131
}
1132
1133    public void warning(SAXParseException JavaDoc e) throws SAXException JavaDoc {
1134        if (errorHandler != null) {
1135            errorHandler.warning(e);
1136        }
1137    }
1138
1139    public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc {
1140        if ((validate) && (!hasDTD)) {
1141            throw new SAXException JavaDoc("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
1142        }
1143        if (errorHandler != null) {
1144            errorHandler.error(e);
1145        }
1146    }
1147
1148    public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc {
1149        if ((validate) && (!hasDTD)) {
1150            throw new SAXException JavaDoc("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
1151        }
1152        if (errorHandler != null) {
1153            errorHandler.fatalError(e);
1154        }
1155    }
1156
1157    public void startDTD(String JavaDoc name, String JavaDoc publicID, String JavaDoc systemID)
1158        throws SAXException JavaDoc {
1159
1160        if ((name == null) || (name.equals(""))) {
1161            docTypeString = "";
1162            return;
1163        }
1164
1165        hasDTD = true;
1166        StringBuffer JavaDoc docTypeSB = new StringBuffer JavaDoc();
1167        boolean hasPublic = false;
1168
1169        docTypeSB.append("<!DOCTYPE ")
1170                 .append(name);
1171
1172        if ((publicID != null) && (!publicID.equals(""))) {
1173            docTypeSB.append(" PUBLIC \"")
1174                     .append(publicID)
1175                     .append("\"");
1176            hasPublic = true;
1177        }
1178
1179        if ((systemID != null) && (!systemID.equals(""))) {
1180            if (!hasPublic) {
1181                docTypeSB.append(" SYSTEM");
1182            }
1183            docTypeSB.append(" \"")
1184                     .append(systemID)
1185                     .append("\"");
1186
1187        }
1188
1189        docTypeSB.append(">");
1190
1191        docTypeString = docTypeSB.toString();
1192    }
1193
1194    public void endDTD() throws SAXException JavaDoc {
1195        // Currently no-op
1196
}
1197
1198    public void startEntity(String JavaDoc name) throws SAXException JavaDoc {
1199        // Currently no-op
1200
}
1201
1202    public void endEntity(String JavaDoc name) throws SAXException JavaDoc {
1203        // Currently no-op
1204
}
1205
1206    public void startCDATA() throws SAXException JavaDoc {
1207        // Currently no-op
1208
}
1209
1210    public void endCDATA() throws SAXException JavaDoc {
1211        // Currently no-op
1212
}
1213
1214}
1215
Popular Tags