XSI/Template Processing [message #1740218] |
Wed, 10 August 2016 14:14  |
Sean Muir Messages: 63 Registered: September 2015 |
Member |
|
|
The current CDA XSI type provider leverages the hierarchy size to determine best fit - This as worked well because until Consol2 - templates followed this pattern
Consol 2 has introduced versions of templates and not all version 2 are inheriting from version 1 introducing a race condition of sorts
Below is a sort approach based on a change to the processing where you collect all possible template classes then sort them and then pop the first one
The first is to check for isa relationships
Second is check for matching template ids - if match check the versions
lastly check the hierarchy size
one option is to add a name space uri preference which could be configured at runtime
Thoughts ?
Comparator<? super EClass> templateComparator = new Comparator<EClass>() {
@Override
public int compare(EClass templatedClass1, EClass templatedClass2) {
// Check hierarchies
if (templatedClass1.getEAllSuperTypes().contains(templatedClass2)) {
return -1;
}
if (templatedClass2.getEAllSuperTypes().contains(templatedClass1)) {
return 1;
}
// Check templates - if equal, check and compare versions - assume no version is earlier then version
String o1TemplateId = EcoreUtil.getAnnotation( templatedClass1, CDA_ANNOTATION_SOURCE, TEMPLATE_ID_ROOT);
String o2TemplateId = EcoreUtil.getAnnotation( templatedClass2, CDA_ANNOTATION_SOURCE, TEMPLATE_ID_ROOT);
if (!StringUtils.isEmpty(o1TemplateId) && o1TemplateId.equals(o2TemplateId)) {
String o1TemplateVersion = EcoreUtil.getAnnotation( templatedClass1, CDA_ANNOTATION_SOURCE, TEMPLATE_ID_EXTENSION);
String o2TemplateVersion = EcoreUtil.getAnnotation( templatedClass1, CDA_ANNOTATION_SOURCE, TEMPLATE_ID_EXTENSION);
if (StringUtils.isEmpty(o1TemplateVersion) && !StringUtils.isEmpty(o2TemplateVersion)) {
return 1;
}
if (!StringUtils.isEmpty(o1TemplateVersion) && StringUtils.isEmpty(o2TemplateVersion)) {
return -1;
}
if (!StringUtils.isEmpty(o1TemplateVersion) && !StringUtils.isEmpty(o2TemplateVersion)) {
Date d1 = null;
Date d2 = null;
try {
d1 =DateFormat.getDateInstance().parse(o1TemplateVersion);
d2 = DateFormat.getDateInstance().parse(o2TemplateVersion);
return d1.compareTo(d2);
} catch (ParseException e) {
if (d1 == null) {
return 1;
}
if (d2 == null) {
return -1;
}
}
}
}
// Lastly default to hierarchy depth - this is how currently done
if (templatedClass1.getEAllSuperTypes().size() > templatedClass2.getEAllSuperTypes().size()) {
return -1;
} else if (templatedClass1.getEAllSuperTypes().size() > templatedClass2.getEAllSuperTypes().size()) {
return 1;
}
return 0;
}
};
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02283 seconds