*/
public ObjectProperty createObjectPropertyByPropertyDefinition(PropertyDefinition propertyDefinition,
List<Resource> domains,
List<Resource> ranges) {
log.debug("Creating Object property for property {}", propertyDefinition);
ObjectProperty objectProperty = null;
try {
objectProperty = getObjectPropertyByReference(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 (objectProperty == null) {
String propertyURI = namingStrategy.getObjectPropertyName(ontologyURI, propertyDefinition);
objectProperty = ontModel.createObjectProperty(propertyURI);
objectProperty.addProperty(CMSAdapterVocabulary.CMSAD_RESOURCE_REF_PROP,
propertyDefinition.getUniqueRef());
if (propertyDefinition.getSourceObjectTypeRef() != null) {
objectProperty.addProperty(CMSAdapterVocabulary.CMSAD_PROPERTY_SOURCE_OBJECT_PROP,
propertyDefinition.getSourceObjectTypeRef());
} else {
log.warn("Source object type reference not found on property definition {}",
propertyDefinition.getLocalname());
}
for (Resource domain : domains) {
objectProperty.addDomain(domain);
}
for (Resource range : ranges) {
objectProperty.addRange(range);
}
log.debug("ObjectProperty {} not found, creating new one...", propertyURI);
} else {
// Add domains to union class
OntResource domain = objectProperty.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);
objectProperty.setDomain(createUnionClass(resources));
}
}
// Add ranges to union class
OntResource range = objectProperty.getRange();
if (range != null) {
if (range.isClass() && range.asClass().isUnionClass()) {
UnionClass unclass = range.asClass().asUnionClass();
for (Resource newRange : ranges) {
unclass.addOperand(newRange);
}
} else {
List<Resource> resources = new ArrayList<Resource>(ranges);
resources.add(range);
objectProperty.setDomain(createUnionClass(resources));
}
}
}
return objectProperty;
}