Search in sources :

Example 1 with ModelException

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

the class ElementReferenceCollectionImpl method getView.

protected Collection<DomElement> getView(ModelElementInstanceImpl referenceSourceParentElement) {
    DomDocument document = referenceSourceParentElement.getModelInstance().getDocument();
    Collection<Source> referenceSourceElements = referenceSourceCollection.get(referenceSourceParentElement);
    Collection<DomElement> referenceTargetElements = new ArrayList<DomElement>();
    for (Source referenceSourceElement : referenceSourceElements) {
        String identifier = getReferenceIdentifier(referenceSourceElement);
        DomElement referenceTargetElement = document.getElementById(identifier);
        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 2 with ModelException

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

the class IdsElementReferenceCollectionImpl method getView.

@Override
protected Collection<DomElement> getView(ModelElementInstanceImpl referenceSourceParentElement) {
    DomDocument document = referenceSourceParentElement.getModelInstance().getDocument();
    Collection<Source> referenceSourceElements = getReferenceSourceCollection().get(referenceSourceParentElement);
    Collection<DomElement> referenceTargetElements = new ArrayList<DomElement>();
    for (Source referenceSourceElement : referenceSourceElements) {
        List<String> identifiers = getReferenceIdentifiers(referenceSourceElement);
        for (String identifier : identifiers) {
            DomElement referenceTargetElement = document.getElementById(identifier);
            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 3 with ModelException

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

the class ReflectUtil method createInstance.

/**
 * Create a new instance of the provided type
 *
 * @param type the class to create a new instance of
 * @param parameters the parameters to pass to the constructor
 * @return the created instance
 */
public static <T> T createInstance(Class<T> type, Object... parameters) {
    // get types for parameters
    Class<?>[] parameterTypes = new Class<?>[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        Object parameter = parameters[i];
        parameterTypes[i] = parameter.getClass();
    }
    try {
        // create instance
        Constructor<T> constructor = type.getConstructor(parameterTypes);
        return constructor.newInstance(parameters);
    } catch (Exception e) {
        throw new ModelException("Exception while creating an instance of type " + type, e);
    }
}
Also used : ModelException(org.camunda.bpm.model.xml.ModelException) URISyntaxException(java.net.URISyntaxException) ModelException(org.camunda.bpm.model.xml.ModelException)

Example 4 with ModelException

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

the class DomElementImpl method replaceChild.

public void replaceChild(DomElement newChildDomElement, DomElement existingChildDomElement) {
    synchronized (document) {
        Element newElement = ((DomElementImpl) newChildDomElement).getElement();
        Element existingElement = ((DomElementImpl) existingChildDomElement).getElement();
        try {
            element.replaceChild(newElement, existingElement);
        } catch (DOMException e) {
            throw new ModelException("Unable to replace child <" + existingElement + "> of element <" + element + "> with element <" + newElement + ">", e);
        }
    }
}
Also used : ModelException(org.camunda.bpm.model.xml.ModelException) DomElement(org.camunda.bpm.model.xml.instance.DomElement)

Example 5 with ModelException

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

the class ChildElementCollectionBuilderImpl method performModelBuild.

public void performModelBuild(Model model) {
    ModelElementType elementType = model.getType(childElementType);
    if (elementType == null) {
        throw new ModelException(parentElementType + " declares undefined child element of type " + childElementType + ".");
    }
    parentElementType.registerChildElementType(elementType);
    parentElementType.registerChildElementCollection(collection);
    for (ModelBuildOperation modelBuildOperation : modelBuildOperations) {
        modelBuildOperation.performModelBuild(model);
    }
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) ModelException(org.camunda.bpm.model.xml.ModelException) ModelBuildOperation(org.camunda.bpm.model.xml.impl.ModelBuildOperation)

Aggregations

ModelException (org.camunda.bpm.model.xml.ModelException)11 DomElement (org.camunda.bpm.model.xml.instance.DomElement)4 ArrayList (java.util.ArrayList)3 ModelElementTypeImpl (org.camunda.bpm.model.xml.impl.type.ModelElementTypeImpl)3 AttributeImpl (org.camunda.bpm.model.xml.impl.type.attribute.AttributeImpl)3 DomDocument (org.camunda.bpm.model.xml.instance.DomDocument)3 ModelElementType (org.camunda.bpm.model.xml.type.ModelElementType)2 URISyntaxException (java.net.URISyntaxException)1 ModelBuildOperation (org.camunda.bpm.model.xml.impl.ModelBuildOperation)1 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)1