use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.
the class ReferenceImpl method setReferenceTargetElement.
/**
* Set the reference target model element instance
*
* @param referenceSourceElement the reference source model element instance
* @param referenceTargetElement the reference target model element instance
* @throws ModelReferenceException if element is not already added to the model
*/
public void setReferenceTargetElement(ModelElementInstance referenceSourceElement, T referenceTargetElement) {
ModelInstance modelInstance = referenceSourceElement.getModelInstance();
String referenceTargetIdentifier = referenceTargetAttribute.getValue(referenceTargetElement);
ModelElementInstance existingElement = modelInstance.getModelElementById(referenceTargetIdentifier);
if (existingElement == null || !existingElement.equals(referenceTargetElement)) {
throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement + ": element is not part of model. Please connect element to the model first.");
} else {
setReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier);
}
}
use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.
the class ModelInstanceValidator method validate.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ValidationResults validate() {
ValidationResultsCollectorImpl resultsCollector = new ValidationResultsCollectorImpl();
for (ModelElementValidator validator : validators) {
Class<? extends ModelElementInstance> elementType = validator.getElementType();
Collection<? extends ModelElementInstance> modelElementsByType = modelInstanceImpl.getModelElementsByType(elementType);
for (ModelElementInstance element : modelElementsByType) {
resultsCollector.setCurrentElement(element);
try {
validator.validate(element, resultsCollector);
} catch (RuntimeException e) {
throw new RuntimeException("Validator " + validator + " threw an exception while validating " + element, e);
}
}
}
return resultsCollector.getResults();
}
use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.
the class ModelValidationResultsImpl method write.
@Override
public void write(StringWriter writer, ValidationResultFormatter formatter) {
for (Entry<ModelElementInstance, List<ValidationResult>> entry : collectedResults.entrySet()) {
ModelElementInstance element = entry.getKey();
List<ValidationResult> results = entry.getValue();
formatter.formatElement(writer, element);
for (ValidationResult result : results) {
formatter.formatResult(writer, result);
}
}
}
use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.
the class AbstractModelElementInstanceTest method testType.
@Test
public void testType() {
assertThatType().isPartOfModel(model);
TypeAssumption assumption = getTypeAssumption();
assertThatType().hasTypeNamespace(assumption.namespaceUri);
if (assumption.isAbstract) {
assertThatType().isAbstract();
} else {
assertThatType().isNotAbstract();
}
if (assumption.extendsType == null) {
assertThatType().extendsNoType();
} else {
assertThatType().extendsType(assumption.extendsType);
}
if (assumption.isAbstract) {
try {
modelInstance.newInstance(modelElementType);
fail("Element type " + modelElementType.getTypeName() + " is abstract.");
} catch (DOMException e) {
// expected exception
} catch (ModelTypeException e) {
// expected exception
} catch (Exception e) {
fail("Unexpected exception " + e.getMessage());
}
} else {
ModelElementInstance modelElementInstance = modelInstance.newInstance(modelElementType);
assertThat(modelElementInstance).isNotNull();
}
}
use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.
the class AbstractReferenceAssert method hasNoTargetElement.
public S hasNoTargetElement(ModelElementInstance instance) {
isNotNull();
ModelElementInstance actualTargetElement = actual.getReferenceTargetElement(instance);
if (actualTargetElement != null) {
failWithMessage("Expected reference <%s> to have no target element but has <%s>", actualTargetElement, actualTargetElement);
}
return myself;
}
Aggregations