Skip to content

Commit

Permalink
When applyingDefinition to a container, definitions for dynamically-d…
Browse files Browse the repository at this point in the history
…efined items are looked for as well.
  • Loading branch information
mederly committed Jun 19, 2015
1 parent 96d996c commit ef7c0a3
Showing 1 changed file with 45 additions and 6 deletions.
Expand Up @@ -154,6 +154,14 @@ public void revive(PrismContext prismContext) {
}
}

/*
* TODO clean this up: There are three definition-finding algorithms:
* - findItemDefinition (QName ...)
* - findItemDefinition (ItemPath ...)
* - findPropertyDefinition (ItemPath ...)
*
* This has to be replaced by a single algorithm.
*/
public <D extends ItemDefinition> D findItemDefinition(QName name, Class<D> clazz) {
return findItemDefinition(name, clazz, false);
}
Expand All @@ -165,13 +173,38 @@ public <D extends ItemDefinition> D findItemDefinition(QName name, Class<D> claz
if (name == null) {
throw new IllegalArgumentException("name not specified while searching in " + this);
}

if (complexTypeDefinition == null) {

D itemDefinition;
if (complexTypeDefinition != null) {
itemDefinition = complexTypeDefinition.findItemDefinition(name, clazz, caseInsensitive);
} else {
// xsd:any and similar dynamic definitions
return null;
itemDefinition = null;
}

if (itemDefinition == null && isRuntimeSchema()) {
itemDefinition = findRuntimeItemDefinition(name, null, clazz); // TODO what about case insensitive?
}
return itemDefinition;
}

return complexTypeDefinition.findItemDefinition(name, clazz, caseInsensitive);
private <D extends ItemDefinition> D findRuntimeItemDefinition(QName firstName, ItemPath rest, Class<D> clazz) {
if (prismContext == null) {
return null; // should not occur
}
ItemDefinition definition = prismContext.getSchemaRegistry().findItemDefinitionByElementName(firstName);
if (definition == null) {
return null;
}
if (rest != null && !rest.isEmpty()) {
return (D) definition.findItemDefinition(rest, clazz);
}
// this is the last step of search
if (clazz.isAssignableFrom(definition.getClass())) {
return (D) definition;
} else {
return null;
}
}

public <ID extends ItemDefinition> ID findItemDefinition(ItemPath path, Class<ID> clazz) {
Expand All @@ -183,23 +216,29 @@ public <ID extends ItemDefinition> ID findItemDefinition(ItemPath path, Class<ID
}

QName firstName = ((NameItemPathSegment)path.first()).getName();
ItemPath rest = path.rest();

// we need to be compatible with older versions..soo if the path does
// not contains qnames with namespaces defined (but the prefix was
// specified) match definition according to the local name
if (StringUtils.isEmpty(firstName.getNamespaceURI())) {
for (ItemDefinition def : getDefinitions()){
if (QNameUtil.match(firstName, def.getName())){
return (ID) def.findItemDefinition(path.rest(), clazz);
return (ID) def.findItemDefinition(rest, clazz);
}
}
}

for (ItemDefinition def : getDefinitions()) {
if (firstName.equals(def.getName())) {
return (ID) def.findItemDefinition(path.rest(), clazz);
return (ID) def.findItemDefinition(rest, clazz);
}
}

if (isRuntimeSchema()) {
return findRuntimeItemDefinition(firstName, rest, clazz);
}

return null;
}

Expand Down

0 comments on commit ef7c0a3

Please sign in to comment.