summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/persistency/outcome/OutcomeValidator.java
diff options
context:
space:
mode:
authorabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
committerabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
commit0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch)
tree5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/persistency/outcome/OutcomeValidator.java
parent036cbdba66f804743c4c838ed598d6972c4b3e17 (diff)
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/persistency/outcome/OutcomeValidator.java')
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/outcome/OutcomeValidator.java63
1 files changed, 34 insertions, 29 deletions
diff --git a/source/com/c2kernel/persistency/outcome/OutcomeValidator.java b/source/com/c2kernel/persistency/outcome/OutcomeValidator.java
index 1a76322..73f5706 100755..100644
--- a/source/com/c2kernel/persistency/outcome/OutcomeValidator.java
+++ b/source/com/c2kernel/persistency/outcome/OutcomeValidator.java
@@ -10,7 +10,6 @@ import org.apache.xerces.parsers.XMLGrammarPreparser;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.util.XMLGrammarPoolImpl;
import org.apache.xerces.xni.XNIException;
-import org.apache.xerces.xni.grammars.Grammar;
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
import org.apache.xerces.xni.parser.XMLErrorHandler;
import org.apache.xerces.xni.parser.XMLInputSource;
@@ -43,33 +42,33 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
/** Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking). */
protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking";
public static final String GRAMMAR_POOL = "http://apache.org/xml/properties/internal/grammar-pool";
-
+
static SchemaValidator schemaValid = new SchemaValidator();
-
+
Schema schema;
protected StringBuffer errors = null;
- XMLGrammarPoolImpl schemaGrammarPool = new XMLGrammarPoolImpl(1);
- SymbolTable sym = new SymbolTable();
-
+ XMLGrammarPoolImpl schemaGrammarPool = new XMLGrammarPoolImpl(1);
+ SymbolTable sym = new SymbolTable();
+
public static OutcomeValidator getValidator(Schema schema) throws InvalidDataException {
String schemaId = schema.docType+"_"+schema.docVersion;
-
+
if (schemaId.equals("Schema_0"))
return schemaValid;
-
+
return new OutcomeValidator(schema);
}
-
+
protected OutcomeValidator() {
errors = new StringBuffer();
}
-
+
public OutcomeValidator(Schema schema) throws InvalidDataException {
this.schema = schema;
-
+
if (schema.docType.equals("Schema"))
throw new InvalidDataException("Use SchemaValidator to validate schema", "");
-
+
errors = new StringBuffer();
Logger.msg(5, "Parsing "+schema.docType+" version "+schema.docVersion+". "+schema.schema.length()+" chars");
@@ -83,7 +82,7 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
preparser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
preparser.setErrorHandler(this);
try {
- Grammar g = preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, null, null, new StringReader(schema.schema), null));
+ preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, null, null, new StringReader(schema.schema), null));
} catch (IOException ex) {
throw new InvalidDataException("Error parsing schema: "+ex.getMessage(), "");
}
@@ -91,13 +90,13 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
if (errors.length() > 0) {
throw new InvalidDataException("Schema error: \n"+errors.toString(), "");
}
-
+
}
-
+
public synchronized String validate(Outcome outcome) {
if (outcome == null) return "Outcome object was null";
Logger.msg(5, "Validating outcome no "+outcome.getID()+" as "+schema.docType+" v"+schema.docVersion);
- if (outcome.getSchemaType().equals(schema.docType)
+ if (outcome.getSchemaType().equals(schema.docType)
&& outcome.getSchemaVersion() == schema.docVersion) {
return validate(outcome.getData());
}
@@ -112,20 +111,20 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
XMLParserConfiguration parserConfiguration = new IntegratedParserConfiguration(sym, schemaGrammarPool);
parserConfiguration.setFeature(NAMESPACES_FEATURE_ID, true);
parserConfiguration.setFeature(VALIDATION_FEATURE_ID, true);
- // now we can still do schema features just in case,
+ // now we can still do schema features just in case,
// so long as it's our configuraiton......
parserConfiguration.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
parserConfiguration.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
DOMParser parser = new DOMParser(parserConfiguration);
parser.setErrorHandler(this);
-
+
parser.parse(new XMLInputSource(null, null, null, new StringReader(outcome), null));
} catch (Exception e) {
return e.getMessage();
}
- return errors.toString();
- }
-
+ return errors.toString();
+ }
+
private void appendError(String level, Exception ex) {
errors.append(level);
String message = ex.getMessage();
@@ -134,32 +133,36 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
errors.append(message);
errors.append("\n");
}
-
+
/**
* ErrorHandler for instances
*/
- public void error(SAXParseException ex) throws SAXException {
+ @Override
+ public void error(SAXParseException ex) throws SAXException {
appendError("ERROR: ", ex);
}
/**
*
*/
- public void fatalError(SAXParseException ex) throws SAXException {
+ @Override
+ public void fatalError(SAXParseException ex) throws SAXException {
appendError("FATAL: ", ex);
}
/**
*
*/
- public void warning(SAXParseException ex) throws SAXException {
+ @Override
+ public void warning(SAXParseException ex) throws SAXException {
appendError("WARNING: ", ex);
}
/**
* XMLErrorHandler for schema
*/
- public void error(String domain, String key, XMLParseException ex)
+ @Override
+ public void error(String domain, String key, XMLParseException ex)
throws XNIException {
appendError("ERROR: ", ex);
}
@@ -167,7 +170,8 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
/**
*
*/
- public void fatalError(String domain, String key, XMLParseException ex)
+ @Override
+ public void fatalError(String domain, String key, XMLParseException ex)
throws XNIException {
appendError("FATAL: ", ex);
}
@@ -175,9 +179,10 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
/**
*
*/
- public void warning(String domain, String key, XMLParseException ex)
+ @Override
+ public void warning(String domain, String key, XMLParseException ex)
throws XNIException {
- appendError("WARNING: ", ex);
+ appendError("WARNING: ", ex);
}
}