Search in sources :

Example 1 with ModelInstance

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

the class ReferenceImpl method setReferenceTargetElement.

/**
 * Set the reference target model element instance
 *
 * @param referenceSourceElement the reference source model element instance
 * @param referenceTargetElement the reference target model element instance
 * @throws ModelReferenceException if element is not already added to the model
 */
public void setReferenceTargetElement(ModelElementInstance referenceSourceElement, T referenceTargetElement) {
    ModelInstance modelInstance = referenceSourceElement.getModelInstance();
    String referenceTargetIdentifier = referenceTargetAttribute.getValue(referenceTargetElement);
    ModelElementInstance existingElement = modelInstance.getModelElementById(referenceTargetIdentifier);
    if (existingElement == null || !existingElement.equals(referenceTargetElement)) {
        throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement + ": element is not part of model. Please connect element to the model first.");
    } else {
        setReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier);
    }
}
Also used : ModelInstance(org.camunda.bpm.model.xml.ModelInstance) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ModelReferenceException(org.camunda.bpm.model.xml.ModelReferenceException)

Example 2 with ModelInstance

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

the class AnimalTest method createModel.

public static Object[] createModel() {
    TestModelParser modelParser = new TestModelParser();
    ModelInstance modelInstance = modelParser.getEmptyModel();
    Animals animals = modelInstance.newInstance(Animals.class);
    modelInstance.setDocumentElement(animals);
    // add a tns namespace prefix for QName testing
    animals.getDomElement().registerNamespace("tns", MODEL_NAMESPACE);
    Animal tweety = createBird(modelInstance, "tweety", Gender.Female);
    Animal hedwig = createBird(modelInstance, "hedwig", Gender.Male);
    Animal birdo = createBird(modelInstance, "birdo", Gender.Female);
    Animal plucky = createBird(modelInstance, "plucky", Gender.Unknown);
    Animal fiffy = createBird(modelInstance, "fiffy", Gender.Female);
    createBird(modelInstance, "timmy", Gender.Male);
    createBird(modelInstance, "daisy", Gender.Female);
    // create and add some relationships
    RelationshipDefinition hedwigRelationship = createRelationshipDefinition(modelInstance, hedwig, ChildRelationshipDefinition.class);
    addRelationshipDefinition(tweety, hedwigRelationship);
    RelationshipDefinition birdoRelationship = createRelationshipDefinition(modelInstance, birdo, ChildRelationshipDefinition.class);
    addRelationshipDefinition(tweety, birdoRelationship);
    RelationshipDefinition pluckyRelationship = createRelationshipDefinition(modelInstance, plucky, FriendRelationshipDefinition.class);
    addRelationshipDefinition(tweety, pluckyRelationship);
    RelationshipDefinition fiffyRelationship = createRelationshipDefinition(modelInstance, fiffy, FriendRelationshipDefinition.class);
    addRelationshipDefinition(tweety, fiffyRelationship);
    tweety.getRelationshipDefinitionRefs().add(hedwigRelationship);
    tweety.getRelationshipDefinitionRefs().add(birdoRelationship);
    tweety.getRelationshipDefinitionRefs().add(pluckyRelationship);
    tweety.getRelationshipDefinitionRefs().add(fiffyRelationship);
    tweety.getBestFriends().add(birdo);
    tweety.getBestFriends().add(plucky);
    return new Object[] { "created", modelInstance, modelParser };
}
Also used : ModelInstance(org.camunda.bpm.model.xml.ModelInstance) TestModelParser(org.camunda.bpm.model.xml.testmodel.TestModelParser)

Example 3 with ModelInstance

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

the class BirdTest method createModel.

