Search in sources :

Example 16 with DomElement

use of org.camunda.bpm.model.xml.instance.DomElement in project camunda-xml-model by camunda.

the class ModelElementInstanceImpl method getUniqueChildElementByNameNs.

public ModelElementInstance getUniqueChildElementByNameNs(String namespaceUri, String elementName) {
    Model model = modelInstance.getModel();
    List<DomElement> childElements = domElement.getChildElementsByNameNs(asSet(namespaceUri, model.getAlternativeNamespace(namespaceUri)), elementName);
    if (!childElements.isEmpty()) {
        return ModelUtil.getModelElement(childElements.get(0), modelInstance);
    } else {
        return null;
    }
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement) Model(org.camunda.bpm.model.xml.Model)

Example 17 with DomElement

use of org.camunda.bpm.model.xml.instance.DomElement in project camunda-xml-model by camunda.

the class ModelElementInstanceImpl method replaceChildElement.

public void replaceChildElement(ModelElementInstance existingChild, ModelElementInstance newChild) {
    DomElement existingChildDomElement = existingChild.getDomElement();
    DomElement newChildDomElement = newChild.getDomElement();
    // unlink (remove all references) of child elements
    ((ModelElementInstanceImpl) existingChild).unlinkAllChildReferences();
    // update incoming references from old to new child element
    updateIncomingReferences(existingChild, newChild);
    // replace the existing child with the new child in the DOM
    domElement.replaceChild(newChildDomElement, existingChildDomElement);
    // execute after replacement updates
    newChild.updateAfterReplacement();
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement)

Example 18 with DomElement

use of org.camunda.bpm.model.xml.instance.DomElement in project camunda-xml-model by camunda.

the class ModelElementTypeImpl method newInstance.

public ModelElementInstance newInstance(ModelInstance modelInstance) {
    ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl) modelInstance;
    DomDocument document = modelInstanceImpl.getDocument();
    DomElement domElement = document.createElement(typeNamespace, typeName);
    return newInstance(modelInstanceImpl, domElement);
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement) ModelInstanceImpl(org.camunda.bpm.model.xml.impl.ModelInstanceImpl) DomDocument(org.camunda.bpm.model.xml.instance.DomDocument)

Example 19 with DomElement

use of org.camunda.bpm.model.xml.instance.DomElement in project camunda-xml-model by camunda.

the class ModelElementTypeImpl method getInstances.

public Collection<ModelElementInstance> getInstances(ModelInstance modelInstance) {
    ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl) modelInstance;
    DomDocument document = modelInstanceImpl.getDocument();
    List<DomElement> elements = getElementsByNameNs(document, typeNamespace);
    List<ModelElementInstance> resultList = new ArrayList<ModelElementInstance>();
    for (DomElement element : elements) {
        resultList.add(ModelUtil.getModelElement(element, modelInstanceImpl, this));
    }
    return resultList;
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList) ModelInstanceImpl(org.camunda.bpm.model.xml.impl.ModelInstanceImpl) DomDocument(org.camunda.bpm.model.xml.instance.DomDocument)

Example 20 with DomElement

use of org.camunda.bpm.model.xml.instance.DomElement in project camunda-xml-model by camunda.

the class ChildElementCollectionImpl method get.

