You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by an...@apache.org on 2009/09/21 14:35:51 UTC
svn commit: r817228 -
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
Author: andrey
Date: Mon Sep 21 12:35:50 2009
New Revision: 817228
URL: http://svn.apache.org/viewvc?rev=817228&view=rev
Log:
better error message
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java?rev=817228&r1=817227&r2=817228&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java Mon Sep 21 12:35:50 2009
@@ -158,6 +158,7 @@
private Map<String, StartClosure> startTagOpMap;
private Map<String, EndClosure> endTagOpMap;
private String currentTag;
+ private Attributes currentAttributes;
private StringBuilder charactersBuffer;
private Map<String, Object> mapProperties;
@@ -680,17 +681,35 @@
catch (SAXException e) {
dataMap = null;
throw new CayenneRuntimeException(
- "Wrong DataMap format, last processed tag: <" + currentTag,
+ "Wrong DataMap format, last processed tag: " + constructCurrentStateString(),
Util.unwindException(e));
}
catch (Exception e) {
dataMap = null;
throw new CayenneRuntimeException(
- "Error loading DataMap, last processed tag: <" + currentTag,
+ "Error loading DataMap, last processed tag: " + constructCurrentStateString(),
Util.unwindException(e));
}
return dataMap;
}
+
+ /**
+ * Constructs error message for displaying as exception message
+ */
+ private Appendable constructCurrentStateString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<").append(currentTag);
+
+ if (currentAttributes != null) {
+ for (int i = 0; i < currentAttributes.getLength(); i++) {
+ sb.append(" ").append(currentAttributes.getLocalName(i)).append("=").
+ append("\"").append(currentAttributes.getValue(i)).append("\"");
+ }
+ }
+ sb.append(">");
+
+ return sb;
+ }
/**
* Loads DataMap from file specified by <code>uri</code> parameter.
@@ -788,7 +807,7 @@
String qName,
Attributes attributes) throws SAXException {
- rememberCurrentTag(localName);
+ rememberCurrentState(localName, attributes);
StartClosure op = startTagOpMap.get(localName);
if (op != null) {
@@ -805,7 +824,7 @@
op.execute();
}
- resetCurrentTag();
+ resetCurrentState();
charactersBuffer = null;
}
@@ -1352,12 +1371,14 @@
}
}
- private void rememberCurrentTag(String tag) {
+ private void rememberCurrentState(String tag, Attributes attrs) {
currentTag = tag;
+ currentAttributes = attrs;
}
- private void resetCurrentTag() {
+ private void resetCurrentState() {
currentTag = null;
+ currentAttributes = null;
}
/**