Search in sources :

Example 6 with ModelException

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

the class ElementReferenceCollectionBuilderImpl method performModelBuild.

@SuppressWarnings("unchecked")
public void performModelBuild(Model model) {
    ModelElementTypeImpl referenceTargetType = (ModelElementTypeImpl) model.getType(referenceTargetClass);
    ModelElementTypeImpl referenceSourceType = (ModelElementTypeImpl) model.getType(childElementType);
    elementReferenceCollectionImpl.setReferenceTargetElementType(referenceTargetType);
    elementReferenceCollectionImpl.setReferenceSourceElementType(referenceSourceType);
    // the referenced attribute may be declared on a base type of the referenced type.
    AttributeImpl<String> idAttribute = (AttributeImpl<String>) referenceTargetType.getAttribute("id");
    if (idAttribute != null) {
        idAttribute.registerIncoming(elementReferenceCollectionImpl);
        elementReferenceCollectionImpl.setReferenceTargetAttribute(idAttribute);
    } else {
        throw new ModelException("Unable to find id attribute of " + referenceTargetClass);
    }
}
Also used : ModelException(org.camunda.bpm.model.xml.ModelException) AttributeImpl(org.camunda.bpm.model.xml.impl.type.attribute.AttributeImpl) ModelElementTypeImpl(org.camunda.bpm.model.xml.impl.type.ModelElementTypeImpl)

Example 7 with ModelException

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

the class ElementReferenceImpl method getReferenceTargetElement.

@SuppressWarnings("unchecked")
public Target getReferenceTargetElement(ModelElementInstanceImpl referenceSourceParentElement) {
    Source referenceSource = getReferenceSource(referenceSourceParentElement);
    if (referenceSource != null) {
        String identifier = getReferenceIdentifier(referenceSource);
        ModelElementInstance referenceTargetElement = referenceSourceParentElement.getModelInstance().getModelElementById(identifier);
        if (referenceTargetElement != null) {
            return (Target) referenceTargetElement;
        } else {
            throw new ModelException("Unable to find a model element instance for id " + identifier);
        }
    } else {
        return null;
    }
}
Also used : ModelException(org.camunda.bpm.model.xml.ModelException) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 8 with ModelException

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

the class ModelUtil method getIndexOfElementType.

/**
 * Find the index of the type of a model element in a list of element types
 *
 * @param modelElement the model element which type is searched for
 * @param childElementTypes the list to search the type
 * @return the index of the model element type in the list or -1 if it is not found
 */
public static int getIndexOfElementType(ModelElementInstance modelElement, List<ModelElementType> childElementTypes) {
    for (int index = 0; index < childElementTypes.size(); index++) {
        ModelElementType childElementType = childElementTypes.get(index);
        Class<? extends ModelElementInstance> instanceType = childElementType.getInstanceType();
        if (instanceType.isAssignableFrom(modelElement.getClass())) {
            return index;
        }
    }
    Collection<String> childElementTypeNames = new ArrayList<String>();
    for (ModelElementType childElementType : childElementTypes) {
        childElementTypeNames.add(childElementType.getTypeName());
    }
    throw new ModelException("New child is not a valid child element type: " + modelElement.getElementType().getTypeName() + "; valid types are: " + childElementTypeNames);
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) ModelException(org.camunda.bpm.model.xml.ModelException)

Example 9 with ModelException

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

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

the class AttributeReferenceBuilderImpl method performModelBuild.

@SuppressWarnings("unchecked")
public void performModelBuild(Model model) {
    // register declaring type as a referencing type of referenced type
    ModelElementTypeImpl referenceTargetType = (ModelElementTypeImpl) model.getType(referenceTargetElement);
    // the actual referenced type
    attributeReferenceImpl.setReferenceTargetElementType(referenceTargetType);
    // the referenced attribute may be declared on a base type of the referenced type.
    AttributeImpl<String> idAttribute = (AttributeImpl<String>) referenceTargetType.getAttribute("id");
    if (idAttribute != null) {
        idAttribute.registerIncoming(attributeReferenceImpl);
        attributeReferenceImpl.setReferenceTargetAttribute(idAttribute);
    } else {
        throw new ModelException("Element type " + referenceTargetType.getTypeNamespace() + ":" + referenceTargetType.getTypeName() + " has no id attribute");
    }
}
Also used : ModelException(org.camunda.bpm.model.xml.ModelException) AttributeImpl(org.camunda.bpm.model.xml.impl.type.attribute.AttributeImpl) ModelElementTypeImpl(org.camunda.bpm.model.xml.impl.type.ModelElementTypeImpl)

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