* {@link Resource}s that will be set as domains of the resultant property
* @return {@link DatatypeProperty} instance.
*/
public DatatypeProperty createDatatypePropertyByPropertyDefinition(PropertyDefinition propertyDefinition,
List<Resource> domains) {
DatatypeProperty datatypeProperty = null;
try {
datatypeProperty = getDatatypePropertyByReference(propertyDefinition.getUniqueRef());
} catch (UnsupportedPolymorphismException e) {
log.warn("Another type of resource has been created for the property definition: {}",
propertyDefinition.getLocalname());
return null;
} catch (ConversionException e) {
log.warn("Another type of resource has been created for the property definition: {}",
propertyDefinition.getLocalname());
return null;
}
if (datatypeProperty == null) {
String propertyURI = namingStrategy.getDataPropertyName(ontologyURI, propertyDefinition);
Resource range = getDatatypePropertyRange(propertyDefinition.getPropertyType());
datatypeProperty = ontModel.createDatatypeProperty(propertyURI);
datatypeProperty.addProperty(CMSAdapterVocabulary.CMSAD_RESOURCE_REF_PROP,
propertyDefinition.getUniqueRef());
if (propertyDefinition.getSourceObjectTypeRef() != null) {
datatypeProperty.addProperty(CMSAdapterVocabulary.CMSAD_PROPERTY_SOURCE_OBJECT_PROP,
propertyDefinition.getSourceObjectTypeRef());
} else {
log.info("Source object type reference not found on property definition {}",
propertyDefinition.getLocalname());
}
for (Resource domain : domains) {
datatypeProperty.addDomain(domain);
}
datatypeProperty.addRange(range);
} else {
// Add domains to union class
OntResource domain = datatypeProperty.getDomain();
if (domain != null) {
if (domain.isClass() && domain.asClass().isUnionClass()) {
UnionClass unclass = domain.asClass().asUnionClass();
for (Resource newDomain : domains) {
unclass.addOperand(newDomain);
}
} else {
List<Resource> resources = new ArrayList<Resource>(domains);
resources.add(domain);
datatypeProperty.setDomain(createUnionClass(resources));
}
}
}
return datatypeProperty;
}