sanders 02/01/03 18:34:08
Modified: digester/src/java/org/apache/commons/digester Digester.java
FactoryCreateRule.java ObjectCreateRule.java
digester/src/test/org/apache/commons/digester
RuleTestCase.java TestRuleSet.java
Log:
Added support for specifying classes instead of string classnames in Rule
definitions.
Suggested by Tal Dayan <[EMAIL PROTECTED]>
Revision Changes Path
1.30 +277 -221
jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java
Index: Digester.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- Digester.java 4 Dec 2001 17:11:08 -0000 1.29
+++ Digester.java 4 Jan 2002 02:34:08 -0000 1.30
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
1.29 2001/12/04 17:11:08 jstrachan Exp $
- * $Revision: 1.29 $
- * $Date: 2001/12/04 17:11:08 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
1.30 2002/01/04 02:34:08 sanders Exp $
+ * $Revision: 1.30 $
+ * $Date: 2002/01/04 02:34:08 $
*
* ====================================================================
*
@@ -109,7 +109,7 @@
*
* @author Craig McClanahan
* @author Scott Sanders
- * @version $Revision: 1.29 $ $Date: 2001/12/04 17:11:08 $
+ * @version $Revision: 1.30 $ $Date: 2002/01/04 02:34:08 $
*/
public class Digester extends DefaultHandler {
@@ -123,7 +123,7 @@
*/
public Digester() {
- super();
+ super();
}
@@ -137,7 +137,7 @@
*/
public Digester(SAXParser parser) {
- super();
+ super();
this.parser = parser;
@@ -153,7 +153,7 @@
*/
public Digester(XMLReader reader) {
- super();
+ super();
this.reader = reader;
@@ -353,7 +353,7 @@
return (this.classLoader);
if (this.useContextClassLoader) {
ClassLoader classLoader =
- Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().getContextClassLoader();
if (classLoader != null)
return (classLoader);
}
@@ -381,7 +381,7 @@
*/
public int getCount() {
- return (stack.size());
+ return (stack.size());
}
@@ -405,7 +405,7 @@
*/
public int getDebug() {
- return (this.debug);
+ return (this.debug);
}
@@ -417,7 +417,7 @@
*/
public void setDebug(int debug) {
- this.debug = debug;
+ this.debug = debug;
}
@@ -509,11 +509,11 @@
*/
public SAXParser getParser() {
- // Return the parser we already created (if any)
- if (parser != null)
- return (parser);
+ // Return the parser we already created (if any)
+ if (parser != null)
+ return (parser);
- // Create and return a new parser
+ // Create and return a new parser
synchronized (this) {
try {
if (factory == null)
@@ -554,9 +554,6 @@
}
-
-
-
/**
* Return the <code>Rules</code> implementation object containing our
* rules collection and associated matching policy. If none has been
@@ -592,7 +589,7 @@
*/
public boolean getValidating() {
- return (this.validating);
+ return (this.validating);
}
@@ -605,7 +602,7 @@
*/
public void setValidating(boolean validating) {
- this.validating = validating;
+ this.validating = validating;
}
@@ -656,7 +653,7 @@
useContextClassLoader = use;
- }
+ }
// ------------------------------------------------- ContentHandler Methods
@@ -673,12 +670,12 @@
* @exception SAXException if a parsing error is to be reported
*/
public void characters(char buffer[], int start, int length)
- throws SAXException {
+ throws SAXException {
if (debug >= 3)
log("characters(" + new String(buffer, start, length) + ")");
- bodyText.append(buffer, start, length);
+ bodyText.append(buffer, start, length);
}
@@ -690,15 +687,15 @@
*/
public void endDocument() throws SAXException {
- if (debug >= 3)
+ if (debug >= 3)
log("endDocument()");
- if (getCount() > 1)
- log("endDocument(): " + getCount() + " elements left");
- while (getCount() > 1)
- pop();
+ if (getCount() > 1)
+ log("endDocument(): " + getCount() + " elements left");
+ while (getCount() > 1)
+ pop();
- // Fire "finish" events for all defined rules
+ // Fire "finish" events for all defined rules
Iterator rules = getRules().rules().iterator();
while (rules.hasNext()) {
Rule rule = (Rule) rules.next();
@@ -711,10 +708,10 @@
log("Finish event threw exception", t);
throw createSAXException(t.getMessage());
}
- }
+ }
- // Perform final cleanup
- clear();
+ // Perform final cleanup
+ clear();
}
@@ -736,64 +733,64 @@
if (debug >= 3) {
log("endElement(" + namespaceURI + "," + localName +
- "," + qName + ")");
+ "," + qName + ")");
log(" match='" + match + "'");
log(" bodyText='" + bodyText + "'");
}
- // Fire "body" events for all relevant rules
- List rules = getRules().match(namespaceURI, match);
- if ((rules != null) && (rules.size() > 0)) {
- String bodyText = this.bodyText.toString().trim();
- for (int i = 0; i < rules.size(); i++) {
- try {
+ // Fire "body" events for all relevant rules
+ List rules = getRules().match(namespaceURI, match);
+ if ((rules != null) && (rules.size() > 0)) {
+ String bodyText = this.bodyText.toString().trim();
+ for (int i = 0; i < rules.size(); i++) {
+ try {
Rule rule = (Rule) rules.get(i);
if (debug >= 4)
log(" Fire body() for " + rule);
rule.body(bodyText);
- } catch (Exception e) {
- log("Body event threw exception", e);
- throw createSAXException(e);
- } catch (Throwable t) {
+ } catch (Exception e) {
+ log("Body event threw exception", e);
+ throw createSAXException(e);
+ } catch (Throwable t) {
log("Body event threw exception", t);
- throw createSAXException(t.getMessage());
+ throw createSAXException(t.getMessage());
}
- }
- } else {
+ }
+ } else {
if (debug >= 3)
log(" No rules found matching '" + match + "'.");
}
- // Recover the body text from the surrounding element
- bodyText = (StringBuffer) bodyTexts.pop();
+ // Recover the body text from the surrounding element
+ bodyText = (StringBuffer) bodyTexts.pop();
if (debug >= 4)
log(" Popping body text '" + bodyText.toString() + "'");
- // Fire "end" events for all relevant rules in reverse order
- if (rules != null) {
- for (int i = 0; i < rules.size(); i++) {
- int j = (rules.size() - i) - 1;
- try {
+ // Fire "end" events for all relevant rules in reverse order
+ if (rules != null) {
+ for (int i = 0; i < rules.size(); i++) {
+ int j = (rules.size() - i) - 1;
+ try {
Rule rule = (Rule) rules.get(j);
if (debug >= 4)
log(" Fire end() for " + rule);
rule.end();
- } catch (Exception e) {
- log("End event threw exception", e);
- throw createSAXException(e);
- } catch (Throwable t) {
- log("End event threw exception", t);
- throw createSAXException(t.getMessage());
+ } catch (Exception e) {
+ log("End event threw exception", e);
+ throw createSAXException(e);
+ } catch (Throwable t) {
+ log("End event threw exception", t);
+ throw createSAXException(t.getMessage());
}
- }
- }
+ }
+ }
- // Recover the previous match expression
- int slash = match.lastIndexOf('/');
- if (slash >= 0)
- match = match.substring(0, slash);
- else
- match = "";
+ // Recover the previous match expression
+ int slash = match.lastIndexOf('/');
+ if (slash >= 0)
+ match = match.substring(0, slash);
+ else
+ match = "";
}
@@ -836,13 +833,13 @@
* @exception SAXException if a parsing error is to be reported
*/
public void ignorableWhitespace(char buffer[], int start, int len)
- throws SAXException {
+ throws SAXException {
if (debug >= 3)
log("ignorableWhitespace(" +
- new String(buffer, start, len) + ")");
+ new String(buffer, start, len) + ")");
- ; // No processing required
+ ; // No processing required
}
@@ -856,12 +853,12 @@
* @exception SAXException if a parsing error is to be reported
*/
public void processingInstruction(String target, String data)
- throws SAXException {
+ throws SAXException {
if (debug >= 3)
- log("processingInstruction('" + target + "','" + data + "')");
+ log("processingInstruction('" + target + "','" + data + "')");
- ; // No processing is required
+ ; // No processing is required
}
@@ -874,9 +871,9 @@
public void setDocumentLocator(Locator locator) {
if (debug >= 3)
- log("setDocumentLocator(" + locator + ")");
+ log("setDocumentLocator(" + locator + ")");
- this.locator = locator;
+ this.locator = locator;
}
@@ -928,19 +925,19 @@
*/
public void startElement(String namespaceURI, String localName,
String qName, Attributes list)
- throws SAXException {
+ throws SAXException {
if (debug >= 3)
log("startElement(" + namespaceURI + "," + localName + "," +
- qName + ")");
+ qName + ")");
- // Save the body text accumulated for our surrounding element
- bodyTexts.push(bodyText);
+ // Save the body text accumulated for our surrounding element
+ bodyTexts.push(bodyText);
if (debug >= 4)
log(" Pushing body text '" + bodyText.toString() + "'");
- bodyText = new StringBuffer();
+ bodyText = new StringBuffer();
- // Compute the current matching rule
+ // Compute the current matching rule
StringBuffer sb = new StringBuffer(match);
if (match.length() > 0)
sb.append('/');
@@ -952,25 +949,25 @@
if (debug >= 3)
log(" New match='" + match + "'");
- // Fire "begin" events for all relevant rules
- List rules = getRules().match(namespaceURI, match);
- if ((rules != null) && (rules.size() > 0)) {
- String bodyText = this.bodyText.toString();
- for (int i = 0; i < rules.size(); i++) {
- try {
+ // Fire "begin" events for all relevant rules
+ List rules = getRules().match(namespaceURI, match);
+ if ((rules != null) && (rules.size() > 0)) {
+ String bodyText = this.bodyText.toString();
+ for (int i = 0; i < rules.size(); i++) {
+ try {
Rule rule = (Rule) rules.get(i);
if (debug >= 4)
log(" Fire begin() for " + rule);
rule.begin(list);
- } catch (Exception e) {
- log("Begin event threw exception", e);
- throw createSAXException(e);
- } catch (Throwable t) {
- log("Begin event threw exception", t);
- throw createSAXException(t.getMessage());
- }
- }
- } else {
+ } catch (Exception e) {
+ log("Begin event threw exception", e);
+ throw createSAXException(e);
+ } catch (Throwable t) {
+ log("Begin event threw exception", t);
+ throw createSAXException(t.getMessage());
+ }
+ }
+ } else {
if (debug >= 3)
log(" No rules found matching '" + match + "'.");
}
@@ -987,7 +984,7 @@
* @exception SAXException if a parsing error is to be reported
*/
public void startPrefixMapping(String prefix, String namespaceURI)
- throws SAXException {
+ throws SAXException {
if (debug >= 3)
log("startPrefixMapping(" + prefix + "," + namespaceURI + ")");
@@ -1015,9 +1012,9 @@
*/
public void notationDecl(String name, String publicId, String systemId) {
- if (debug >= 3)
- log("notationDecl(" + name + "," + publicId + "," +
- systemId + ")");
+ if (debug >= 3)
+ log("notationDecl(" + name + "," + publicId + "," +
+ systemId + ")");
}
@@ -1031,11 +1028,11 @@
* @param notation The name of the associated notation
*/
public void unparsedEntityDecl(String name, String publicId,
- String systemId, String notation) {
+ String systemId, String notation) {
- if (debug >= 3)
- log("unparsedEntityDecl(" + name + "," + publicId + "," +
- systemId + "," + notation + ")");
+ if (debug >= 3)
+ log("unparsedEntityDecl(" + name + "," + publicId + "," +
+ systemId + "," + notation + ")");
}
@@ -1052,25 +1049,25 @@
* @exception SAXException if a parsing exception occurs
*/
public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException {
+ throws SAXException {
- if (debug >= 1)
- log("resolveEntity('" + publicId + "', '" + systemId + "')");
+ if (debug >= 1)
+ log("resolveEntity('" + publicId + "', '" + systemId + "')");
this.publicId = publicId;
- // Has this system identifier been registered?
- String dtdURL = null;
+ // Has this system identifier been registered?
+ String dtdURL = null;
if (publicId != null)
dtdURL = (String) dtds.get(publicId);
- if (dtdURL == null) {
- if (debug >= 1)
- log(" Not registered, use system identifier");
- return (null);
- }
-
- // Return an input source to our alternative URL
- if (debug >= 1)
- log(" Resolving to alternate DTD '" + dtdURL + "'");
+ if (dtdURL == null) {
+ if (debug >= 1)
+ log(" Not registered, use system identifier");
+ return (null);
+ }
+
+ // Return an input source to our alternative URL
+ if (debug >= 1)
+ log(" Resolving to alternate DTD '" + dtdURL + "'");
try {
URL url = new URL(dtdURL);
InputStream stream = url.openStream();
@@ -1095,9 +1092,9 @@
*/
public void error(SAXParseException exception) throws SAXException {
- log("Parse Error at line " + exception.getLineNumber() +
- " column " + exception.getColumnNumber() + ": " +
- exception.getMessage(), exception);
+ log("Parse Error at line " + exception.getLineNumber() +
+ " column " + exception.getColumnNumber() + ": " +
+ exception.getMessage(), exception);
if (errorHandler != null)
errorHandler.error(exception);
@@ -1114,9 +1111,9 @@
*/
public void fatalError(SAXParseException exception) throws SAXException {
- log("Parse Fatal Error at line " + exception.getLineNumber() +
- " column " + exception.getColumnNumber() + ": " +
- exception.getMessage(), exception);
+ log("Parse Fatal Error at line " + exception.getLineNumber() +
+ " column " + exception.getColumnNumber() + ": " +
+ exception.getMessage(), exception);
if (errorHandler != null)
errorHandler.fatalError(exception);
@@ -1133,9 +1130,9 @@
*/
public void warning(SAXParseException exception) throws SAXException {
- log("Parse Warning at line " + exception.getLineNumber() +
- " column " + exception.getColumnNumber() + ": " +
- exception.getMessage(), exception);
+ log("Parse Warning at line " + exception.getLineNumber() +
+ " column " + exception.getColumnNumber() + ": " +
+ exception.getMessage(), exception);
if (errorHandler != null)
errorHandler.warning(exception);
@@ -1195,8 +1192,8 @@
public Object parse(File file) throws IOException, SAXException {
configure();
- getReader().parse(new InputSource(new FileReader(file)));
- return (root);
+ getReader().parse(new InputSource(new FileReader(file)));
+ return (root);
}
@@ -1213,8 +1210,8 @@
public Object parse(InputSource input) throws IOException, SAXException {
configure();
- getReader().parse(input);
- return (root);
+ getReader().parse(input);
+ return (root);
}
@@ -1231,8 +1228,8 @@
public Object parse(InputStream input) throws IOException, SAXException {
configure();
- getReader().parse(new InputSource(input));
- return (root);
+ getReader().parse(new InputSource(input));
+ return (root);
}
@@ -1249,8 +1246,8 @@
public Object parse(Reader reader) throws IOException, SAXException {
configure();
- getReader().parse(new InputSource(reader));
- return (root);
+ getReader().parse(new InputSource(reader));
+ return (root);
}
@@ -1267,8 +1264,8 @@
public Object parse(String uri) throws IOException, SAXException {
configure();
- getReader().parse(uri);
- return (root);
+ getReader().parse(uri);
+ return (root);
}
@@ -1284,7 +1281,7 @@
if (debug >= 1)
log("register('" + publicId + "', '" + dtdURL + "'");
- dtds.put(publicId, dtdURL);
+ dtds.put(publicId, dtdURL);
}
@@ -1305,7 +1302,6 @@
}
-
/**
* Register a set of Rule instances defined in a RuleSet.
*
@@ -1365,10 +1361,10 @@
* for a single parameter from the body of this element)
*/
public void addCallMethod(String pattern, String methodName,
- int paramCount) {
+ int paramCount) {
- addRule(pattern,
- new CallMethodRule(this, methodName, paramCount));
+ addRule(pattern,
+ new CallMethodRule(this, methodName, paramCount));
}
@@ -1387,11 +1383,11 @@
* for a <code>boolean</code> parameter)
*/
public void addCallMethod(String pattern, String methodName,
- int paramCount, String paramTypes[]) {
+ int paramCount, String paramTypes[]) {
- addRule(pattern,
- new CallMethodRule(this, methodName,
- paramCount, paramTypes));
+ addRule(pattern,
+ new CallMethodRule(this, methodName,
+ paramCount, paramTypes));
}
@@ -1409,11 +1405,11 @@
* for a <code>boolean</code> parameter)
*/
public void addCallMethod(String pattern, String methodName,
- int paramCount, Class paramTypes[]) {
+ int paramCount, Class paramTypes[]) {
- addRule(pattern,
- new CallMethodRule(this, methodName,
- paramCount, paramTypes));
+ addRule(pattern,
+ new CallMethodRule(this, methodName,
+ paramCount, paramTypes));
}
@@ -1427,8 +1423,8 @@
*/
public void addCallParam(String pattern, int paramIndex) {
- addRule(pattern,
- new CallParamRule(this, paramIndex));
+ addRule(pattern,
+ new CallParamRule(this, paramIndex));
}
@@ -1443,10 +1439,10 @@
* parameter value
*/
public void addCallParam(String pattern, int paramIndex,
- String attributeName) {
+ String attributeName) {
- addRule(pattern,
- new CallParamRule(this, paramIndex, attributeName));
+ addRule(pattern,
+ new CallParamRule(this, paramIndex, attributeName));
}
@@ -1469,6 +1465,20 @@
* Add a "factory create" rule for the specified parameters.
*
* @param pattern Element matching pattern
+ * @param clazz Java class of the object creation factory class
+ */
+ public void addFactoryCreate(String pattern, Class clazz) {
+
+ addRule(pattern,
+ new FactoryCreateRule(this, clazz));
+
+ }
+
+
+ /**
+ * Add a "factory create" rule for the specified parameters.
+ *
+ * @param pattern Element matching pattern
* @param className Java class name of the object creation factory class
* @param attributeName Attribute name which, if present, overrides the
* value specified by <code>className</code>
@@ -1486,6 +1496,23 @@
* Add a "factory create" rule for the specified parameters.
*
* @param pattern Element matching pattern
+ * @param clazz Java class of the object creation factory class
+ * @param attributeName Attribute name which, if present, overrides the
+ * value specified by <code>className</code>
+ */
+ public void addFactoryCreate(String pattern, Class clazz,
+ String attributeName) {
+
+ addRule(pattern,
+ new FactoryCreateRule(this, clazz, attributeName));
+
+ }
+
+
+ /**
+ * Add a "factory create" rule for the specified parameters.
+ *
+ * @param pattern Element matching pattern
* @param creationFactory Previously instantiated ObjectCreationFactory
* to be utilized
*/
@@ -1507,8 +1534,22 @@
*/
public void addObjectCreate(String pattern, String className) {
- addRule(pattern,
- new ObjectCreateRule(this, className));
+ addRule(pattern,
+ new ObjectCreateRule(this, className));
+
+ }
+
+
+ /**
+ * Add an "object create" rule for the specified parameters.
+ *
+ * @param pattern Element matching pattern
+ * @param clazz Java class to be created
+ */
+ public void addObjectCreate(String pattern, Class clazz) {
+
+ addRule(pattern,
+ new ObjectCreateRule(this, clazz));
}
@@ -1522,10 +1563,27 @@
* the default Java class name to be created
*/
public void addObjectCreate(String pattern, String className,
- String attributeName) {
+ String attributeName) {
- addRule(pattern,
- new ObjectCreateRule(this, className, attributeName));
+ addRule(pattern,
+ new ObjectCreateRule(this, className, attributeName));
+
+ }
+
+
+ /**
+ * Add an "object create" rule for the specified parameters.
+ *
+ * @param pattern Element matching pattern
+ * @param clazz Default Java class to be created
+ * @param attributeName Attribute name that optionally overrides
+ * the default Java class name to be created
+ */
+ public void addObjectCreate(String pattern, Class clazz,
+ String attributeName) {
+
+ addRule(pattern,
+ new ObjectCreateRule(this, clazz, attributeName));
}
@@ -1538,8 +1596,8 @@
*/
public void addSetNext(String pattern, String methodName) {
- addRule(pattern,
- new SetNextRule(this, methodName));
+ addRule(pattern,
+ new SetNextRule(this, methodName));
}
@@ -1555,10 +1613,10 @@
* for a <code>boolean</code> parameter)
*/
public void addSetNext(String pattern, String methodName,
- String paramType) {
+ String paramType) {
- addRule(pattern,
- new SetNextRule(this, methodName, paramType));
+ addRule(pattern,
+ new SetNextRule(this, methodName, paramType));
}
@@ -1570,8 +1628,8 @@
*/
public void addSetProperties(String pattern) {
- addRule(pattern,
- new SetPropertiesRule(this));
+ addRule(pattern,
+ new SetPropertiesRule(this));
}
@@ -1585,8 +1643,8 @@
*/
public void addSetProperty(String pattern, String name, String value) {
- addRule(pattern,
- new SetPropertyRule(this, name, value));
+ addRule(pattern,
+ new SetPropertyRule(this, name, value));
}
@@ -1599,8 +1657,8 @@
*/
public void addSetTop(String pattern, String methodName) {
- addRule(pattern,
- new SetTopRule(this, methodName));
+ addRule(pattern,
+ new SetTopRule(this, methodName));
}
@@ -1616,10 +1674,10 @@
* for a <code>boolean</code> parameter)
*/
public void addSetTop(String pattern, String methodName,
- String paramType) {
+ String paramType) {
- addRule(pattern,
- new SetTopRule(this, methodName, paramType));
+ addRule(pattern,
+ new SetTopRule(this, methodName, paramType));
}
@@ -1632,7 +1690,7 @@
*/
public void clear() {
- match = "";
+ match = "";
bodyTexts.clear();
params.clear();
publicId = null;
@@ -1647,13 +1705,13 @@
*/
public Object peek() {
- try {
- return (stack.peek());
- } catch (EmptyStackException e) {
+ try {
+ return (stack.peek());
+ } catch (EmptyStackException e) {
if (debug >= 1)
log("Empty stack (returning null)");
- return (null);
- }
+ return (null);
+ }
}
@@ -1668,13 +1726,13 @@
*/
public Object peek(int n) {
- try {
- return (stack.peek(n));
- } catch (EmptyStackException e) {
+ try {
+ return (stack.peek(n));
+ } catch (EmptyStackException e) {
if (debug >= 1)
log("Empty stack (returning null)");
- return (null);
- }
+ return (null);
+ }
}
@@ -1685,13 +1743,13 @@
*/
public Object pop() {
- try {
- return (stack.pop());
- } catch (EmptyStackException e) {
+ try {
+ return (stack.pop());
+ } catch (EmptyStackException e) {
if (debug >= 1)
log("Empty stack (returning null)");
- return (null);
- }
+ return (null);
+ }
}
@@ -1705,7 +1763,7 @@
if (stack.size() == 0)
root = object;
- stack.push(object);
+ stack.push(object);
}
@@ -1775,11 +1833,11 @@
*/
Object peekParams() {
- try {
- return (params.peek());
- } catch (EmptyStackException e) {
- return (null);
- }
+ try {
+ return (params.peek());
+ } catch (EmptyStackException e) {
+ return (null);
+ }
}
@@ -1794,11 +1852,11 @@
*/
Object peekParams(int n) {
- try {
- return (params.peek(n));
- } catch (EmptyStackException e) {
- return (null);
- }
+ try {
+ return (params.peek(n));
+ } catch (EmptyStackException e) {
+ return (null);
+ }
}
@@ -1809,11 +1867,11 @@
*/
Object popParams() {
- try {
- return (params.pop());
- } catch (EmptyStackException e) {
- return (null);
- }
+ try {
+ return (params.pop());
+ } catch (EmptyStackException e) {
+ return (null);
+ }
}
@@ -1825,7 +1883,7 @@
*/
void pushParams(Object object) {
- params.push(object);
+ params.push(object);
}
@@ -1836,25 +1894,23 @@
* @return the new exception
*/
protected SAXException createSAXException(String message, Exception e) {
- if ( locator != null ) {
- String error = "Error at (" + locator.getLineNumber() + ", "
- + locator.getColumnNumber() + ": " + message;
- if ( e != null ) {
- return new SAXParseException( error, locator, e );
- }
- else {
- return new SAXParseException( error, locator );
+ if (locator != null) {
+ String error = "Error at (" + locator.getLineNumber() + ", "
+ + locator.getColumnNumber() + ": " + message;
+ if (e != null) {
+ return new SAXParseException(error, locator, e);
+ } else {
+ return new SAXParseException(error, locator);
}
}
- System.out.println( "No Locator!" );
- if ( e != null ) {
+ System.out.println("No Locator!");
+ if (e != null) {
return new SAXException(message, e);
- }
- else {
+ } else {
return new SAXException(message);
}
}
-
+
/**
* Create a SAX exception which also understands about the location in
* the digester file where the exception occurs
@@ -1864,7 +1920,7 @@
protected SAXException createSAXException(Exception e) {
return createSAXException(e.getMessage(), e);
}
-
+
/**
* Create a SAX exception which also understands about the location in
* the digester file where the exception occurs
1.5 +37 -4
jakarta-commons/digester/src/java/org/apache/commons/digester/FactoryCreateRule.java
Index: FactoryCreateRule.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/FactoryCreateRule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FactoryCreateRule.java 20 Aug 2001 18:28:40 -0000 1.4
+++ FactoryCreateRule.java 4 Jan 2002 02:34:08 -0000 1.5
@@ -59,7 +59,6 @@
package org.apache.commons.digester;
-import java.lang.ClassLoader;
import org.xml.sax.Attributes;
@@ -74,7 +73,7 @@
* in a call to either a factory method or to a non-empty constructor.
*
* @author Robert Burrell Donkin
- * @version $Revision: 1.4 $ $Date: 2001/08/20 18:28:40 $
+ * @version $Revision: 1.5 $ $Date: 2002/01/04 02:34:08 $
*/
public class FactoryCreateRule extends Rule {
@@ -100,6 +99,21 @@
/**
* Construct a factory create rule that will use the specified
+ * class to create an {@link ObjectCreationFactory} which will
+ * then be used to create an object and push it on the stack.
+ *
+ * @param digester The associated Digester
+ * @param clazz Java class name of the object creation factory class
+ */
+ public FactoryCreateRule(Digester digester, Class clazz) {
+
+ this(digester, clazz, null);
+
+ }
+
+
+ /**
+ * Construct a factory create rule that will use the specified
* class name (possibly overridden by the specified attribute if present)
* to create an {@link ObjectCreationFactory}, which will then be used
* to instantiate an object instance and push it onto the stack.
@@ -120,6 +134,25 @@
/**
+ * Construct a factory create rule that will use the specified
+ * class (possibly overridden by the specified attribute if present)
+ * to create an {@link ObjectCreationFactory}, which will then be used
+ * to instantiate an object instance and push it onto the stack.
+ *
+ * @param digester The associated Digester
+ * @param clazz Default Java class name of the factory class
+ * @param attributeName Attribute name which, if present, contains an
+ * override of the class name of the object creation factory to create.
+ */
+ public FactoryCreateRule(Digester digester,
+ Class clazz, String attributeName) {
+
+ this(digester, clazz.getName(), attributeName);
+
+ }
+
+
+ /**
* Construct a factory create rule using the given, already instantiated,
* {@link ObjectCreationFactory}.
*
@@ -232,7 +265,7 @@
* @exception Exception if any error occurs
*/
protected ObjectCreationFactory getFactory(Attributes attributes)
- throws Exception {
+ throws Exception {
if (creationFactory == null) {
String realClassName = className;
@@ -245,7 +278,7 @@
digester.log("New factory " + realClassName);
Class clazz = digester.getClassLoader().loadClass(realClassName);
creationFactory = (ObjectCreationFactory)
- clazz.newInstance();
+ clazz.newInstance();
creationFactory.setDigester(digester);
}
return (creationFactory);
1.7 +53 -24
jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java
Index: ObjectCreateRule.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ObjectCreateRule.java 20 Aug 2001 18:28:40 -0000 1.6
+++ ObjectCreateRule.java 4 Jan 2002 02:34:08 -0000 1.7
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java,v
1.6 2001/08/20 18:28:40 craigmcc Exp $
- * $Revision: 1.6 $
- * $Date: 2001/08/20 18:28:40 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java,v
1.7 2002/01/04 02:34:08 sanders Exp $
+ * $Revision: 1.7 $
+ * $Date: 2002/01/04 02:34:08 $
*
* ====================================================================
*
@@ -63,7 +63,6 @@
package org.apache.commons.digester;
-import java.lang.ClassLoader;
import org.xml.sax.Attributes;
@@ -74,7 +73,7 @@
*
* @author Craig McClanahan
* @author Scott Sanders
- * @version $Revision: 1.6 $ $Date: 2001/08/20 18:28:40 $
+ * @version $Revision: 1.7 $ $Date: 2002/01/04 02:34:08 $
*/
public class ObjectCreateRule extends Rule {
@@ -91,7 +90,20 @@
*/
public ObjectCreateRule(Digester digester, String className) {
- this(digester, className, null);
+ this(digester, className, null);
+
+ }
+
+
+ /**
+ * Construct an object create rule with the specified class.
+ *
+ * @param digester The associated Digester
+ * @param clazz Java class name of the object to be created
+ */
+ public ObjectCreateRule(Digester digester, Class clazz) {
+
+ this(digester, clazz.getName(), null);
}
@@ -106,11 +118,28 @@
* override of the class name to create
*/
public ObjectCreateRule(Digester digester, String className,
- String attributeName) {
+ String attributeName) {
+
+ super(digester);
+ this.className = className;
+ this.attributeName = attributeName;
+
+ }
+
+
+ /**
+ * Construct an object create rule with the specified class and an
+ * optional attribute name containing an override.
+ *
+ * @param digester The associated Digester
+ * @param clazz Java class name of the object to be created
+ * @param attributeName Attribute name which, if present, contains an
+ * override of the class name to create
+ */
+ public ObjectCreateRule(Digester digester, Class clazz,
+ String attributeName) {
- super(digester);
- this.className = className;
- this.attributeName = attributeName;
+ this(digester, clazz.getName(), attributeName);
}
@@ -140,20 +169,20 @@
*/
public void begin(Attributes attributes) throws Exception {
- // Identify the name of the class to instantiate
- String realClassName = className;
- if (attributeName != null) {
- String value = attributes.getValue(attributeName);
- if (value != null)
- realClassName = value;
- }
- if (digester.getDebug() >= 1)
- digester.log("New " + realClassName);
+ // Identify the name of the class to instantiate
+ String realClassName = className;
+ if (attributeName != null) {
+ String value = attributes.getValue(attributeName);
+ if (value != null)
+ realClassName = value;
+ }
+ if (digester.getDebug() >= 1)
+ digester.log("New " + realClassName);
- // Instantiate the new object and push it on the context stack
+ // Instantiate the new object and push it on the context stack
Class clazz = digester.getClassLoader().loadClass(realClassName);
Object instance = clazz.newInstance();
- digester.push(instance);
+ digester.push(instance);
}
@@ -163,9 +192,9 @@
*/
public void end() throws Exception {
- Object top = digester.pop();
- if (digester.getDebug() >= 1)
- digester.log("Pop " + top.getClass().getName());
+ Object top = digester.pop();
+ if (digester.getDebug() >= 1)
+ digester.log("Pop " + top.getClass().getName());
}
1.6 +8 -12
jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java
Index: RuleTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- RuleTestCase.java 11 Oct 2001 00:28:42 -0000 1.5
+++ RuleTestCase.java 4 Jan 2002 02:34:08 -0000 1.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
1.5 2001/10/11 00:28:42 craigmcc Exp $
- * $Revision: 1.5 $
- * $Date: 2001/10/11 00:28:42 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
1.6 2002/01/04 02:34:08 sanders Exp $
+ * $Revision: 1.6 $
+ * $Date: 2002/01/04 02:34:08 $
*
* ====================================================================
*
@@ -75,7 +75,7 @@
* XML documents to exercise the built-in rules.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.5 $ $Date: 2001/10/11 00:28:42 $
+ * @version $Revision: 1.6 $ $Date: 2002/01/04 02:34:08 $
*/
public class RuleTestCase extends TestCase {
@@ -185,8 +185,7 @@
public void testObjectCreate2() {
// Configure the digester as required
- digester.addObjectCreate("employee",
- "org.apache.commons.digester.Employee");
+ digester.addObjectCreate("employee", Employee.class);
digester.addSetProperties("employee");
digester.addObjectCreate("employee/address",
"org.apache.commons.digester.Address");
@@ -223,8 +222,7 @@
public void testObjectCreate3() {
// Configure the digester as required
- digester.addObjectCreate("employee",
- "org.apache.commons.digester.Employee");
+ digester.addObjectCreate("employee", Employee.class);
digester.addSetProperties("employee");
digester.addObjectCreate("employee/address",
"org.apache.commons.digester.Address");
@@ -259,8 +257,7 @@
public void testObjectCreate4() {
// Configure the digester as required
- digester.addObjectCreate("employee",
- "org.apache.commons.digester.Employee");
+ digester.addObjectCreate("employee", Employee.class);
digester.addCallMethod("employee",
"setFirstName", 1);
digester.addCallParam("employee", 0, "firstName");
@@ -298,8 +295,7 @@
public void testRepeatedParse() {
// Configure the digester as required
- digester.addObjectCreate("employee",
- "org.apache.commons.digester.Employee");
+ digester.addObjectCreate("employee", Employee.class);
digester.addSetProperties("employee");
digester.addObjectCreate("employee/address",
"org.apache.commons.digester.Address");
1.2 +5 -6
jakarta-commons/digester/src/test/org/apache/commons/digester/TestRuleSet.java
Index: TestRuleSet.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/TestRuleSet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestRuleSet.java 26 Aug 2001 22:13:44 -0000 1.1
+++ TestRuleSet.java 4 Jan 2002 02:34:08 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/TestRuleSet.java,v
1.1 2001/08/26 22:13:44 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/08/26 22:13:44 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/TestRuleSet.java,v
1.2 2002/01/04 02:34:08 sanders Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/01/04 02:34:08 $
*
* ====================================================================
*
@@ -68,7 +68,7 @@
* optionally associated with a particular namespace URI.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/08/26 22:13:44 $
+ * @version $Revision: 1.2 $ $Date: 2002/01/04 02:34:08 $
*/
public class TestRuleSet extends RuleSetBase {
@@ -143,8 +143,7 @@
*/
public void addRuleInstances(Digester digester) {
- digester.addObjectCreate(prefix + "employee",
- "org.apache.commons.digester.Employee");
+ digester.addObjectCreate(prefix + "employee", Employee.class);
digester.addSetProperties(prefix + "employee");
digester.addObjectCreate("employee/address",
"org.apache.commons.digester.Address");
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>