30
30
import org .exist .Namespaces ;
31
31
32
32
/**
33
- * Wrapper around the Xerces XMLGrammarPoolImpl, so debugging of
33
+ * Wrapper around the Xerces XMLGrammarPoolImpl, so debugging of
34
34
* actions can be monitored. Javadoc copied from xml.apache.org.
35
35
*
36
36
* @author Dannes Wessels ([email protected] )
37
- *
38
37
* @see org.apache.xerces.xni.grammars.XMLGrammarPool
39
38
* @see org.apache.xerces.util.XMLGrammarPoolImpl
40
39
* @see org.apache.xerces.xni.grammars.Grammar
41
40
* @see org.apache.xerces.xni.grammars.XMLGrammarDescription
42
41
*/
43
42
public class GrammarPool implements XMLGrammarPool {
44
-
43
+
45
44
private final static Logger logger = LogManager .getLogger (GrammarPool .class );
46
-
45
+
47
46
private final XMLGrammarPool pool ;
48
-
47
+
49
48
/**
50
- * Constructs a grammar pool with a default number of buckets.
49
+ * Constructs a grammar pool with a default number of buckets.
51
50
*/
52
51
public GrammarPool () {
53
- if (logger .isInfoEnabled ())
54
- {logger .info ("Initializing GrammarPool." );}
52
+ if (logger .isInfoEnabled ()) {
53
+ logger .info ("Initializing GrammarPool." );
54
+ }
55
55
pool = new XMLGrammarPoolImpl ();
56
56
}
57
-
58
- /**
57
+
58
+ /**
59
59
* Constructs a grammar pool with a default number of buckets using pool.
60
- *
60
+ *
61
61
* @param pool The supplied grammar pool is reused.
62
62
*/
63
- public GrammarPool (XMLGrammarPool pool ) {
64
- if (logger .isInfoEnabled ())
65
- {logger .info ("Initializing GrammarPool using supplied pool." );}
66
- this .pool =pool ;
63
+ public GrammarPool (final XMLGrammarPool pool ) {
64
+ if (logger .isInfoEnabled ()) {
65
+ logger .info ("Initializing GrammarPool using supplied pool." );
66
+ }
67
+ this .pool = pool ;
67
68
}
68
-
69
+
69
70
/**
70
- * Retrieve the initial known set of grammars. this method is called
71
- * by a validator before the validation starts. the application can provide
71
+ * Retrieve the initial known set of grammars. this method is called
72
+ * by a validator before the validation starts. the application can provide
72
73
* an initial set of grammars available to the current validation attempt.
73
74
*
75
+ * @param type The type of the grammar, from the
76
+ * org.apache.xerces.xni.grammars.Grammar interface.
77
+ * @return The set of grammars the validator may put in its "bucket"
74
78
* @see org.apache.xerces.xni.grammars.XMLGrammarPool#retrieveInitialGrammarSet(String)
75
- *
76
- * @param type The type of the grammar, from the
77
- * org.apache.xerces.xni.grammars.Grammar interface.
78
- * @return The set of grammars the validator may put in its "bucket"
79
79
*/
80
- public Grammar [] retrieveInitialGrammarSet (String type ) {
81
- if (logger .isDebugEnabled ())
82
- {
83
- logger . debug ( "Retrieve initial grammarset ({})." , type ); }
84
-
80
+ public Grammar [] retrieveInitialGrammarSet (final String type ) {
81
+ if (logger .isDebugEnabled ()) {
82
+ logger . debug ( "Retrieve initial grammarset ({})." , type );
83
+ }
84
+
85
85
final Grammar [] grammars = pool .retrieveInitialGrammarSet (type );
86
- if (logger .isDebugEnabled ())
87
- {
88
- logger . debug ( "Found {} grammars." , grammars . length ); }
86
+ if (logger .isDebugEnabled ()) {
87
+ logger . debug ( "Found {} grammars." , grammars . length );
88
+ }
89
89
return grammars ;
90
90
}
91
-
91
+
92
92
/**
93
- * Return the final set of grammars that the validator ended up with.
93
+ * Return the final set of grammars that the validator ended up with.
94
94
*
95
- * @see org.apache.xerces.xni.grammars.XMLGrammarPool#cacheGrammars(String,Grammar[])
96
- *
97
- * @param type The type of the grammars being returned
98
- * @param grammar an array containing the set of grammars being
99
- * returned; order is not significant.
95
+ * @param type The type of the grammars being returned
96
+ * @param grammar an array containing the set of grammars being
97
+ * returned; order is not significant.
98
+ * @see org.apache.xerces.xni.grammars.XMLGrammarPool#cacheGrammars(String, Grammar[])
100
99
*/
101
- public void cacheGrammars (String type , Grammar [] grammar ) {
102
- if (logger .isDebugEnabled ())
103
- {
104
- logger . debug ( "Cache {} grammars ({})." , grammar . length , type ); }
100
+ public void cacheGrammars (final String type , final Grammar [] grammar ) {
101
+ if (logger .isDebugEnabled ()) {
102
+ logger . debug ( "Cache {} grammars ({})." , grammar . length , type );
103
+ }
105
104
pool .cacheGrammars (type , grammar );
106
105
}
107
-
106
+
108
107
/**
109
- * Allows the XMLGrammarPool to store grammars when its
110
- * cacheGrammars(String, Grammar[]) method is called. This is the default
108
+ * Allows the XMLGrammarPool to store grammars when its
109
+ * cacheGrammars(String, Grammar[]) method is called. This is the default
111
110
* state of the object.
112
111
*
113
112
* @see org.apache.xerces.xni.grammars.XMLGrammarPool#unlockPool
114
113
*/
115
114
public void unlockPool () {
116
- if (logger .isDebugEnabled ())
117
- {logger .debug ("Unlock grammarpool." );}
115
+ if (logger .isDebugEnabled ()) {
116
+ logger .debug ("Unlock grammarpool." );
117
+ }
118
118
pool .unlockPool ();
119
119
}
120
-
120
+
121
121
/**
122
- * This method requests that the application retrieve a grammar
123
- * corresponding to the given GrammarIdentifier from its cache. If it
124
- * cannot do so it must return null; the parser will then call the
125
- * EntityResolver. An application must not call its EntityResolver itself
122
+ * This method requests that the application retrieve a grammar
123
+ * corresponding to the given GrammarIdentifier from its cache. If it
124
+ * cannot do so it must return null; the parser will then call the
125
+ * EntityResolver. An application must not call its EntityResolver itself
126
126
* from this method; this may result in infinite recursions.
127
127
*
128
+ * @param xgd The description of the Grammar being requested.
129
+ * @return the Grammar corresponding to this description or null
130
+ * if no such Grammar is known.
128
131
* @see org.apache.xerces.xni.grammars.XMLGrammarPool#retrieveGrammar(XMLGrammarDescription)
129
- *
130
- * @param xgd The description of the Grammar being requested.
131
- * @return the Grammar corresponding to this description or null
132
- * if no such Grammar is known.
133
132
*/
134
- public Grammar retrieveGrammar (XMLGrammarDescription xgd ) {
133
+ public Grammar retrieveGrammar (final XMLGrammarDescription xgd ) {
135
134
136
135
if (xgd == null ) {
137
136
if (logger .isDebugEnabled ()) {
@@ -154,53 +153,55 @@ public Grammar retrieveGrammar(XMLGrammarDescription xgd) {
154
153
155
154
return pool .retrieveGrammar (xgd );
156
155
}
157
-
156
+
158
157
/**
159
- * Causes the XMLGrammarPool not to store any grammars when the
158
+ * Causes the XMLGrammarPool not to store any grammars when the
160
159
* cacheGrammars(String, Grammar[[]) method is called.
161
160
*
162
161
* @see org.apache.xerces.xni.grammars.XMLGrammarPool#lockPool
163
162
*/
164
163
public void lockPool () {
165
- if (logger .isDebugEnabled ())
166
- {logger .debug ("Lock grammarpool." );}
164
+ if (logger .isDebugEnabled ()) {
165
+ logger .debug ("Lock grammarpool." );
166
+ }
167
167
pool .lockPool ();
168
168
}
169
-
169
+
170
170
/**
171
- * Removes all grammars from the pool.
171
+ * Removes all grammars from the pool.
172
172
*
173
173
* @see org.apache.xerces.xni.grammars.XMLGrammarPool#clear
174
174
*/
175
175
public void clear () {
176
- if (logger .isDebugEnabled ())
177
- {logger .debug ("Clear grammarpool." );}
176
+ if (logger .isDebugEnabled ()) {
177
+ logger .debug ("Clear grammarpool." );
178
+ }
178
179
pool .clear ();
179
180
}
180
-
181
+
181
182
/**
182
- * Removes all DTD grammars from the pool. Workaround for Xerces bug.
183
+ * Removes all DTD grammars from the pool. Workaround for Xerces bug.
183
184
*
184
185
* @see org.apache.xerces.xni.grammars.XMLGrammarPool#clear
185
186
*/
186
187
public void clearDTDs () {
187
188
//if (logger.isDebugEnabled())
188
189
// logger.debug("Removing DTD's from grammarpool.");
189
190
190
- final Grammar dtds [] = retrieveInitialGrammarSet (Namespaces .DTD_NS );
191
+ final Grammar [] dtds = retrieveInitialGrammarSet (Namespaces .DTD_NS );
191
192
if (dtds .length > 0 ) {
192
193
if (logger .isDebugEnabled ()) {
193
194
logger .debug ("Removing {} DTDs." , dtds .length );
194
195
}
195
- final Grammar schemas [] = retrieveInitialGrammarSet (Namespaces .SCHEMA_NS );
196
+ final Grammar [] schemas = retrieveInitialGrammarSet (Namespaces .SCHEMA_NS );
196
197
clear ();
197
198
cacheGrammars (Namespaces .SCHEMA_NS , schemas );
198
-
199
+
199
200
} else {
200
201
//if (logger.isDebugEnabled())
201
202
// logger.debug("No DTDs to be removed.");
202
203
}
203
204
}
204
-
205
-
205
+
206
+
206
207
}
0 commit comments