public static Object[] createModel() {
    TestModelParser modelParser = new TestModelParser();
    ModelInstance modelInstance = modelParser.getEmptyModel();
    Animals animals = modelInstance.newInstance(Animals.class);
    modelInstance.setDocumentElement(animals);
    // add a tns namespace prefix for QName testing
    animals.getDomElement().registerNamespace("tns", MODEL_NAMESPACE);
    Bird tweety = createBird(modelInstance, "tweety", Gender.Female);
    Bird hedwig = createBird(modelInstance, "hedwig", Gender.Female);
    Bird timmy = createBird(modelInstance, "timmy", Gender.Female);
    Egg egg1 = createEgg(modelInstance, "egg1");
    egg1.setMother(tweety);
    Collection<Animal> guards = egg1.getGuardians();
    guards.add(hedwig);
    guards.add(timmy);
    Egg egg2 = createEgg(modelInstance, "egg2");
    egg2.setMother(tweety);
    guards = egg2.getGuardians();
    guards.add(hedwig);
    guards.add(timmy);
    Egg egg3 = createEgg(modelInstance, "egg3");
    guards = egg3.getGuardians();
    guards.add(timmy);
    tweety.setSpouse(hedwig);
    tweety.getEggs().add(egg1);
    tweety.getEggs().add(egg2);
    tweety.getEggs().add(egg3);
    Collection<Egg> guardedEggs = hedwig.getGuardedEggs();
    guardedEggs.add(egg1);
    guardedEggs.add(egg2);
    GuardEgg guardEgg = modelInstance.newInstance(GuardEgg.class);
    guardEgg.setTextContent(egg1.getId() + " " + egg2.getId());
    timmy.getGuardedEggRefs().add(guardEgg);
    timmy.getGuardedEggs().add(egg3);
    return new Object[] { "created", modelInstance, modelParser };
}
Also used : ModelInstance(org.camunda.bpm.model.xml.ModelInstance) TestModelParser(org.camunda.bpm.model.xml.testmodel.TestModelParser)

Example 4 with ModelInstance

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

the class FlyingAnimalTest method createModel.

public static Object[] createModel() {
    TestModelParser modelParser = new TestModelParser();
    ModelInstance modelInstance = modelParser.getEmptyModel();
    Animals animals = modelInstance.newInstance(Animals.class);
    modelInstance.setDocumentElement(animals);
    // add a tns namespace prefix for QName testing
    animals.getDomElement().registerNamespace("tns", MODEL_NAMESPACE);
    FlyingAnimal tweety = createBird(modelInstance, "tweety", Gender.Female);
    FlyingAnimal hedwig = createBird(modelInstance, "hedwig", Gender.Male);
    FlyingAnimal birdo = createBird(modelInstance, "birdo", Gender.Female);
    FlyingAnimal plucky = createBird(modelInstance, "plucky", Gender.Unknown);
    FlyingAnimal fiffy = createBird(modelInstance, "fiffy", Gender.Female);
    createBird(modelInstance, "timmy", Gender.Male);
    createBird(modelInstance, "daisy", Gender.Female);
    tweety.setFlightInstructor(hedwig);
    tweety.getFlightPartnerRefs().add(hedwig);
    tweety.getFlightPartnerRefs().add(birdo);
    tweety.getFlightPartnerRefs().add(plucky);
    tweety.getFlightPartnerRefs().add(fiffy);
    return new Object[] { "created", modelInstance, modelParser };
}
Also used : ModelInstance(org.camunda.bpm.model.xml.ModelInstance) TestModelParser(org.camunda.bpm.model.xml.testmodel.TestModelParser)

Example 5 with ModelInstance

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

the class ChildElementCollectionTest method createModel.

public static Object[] createModel() {
    TestModelParser modelParser = new TestModelParser();
    ModelInstance modelInstance = modelParser.getEmptyModel();
    Animals animals = modelInstance.newInstance(Animals.class);
    modelInstance.setDocumentElement(animals);
    Bird tweety = createBird(modelInstance, "tweety", Gender.Female);
    Bird daffy = createBird(modelInstance, "daffy", Gender.Male);
    Bird daisy = createBird(modelInstance, "daisy", Gender.Female);
    Bird plucky = createBird(modelInstance, "plucky", Gender.Male);
    createBird(modelInstance, "birdo", Gender.Female);
    tweety.setFlightInstructor(daffy);
    tweety.getFlightPartnerRefs().add(daisy);
    tweety.getFlightPartnerRefs().add(plucky);
    return new Object[] { "created", modelInstance, modelParser };
}
Also used : ModelInstance(org.camunda.bpm.model.xml.ModelInstance) TestModelParser(org.camunda.bpm.model.xml.testmodel.TestModelParser)

Aggregations

ModelInstance (org.camunda.bpm.model.xml.ModelInstance)11 TestModelParser (org.camunda.bpm.model.xml.testmodel.TestModelParser)8 Animals (org.camunda.bpm.model.xml.testmodel.instance.Animals)4 InputStream (java.io.InputStream)1 ModelReferenceException (org.camunda.bpm.model.xml.ModelReferenceException)1 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)1 Animal (org.camunda.bpm.model.xml.testmodel.instance.Animal)1 Bird (org.camunda.bpm.model.xml.testmodel.instance.Bird)1 Description (org.camunda.bpm.model.xml.testmodel.instance.Description)1 Test (org.junit.Test)1