org.camunda.bpm.model.xml.ModelException Java Examples

The following examples show how to use org.camunda.bpm.model.xml.ModelException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnknownAnimalTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddRelationshipDefinitionToUnknownAnimal() {
  RelationshipDefinition friendRelationshipDefinition = modelInstance.newInstance(FriendRelationshipDefinition.class);
  friendRelationshipDefinition.setId("friend-relationship");
  friendRelationshipDefinition.setAttributeValue("animalRef", flipper.getAttributeValue("id"));

  try {
    wanda.addChildElement(friendRelationshipDefinition);
    fail("Cannot add relationship definition to UnknownAnimal cause no child types are defined");
  }
  catch (Exception e) {
    assertThat(e).isInstanceOf(ModelException.class);
  }

  wanda.insertElementAfter(friendRelationshipDefinition, null);

  Animal tweety = modelInstance.getModelElementById("tweety");
  RelationshipDefinition childRelationshipDefinition = modelInstance.newInstance(ChildRelationshipDefinition.class);
  childRelationshipDefinition.setId("child-relationship");
  childRelationshipDefinition.setAnimal(tweety);

  wanda.insertElementAfter(childRelationshipDefinition, friendRelationshipDefinition);
}
 
Example #2
Source File: AttributeReferenceCollection.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: ElementReferenceCollectionImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: AttributeReferenceCollectionBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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
  attributeReferenceCollection.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(attributeReferenceCollection);
    attributeReferenceCollection.setReferenceTargetAttribute(idAttribute);
  } else {
    throw new ModelException("Element type " + referenceTargetType.getTypeNamespace() + ":" + referenceTargetType.getTypeName() + " has no id attribute");
  }
}
 
Example #5
Source File: DomDocumentImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected String getUnusedGenericNsPrefix() {
  synchronized(document) {
    Element documentElement = document.getDocumentElement();
    if (documentElement == null) {
      return GENERIC_NS_PREFIX + "0";
    }
    else {
      for (int i = 0; i < Integer.MAX_VALUE; i++) {
        if (!documentElement.hasAttributeNS(XMLNS_ATTRIBUTE_NS_URI, GENERIC_NS_PREFIX + i)) {
          return GENERIC_NS_PREFIX + i;
        }
      }
      throw new ModelException("Unable to find an unused namespace prefix");
    }
  }
}
 
Example #6
Source File: ElementReferenceCollectionBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example #7
Source File: IdsElementReferenceCollectionImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #8
Source File: AttributeReferenceBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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");
  }
}
 
Example #9
Source File: ReflectUtil.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example #10
Source File: ElementReferenceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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;
  }
}
 
Example #11
Source File: ModelImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public String getAlternativeNamespace(String actualNs) {
  Set<String> alternatives = getAlternativeNamespaces(actualNs);

  if (alternatives == null || alternatives.size() == 0) {
    return null;
  }
  else if (alternatives.size() == 1) {
    return alternatives.iterator().next();
  }
  else
  {
    throw new ModelException("There is more than one alternative namespace registered");
  }
}
 
Example #12
Source File: ChildElementCollectionBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example #13
Source File: ChildElementCollectionBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void setReferenceBuilder(ElementReferenceCollectionBuilder<?, ?> referenceBuilder) {
  if (this.referenceBuilder != null) {
    throw new ModelException("An collection cannot have more than one reference");
  }
  this.referenceBuilder = referenceBuilder;
  modelBuildOperations.add(referenceBuilder);
}
 
Example #14
Source File: ModelElementTypeBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void buildTypeHierarchy(Model model) {

    // build type hierarchy
    if(extendedType != null) {
      ModelElementTypeImpl extendedModelElementType = (ModelElementTypeImpl) model.getType(extendedType);
      if(extendedModelElementType == null) {
        throw new ModelException("Type "+modelType+" is defined to extend "+extendedType+" but no such type is defined.");

      } else {
        modelType.setBaseType(extendedModelElementType);
        extendedModelElementType.registerExtendingType(modelType);
      }
    }
  }
 
Example #15
Source File: ModelElementTypeImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void setBaseType(ModelElementTypeImpl baseType) {
  if (this.baseType == null) {
    this.baseType = baseType;
  }
  else if (!this.baseType.equals(baseType)) {
    throw new ModelException("Type can not have multiple base types. " + this.getClass() + " already extends type " + this.baseType.getClass()
        + " and can not also extend type " + baseType.getClass());
  }
}
 
