[infinispan-commits] Infinispan SVN: r947 - trunk/core/src/main/java/org/infinispan/config.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Oct 14 15:17:16 EDT 2009
Author: vblagojevic at jboss.com
Date: 2009-10-14 15:17:16 -0400 (Wed, 14 Oct 2009)
New Revision: 947
Modified:
trunk/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java
Log:
simpler ValidationEventHandler (see https://jira.jboss.com/jira/browse/JBWS-2686)
Modified: trunk/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java 2009-10-14 17:12:25 UTC (rev 946)
+++ trunk/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java 2009-10-14 19:17:16 UTC (rev 947)
@@ -190,18 +190,21 @@
InputStream schema, ConfigurationBeanVisitor cbv) throws IOException {
try {
JAXBContext jc = JAXBContext.newInstance(InfinispanConfiguration.class);
- Unmarshaller u = jc.createUnmarshaller();
- ErrorValidationHandler handler = new ErrorValidationHandler();
- u.setEventHandler(handler);
+ Unmarshaller u = jc.createUnmarshaller();
if (schema != null) {
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
u.setSchema(factory.newSchema(new StreamSource(schema)));
+ u.setEventHandler(new ValidationEventHandler() {
+ @Override
+ public boolean handleEvent(ValidationEvent event) {
+ int severity = event.getSeverity();
+ return (severity != ValidationEvent.FATAL_ERROR && severity != ValidationEvent.ERROR);
+ }
+ });
}
- InfinispanConfiguration ic = (InfinispanConfiguration) u.unmarshal(config);
- if (handler.errorsReported()) {
- throw new ConfigurationException("Exception were reported during parsing the config file: " + handler.getReportedErrors());
- }
+
+ InfinispanConfiguration ic = (InfinispanConfiguration) u.unmarshal(config);
// legacy, don't ask
ic.parseGlobalConfiguration().setDefaultConfiguration(ic.parseDefaultConfiguration());
if (cbv != null) {
@@ -209,44 +212,12 @@
}
return ic;
} catch (Exception e) {
- log.error("Cought unexpected ex: ", e);
IOException ioe = new IOException(e.getLocalizedMessage());
ioe.initCause(e);
throw ioe;
}
}
- public static class ErrorValidationHandler implements ValidationEventHandler {
- private boolean errorsReported = false;
- private StringBuilder errors;
-
- public boolean handleEvent(ValidationEvent event) {
- if (event != null && event.getLinkedException() != null) {
- errorsReported = true;
- getErrors().append(event.getMessage());
- log.error("Exception while parsing the xml file: ", event.getLinkedException());
- }
- return true;
- }
-
- private StringBuilder getErrors() {
- if (errors == null) {
- errors = new StringBuilder();
- } else {
- errors.append('\n');
- }
- return errors;
- }
-
- public boolean errorsReported() {
- return errorsReported;
- }
-
- public String getReportedErrors() {
- return errors.toString();
- }
- }
-
private static boolean skipSchemaValidation() {
String s = System.getProperty(VALIDATING_SYSTEM_PROPERTY);
return s != null && !Boolean.parseBoolean(s);
More information about the infinispan-commits
mailing list