use of org.onosproject.yang.model.ListKey.ListKeyBuilder in project onos by opennetworkinglab.
the class ResourceIds method toNodeKey.
/**
* Converts node-identifier element to a NodeKey.
*
* @param id to parse (node-identifier fragment between '/')
* @return NodeKey (warning: returned namespace can be null, which should be interpreted as
* same as parent)
*/
private static NodeKey toNodeKey(String id) {
Pattern nodeId = Pattern.compile("^((?<prefix>[a-zA-Z_](?:[a-zA-Z0-9_.\\-]*)):)?" + "(?<identifier>[a-zA-Z_](?:[a-zA-Z0-9_.-]*))");
Matcher nidMatcher = nodeId.matcher(id);
if (!nidMatcher.find()) {
throw new IllegalArgumentException("node identifier not found in " + id);
}
String prefix = nidMatcher.group("prefix");
String identifier = nidMatcher.group("identifier");
// key and val pattern is a bit loosened from RFC for simplicity
Pattern preds = Pattern.compile("\\[\\s*(?<key>[^=\\s]+)\\s*=\\s*\\\"(?<val>[^\\]]+)\\\"\\s*\\]");
Matcher predMatcher = preds.matcher(id);
predMatcher.region(nidMatcher.end(), id.length());
LeafListKeyBuilder llkb = null;
ListKeyBuilder llb = null;
while (predMatcher.find()) {
String key = predMatcher.group("key");
String val = predMatcher.group("val");
if (key.equals(".")) {
// LeafList
if (llkb == null) {
llkb = new LeafListKeyBuilder();
}
llkb.schemaId(identifier, prefix).value(val);
} else {
// ListKey
if (llb == null) {
llb = new ListKeyBuilder();
}
llb.schemaId(identifier, prefix);
Matcher m = nodeId.matcher(key);
m.matches();
llb.addKeyLeaf(m.group("identifier"), m.group("prefix"), val);
}
}
if (llkb != null) {
return llkb.build();
} else if (llb != null) {
return llb.build();
} else {
return NodeKey.builder().schemaId(identifier, prefix).build();
}
}
Aggregations