Search in sources :

Example 16 with ModelElementInstance

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);
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 17 with ModelElementInstance

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;
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) DomElement(org.camunda.bpm.model.xml.instance.DomElement) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList) Model(org.camunda.bpm.model.xml.Model)

Example 18 with ModelElementInstance

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();
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) SequenceBuilder(org.camunda.bpm.model.xml.type.child.SequenceBuilder) ModelElementTypeBuilder(org.camunda.bpm.model.xml.type.ModelElementTypeBuilder) ModelTypeInstanceContext(org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)

Example 19 with ModelElementInstance

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;
        }
    }
}
Also used : BpmnShape(org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) Bounds(org.camunda.bpm.model.bpmn.instance.dc.Bounds)

Example 20 with ModelElementInstance

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);
}
Also used : ModelElementValidator(org.camunda.bpm.model.xml.validation.ModelElementValidator) ValidationResults(org.camunda.bpm.model.xml.validation.ValidationResults) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Process(org.camunda.bpm.model.bpmn.instance.Process) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) ValidationResult(org.camunda.bpm.model.xml.validation.ValidationResult) Test(org.junit.Test)

Aggregations

ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)55 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)8 ModelElementType (org.camunda.bpm.model.xml.type.ModelElementType)8 Process (org.camunda.bpm.model.bpmn.instance.Process)5 ModelInstanceImpl (org.camunda.bpm.model.xml.impl.ModelInstanceImpl)5 ModelReferenceException (org.camunda.bpm.model.xml.ModelReferenceException)4 DomElement (org.camunda.bpm.model.xml.instance.DomElement)4 List (java.util.List)3 Model (org.camunda.bpm.model.xml.Model)3 Deployment (org.camunda.bpm.engine.test.Deployment)2 Event (org.camunda.bpm.model.bpmn.instance.Event)2 SequenceFlow (org.camunda.bpm.model.bpmn.instance.SequenceFlow)2 BpmnShape (org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape)2 Case (org.camunda.bpm.model.cmmn.instance.Case)2 PlanItem (org.camunda.bpm.model.cmmn.instance.PlanItem)2 TestModelTest (org.camunda.bpm.model.xml.testmodel.TestModelTest)2 ModelElementValidator (org.camunda.bpm.model.xml.validation.ModelElementValidator)2 ValidationResult (org.camunda.bpm.model.xml.validation.ValidationResult)2