summaryrefslogtreecommitdiffstats
path: root/dcaedt_validator/kwalify/src/main
diff options
context:
space:
mode:
authorStone, Avi (as206k) <as206k@att.com>2018-05-23 11:21:11 +0300
committerStone, Avi (as206k) <as206k@att.com>2018-05-23 11:30:13 +0300
commit3e4c18770957b55e2f80da32c3a32caa908f1386 (patch)
tree8a94c656300e75e38febfe9826ad36fc54fe14f5 /dcaedt_validator/kwalify/src/main
parentda9db1b89e8c9199da4791a2ccd26d1628120a08 (diff)
Upgrade dt-be-main
Update sources for dcae-dt-be-main to latest version Change-Id: I3d58a2dc32611c0ca90f1c97e1294a17d5748623 Issue-ID: SDC-1359 Signed-off-by: Stone, Avi (as206k) <as206k@att.com>
Diffstat (limited to 'dcaedt_validator/kwalify/src/main')
-rw-r--r--dcaedt_validator/kwalify/src/main/java/kwalify/Defaultable.java4
-rw-r--r--dcaedt_validator/kwalify/src/main/java/kwalify/DefaultableHashMap.java9
-rw-r--r--dcaedt_validator/kwalify/src/main/java/kwalify/Messages.java20
-rw-r--r--dcaedt_validator/kwalify/src/main/java/kwalify/MetaValidator.java525
-rw-r--r--dcaedt_validator/kwalify/src/main/java/kwalify/PlainYamlParser.java114
-rw-r--r--dcaedt_validator/kwalify/src/main/java/kwalify/Rule.java135
-rw-r--r--dcaedt_validator/kwalify/src/main/java/kwalify/Validator.java1
-rw-r--r--dcaedt_validator/kwalify/src/main/java/kwalify/YamlParser.java2
8 files changed, 400 insertions, 410 deletions
diff --git a/dcaedt_validator/kwalify/src/main/java/kwalify/Defaultable.java b/dcaedt_validator/kwalify/src/main/java/kwalify/Defaultable.java
index f1de3fc..a2acfee 100644
--- a/dcaedt_validator/kwalify/src/main/java/kwalify/Defaultable.java
+++ b/dcaedt_validator/kwalify/src/main/java/kwalify/Defaultable.java
@@ -8,6 +8,6 @@ package kwalify;
* interface to have default value
*/
public interface Defaultable {
- Object getDefault();
- void setDefault(Object value);
+ Rule getDefault();
+ void setDefault(Rule value);
}
diff --git a/dcaedt_validator/kwalify/src/main/java/kwalify/DefaultableHashMap.java b/dcaedt_validator/kwalify/src/main/java/kwalify/DefaultableHashMap.java
index c2c625c..5846f1b 100644
--- a/dcaedt_validator/kwalify/src/main/java/kwalify/DefaultableHashMap.java
+++ b/dcaedt_validator/kwalify/src/main/java/kwalify/DefaultableHashMap.java
@@ -4,7 +4,6 @@
package kwalify;
-import java.io.Serializable;
import java.util.HashMap;
/**
@@ -14,18 +13,18 @@ public class DefaultableHashMap extends HashMap implements Defaultable {
private static final long serialVersionUID = -5224819562023897380L;
- private Object defaultValue = null;
+ private Rule defaultValue;
public DefaultableHashMap() {
super();
}
- public Object getDefault() { return defaultValue; }
+ public Rule getDefault() { return defaultValue; }
- public void setDefault(Object value) { defaultValue = value; }
+ public void setDefault(Rule value) { defaultValue = value; }
@Override
public Object get(Object key) {
- return containsKey(key) ? super.get(key) : defaultValue;
+ return containsKey(key) ? (Rule)super.get(key) : defaultValue;
}
}
diff --git a/dcaedt_validator/kwalify/src/main/java/kwalify/Messages.java b/dcaedt_validator/kwalify/src/main/java/kwalify/Messages.java
index b77f04b..e0bafb1 100644
--- a/dcaedt_validator/kwalify/src/main/java/kwalify/Messages.java
+++ b/dcaedt_validator/kwalify/src/main/java/kwalify/Messages.java
@@ -1,25 +1,22 @@
/*
- * @(#)Messages.java $Rev: 4 $ $Release: 0.5.1 $
- *
* copyright(c) 2005 kuwata-lab all rights reserved.
*/
package kwalify;
import java.util.ResourceBundle;
-//import java.util.Locale;
/**
* set of utility methods around messages.
*
- * @revision $Rev: 4 $
- * @release $Release: 0.5.1 $
*/
public class Messages {
- private static final String __basename = "kwalify.messages";
- private static ResourceBundle __messages = ResourceBundle.getBundle(__basename);
- //private static ResourceBundle __messages = ResourceBundle.getBundle(__basename, Locale.getDefault());
+ private static final String KWALIFY_MESSAGES = "kwalify.messages";
+ private static ResourceBundle __messages = ResourceBundle.getBundle(KWALIFY_MESSAGES);
+
+ // So that no one instantiate Messages and make sonar happy
+ private Messages(){}
public static String message(String key) {
return __messages.getString(key);
@@ -31,10 +28,9 @@ public class Messages {
public static String buildMessage(String key, Object value, Object[] args) {
String msg = message(key);
- assert msg != null;
if (args != null) {
- for (int i = 0; i < args.length; i++) { // don't use MessageFormat
- msg = msg.replaceFirst("%[sd]", escape(args[i]));
+ for (Object arg : args) { // don't use MessageFormat
+ msg = msg.replaceFirst("%[sd]", escape(arg));
}
}
if (value != null && !Types.isCollection(value)) {
@@ -44,8 +40,6 @@ public class Messages {
}
private static String escape(Object obj) {
- //return obj.toString().replaceAll("\\", "\\\\").replace("\n", "\\n"); // J2SK1.4 doesn't support String#replace(CharSequence, CharSequence)!
return obj.toString().replaceAll("\\\\", "\\\\\\\\").replaceAll("\\n", "\\\\n");
}
-
}
diff --git a/dcaedt_validator/kwalify/src/main/java/kwalify/MetaValidator.java b/dcaedt_validator/kwalify/src/main/java/kwalify/MetaValidator.java
index c8c21a7..8c4d6a2 100644
--- a/dcaedt_validator/kwalify/src/main/java/kwalify/MetaValidator.java
+++ b/dcaedt_validator/kwalify/src/main/java/kwalify/MetaValidator.java
@@ -1,126 +1,138 @@
/*
- * @(#)MetaValidator.java $Rev: 4 $ $Release: 0.5.1 $
- *
* copyright(c) 2005 kuwata-lab all rights reserved.
*/
package kwalify;
-import org.onap.sdc.common.onaplog.OnapLoggerDebug;
import org.onap.sdc.common.onaplog.OnapLoggerError;
import org.onap.sdc.common.onaplog.Enums.LogLevel;
import java.util.Map;
import java.util.List;
-import java.util.Iterator;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.regex.PatternSyntaxException;
/**
* meta validator to validate schema definition
- *
- * @revision $Rev: 4 $
- * @release $Release: 0.5.1 $
*/
public class MetaValidator extends Validator {
+ private static final String RANGE = "range";
+ private static final String MAX_EX = "max-ex";
+ private static final String MIN_EX = "min-ex";
+ private static final String LENGTH = "length";
+ private static final String SEQUENCE = "sequence";
+ private static final String ENUM_CONFLICT = "enum.conflict";
+ private static final String SCALAR_CONFLICT = "scalar.conflict";
+ private static final String IDENT = "ident";
+ private static final String IDENT1 = "ident:";
+ private static final String MAPPING = "mapping";
+ private static final String PATTERN = "pattern:";
+ private static final String PATTERN1 = "pattern";
+ private static final String TYPE_MAP = " type: map\n";
+ private static final String TYPE_STR = " type: str\n";
+ private static final String TYPE_BOOL = " type: bool\n";
+ private static final String MAPPING1 = " mapping:\n";
+ private static final String TYPE_SCALAR = " type: scalar\n";
+ private static final String TYPE_INT = " type: int\n";
+
private static OnapLoggerError errLogger = OnapLoggerError.getInstance();
- private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
- public static final String META_SCHEMA = ""
- + "name: MAIN\n"
- + "type: map\n"
- + "required: yes\n"
- + "mapping: &main-rule\n"
- + " \"name\":\n"
- + " type: str\n"
- + " \"desc\":\n"
- + " type: str\n"
- + " \"type\":\n"
- + " type: str\n"
- + " #required: yes\n"
- + " enum:\n"
- + " - seq\n"
- + " #- sequence\n"
- + " #- list\n"
- + " - map\n"
- + " #- mapping\n"
- + " #- hash\n"
- + " - str\n"
- + " #- string\n"
- + " - int\n"
- + " #- integer\n"
- + " - float\n"
- + " - number\n"
- + " #- numeric\n"
- + " - bool\n"
- + " #- boolean\n"
- + " - text\n"
- + " - date\n"
- + " - time\n"
- + " - timestamp\n"
- + " #- object\n"
- + " - any\n"
- + " - scalar\n"
- + " #- collection\n"
- + " \"required\":\n"
- + " type: bool\n"
- + " \"enum\":\n"
- + " type: seq\n"
- + " sequence:\n"
- + " - type: scalar\n"
- + " unique: yes\n"
- + " \"pattern\":\n"
- + " type: str\n"
- + " \"assert\":\n"
- + " type: str\n"
- + " pattern: /\\bval\\b/\n"
- + " \"range\":\n"
- + " type: map\n"
- + " mapping:\n"
- + " \"max\":\n"
- + " type: scalar\n"
- + " \"min\":\n"
- + " type: scalar\n"
- + " \"max-ex\":\n"
- + " type: scalar\n"
- + " \"min-ex\":\n"
- + " type: scalar\n"
- + " \"length\":\n"
- + " type: map\n"
- + " mapping:\n"
- + " \"max\":\n"
- + " type: int\n"
- + " \"min\":\n"
- + " type: int\n"
- + " \"max-ex\":\n"
- + " type: int\n"
- + " \"min-ex\":\n"
- + " type: int\n"
- + " \"ident\":\n"
- + " type: bool\n"
- + " \"unique\":\n"
- + " type: bool\n"
- + " \"sequence\":\n"
- + " name: SEQUENCE\n"
- + " type: seq\n"
- + " sequence:\n"
- + " - type: map\n"
- + " mapping: *main-rule\n"
- + " name: MAIN\n"
- + " #required: yes\n"
- + " \"mapping\":\n"
- + " name: MAPPING\n"
- + " type: map\n"
- + " mapping:\n"
- + " =:\n"
- + " type: map\n"
- + " mapping: *main-rule\n"
- + " name: MAIN\n"
- + " #required: yes\n"
- ;
+ private static final String META_SCHEMA = new StringBuilder().
+ append("").
+ append("name: MAIN\n").
+ append("type: map\n").
+ append("required: yes\n").
+ append("mapping: &main-rule\n").
+ append(" \"name\":\n").
+ append(TYPE_STR).
+ append(" \"desc\":\n").
+ append(TYPE_STR).
+ append(" \"type\":\n").
+ append(TYPE_STR).
+ append(" #required: yes\n").
+ append(" enum:\n").
+ append(" - seq\n").
+ append(" #- sequence\n").
+ append(" #- list\n").
+ append(" - map\n").
+ append(" #- mapping\n").
+ append(" #- hash\n").
+ append(" - str\n").
+ append(" #- string\n").
+ append(" - int\n").
+ append(" #- integer\n").
+ append(" - float\n").
+ append(" - number\n").
+ append(" #- numeric\n").
+ append(" - bool\n").
+ append(" #- boolean\n").
+ append(" - text\n").
+ append(" - date\n").
+ append(" - time\n").
+ append(" - timestamp\n").
+ append(" #- object\n").
+ append(" - any\n").
+ append(" - scalar\n").
+ append(" #- collection\n").
+ append(" \"required\":\n").
+ append(TYPE_BOOL).
+ append(" \"enum\":\n").
+ append(" type: seq\n").
+ append(" sequence:\n").
+ append(" - type: scalar\n").
+ append(" unique: yes\n").
+ append(" \"pattern\":\n").
+ append(TYPE_STR).
+ append(" \"assert\":\n").
+ append(TYPE_STR).
+ append(" pattern: /\\bval\\b/\n").
+ append(" \"range\":\n").
+ append(TYPE_MAP).
+ append(MAPPING1).
+ append(" \"max\":\n").
+ append(TYPE_SCALAR).
+ append(" \"min\":\n").
+ append(TYPE_SCALAR).
+ append(" \"max-ex\":\n").
+ append(TYPE_SCALAR).
+ append(" \"min-ex\":\n").
+ append(TYPE_SCALAR).
+ append(" \"length\":\n").
+ append(TYPE_MAP).
+ append(MAPPING1).
+ append(" \"max\":\n").
+ append(TYPE_INT).
+ append(" \"min\":\n").
+ append(TYPE_INT).
+ append(" \"max-ex\":\n").
+ append(TYPE_INT).
+ append(" \"min-ex\":\n").
+ append(TYPE_INT).
+ append(" \"ident\":\n").
+ append(TYPE_BOOL).
+ append(" \"unique\":\n").
+ append(TYPE_BOOL).
+ append(" \"sequence\":\n").
+ append(" name: SEQUENCE\n").
+ append(" type: seq\n").
+ append(" sequence:\n").
+ append(" - type: map\n").
+ append(" mapping: *main-rule\n").
+ append(" name: MAIN\n").
+ append(" #required: yes\n").
+ append(" \"mapping\":\n").
+ append(" name: MAPPING\n").
+ append(TYPE_MAP).
+ append(MAPPING1).
+ append(" =:\n").
+ append(" type: map\n").
+ append(" mapping: *main-rule\n").
+ append(" name: MAIN\n").
+ append(" #required: yes\n").
+ toString();
/**
*
@@ -140,6 +152,11 @@ public class MetaValidator extends Validator {
private static Validator __instance;
+ private MetaValidator(Map schema) {
+ super(schema);
+ }
+
+
public static Validator instance() {
synchronized (MetaValidator.class) {
if (__instance == null) {
@@ -147,6 +164,7 @@ public class MetaValidator extends Validator {
Map schema = (Map) YamlUtil.load(META_SCHEMA);
__instance = new MetaValidator(schema);
} catch (SyntaxException ex) {
+ errLogger.log(LogLevel.INFO,"MetaValidator","Failed validating schema: {}",ex);
assert false;
}
}
@@ -155,291 +173,224 @@ public class MetaValidator extends Validator {
return __instance;
}
- private MetaValidator(Map schema) {
- super(schema);
- }
-
+ @Override
public void postValidationHook(Object value, Rule rule, ValidationContext theContext) {
if (value == null) {
- return; // realy?
+ return; // really?
}
if (! "MAIN".equals(rule.getName())) {
return;
}
- //
assert value instanceof Map;
Map map = (Map)value;
String type = (String)map.get("type");
if (type == null) {
type = Types.getDefaultType();
}
- //Class type_class = Types.typeClass(type);
- //if (type_class == null) {
- // theContext.addError(validationError("type.unknown", rule, path + "/type", type, null));
- //}
- //
- //String pattern;
- //if ((pattern = (String)map.get("pattern")) != null) {
- if (map.containsKey("pattern")) {
- String pattern = (String)map.get("pattern");
+
+ if (map.containsKey(PATTERN1)) {
+ String pattern = (String)map.get(PATTERN1);
Matcher m = Util.matcher(pattern, "\\A\\/(.*)\\/([mi]?[mi]?)\\z");
String pat = m.find() ? m.group(1) : pattern;
try {
Pattern.compile(pat);
} catch (PatternSyntaxException ex) {
- theContext.addError("pattern.syntaxerr", rule, "pattern", pattern, null);
+ errLogger.log(LogLevel.INFO,"MetaValidator","pattern.syntaxerr: {}",ex);
+ theContext.addError("pattern.syntaxerr", rule, PATTERN1, pattern, null);
}
}
- //
- //List enum_list;
- //if ((enum_list = (List)map.get("enum")) != null) {
if (map.containsKey("enum")) {
- List enum_list = (List)map.get("enum");
+ List enumList = (List)map.get("enum");
if (Types.isCollectionType(type)) {
theContext.addError("enum.notscalar", rule, "enum:", (Object[])null);
} else {
- for (Iterator it = enum_list.iterator(); it.hasNext(); ) {
- Object elem = it.next();
- if (! Types.isCorrectType(elem, type)) {
- theContext.addError("enum.type.unmatch", rule, "enum", elem, new Object[] { Types.typeName(type) });
- }
- }
+ checkEnum(rule, theContext, type, enumList);
}
}
- //
- //String assert_str;
- //if ((assert_str = (String)map.get("assert")) != null) {
if (map.containsKey("assert")) {
errLogger.log(LogLevel.ERROR, this.getClass().getName(), "*** warning: sorry, 'assert:' is not supported in current version of Kwalify-java.");
- //String assert_str = (String)map.get("assert");
- //if (! Util.matches(assert_str, "\\bval\\b")) {
- // theContext.addError(validationError("assert.noval", rule, path + "/assert", assert_str, null);
- //}
- //try {
- // Expression.parse(assert_str);
- //} catch (InvalidExpressionException ex) {
- // theContext.addError(validationError("assert.syntaxerr", rule, path + "/assert", assert_str, null));
- //}
+
}
- //
- //Map range;
- //if ((range = (Map)map.get("range")) != null) {
- if (map.containsKey("range")) {
- Map range = (Map)map.get("range");
- //if (! (range instanceof Map)) {
- // theContext.addError(validtionError("range.notmap", rule, path + "/range", range, null));
- //} else
- if (Types.isCollectionType(type) || type.equals("bool") || type.equals("any")) {
+
+ if (map.containsKey(RANGE)) {
+ Map range = (Map)map.get(RANGE);
+
+ if (Types.isCollectionType(type) || "bool".equals(type) || "any".equals(type)) {
theContext.addError("range.notscalar", rule, "range:", null, null);
} else {
- for (Iterator it = range.keySet().iterator(); it.hasNext(); ) {
- String k = (String)it.next();
- Object v = range.get(k);
- if (! Types.isCorrectType(v, type)) {
- theContext.addError("range.type.unmatch", rule, "range/" + k, v, new Object[] { Types.typeName(type) });
- }
- }
+ rangeCheck(rule, theContext, type, range);
}
- if (range.containsKey("max") && range.containsKey("max-ex")) {
- theContext.addError("range.twomax", rule, "range", null, null);
+ if (range.containsKey("max") && range.containsKey(MAX_EX)) {
+ theContext.addError("range.twomax", rule, RANGE, null, null);
}
- if (range.containsKey("min") && range.containsKey("min-ex")) {
- theContext.addError("range.twomin", rule, "range", null, null);
+ if (range.containsKey("min") && range.containsKey(MIN_EX)) {
+ theContext.addError("range.twomin", rule, RANGE, null, null);
}
Object max = range.get("max");
Object min = range.get("min");
- Object max_ex = range.get("max-ex");
- Object min_ex = range.get("min-ex");
- Object[] args = null;
- //String error_symbol = null;
+ Object maxEx = range.get(MAX_EX);
+ Object minEx = range.get(MIN_EX);
+ Object[] args;
if (max != null) {
if (min != null && Util.compareValues(max, min) < 0) {
args = new Object[] { max, min };
- theContext.addError("range.maxltmin", rule, "range", null, args);
- } else if (min_ex != null && Util.compareValues(max, min_ex) <= 0) {
- args = new Object[] { max, min_ex };
- theContext.addError("range.maxleminex", rule, "range", null, args);
+ theContext.addError("range.maxltmin", rule, RANGE, null, args);
+ } else if (minEx != null && Util.compareValues(max, minEx) <= 0) {
+ args = new Object[] { max, minEx };
+ theContext.addError("range.maxleminex", rule, RANGE, null, args);
}
- } else if (max_ex != null) {
- if (min != null && Util.compareValues(max_ex, min) <= 0) {
- args = new Object[] { max_ex, min };
- theContext.addError("range.maxexlemin", rule, "range", null, args);
- } else if (min_ex != null && Util.compareValues(max_ex, min_ex) <= 0) {
- args = new Object[] { max_ex, min_ex };
- theContext.addError("range.maxexleminex", rule, "range", null, args);
+ } else if (maxEx != null) {
+ if (min != null && Util.compareValues(maxEx, min) <= 0) {
+ args = new Object[] { maxEx, min };
+ theContext.addError("range.maxexlemin", rule, RANGE, null, args);
+ } else if (minEx != null && Util.compareValues(maxEx, minEx) <= 0) {
+ args = new Object[] { maxEx, minEx };
+ theContext.addError("range.maxexleminex", rule, RANGE, null, args);
}
}
}
- //
- //Map length;
- //if ((length = (Map)map.get("length")) != null) {
- if (map.containsKey("length")) {
- Map length = (Map)map.get("length");
- //if (! (length instanceof Map)) {
- // theContext.addError(validtionError("length.notmap", rule, path + "/length", length, null));
- //} else
- if (! (type.equals("str") || type.equals("text"))) {
+ if (map.containsKey(LENGTH)) {
+ Map length = (Map)map.get(LENGTH);
+
+ if (! ("str".equals(type) || "text".equals(type))) {
theContext.addError("length.nottext", rule, "length:", (Object[])null);
}
- //for (Iterator it = length.keySet().iterator(); it.hasNext(); ) {
- // String k = (String)it.next();
- // Object v = length.get(k);
- // if (k == null || ! (k.equals("max") || k.equals("min") || k.equals("max-ex") || k.equals("min-ex"))) {
- // theContext.addError(validationError("length.undefined", rule, path + "/length/" + k, "" + k + ":", null));
- // } else if (! (v instanceof Integer)) {
- // theContext.addError(validationError("length.notint", rule, path + "/length/" + k, v, null));
- // }
- //}
- if (length.containsKey("max") && length.containsKey("max-ex")) {
- theContext.addError("length.twomax", rule, "length", (Object[])null);
+
+ if (length.containsKey("max") && length.containsKey(MAX_EX)) {
+ theContext.addError("length.twomax", rule, LENGTH, (Object[])null);
}
- if (length.containsKey("min") && length.containsKey("min-ex")) {
- theContext.addError("length.twomin", rule, "length", (Object[])null);
+ if (length.containsKey("min") && length.containsKey(MIN_EX)) {
+ theContext.addError("length.twomin", rule, LENGTH, (Object[])null);
}
Integer max = (Integer)length.get("max");
Integer min = (Integer)length.get("min");
- Integer max_ex = (Integer)length.get("max-ex");
- Integer min_ex = (Integer)length.get("min-ex");
- Object[] args = null;
- //String error_symbol = null;
+ Integer maxEx = (Integer)length.get(MAX_EX);
+ Integer minEx = (Integer)length.get(MIN_EX);
+ Object[] args;
if (max != null) {
if (min != null && max.compareTo(min) < 0) {
args = new Object[] { max, min };
- theContext.addError("length.maxltmin", rule, "length", null, args);
- } else if (min_ex != null && max.compareTo(min_ex) <= 0) {
- args = new Object[] { max, min_ex };
- theContext.addError("length.maxleminex", rule, "length", null, args);
+ theContext.addError("length.maxltmin", rule, LENGTH, null, args);
+ } else if (minEx != null && max.compareTo(minEx) <= 0) {
+ args = new Object[] { max, minEx };
+ theContext.addError("length.maxleminex", rule, LENGTH, null, args);
}
- } else if (max_ex != null) {
- if (min != null && max_ex.compareTo(min) <= 0) {
- args = new Object[] { max_ex, min };
- theContext.addError("length.maxexlemin", rule, "length", null, args);
- } else if (min_ex != null && max_ex.compareTo(min_ex) <= 0) {
- args = new Object[] { max_ex, min_ex };
- theContext.addError("length.maxexleminex", rule, "length", null, args);
+ } else if (maxEx != null) {
+ if (min != null && maxEx.compareTo(min) <= 0) {
+ args = new Object[] { maxEx, min };
+ theContext.addError("length.maxexlemin", rule, LENGTH, null, args);
+ } else if (minEx != null && maxEx.compareTo(minEx) <= 0) {
+ args = new Object[] { maxEx, minEx };
+ theContext.addError("length.maxexleminex", rule, LENGTH, null, args);
}
}
}
- //
- //Boolean unique;
- //if ((unique = (Boolean)map.get("unique")) != null) {
+
if (map.containsKey("unique")) {
Boolean unique = (Boolean)map.get("unique");
- if (unique.booleanValue() == true && Types.isCollectionType(type)) {
+ if (unique && Types.isCollectionType(type)) {
theContext.addError("unique.notscalar", rule, "unique:", (Object[])null);
}
if (theContext.getPath().length() == 0) {
theContext.addError("unique.onroot", rule, "", "unique:", null);
}
}
- //
- //Boolean ident;
- //if ((ident = (Boolean)map.get("ident")) != null) {
- if (map.containsKey("ident")) {
- Boolean ident = (Boolean)map.get("ident");
- if (ident.booleanValue() == true && Types.isCollectionType(type)) {
- theContext.addError("ident.notscalar", rule, "ident:", (Object[])null);
+
+ if (map.containsKey(IDENT)) {
+ Boolean ident = (Boolean)map.get(IDENT);
+ if (ident && Types.isCollectionType(type)) {
+ theContext.addError("ident.notscalar", rule, IDENT1, (Object[])null);
}
if (theContext.getPath().length() == 0) {
- theContext.addError("ident.onroot", rule, "/", "ident:", (Object[])null);
+ theContext.addError("ident.onroot", rule, "/", IDENT1, null);
}
}
- //
- //List seq;
- //if ((seq = (List)map.get("sequence")) != null) {
- if (map.containsKey("sequence")) {
- List seq = (List)map.get("sequence");
- //if (! (seq instanceof List)) {
- // theContext.addError(validationError("sequence.notseq", rule, path + "/sequence", seq, null));
- //} else
- if (seq == null || seq.size() == 0) {
- theContext.addError("sequence.noelem", rule, "sequence", seq, null);
+
+ if (map.containsKey(SEQUENCE)) {
+ List seq = (List)map.get(SEQUENCE);
+
+ if (seq == null || seq.isEmpty()) {
+ theContext.addError("sequence.noelem", rule, SEQUENCE, seq, null);
} else if (seq.size() > 1) {
- theContext.addError("sequence.toomany", rule, "sequence", seq, null);
+ theContext.addError("sequence.toomany", rule, SEQUENCE, seq, null);
} else {
Object item = seq.get(0);
assert item instanceof Map;
Map m = (Map)item;
- Boolean ident2 = (Boolean)m.get("ident");
- if (ident2 != null && ident2.booleanValue() == true && ! "map".equals(m.get("type"))) {
- theContext.addError("ident.notmap", null, "sequence/0", "ident:", null);
+ Boolean ident2 = (Boolean)m.get(IDENT);
+ if (ident2 != null && ident2 && ! "map".equals(m.get("type"))) {
+ theContext.addError("ident.notmap", null, "sequence/0", IDENT1, null);
}
}
}
- //
- //Map mapping;
- //if ((mapping = (Map)map.get("mapping")) != null) {
- if (map.containsKey("mapping")) {
- Map mapping = (Map)map.get("mapping");
- //if (mapping != null && ! (mapping instanceof Map)) {
- // theContext.addError(validationError("mapping.notmap", rule, path + "/mapping", mapping, null));
- //} else
- Object default_value = null;
+ if (map.containsKey(MAPPING)) {
+ Map mapping = (Map)map.get(MAPPING);
+
+ Object defaultValue = null;
if (mapping != null && mapping instanceof Defaultable) {
- default_value = ((Defaultable)mapping).getDefault();
+ defaultValue = ((Defaultable)mapping).getDefault();
}
- if (mapping == null || (mapping.size() == 0 && default_value == null)) {
- theContext.addError("mapping.noelem", rule, "mapping", mapping, null);
+ if (mapping == null || (mapping.size() == 0 && defaultValue == null)) {
+ theContext.addError("mapping.noelem", rule, MAPPING, mapping, null);
}
}
- //
- if (type.equals("seq")) {
- if (! map.containsKey("sequence")) {
+ if ("seq".equals(type)) {
+ if (! map.containsKey(SEQUENCE)) {
theContext.addError("seq.nosequence", rule, null, (Object[])null);
}
- //if (map.containsKey("enum")) {
- // theContext.addError(validationError("seq.conflict", rule, path, "enum:", null));
- //}
- if (map.containsKey("pattern")) {
- theContext.addError("seq.conflict", rule, "pattern:", (Object[])null);
+ if (map.containsKey(PATTERN1)) {
+ theContext.addError("seq.conflict", rule, PATTERN, (Object[])null);
}
- if (map.containsKey("mapping")) {
+ if (map.containsKey(MAPPING)) {
theContext.addError("seq.conflict", rule, "mapping:", (Object[])null);
}
- //if (map.containsKey("range")) {
- // theContext.addError(validationError("seq.conflict", rule, path, "range:", null));
- //}
- //if (map.containsKey("length")) {
- // theContext.addError(validationError("seq.conflict", rule, path, "length:", null));
- //}
- } else if (type.equals("map")) {
- if (! map.containsKey("mapping")) {
+ } else if ("map".equals(type)) {
+ if (! map.containsKey(MAPPING)) {
theContext.addError("map.nomapping", rule, null, (Object[])null);
}
- //if (map.containsKey("enum")) {
- // theContext.addError(validationError("map.conflict", rule, path, "enum:", null));
- //}
- if (map.containsKey("pattern")) {
- theContext.addError("map.conflict", rule, "pattern:", (Object[])null);
+ if (map.containsKey(PATTERN1)) {
+ theContext.addError("map.conflict", rule, PATTERN, (Object[])null);
}
- if (map.containsKey("sequence")) {
+ if (map.containsKey(SEQUENCE)) {
theContext.addError("map.conflict", rule, "sequence:", (Object[])null);
}
- //if (map.containsKey("range")) {
- // theContext.addError(validationError("map.conflict", rule, path, "range:", null));
- //}
- //if (map.containsKey("length")) {
- // theContext.addError(validationError("map.conflict", rule, path, "length:", null));
- //}
} else {
- if (map.containsKey("sequence")) {
- theContext.addError("scalar.conflict", rule, "sequence:", (Object[])null);
+ if (map.containsKey(SEQUENCE)) {
+ theContext.addError(SCALAR_CONFLICT, rule, "sequence:", (Object[])null);
}
- if (map.containsKey("mapping")) {
- theContext.addError("scalar.conflict", rule, "mapping:", (Object[])null);
+ if (map.containsKey(MAPPING)) {
+ theContext.addError(SCALAR_CONFLICT, rule, "mapping:", (Object[])null);
}
if (map.containsKey("enum")) {
- if (map.containsKey("range")) {
- theContext.addError("enum.conflict", rule, "range:", (Object[])null);
+ if (map.containsKey(RANGE)) {
+ theContext.addError(ENUM_CONFLICT, rule, "range:", (Object[])null);
}
- if (map.containsKey("length")) {
- theContext.addError("enum.conflict", rule, "length:", (Object[])null);
+ if (map.containsKey(LENGTH)) {
+ theContext.addError(ENUM_CONFLICT, rule, "length:", (Object[])null);
}
- if (map.containsKey("pattern")) {
- theContext.addError("enum.conflict", rule, "pattern:", (Object[])null);
+ if (map.containsKey(PATTERN1)) {
+ theContext.addError(ENUM_CONFLICT, rule, PATTERN, (Object[])null);
}
}
}
}
+ private void checkEnum(Rule rule, ValidationContext theContext, String type, List enumList) {
+ for (Object elem : enumList) {
+ if (!Types.isCorrectType(elem, type)) {
+ theContext.addError("enum.type.unmatch", rule, "enum", elem, new Object[]{Types.typeName(type)});
+ }
+ }
+ }
+
+ private void rangeCheck(Rule rule, ValidationContext theContext, String type, Map range) {
+ for (Object o : range.keySet()) {
+ String k = (String) o;
+ Object v = range.get(k);
+ if (!Types.isCorrectType(v, type)) {
+ theContext.addError("range.type.unmatch", rule, "range/" + k, v, new Object[]{Types.typeName(type)});
+ }
+ }
+ }
+
}
diff --git a/dcaedt_validator/kwalify/src/main/java/kwalify/PlainYamlParser.java b/dcaedt_validator/kwalify/src/main/java/kwalify/PlainYamlParser.java
index 5f23a19..dd44403 100644
--- a/dcaedt_validator/kwalify/src/main/java/kwalify/PlainYamlParser.java
+++ b/dcaedt_validator/kwalify/src/main/java/kwalify/PlainYamlParser.java
@@ -85,17 +85,13 @@ public class PlainYamlParser implements Parser {
seq.set(index, value);
}
- Map createMapping() {
- return new DefaultableHashMap();
- }
-
private void setMappingValueWith(Map map, Object key, Object value) {
map.put(key, value);
}
void setMappingDefault(Map map, Object value) {
if (map instanceof Defaultable) {
- ((Defaultable)map).setDefault(value);
+ ((Defaultable)map).setDefault((Rule)value);
}
}
@@ -316,14 +312,14 @@ public class PlainYamlParser implements Parser {
private Map parseFlowMapping(int depth) throws SyntaxException {
assert currentChar() == '{';
- Map map = createMapping();
+ Map map = new DefaultableHashMap();
int ch = getChar();
if (ch != '}') {
Object[] pair = parseFlowMappingItem(depth + 1);
Object key = pair[0];
Object value = pair[1];
setMappingValueWith(map, key, value);
- while ((ch = currentChar()) == ',') {
+ while ((currentChar()) == ',') {
ch = getChar();
if (ch == '}') {
throw syntaxError("mapping item required (or last comman is extra.");
@@ -368,7 +364,8 @@ public class PlainYamlParser implements Parser {
scalar = sb.toString();
} else {
sb.append((char)ch);
- while ((ch = getCurrentCharacter()) >= 0 && ch != ':' && ch != ',' && ch != ']' && ch != '}') {
+ String lookup = ":,]}";
+ while ((ch = getCurrentCharacter()) >= 0 && lookup.indexOf(ch) == -1) {
sb.append((char)ch);
}
scalar = toScalar(sb.toString().trim());
@@ -543,15 +540,7 @@ public class PlainYamlParser implements Parser {
} else if (slen < indent) {
throw syntaxError("invalid indent in block text.");
} else {
- if (n > 0) {
- if (blockChar == '>' && sb.length() > 0) {
- sb.deleteCharAt(sb.length() - 1);
- }
- for (int i = 0; i < n; i++) {
- sb.append('\n');
- }
- n = 0;
- }
+ n = indentHandler(blockChar, sb, n);
str = currentLine.substring(indent);
}
}
@@ -563,6 +552,11 @@ public class PlainYamlParser implements Parser {
if (currentLine != null && Util.matches(currentLine, "^ *#")) {
getLine();
}
+ processIndicator(blockChar, indicator, sep, sb, n);
+ return createScalar(text + sb.toString());
+ }
+
+ private void processIndicator(char blockChar, char indicator, char sep, StringBuilder sb, int n) {
switch (indicator) {
case '+':
handlePlus(blockChar, sb, n);
@@ -575,7 +569,19 @@ public class PlainYamlParser implements Parser {
sb.setCharAt(sb.length() - 1, '\n');
}
}
- return createScalar(text + sb.toString());
+ }
+
+ private int indentHandler(char blockChar, StringBuilder sb, int indent) {
+ if (indent > 0) {
+ if (blockChar == '>' && sb.length() > 0) {
+ sb.deleteCharAt(sb.length() - 1);
+ }
+ for (int i = 0; i < indent; i++) {
+ sb.append('\n');
+ }
+ return 0;
+ }
+ return indent;
}
private void handleMinus(char sep, StringBuilder sb) {
@@ -637,7 +643,7 @@ public class PlainYamlParser implements Parser {
private Map parseMapping(int column, String value) throws SyntaxException {
assert Util.matches(value, REGEXP2);
- Map map = createMapping();
+ Map map = new DefaultableHashMap();
while (true) {
Matcher m = Util.matcher(value, REGEXP2);
if (! m.find()) {
@@ -670,16 +676,23 @@ public class PlainYamlParser implements Parser {
Matcher m2 = Util.matcher(currentLine, REGEXP1);
m2.find();
int indent = m2.group(1).length();
- if (indent < column) {
+ if (checkIndent(column, indent)) {
break;
- } else if (indent > column) {
- throw syntaxError("invalid indent of mapping.");
}
value = m2.group(2);
}
return map;
}
+ private boolean checkIndent(int column, int indent) throws SyntaxException {
+ if (indent < column) {
+ return true;
+ } else if (indent > column) {
+ throw syntaxError("invalid indent of mapping.");
+ }
+ return false;
+ }
+
private Object parseScalar(String value) {
Object data = createScalar(toScalar(value));
@@ -690,38 +703,66 @@ public class PlainYamlParser implements Parser {
private Object toScalar(String value) {
Matcher m;
- if ((m = Util.matcher(value, "^\"(.*)\"([ \t]*#.*$)?")).find()) {
+ m = Util.matcher(value, "^\"(.*)\"([ \t]*#.*$)?");
+ if (m.find()) {
return m.group(1);
- } else if ((m = Util.matcher(value, "^'(.*)'([ \t]*#.*$)?")).find()) {
+ }
+
+ m = Util.matcher(value, "^'(.*)'([ \t]*#.*$)?");
+ if (m.find()) {
return m.group(1);
- } else if ((m = Util.matcher(value, "^(.*\\S)[ \t]*#")).find()) {
+ }
+
+ m = Util.matcher(value, "^(.*\\S)[ \t]*#");
+ if (m.find()) {
value = m.group(1);
}
if (Util.matches(value, "^-?0x\\d+$")) {
return Integer.parseInt(value, 16);
- } else if (Util.matches(value, "^-?0\\d+$")) {
+ }
+
+ if (Util.matches(value, "^-?0\\d+$")) {
return Integer.parseInt(value, 8);
- } else if (Util.matches(value, "^-?\\d+$")) {
+ }
+
+ if (Util.matches(value, "^-?\\d+$")) {
return Integer.parseInt(value, 10);
- } else if (Util.matches(value, "^-?\\d+\\.\\d+$")) {
+ }
+
+ if (Util.matches(value, "^-?\\d+\\.\\d+$")) {
return Double.parseDouble(value);
- } else if (Util.matches(value, "^(true|yes|on)$")) {
+ }
+
+ if (Util.matches(value, "^(true|yes|on)$")) {
return Boolean.TRUE;
- } else if (Util.matches(value, "^(false|no|off)$")) {
+ }
+
+ if (Util.matches(value, "^(false|no|off)$")) {
return Boolean.FALSE;
- } else if (Util.matches(value, "^(null|~)$")){
+ }
+
+ if (Util.matches(value, "^(null|~)$")){
return null;
- } else if (Util.matches(value, "^:(\\w+)$")) {
+ }
+
+ if (Util.matches(value, "^:(\\w+)$")) {
return value;
- } else if ((m = Util.matcher(value, "^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$")).find()) {
+ }
+
+ m = Util.matcher(value, "^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$");
+ if (m.find()) {
int year = Integer.parseInt(m.group(1));
int month = Integer.parseInt(m.group(2));
int day = Integer.parseInt(m.group(3));
Calendar cal = Calendar.getInstance();
+ //noinspection MagicConstant
cal.set(year, month, day, 0, 0, 0);
return cal.getTime();
- } else if ((m = Util.matcher(value, "^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)(?:[Tt]|[ \t]+)(\\d\\d?):(\\d\\d):(\\d\\d)(\\.\\d*)?(?:Z|[ \t]*([-+]\\d\\d?)(?::(\\d\\d))?)?$")).find()) {
+ }
+
+ m = Util.matcher(value, "^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)(?:[Tt]|[ \t]+)(\\d\\d?):(\\d\\d):(\\d\\d)(\\.\\d*)?(?:Z|[ \t]*([-+]\\d\\d?)(?::(\\d\\d))?)?$");
+ if (m.find()) {
int year = Integer.parseInt(m.group(1));
int month = Integer.parseInt(m.group(2));
int day = Integer.parseInt(m.group(3));
@@ -731,12 +772,13 @@ public class PlainYamlParser implements Parser {
String timezone = "GMT" + m.group(8) + ":" + m.group(9);
Calendar cal = Calendar.getInstance();
+ //noinspection MagicConstant
cal.set(year, month, day, hour, min, sec);
cal.setTimeZone(TimeZone.getTimeZone(timezone));
return cal.getTime();
- } else {
- return value;
}
+
+ return value;
}
}
diff --git a/dcaedt_validator/kwalify/src/main/java/kwalify/Rule.java b/dcaedt_validator/kwalify/src/main/java/kwalify/Rule.java
index 8dbe0b7..29a0fb5 100644
--- a/dcaedt_validator/kwalify/src/main/java/kwalify/Rule.java
+++ b/dcaedt_validator/kwalify/src/main/java/kwalify/Rule.java
@@ -5,12 +5,7 @@
package kwalify;
import java.io.Serializable;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
+import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.regex.PatternSyntaxException;
@@ -88,32 +83,32 @@ public class Rule implements Serializable{
private static final String UNIQUE3 = "unique: ";
private static final String ENUM2 = "enum:\n";
private static final String RANGE3 = "range: { ";
- private static final String NAME = "name";
- private static final String DESC = "desc";
+ private static final String NAME_CONSTANT = "name";
+ private static final String DESC_CONSTANT = "desc";
private static final String SHORT = "short";
- private static final String REQUIRED = "required";
+ private static final String REQUIRED_CONSTANT = "required";
private static final String TYPE = "type";
- private static final String PATTERN = "pattern";
- private static final String SEQUENCE = "sequence";
+ private static final String PATTERN_CONSTANT = "pattern";
+ private static final String SEQUENCE_CONSTANT = "sequence";
private static final String MAPPING = "mapping";
private static final String ASSERT = "assert";
- private static final String RANGE = "range";
- private static final String LENGTH = "length";
- private static final String IDENT = "ident";
- private static final String UNIQUE = "unique";
+ private static final String RANGE_CONSTANT = "range";
+ private static final String LENGTH_CONSTANT = "length";
+ private static final String IDENT_CONSTANT = "ident";
+ private static final String UNIQUE_CONSTANT = "unique";
private static final String ENUM = "enum:";
private static final String ENUM1 = "/enum";
- public static final String MAX = "max";
- public static final String MIN = "min";
+ private static final String MAX = "max";
+ private static final String MIN = "min";
private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
private Rule parent;
private String name = null;
private String desc = null;
- private String _short = null; //added by jora: only used for map types
+ private String shortValue = null; //added by jora: only used for map types
private boolean required = false;
- private String _type = null;
+ private String typeValue = null;
private Class typeClass = null;
private String pattern = null;
private Pattern patternRegexp = null;
@@ -126,20 +121,20 @@ public class Rule implements Serializable{
private boolean ident = false;
private boolean unique = false;
- private static final int CODE_NAME = NAME.hashCode();
- private static final int CODE_DESC = DESC.hashCode();
+ private static final int CODE_NAME = NAME_CONSTANT.hashCode();
+ private static final int CODE_DESC = DESC_CONSTANT.hashCode();
private static final int CODE_SHORT = SHORT.hashCode();
- private static final int CODE_REQUIRED = REQUIRED.hashCode();
+ private static final int CODE_REQUIRED = REQUIRED_CONSTANT.hashCode();
private static final int CODE_TYPE = TYPE.hashCode();
- private static final int CODE_PATTERN = PATTERN.hashCode();
- private static final int CODE_LENGTH = LENGTH.hashCode();
- private static final int CODE_RANGE = RANGE.hashCode();
+ private static final int CODE_PATTERN = PATTERN_CONSTANT.hashCode();
+ private static final int CODE_LENGTH = LENGTH_CONSTANT.hashCode();
+ private static final int CODE_RANGE = RANGE_CONSTANT.hashCode();
private static final int CODE_ASSERT = ASSERT.hashCode();
- private static final int CODE_IDENT = IDENT.hashCode();
- private static final int CODE_UNIQUE = UNIQUE.hashCode();
+ private static final int CODE_IDENT = IDENT_CONSTANT.hashCode();
+ private static final int CODE_UNIQUE = UNIQUE_CONSTANT.hashCode();
private static final int CODE_ENUM = ENUM.hashCode();
private static final int CODE_MAPPING = MAPPING.hashCode();
- private static final int CODE_SEQUENCE = SEQUENCE.hashCode();
+ private static final int CODE_SEQUENCE = SEQUENCE_CONSTANT.hashCode();
public Rule(Object schema, Rule parent) {
if (schema != null) {
@@ -175,21 +170,23 @@ public class Rule implements Serializable{
public String getName() { return name; }
public void setName(String name) { this.name = name; }
- public String getShort() { return _short; }
- public void setShort(String key) { _short = key; }
+ public String getShort() { return shortValue; }
+ public void setShort(String key) { shortValue = key; }
public boolean isRequired() { return required; }
public void setRequired(boolean required) { this.required = required; }
- public String getType() { return _type; }
- public void setType(String type) { this._type = type; }
+ public String getType() { return typeValue; }
+ public void setType(String type) { this.typeValue = type; }
public String getPattern() { return pattern; }
public void setPattern(String pattern) { this.pattern = pattern; }
public Pattern getPatternRegexp() { return patternRegexp; }
- public List getEnum() { return enumList; }
+ public List getEnum() {
+ return enumList;
+ }
public void setEnum(List enumList) { this.enumList = enumList; }
public List getSequence() { return sequence; }
@@ -245,29 +242,29 @@ public class Rule implements Serializable{
if (code == CODE_TYPE && key.equals(TYPE)) {
// done
- } else if (code == CODE_NAME && key.equals(NAME)) {
+ } else if (code == CODE_NAME && key.equals(NAME_CONSTANT)) {
initNameValue(value);
- } else if (code == CODE_DESC && key.equals(DESC)) {
+ } else if (code == CODE_DESC && key.equals(DESC_CONSTANT)) {
initDescValue(value);
} else if (code == CODE_SHORT && key.equals(SHORT)) {
initShortValue(value, rule, path);
- } else if (code == CODE_REQUIRED && key.equals(REQUIRED)) {
+ } else if (code == CODE_REQUIRED && key.equals(REQUIRED_CONSTANT)) {
initRequiredValue(value, rule, path);
- } else if (code == CODE_PATTERN && key.equals(PATTERN)) {
+ } else if (code == CODE_PATTERN && key.equals(PATTERN_CONSTANT)) {
initPatternValue(value, rule, path);
} else if (code == CODE_ENUM && key.equals(ENUM)) {
initEnumValue(value, rule, path);
} else if (code == CODE_ASSERT && key.equals(ASSERT)) {
initAssertValue(value, rule, path);
- } else if (code == CODE_RANGE && key.equals(RANGE)) {
+ } else if (code == CODE_RANGE && key.equals(RANGE_CONSTANT)) {
initRangeValue(value, rule, path);
- } else if (code == CODE_LENGTH && key.equals(LENGTH)) {
+ } else if (code == CODE_LENGTH && key.equals(LENGTH_CONSTANT)) {
initLengthValue(value, rule, path);
- } else if (code == CODE_IDENT && key.equals(IDENT)) {
+ } else if (code == CODE_IDENT && key.equals(IDENT_CONSTANT)) {
initIdentValue(value, rule, path);
- } else if (code == CODE_UNIQUE && key.equals(UNIQUE)) {
+ } else if (code == CODE_UNIQUE && key.equals(UNIQUE_CONSTANT)) {
initUniqueValue(value, rule, path);
- } else if (code == CODE_SEQUENCE && key.equals(SEQUENCE)) {
+ } else if (code == CODE_SEQUENCE && key.equals(SEQUENCE_CONSTANT)) {
rule = initSequenceValue(value, rule, path, ruleTable);
} else if (code == CODE_MAPPING && key.equals(MAPPING)) {
rule = initMappingValue(value, rule, path, ruleTable);
@@ -282,12 +279,12 @@ public class Rule implements Serializable{
value = Types.getDefaultType();
}
if (! (value instanceof String)) {
- throw schemaError(TYPE_NOTSTR, rule, path + TYPE1, _type, null);
+ throw schemaError(TYPE_NOTSTR, rule, path + TYPE1, typeValue, null);
}
- _type = (String)value;
- typeClass = Types.typeClass(_type);
- if (! Types.isBuiltinType(_type)) {
- throw schemaError(TYPE_UNKNOWN, rule, path + TYPE1, _type, null);
+ typeValue = (String)value;
+ typeClass = Types.typeClass(typeValue);
+ if (! Types.isBuiltinType(typeValue)) {
+ throw schemaError(TYPE_UNKNOWN, rule, path + TYPE1, typeValue, null);
}
}
@@ -305,12 +302,12 @@ public class Rule implements Serializable{
//the short form specification is to be interpreted as key if the type is a map or as an
//index if the target is a sequence (as index 0 actually)
- if (!Types.isCollectionType(_type)) {
+ if (!Types.isCollectionType(typeValue)) {
throw schemaError("range.notcollection", rule, path + "/short", value, null);
}
//we should also verify that it points to a declared key of the mapping .. not really, as it would
//fail the overall grammar
- _short = value.toString();
+ shortValue = value.toString();
}
private void initRequiredValue(Object value, Rule rule, String path) {
@@ -353,14 +350,14 @@ public class Rule implements Serializable{
throw schemaError("enum.notseq", rule, path + ENUM1, value, null);
}
enumList = (List)value;
- if (Types.isCollectionType(_type)) {
+ if (Types.isCollectionType(typeValue)) {
throw schemaError("enum.notscalar", rule, path, ENUM, null);
}
Map elemTable = new HashMap();
for (Iterator it = enumList.iterator(); it.hasNext(); ) {
Object elem = it.next();
if (! Util.isInstanceOf(elem, typeClass)) {
- throw schemaError("enum.type.unmatch", rule, path + ENUM1, elem, new Object[] { Types.typeName(_type) });
+ throw schemaError("enum.type.unmatch", rule, path + ENUM1, elem, new Object[] { Types.typeName(typeValue) });
}
if (elemTable.containsKey(elem)) {
throw schemaError("enum.duplicate", rule, path + ENUM1, elem, null);
@@ -385,7 +382,7 @@ public class Rule implements Serializable{
if (! (value instanceof Map)) {
throw schemaError("range.notmap", rule, path + RANGE1, value, null);
}
- if (Types.isCollectionType(_type) || "bool".equals(_type)) {
+ if (Types.isCollectionType(typeValue) || "bool".equals(typeValue)) {
throw schemaError("range.notscalar", rule, path, RANGE2, null);
}
range = (Map)value;
@@ -394,7 +391,7 @@ public class Rule implements Serializable{
Object rval = range.get(rkey);
if (MAX.equals(rkey) || MIN.equals(rkey) || rkey.equals(MAX_EX) || rkey.equals(MIN_EX)) {
if (! Util.isInstanceOf(rval, typeClass)) {
- String typename = Types.typeName(_type);
+ String typename = Types.typeName(typeValue);
throw schemaError("range.type.unmatch", rule, path + "/range/" + rkey, rval, new Object[] { typename });
}
} else {
@@ -439,7 +436,7 @@ public class Rule implements Serializable{
throw schemaError("length.notmap", rule, path + LENGTH1, value, null);
}
length = (Map)value;
- if (! ("str".equals(_type) || "text".equals(_type))) {
+ if (! ("str".equals(typeValue) || "text".equals(typeValue))) {
throw schemaError("length.nottext", rule, path, LENGTH2, null);
}
for (String k : length.keySet()) {
@@ -490,7 +487,7 @@ public class Rule implements Serializable{
}
ident = (Boolean) value;
required = true;
- if (Types.isCollectionType(_type)) {
+ if (Types.isCollectionType(typeValue)) {
throw schemaError(IDENT_NOTSCALAR, rule, path, IDENT1, null);
}
if (EMPTY_STRING.equals(path)) {
@@ -507,7 +504,7 @@ public class Rule implements Serializable{
throw schemaError(UNIQUE_NOTBOOL, rule, path + UNIQUE2, value, null);
}
unique = (Boolean) value;
- if (Types.isCollectionType(_type)) {
+ if (Types.isCollectionType(typeValue)) {
throw schemaError(UNIQUE_NOTSCALAR, rule, path, UNIQUE1, null);
}
if (path.equals(EMPTY_STRING)) {
@@ -557,6 +554,7 @@ public class Rule implements Serializable{
}
// create hash of rule
_mapping = new DefaultableHashMap();
+
if (defaultValue != null) {
rule = (Rule)ruleTable.get(defaultValue);
if (rule == null) {
@@ -565,15 +563,20 @@ public class Rule implements Serializable{
}
_mapping.setDefault(rule);
}
+
// put rules into _mapping
- Map map = (Map)value;
- for (Iterator it = map.keySet().iterator(); it.hasNext(); ) {
- Object k = it.next();
- Object v = map.get(k); // DefaultableHashMap
+ rule = putRulesIntoMap((Map) value, rule, path, ruleTable);
+ return rule;
+ }
+
+ private Rule putRulesIntoMap(Map value, Rule rule, String path, Map ruleTable) {
+ Map map = value;
+ for (Object k : map.keySet()) {
+ Object v = map.get(k);
if (v == null) {
v = new DefaultableHashMap();
}
- rule = (Rule)ruleTable.get(v);
+ rule = (Rule) ruleTable.get(v);
if (rule == null) {
rule = new Rule(null, this);
rule.init(v, path + MAPPING4 + k, ruleTable);
@@ -589,8 +592,8 @@ public class Rule implements Serializable{
private void checkConfliction(Map hash, Rule rule, String path) {
- if ("seq".equals(_type)) {
- if (! hash.containsKey(SEQUENCE)) {
+ if ("seq".equals(typeValue)) {
+ if (! hash.containsKey(SEQUENCE_CONSTANT)) {
throw schemaError("seq.nosequence", rule, path, null, null);
}
if (enumList != null) {
@@ -608,7 +611,7 @@ public class Rule implements Serializable{
if (length != null) {
throw schemaError(SEQ_CONFLICT, rule, path, LENGTH2, null);
}
- } else if (_type.equals(MAP)) {
+ } else if (typeValue.equals(MAP)) {
if (! hash.containsKey(MAPPING)) {
throw schemaError("map.nomapping", rule, path, null, null);
}
@@ -665,8 +668,8 @@ public class Rule implements Serializable{
if (desc != null) {
sb.append(indent).append(DESC1).append(desc).append("\n");
}
- if (_type != null) {
- sb.append(indent).append(TYPE2).append(_type).append("\n");
+ if (typeValue != null) {
+ sb.append(indent).append(TYPE2).append(typeValue).append("\n");
}
if (required) {
sb.append(indent).append(REQUIRED2).append(required).append("\n");
diff --git a/dcaedt_validator/kwalify/src/main/java/kwalify/Validator.java b/dcaedt_validator/kwalify/src/main/java/kwalify/Validator.java
index e0f5af0..9129c53 100644
--- a/dcaedt_validator/kwalify/src/main/java/kwalify/Validator.java
+++ b/dcaedt_validator/kwalify/src/main/java/kwalify/Validator.java
@@ -77,6 +77,7 @@ public class Validator {
}
protected void postValidationHook(Object value, Rule rule, ValidationContext context) {
+ // nothing
}
private void _validateRule(Object value, Rule rule, ValidationContext context) {
diff --git a/dcaedt_validator/kwalify/src/main/java/kwalify/YamlParser.java b/dcaedt_validator/kwalify/src/main/java/kwalify/YamlParser.java
index b5789d3..7192e5d 100644
--- a/dcaedt_validator/kwalify/src/main/java/kwalify/YamlParser.java
+++ b/dcaedt_validator/kwalify/src/main/java/kwalify/YamlParser.java
@@ -94,7 +94,7 @@ public class YamlParser extends PlainYamlParser {
}
protected Map createMapping() {
- Map map = super.createMapping();
+ Map map = new DefaultableHashMap();
linenumsTable.put(map, new HashMap());
return map;
}