use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.
the class ModelElementInstanceImpl method addChildElement.
public void addChildElement(ModelElementInstance newChild) {
ModelUtil.ensureInstanceOf(newChild, ModelElementInstanceImpl.class);
ModelElementInstance elementToInsertAfter = findElementToInsertAfter(newChild);
insertElementAfter(newChild, elementToInsertAfter);
}
use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.
the class ModelElementInstanceImpl method getChildElementsByType.
public Collection<ModelElementInstance> getChildElementsByType(ModelElementType childElementType) {
List<ModelElementInstance> instances = new ArrayList<ModelElementInstance>();
for (ModelElementType extendingType : childElementType.getExtendingTypes()) {
instances.addAll(getChildElementsByType(extendingType));
}
Model model = modelInstance.getModel();
String alternativeNamespace = model.getAlternativeNamespace(childElementType.getTypeNamespace());
List<DomElement> elements = domElement.getChildElementsByNameNs(asSet(childElementType.getTypeNamespace(), alternativeNamespace), childElementType.getTypeName());
instances.addAll(ModelUtil.getModelElementCollection(elements, modelInstance));
return instances;
}
use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-bpmn-model by camunda.
the class CallableElementImpl method registerType.
public static void registerType(ModelBuilder bpmnModelBuilder) {
ModelElementTypeBuilder typeBuilder = bpmnModelBuilder.defineType(CallableElement.class, BPMN_ELEMENT_CALLABLE_ELEMENT).namespaceUri(BPMN20_NS).extendsType(RootElement.class).instanceProvider(new ModelTypeInstanceProvider<ModelElementInstance>() {
public ModelElementInstance newInstance(ModelTypeInstanceContext instanceContext) {
return new CallableElementImpl(instanceContext);
}
});
nameAttribute = typeBuilder.stringAttribute(BPMN_ATTRIBUTE_NAME).build();
SequenceBuilder sequenceBuilder = typeBuilder.sequence();
supportedInterfaceRefCollection = sequenceBuilder.elementCollection(SupportedInterfaceRef.class).qNameElementReferenceCollection(Interface.class).build();
ioSpecificationChild = sequenceBuilder.element(IoSpecification.class).build();
ioBindingCollection = sequenceBuilder.elementCollection(IoBinding.class).build();
typeBuilder.build();
}
use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-bpmn-model by camunda.
the class AbstractBaseElementBuilder method resizeSubProcess.
protected void resizeSubProcess(BpmnShape innerShape) {
BaseElement innerElement = innerShape.getBpmnElement();
Bounds innerShapeBounds = innerShape.getBounds();
ModelElementInstance parent = innerElement.getParentElement();
while (parent instanceof SubProcess) {
BpmnShape subProcessShape = findBpmnShape((SubProcess) parent);
if (subProcessShape != null) {
Bounds subProcessBounds = subProcessShape.getBounds();
double innerX = innerShapeBounds.getX();
double innerWidth = innerShapeBounds.getWidth();
double innerY = innerShapeBounds.getY();
double innerHeight = innerShapeBounds.getHeight();
double subProcessY = subProcessBounds.getY();
double subProcessHeight = subProcessBounds.getHeight();
double subProcessX = subProcessBounds.getX();
double subProcessWidth = subProcessBounds.getWidth();
double tmpWidth = innerX + innerWidth + SPACE;
double tmpHeight = innerY + innerHeight + SPACE;
if (innerY == subProcessY) {
subProcessBounds.setY(subProcessY - SPACE);
subProcessBounds.setHeight(subProcessHeight + SPACE);
}
if (tmpWidth >= subProcessX + subProcessWidth) {
double newWidth = tmpWidth - subProcessX;
subProcessBounds.setWidth(newWidth);
}
if (tmpHeight >= subProcessY + subProcessHeight) {
double newHeight = tmpHeight - subProcessY;
subProcessBounds.setHeight(newHeight);
}
innerElement = (SubProcess) parent;
innerShapeBounds = subProcessBounds;
parent = innerElement.getParentElement();
} else {
break;
}
}
}
use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-bpmn-model by camunda.
the class ValidateProcessTest method validationFailsIfNoStartEventFound.
@Test
public void validationFailsIfNoStartEventFound() {
List<ModelElementValidator<?>> validators = new ArrayList<ModelElementValidator<?>>();
validators.add(new ProcessStartEventValidator());
BpmnModelInstance bpmnModelInstance = Bpmn.createProcess().done();
ValidationResults validationResults = bpmnModelInstance.validate(validators);
assertThat(validationResults.hasErrors()).isTrue();
Map<ModelElementInstance, List<ValidationResult>> results = validationResults.getResults();
assertThat(results.size()).isEqualTo(1);
Process process = bpmnModelInstance.getDefinitions().getChildElementsByType(Process.class).iterator().next();
assertThat(results.containsKey(process)).isTrue();
List<ValidationResult> resultsForProcess = results.get(process);
assertThat(resultsForProcess.size()).isEqualTo(1);
ValidationResult validationResult = resultsForProcess.get(0);
assertThat(validationResult.getElement()).isEqualTo(process);
assertThat(validationResult.getCode()).isEqualTo(10);
assertThat(validationResult.getMessage()).isEqualTo("Process does not have exactly one start event. Got 0.");
assertThat(validationResult.getType()).isEqualTo(ValidationResultType.ERROR);
}
Aggregations