You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2013/10/29 19:38:33 UTC
svn commit: r1536841 - in /pivot/branches/2.0.x: ./
core/src/org/apache/pivot/beans/BXMLSerializer.java
Author: rwhitcomb
Date: Tue Oct 29 18:38:33 2013
New Revision: 1536841
URL: http://svn.apache.org/r1536841
Log:
PIVOT-924: Provide a standard mechanism in BXMLSerializer to report exceptions
so that a particular application can subclass and report exceptions in a different
way than writing to System.err.
This is a merge of revision 1536829 from trunk to branches/2.0.x.
Modified:
pivot/branches/2.0.x/ (props changed)
pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java
Propchange: pivot/branches/2.0.x/
------------------------------------------------------------------------------
Merged /pivot/trunk:r1536829
Modified: pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java?rev=1536841&r1=1536840&r2=1536841&view=diff
==============================================================================
--- pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java (original)
+++ pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java Tue Oct 29 18:38:33 2013
@@ -112,7 +112,7 @@ public class BXMLSerializer implements S
}
}
- private static class AttributeInvocationHandler implements InvocationHandler {
+ private class AttributeInvocationHandler implements InvocationHandler {
private ScriptEngine scriptEngine;
private String event;
private String script;
@@ -138,8 +138,7 @@ public class BXMLSerializer implements S
scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
scriptEngine.eval(script);
} catch (ScriptException exception) {
- System.err.println(exception);
- System.err.println(script);
+ reportException(exception, script);
}
}
@@ -458,13 +457,13 @@ public class BXMLSerializer implements S
throw new SerializationException(exception);
}
} catch (IOException exception) {
- logException();
+ logException(exception);
throw exception;
} catch (SerializationException exception) {
- logException();
+ logException(exception);
throw exception;
} catch (RuntimeException exception) {
- logException();
+ logException(exception);
throw exception;
}
@@ -1291,7 +1290,7 @@ public class BXMLSerializer implements S
try {
scriptEngine.eval(script);
} catch (ScriptException exception) {
- System.err.println(exception);
+ reportException(exception, script);
break;
}
@@ -1362,7 +1361,7 @@ public class BXMLSerializer implements S
scriptReader = new BufferedReader(new InputStreamReader(scriptLocation.openStream()));
scriptEngine.eval(scriptReader);
} catch(ScriptException exception) {
- exception.printStackTrace();
+ reportException(exception);
} finally {
if (scriptReader != null) {
scriptReader.close();
@@ -1388,8 +1387,7 @@ public class BXMLSerializer implements S
try {
scriptEngine.eval(script);
} catch (ScriptException exception) {
- System.err.println(exception);
- System.err.println(script);
+ reportException(exception, script);
}
}
@@ -1423,7 +1421,7 @@ public class BXMLSerializer implements S
return xmlStreamReader.getLocation();
}
- private void logException() {
+ private void logException(Throwable exception) {
Location streamReaderlocation = xmlStreamReader.getLocation();
String message = "An error occurred at line number " + streamReaderlocation.getLineNumber();
@@ -1433,7 +1431,25 @@ public class BXMLSerializer implements S
message += ":";
- System.err.println(message);
+ reportException(new SerializationException(message, exception));
+ }
+
+ private void reportException(ScriptException exception, String script) {
+ reportException(new SerializationException("Failed to execute script:\n"+script, exception));
+ }
+
+ /**
+ * Hook used for standardized reporting of exceptions during this process.
+ * <p>Subclasses should override this method in order to do something besides
+ * print to <tt>System.err</tt>.
+ */
+ protected void reportException(Throwable exception) {
+ String message = exception.getLocalizedMessage();
+ if (message == null || message.isEmpty()) {
+ message = exception.getClass().getSimpleName();
+ }
+ System.err.println("Exception: " + message);
+ exception.printStackTrace(System.err);
}
@Override