Example #16
Source File: ParseDecisionTest.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFailIfRequiredDecisionReferenceMissing() {
  try {
    parseDecisionsFromFile(MISSING_REQUIRED_DECISION_REFERENCE_DMN);
    failBecauseExceptionWasNotThrown(DmnTransformException.class);
  }
  catch (DmnTransformException e) {
    assertThat(e)
      .hasCauseExactlyInstanceOf(ModelException.class)
      .hasMessageStartingWith("DMN-02004")
      .hasMessageContaining("Unable to find a model element instance for id null");
  }
}
 
Example #17
Source File: ReflectUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static File getResourceAsFile(String path) {
  URL resource = getResource(path);
  try {
    return new File(resource.toURI());
  } catch (URISyntaxException e) {
    throw new ModelException("Exception while loading resource file " + path, e);
  }
}
 
Example #18
Source File: ModelInstanceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public <T extends ModelElementInstance> T newInstance(Class<T> type, String id) {
  ModelElementType modelElementType = model.getType(type);
  if(modelElementType != null) {
    return newInstance(modelElementType, id);
  } else {
    throw new ModelException("Cannot create instance of ModelType "+type+": no such type registered.");
  }
}
 
Example #19
Source File: DomDocumentImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void registerNamespace(String prefix, String namespaceUri) {
  synchronized(document) {
    DomElement rootElement = getRootElement();
    if (rootElement != null) {
      rootElement.registerNamespace(prefix, namespaceUri);
    }
    else {
      throw new ModelException("Unable to define a new namespace without a root document element");
    }
  }
}
 
Example #20
Source File: DomDocumentImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public String registerNamespace(String namespaceUri) {
  synchronized(document) {
    DomElement rootElement = getRootElement();
    if (rootElement != null) {
      return rootElement.registerNamespace(namespaceUri);
    }
    else {
      throw new ModelException("Unable to define a new namespace without a root document element");
    }
  }
}
 
Example #21
Source File: ModelElementInstanceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void replaceWithElement(ModelElementInstance newElement) {
  ModelElementInstanceImpl parentElement = (ModelElementInstanceImpl) getParentElement();
  if (parentElement != null) {
    parentElement.replaceChildElement(this, newElement);
  }
  else {
    throw new ModelException("Unable to remove replace without parent");
  }
}
 
Example #22
Source File: DomElementImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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);
    }
  }
}
 
Example #23
Source File: ParseDecisionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFailIfWrongRequiredDecisionReference() {
  try {
    parseDecisionsFromFile(WRONG_REQUIRED_DECISION_REFERENCE_DMN);
    failBecauseExceptionWasNotThrown(DmnTransformException.class);
  }
  catch (DmnTransformException e) {
    assertThat(e)
      .hasCauseExactlyInstanceOf(ModelException.class)
      .hasMessageStartingWith("DMN-02004")
      .hasMessageContaining("Unable to find a model element instance for id");
  }
}
 
Example #24
Source File: ParseDecisionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFailIfRequiredDecisionReferenceMissing() {
  try {
    parseDecisionsFromFile(MISSING_REQUIRED_DECISION_REFERENCE_DMN);
    failBecauseExceptionWasNotThrown(DmnTransformException.class);
  }
  catch (DmnTransformException e) {
    assertThat(e)
      .hasCauseExactlyInstanceOf(ModelException.class)
      .hasMessageStartingWith("DMN-02004")
      .hasMessageContaining("Unable to find a model element instance for id null");
  }
}
 
Example #25
Source File: ParseDecisionTest.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFailIfWrongRequiredDecisionReference() {
  try {
    parseDecisionsFromFile(WRONG_REQUIRED_DECISION_REFERENCE_DMN);
    failBecauseExceptionWasNotThrown(DmnTransformException.class);
  }
  catch (DmnTransformException e) {
    assertThat(e)
      .hasCauseExactlyInstanceOf(ModelException.class)
      .hasMessageStartingWith("DMN-02004")
      .hasMessageContaining("Unable to find a model element instance for id");
  }
}
 
Example #26
Source File: StringAttributeBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected <V extends ModelElementInstance> void setAttributeReference(AttributeReferenceBuilder<V> referenceBuilder) {
  if (this.referenceBuilder != null) {
    throw new ModelException("An attribute cannot have more than one reference");
  }
  this.referenceBuilder = referenceBuilder;
}
 
Example #27
Source File: ModelUtil.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public static void ensureInstanceOf(Object instance, Class<?> type) {
  if(!type.isAssignableFrom(instance.getClass())) {
    throw new ModelException("Object is not instance of type "+type.getName());
  }
}