Validation of term bindings within ArchetypeInternalRefs // loadInternalRefs

Hi Rong and all,

In the Archetype class in the Java Reference Implementation, there is a method loadInternalRefs.

I am wondering what it is actually doing except for calling itself recursively?

Why I am asking:
The Java ADL validator checks if a path of a term binding is actually a valid path within the archetype.
It does so by checking if the binding path is part of the physicalPaths of the archetype.
This works fine as long as it is not within an ArchetypeInternalRef, but when that is the case, it does not find the path and adds an (incorrect) validation error:
if (!archetype.physicalPaths().contains(obi.getCode())) {
error = new ValidationError(ErrorType.WITB,
"The path of the term binding " + obi.getCode() +" doesn't exist in the archetype.");
errors.add(error);
}

I am not sure, but I think that:
a) The validator code is correct because the physicalPaths should also contain paths within an ArchetypeInternalRef
b) loadInternalRefs in the Archetype class should call loadMaps somewhere to make sure that we are adding the paths within ArchetypeInternalRefs to the physicalPaths (probably in the for (CObject child : attribute.getChildren()) loop at the very end)

Any ideas?

Cheers
Sebastian

Hi again,

Thomas has confirmed that the physicalPaths should contain paths within an ArchetypeInternalRef as well.

I have therefore changed the code of loadInternalRefs to the following (see below).
Not sure this is entirely correct, because I still haven’t understood what this method was doing at all before…without the changes below it just seems to traverse the nodes, but never actually do something.
This is likely my lack of understanding.
At least it passes all tests, including a new one that is looking for term binding for a node within an ArchetypeInternalRef.

Rong, do you think this is going into the right direction? If so, I can commit the changes, but I am frankly quite unsure.

Cheers
Sebastian

private void loadInternalRefs(CObject node, boolean required, String refPath, String baseTargetPath) {
if (node == null) {
return; // if the target wasn't found
}
if (refPath!= null && baseTargetPath != null && node.path() != null) {
String usenodePath = refPath + node.path().substring(baseTargetPath.length());
pathNodeMap.put(usenodePath, node);
}

if (node instanceof ArchetypeInternalRef) {
ArchetypeInternalRef ref = (ArchetypeInternalRef) node;
``
ArchetypeConstraint target = node(ref.getTargetPath());
if(target instanceof CObject) {
String atpart="";
if (!ref.path().endsWith("]" ) && ref.getTargetPath().endsWith("]")) {
atpart+= ref.getTargetPath().substring(ref.getTargetPath().lastIndexOf("["));
}

loadInternalRefs((CObject) target, required
&& node.isRequired(), ref.path()+atpart, ref.getTargetPath());
}
}

if (!(node instanceof CComplexObject)) {
return; // other types of cobject
}
CComplexObject parent = (CComplexObject) node;

if (parent.getAttributes() == null) {
return; // no attribute
}
for (CAttribute attribute : parent.getAttributes()) {
if (attribute.getExistence().equals(
CAttribute.Existence.NOT_ALLOWED)) {
continue;
}
if (attribute.getChildren() == null) {
continue; // no child
}
for (CObject child : attribute.getChildren()) {
loadInternalRefs(child, required && node.isRequired()
&& attribute.isRequired(), refPath, baseTargetPath);
}
}
}

the current build of ADL workbench is broken for this by the way - due to a bug introduced recently, but we only just noticed it. Secondly, the ADL Workbench doesn’t properly check the bindings to paths generated by use_node refs. I will put a new beta build fixing all this up in a day or two. It will also include the new validation codes: VOTBK: ontology term binding key valid. Every term binding must be to either a defined archetype term (‘at-code’) or to a path that is valid in the flat archetype. VOCBK: ontology constraint binding key valid. Every constraint binding must be to a defined archetype constraint code (‘ac-code’). The error messages I use for this are as follows: [“VOTBK”] = <“term binding key $1 must either be valid term code or valid path in flat archetype”> [“VOCBK”] = <“constraint binding key $1 must be a valid constraint code”> - thomas