Search in sources :

Example 1 with UnsupportedModelOperationException

use of org.camunda.bpm.model.xml.UnsupportedModelOperationException 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 2 with UnsupportedModelOperationException

use of org.camunda.bpm.model.xml.UnsupportedModelOperationException 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

Collection (java.util.Collection)2 UnsupportedModelOperationException (org.camunda.bpm.model.xml.UnsupportedModelOperationException)2 DomElement (org.camunda.bpm.model.xml.instance.DomElement)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 ChildElementCollection (org.camunda.bpm.model.xml.type.child.ChildElementCollection)1