public synchronized Profile toProfile() {
if (myProfileDef != null) {
return myProfileDef;
}
Profile retVal = new Profile();
RuntimeResourceDefinition def = this;
if (StringUtils.isNotBlank(myId)) {
retVal.setId(new IdDt(myId));
}else {
throw new ConfigurationException("Resource class " + getImplementingClass().getCanonicalName() + " has no ID specified");
}
// Scan for extensions
scanForExtensions(retVal, def);
Collections.sort(retVal.getExtensionDefn(), new Comparator<ExtensionDefn>() {
@Override
public int compare(ExtensionDefn theO1, ExtensionDefn theO2) {
return theO1.getCode().compareTo(theO2.getCode());
}
});
// Scan for children
retVal.setName(getName());
Structure struct = retVal.addStructure();
LinkedList<String> path = new LinkedList<String>();
StructureElement element = struct.addElement();
element.getDefinition().setMin(1);
element.getDefinition().setMax("1");
fillProfile(struct, element, def, path, null);
retVal.getStructure().get(0).getElement().get(0).getDefinition().addType().getCode().setValue("Resource");
myProfileDef = retVal;
return retVal;
}