[Mulgara-svn] r712 - trunk/src/jar/krule/java/org/mulgara/krule
pag at mulgara.org
pag at mulgara.org
Wed Mar 26 00:37:58 UTC 2008
Author: pag
Date: 2008-03-25 17:37:55 -0700 (Tue, 25 Mar 2008)
New Revision: 712
Modified:
trunk/src/jar/krule/java/org/mulgara/krule/KruleLoader.java
Log:
Made rule loading more robust in the face of bad structures, and provided some better error reporting. Also found a typo in a configuration query that would ultimately have affected OWL
Modified: trunk/src/jar/krule/java/org/mulgara/krule/KruleLoader.java
===================================================================
--- trunk/src/jar/krule/java/org/mulgara/krule/KruleLoader.java 2008-03-25 20:48:38 UTC (rev 711)
+++ trunk/src/jar/krule/java/org/mulgara/krule/KruleLoader.java 2008-03-26 00:37:55 UTC (rev 712)
@@ -441,7 +441,15 @@
}
for (int select = 0; select < elements.length; select++) {
if (elements[select] == null || types[select] == null) {
- throw new KruleStructureException("Rule " + rule.getName() + " does not have enough insertion elements");
+ // one element was set. Get a descriptive error message
+ StringBuffer errorMsg = new StringBuffer();
+ for (int s = 0; s < elements.length; s++) {
+ if (elements[s] == null) errorMsg.append(" <null>");
+ else errorMsg.append(" ").append(elements[s]);
+ if (types[s] == null) errorMsg.append("^^<null>");
+ else errorMsg.append("^^<").append(types[s]).append(">");
+ }
+ throw new KruleStructureException("Rule " + rule.getName() + " does not have enough insertion elements. Got: " + errorMsg);
}
}
// convert these elements into ConstraintElements for the query
@@ -807,7 +815,7 @@
// find the URI references and the referred URIs.
query = interpreter.parseQuery("select $constraint $constraint2 $type from <" + ruleModel +
"> where $constraint <krule:argument> $constraint2 and $constraint <rdf:type> $type and " +
- "($type <mulgara:is> <krule:ConstraintConjunction> or $type <mulgara:is> <krule:ConstraintDisjuntion>);");
+ "($type <mulgara:is> <krule:ConstraintConjunction> or $type <mulgara:is> <krule:ConstraintDisjunction>);");
} catch (Exception e) {
throw new QueryException("Invalid query.", e);
}
@@ -992,6 +1000,11 @@
// build the return list
List<ConstraintExpression> cList = new ArrayList<ConstraintExpression>();
+ // check argument validity
+ if (constraints == null) {
+ logger.warn("Empty constraint found in data. Ignored.");
+ return cList;
+ }
// go through the arguments
for (Node cNode: constraints) {
logger.debug("converting: " + cNode);
@@ -1006,7 +1019,8 @@
constraintExpr = newJoinConstraint((Node)typeMap.get(cNode), constraintArgs);
}
// add the constraint argument to the list
- cList.add(constraintExpr);
+ if (constraintExpr != null) cList.add(constraintExpr);
+ else logger.warn("Missing constraint expression. Ignoring.");
}
return cList;
}
@@ -1015,12 +1029,14 @@
/**
* Create a new join constraint.
*
- * @param type The URI for the type to create.
+ * @param type The URI for the type to create. <code>null</code> is a handled error.
* @param args The list of arguments for the constraint.
- * @return a new join constraint of the correct type.
+ * @return a new join constraint of the correct type, or <code>null</code> if the type is null.
*/
private ConstraintExpression newJoinConstraint(Node type, List<ConstraintExpression> args) throws KruleStructureException {
logger.debug("Building join constraint of type <" + type + ">: " + args);
+ // confirm arguments
+ if (type == null) return null;
if (type.equals(CONSTRAINT_CONJUNCTION)) {
return new ConstraintConjunction(args);
More information about the Mulgara-svn
mailing list