Search in sources :

Example 11 with DomElement

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

the class CamundaListImpl method getValues.

@SuppressWarnings("unchecked")
public <T extends BpmnModelElementInstance> Collection<T> getValues() {
    return new Collection<T>() {

        protected Collection<T> getElements() {
            return ModelUtil.getModelElementCollection(getDomElement().getChildElements(), getModelInstance());
        }

        public int size() {
            return getElements().size();
        }

        public boolean isEmpty() {
            return getElements().isEmpty();
        }

        public boolean contains(Object o) {
            return getElements().contains(o);
        }

        public Iterator<T> iterator() {
            return (Iterator<T>) getElements().iterator();
        }

        public Object[] toArray() {
            return getElements().toArray();
        }

        public <T1> T1[] toArray(T1[] a) {
            return getElements().toArray(a);
        }

        public boolean add(T t) {
            getDomElement().appendChild(t.getDomElement());
            return true;
        }

        public boolean remove(Object o) {
            ModelUtil.ensureInstanceOf(o, BpmnModelElementInstance.class);
            return getDomElement().removeChild(((BpmnModelElementInstance) o).getDomElement());
        }

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

        public boolean addAll(Collection<? extends T> c) {
            for (T element : c) {
                add(element);
            }
            return true;
        }

        public boolean removeAll(Collection<?> c) {
            boolean result = false;
            for (Object o : c) {
                result |= remove(o);
            }
            return result;
        }

        public boolean retainAll(Collection<?> c) {
            throw new UnsupportedModelOperationException("retainAll()", "not implemented");
        }

        public void clear() {
            DomElement domElement = getDomElement();
            List<DomElement> childElements = domElement.getChildElements();
            for (DomElement childElement : childElements) {
                domElement.removeChild(childElement);
            }
        }
    };
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement) CAMUNDA_ELEMENT_LIST(org.camunda.bpm.model.bpmn.impl.BpmnModelConstants.CAMUNDA_ELEMENT_LIST) Iterator(java.util.Iterator) Collection(java.util.Collection) UnsupportedModelOperationException(org.camunda.bpm.model.xml.UnsupportedModelOperationException)

Example 12 with DomElement

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

the class CamundaGenericValueElementImpl method removeValue.

public void removeValue() {
    DomElement domElement = getDomElement();
    List<DomElement> childElements = domElement.getChildElements();
    for (DomElement childElement : childElements) {
        domElement.removeChild(childElement);
    }
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement)

Example 13 with DomElement

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

the class AttributeReferenceCollection method getView.

private Collection<DomElement> getView(ModelElementInstance referenceSourceElement) {
    DomDocument document = referenceSourceElement.getModelInstance().getDocument();
    String identifier = getReferenceIdentifier(referenceSourceElement);
    List<String> references = StringUtil.splitListBySeparator(identifier, separator);
    Collection<DomElement> referenceTargetElements = new ArrayList<DomElement>();
    for (String reference : references) {
        DomElement referenceTargetElement = document.getElementById(reference);
        if (referenceTargetElement != null) {
            referenceTargetElements.add(referenceTargetElement);
        } else {
            throw new ModelException("Unable to find a model element instance for id " + identifier);
        }
    }
    return referenceTargetElements;
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement) ModelException(org.camunda.bpm.model.xml.ModelException) ArrayList(java.util.ArrayList) DomDocument(org.camunda.bpm.model.xml.instance.DomDocument)

Example 14 with DomElement

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

the class DomDocumentImpl method setRootElement.

public void setRootElement(DomElement rootElement) {
    synchronized (document) {
        Element documentElement = document.getDocumentElement();
        Element newDocumentElement = ((DomElementImpl) rootElement).getElement();
        if (documentElement != null) {
            document.replaceChild(newDocumentElement, documentElement);
        } else {
            document.appendChild(newDocumentElement);
        }
    }
}
Also used : Element(org.w3c.dom.Element) DomElement(org.camunda.bpm.model.xml.instance.DomElement)

Example 15 with DomElement

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

the class DomDocumentImpl method createElement.

public DomElement createElement(String namespaceUri, String localName) {
    synchronized (document) {
        XmlQName xmlQName = new XmlQName(this, namespaceUri, localName);
        Element element = document.createElementNS(xmlQName.getNamespaceUri(), xmlQName.getPrefixedName());
        return new DomElementImpl(element);
    }
}
Also used : XmlQName(org.camunda.bpm.model.xml.impl.util.XmlQName) Element(org.w3c.dom.Element) DomElement(org.camunda.bpm.model.xml.instance.DomElement)

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