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);
}
}
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;
}
}
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);
}
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;
}
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");
}
}
Aggregations