diff options
Diffstat (limited to 'source/com/c2kernel/persistency/outcome')
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/outcome/Outcome.java | 45 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/outcome/OutcomeValidator.java | 63 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/outcome/Schema.java | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/outcome/SchemaValidator.java | 7 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/persistency/outcome/Viewpoint.java | 18 |
5 files changed, 74 insertions, 61 deletions
diff --git a/source/com/c2kernel/persistency/outcome/Outcome.java b/source/com/c2kernel/persistency/outcome/Outcome.java index f919230..a5ecb29 100755..100644 --- a/source/com/c2kernel/persistency/outcome/Outcome.java +++ b/source/com/c2kernel/persistency/outcome/Outcome.java @@ -24,18 +24,18 @@ public class Outcome implements C2KLocalObject { String mSchemaType;
int mSchemaVersion;
static DocumentBuilder parser;
-
+
static {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
- dbf.setNamespaceAware(false);
+ dbf.setNamespaceAware(false);
try {
parser = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
Logger.error(e);
- }
+ }
}
-
+
//id is the eventID
public Outcome(int id, String data, String schemaType, int schemaVersion) {
mID = id;
@@ -43,23 +43,23 @@ public class Outcome implements C2KLocalObject { mSchemaType = schemaType;
mSchemaVersion = schemaVersion;
}
-
+
public Outcome(String path, String data) throws PersistencyException {
// derive all the meta data from the path
StringTokenizer tok = new StringTokenizer(path,"/");
- if (tok.countTokens() != 3 && !(tok.nextToken().equals("Outcome")))
+ if (tok.countTokens() != 3 && !(tok.nextToken().equals("Outcome")))
throw new PersistencyException("Outcome() - Outcome path must have three components: "+path, null);
mSchemaType = tok.nextToken();
String verstring = tok.nextToken();
String objId = tok.nextToken();
try {
mSchemaVersion = Integer.parseInt(verstring);
- } catch (NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
throw new PersistencyException("Outcome() - Outcome version was an invalid number: "+verstring, null);
}
try {
mID = Integer.parseInt(objId);
- } catch (NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
mID = -1;
}
mData = data;
@@ -73,7 +73,8 @@ public class Outcome implements C2KLocalObject { return mID;
}
- public void setName(String name) {
+ @Override
+ public void setName(String name) {
try {
mID = Integer.parseInt(name);
} catch (NumberFormatException e) {
@@ -81,14 +82,15 @@ public class Outcome implements C2KLocalObject { }
}
- public String getName() {
+ @Override
+ public String getName() {
return String.valueOf(mID);
}
public void setData(String data) {
mData = data;
}
-
+
public void setData(Document data) {
mData = serialize(data, false);
}
@@ -96,11 +98,11 @@ public class Outcome implements C2KLocalObject { public String getData() {
return mData;
}
-
+
public void setSchemaType(String schemaType) {
mSchemaType = schemaType;
}
-
+
public String getSchemaType() {
return mSchemaType;
}
@@ -108,24 +110,25 @@ public class Outcome implements C2KLocalObject { public void setSchemaURL(int schemaVersion) {
mSchemaVersion = schemaVersion;
}
-
+
public int getSchemaVersion() {
return mSchemaVersion;
- }
-
+ }
+
public void setSchemaVersion(int schVer) {
mSchemaVersion = schVer;
- }
-
+ }
+
+ @Override
public String getClusterType() {
return ClusterStorage.OUTCOME;
}
-
+
// special script API methods
/**
* Parses the outcome into a DOM tree
- * @return a DOM Document
+ * @return a DOM Document
*/
public Document getDOM() {
try {
@@ -137,7 +140,7 @@ public class Outcome implements C2KLocalObject { return null;
}
}
-
+
static public String serialize(Document doc, boolean prettyPrint)
{
String serializedDoc = null;
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);
}
}
diff --git a/source/com/c2kernel/persistency/outcome/Schema.java b/source/com/c2kernel/persistency/outcome/Schema.java index 9514ebe..73969f2 100755..100644 --- a/source/com/c2kernel/persistency/outcome/Schema.java +++ b/source/com/c2kernel/persistency/outcome/Schema.java @@ -7,7 +7,7 @@ package com.c2kernel.persistency.outcome; * $Date: 2006/09/14 14:13:26 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
+ * All rights reserved.
*/
public class Schema {
diff --git a/source/com/c2kernel/persistency/outcome/SchemaValidator.java b/source/com/c2kernel/persistency/outcome/SchemaValidator.java index f2dfa0b..be8564b 100755..100644 --- a/source/com/c2kernel/persistency/outcome/SchemaValidator.java +++ b/source/com/c2kernel/persistency/outcome/SchemaValidator.java @@ -26,18 +26,19 @@ public class SchemaValidator extends OutcomeValidator { */
public SchemaValidator() {
-
+
}
public org.exolab.castor.xml.schema.Schema getSOM() {
- return castorSchema;
+ return castorSchema;
}
/**
*
*/
- public synchronized String validate(String outcome) {
+ @Override
+ public synchronized String validate(String outcome) {
errors = new StringBuffer();
try {
InputSource schemaSource = new InputSource(new StringReader(outcome));
diff --git a/source/com/c2kernel/persistency/outcome/Viewpoint.java b/source/com/c2kernel/persistency/outcome/Viewpoint.java index 7fc2aa5..a3fe283 100755..100644 --- a/source/com/c2kernel/persistency/outcome/Viewpoint.java +++ b/source/com/c2kernel/persistency/outcome/Viewpoint.java @@ -16,13 +16,13 @@ import com.c2kernel.process.Gateway; * $Date: 2005/10/05 07:39:36 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
+ * All rights reserved.
*/
// public static final String codeRevision =
// "$Revision: 1.10 $ $Date: 2005/10/05 07:39:36 $ $Author: abranson $";
public class Viewpoint implements C2KLocalObject {
-
+
int ID = -1; // not really used in this
// db fields
@@ -30,9 +30,9 @@ public class Viewpoint implements C2KLocalObject { String schemaName;
String name;
int schemaVersion;
- int eventId;
+ int eventId;
public static final int NONE = -1;
-
+
public Viewpoint() {
eventId = NONE;
sysKey = Path.INVALID;
@@ -40,7 +40,7 @@ public class Viewpoint implements C2KLocalObject { schemaName = null;
name = null;
}
-
+
public Viewpoint(int sysKey, String schemaName, String name, int schemaVersion, int eventId) {
this.sysKey = sysKey;
this.schemaName = schemaName;
@@ -55,6 +55,7 @@ public class Viewpoint implements C2KLocalObject { return retVal;
}
+ @Override
public String getClusterType() {
return ClusterStorage.VIEWPOINT;
}
@@ -80,6 +81,7 @@ public class Viewpoint implements C2KLocalObject { * Returns the name.
* @return String
*/
+ @Override
public String getName() {
return name;
}
@@ -128,6 +130,7 @@ public class Viewpoint implements C2KLocalObject { * Sets the name.
* @param name The name to set
*/
+ @Override
public void setName(String name) {
this.name = name;
}
@@ -168,8 +171,9 @@ public class Viewpoint implements C2KLocalObject { return (Event)Gateway.getStorage().get(sysKey, ClusterStorage.HISTORY+"/"+eventId, null);
}
-
- public String toString() {
+
+ @Override
+ public String toString() {
return name;
}
|
