1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.webapp;
20
21 import java.net.URL;
22
23 import org.eclipse.jetty.util.resource.Resource;
24 import org.eclipse.jetty.xml.XmlParser;
25
26 public abstract class Descriptor
27 {
28 protected Resource _xml;
29 protected XmlParser.Node _root;
30 protected XmlParser _parser;
31 protected boolean _validating;
32
33 public Descriptor (Resource xml)
34 {
35 _xml = xml;
36 }
37
38 public abstract XmlParser newParser()
39 throws ClassNotFoundException;
40
41 public abstract void ensureParser()
42 throws ClassNotFoundException;
43
44 protected void redirect(XmlParser parser, String resource, URL source)
45 {
46 if (source != null) parser.redirectEntity(resource, source);
47 }
48
49
50 public void setValidating (boolean validating)
51 {
52 _validating = validating;
53 }
54
55 public void parse ()
56 throws Exception
57 {
58 if (_parser == null)
59 ensureParser();
60
61 if (_root == null)
62 {
63 try
64 {
65 _root = _parser.parse(_xml.getInputStream());
66 }
67 finally
68 {
69 _xml.close();
70 }
71 }
72 }
73
74 public Resource getResource ()
75 {
76 return _xml;
77 }
78
79 public XmlParser.Node getRoot ()
80 {
81 return _root;
82 }
83
84 public String toString()
85 {
86 return this.getClass().getSimpleName()+"("+_xml+")";
87 }
88 }