public Collection<T> get(ModelElementInstance element) {
    final ModelElementInstanceImpl modelElement = (ModelElementInstanceImpl) element;
    return new Collection<T>() {

        public boolean contains(Object o) {
            if (o == null) {
                return false;
            } else if (!(o instanceof ModelElementInstanceImpl)) {
                return false;
            } else {
                return getView(modelElement).contains(((ModelElementInstanceImpl) o).getDomElement());
            }
        }

        public boolean containsAll(Collection<?> c) {
            for (Object elementToCheck : c) {
                if (!contains(elementToCheck)) {
                    return false;
                }
            }
            return true;
        }

        public boolean isEmpty() {
            return getView(modelElement).isEmpty();
        }

        public Iterator<T> iterator() {
            Collection<T> modelElementCollection = ModelUtil.getModelElementCollection(getView(modelElement), modelElement.getModelInstance());
            return modelElementCollection.iterator();
        }

        public Object[] toArray() {
            Collection<T> modelElementCollection = ModelUtil.getModelElementCollection(getView(modelElement), modelElement.getModelInstance());
            return modelElementCollection.toArray();
        }

        public <U> U[] toArray(U[] a) {
            Collection<T> modelElementCollection = ModelUtil.getModelElementCollection(getView(modelElement), modelElement.getModelInstance());
            return modelElementCollection.toArray(a);
        }

        public int size() {
            return getView(modelElement).size();
        }

        public boolean add(T e) {
            if (!isMutable) {
                throw new UnsupportedModelOperationException("add()", "collection is immutable");
            }
            performAddOperation(modelElement, e);
            return true;
        }

        public boolean addAll(Collection<? extends T> c) {
            if (!isMutable) {
                throw new UnsupportedModelOperationException("addAll()", "collection is immutable");
            }
            boolean result = false;
            for (T t : c) {
                result |= add(t);
            }
            return result;
        }

        public void clear() {
            if (!isMutable) {
                throw new UnsupportedModelOperationException("clear()", "collection is immutable");
            }
            Collection<DomElement> view = getView(modelElement);
            performClearOperation(modelElement, view);
        }

        public boolean remove(Object e) {
            if (!isMutable) {
                throw new UnsupportedModelOperationException("remove()", "collection is immutable");
            }
            ModelUtil.ensureInstanceOf(e, ModelElementInstanceImpl.class);
            return performRemoveOperation(modelElement, e);
        }

        public boolean removeAll(Collection<?> c) {
            if (!isMutable) {
                throw new UnsupportedModelOperationException("removeAll()", "collection is immutable");
            }
            boolean result = false;
            for (Object t : c) {
                result |= remove(t);
            }
            return result;
        }

        public boolean retainAll(Collection<?> c) {
            throw new UnsupportedModelOperationException("retainAll()", "not implemented");
        }
    };
}
Also used : ModelElementInstanceImpl(org.camunda.bpm.model.xml.impl.instance.ModelElementInstanceImpl) DomElement(org.camunda.bpm.model.xml.instance.DomElement) ChildElementCollection(org.camunda.bpm.model.xml.type.child.ChildElementCollection) Collection(java.util.Collection) UnsupportedModelOperationException(org.camunda.bpm.model.xml.UnsupportedModelOperationException)

Aggregations

DomElement (org.camunda.bpm.model.xml.instance.DomElement)20 ArrayList (java.util.ArrayList)5 DomDocument (org.camunda.bpm.model.xml.instance.DomDocument)5 ModelException (org.camunda.bpm.model.xml.ModelException)4 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)4 Collection (java.util.Collection)2 Model (org.camunda.bpm.model.xml.Model)2 UnsupportedModelOperationException (org.camunda.bpm.model.xml.UnsupportedModelOperationException)2 ModelInstanceImpl (org.camunda.bpm.model.xml.impl.ModelInstanceImpl)2 ModelElementType (org.camunda.bpm.model.xml.type.ModelElementType)2 Element (org.w3c.dom.Element)2 Iterator (java.util.Iterator)1 CAMUNDA_ELEMENT_LIST (org.camunda.bpm.model.bpmn.impl.BpmnModelConstants.CAMUNDA_ELEMENT_LIST)1 ModelElementInstanceImpl (org.camunda.bpm.model.xml.impl.instance.ModelElementInstanceImpl)1 XmlQName (org.camunda.bpm.model.xml.impl.util.XmlQName)1 ChildElementCollection (org.camunda.bpm.model.xml.type.child.ChildElementCollection)1