public virtual IModelElementInstance NewInstance(IModelInstance modelInstance)
        {
            ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl)modelInstance;
            IDomDocument      document          = modelInstanceImpl.Document;
            IDomElement       domElement        = document.CreateElement(_typeNamespace, _typeName);

            return(NewInstance(modelInstanceImpl, domElement));
        }
Beispiel #2
0
        /// <summary>
        /// Returns the <seealso cref="ModelElementInstanceImpl ModelElement"/> for a DOM element.
        /// If the model element does not yet exist, it is created and linked to the DOM.
        /// </summary>
        /// <param name="domElement"> the child element to create a new <seealso cref="ModelElementInstanceImpl ModelElement"/> for </param>
        /// <param name="modelInstance"> the <seealso cref="ModelInstanceImpl ModelInstance"/> for which the new <seealso cref="ModelElementInstanceImpl ModelElement"/> is created </param>
        /// <param name="modelType"> the <seealso cref="ModelElementTypeImpl ModelElementType"/> to create a new <seealso cref="ModelElementInstanceImpl ModelElement"/> for </param>
        /// <returns> the child model element </returns>
        public static ModelElementInstance getModelElement(DomElement domElement, ModelInstanceImpl modelInstance, ModelElementTypeImpl modelType)
        {
            ModelElementInstance modelElement = domElement.ModelElementInstance;

            if (modelElement == null)
            {
                modelElement = modelType.newInstance(modelInstance, domElement);
                domElement.ModelElementInstance = modelElement;
            }
            return(modelElement);
        }
        public virtual void SetReferenceTargetElement <TTarget>(ModelElementInstanceImpl referenceSourceParentElement, TTarget referenceTargetElement) where TTarget : IModelElementInstance
        {
            ModelInstanceImpl     modelInstance   = (ModelInstanceImpl)referenceSourceParentElement.ModelInstance;
            string                identifier      = ReferenceTargetAttribute.GetValue <String>(referenceTargetElement);
            IModelElementInstance existingElement = modelInstance.GetModelElementById(identifier);

            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.");
            }
            TSource referenceSourceElement = modelInstance.NewInstance <TSource>(ReferenceSourceElementType);

            SetReferenceSource(referenceSourceParentElement, referenceSourceElement);
            SetReferenceIdentifier(referenceSourceElement, identifier);
        }
Beispiel #4
0
        public virtual void setReferenceTargetElement(ModelElementInstanceImpl referenceSourceParentElement, Target referenceTargetElement)
        {
            ModelInstanceImpl    modelInstance   = referenceSourceParentElement.ModelInstance;
            string               identifier      = referenceTargetAttribute.getValue(referenceTargetElement);
            ModelElementInstance existingElement = modelInstance.getModelElementById(identifier);

            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
            {
                Source referenceSourceElement = modelInstance.newInstance(ReferenceSourceElementType);
                setReferenceSource(referenceSourceParentElement, referenceSourceElement);
                setReferenceIdentifier(referenceSourceElement, identifier);
            }
        }
Beispiel #5
0
        protected internal virtual void performAddOperation(ModelElementInstanceImpl referenceSourceParentElement, Target referenceTargetElement)
        {
            ModelInstanceImpl    modelInstance             = referenceSourceParentElement.ModelInstance;
            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
            {
                ICollection <Source> referenceSourceElements = referenceSourceCollection.get(referenceSourceParentElement);
                Source referenceSourceElement = modelInstance.newInstance(referenceSourceType);
                referenceSourceElements.Add(referenceSourceElement);
                setReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier);
            }
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testGetUnknownAnimalByType()
        public virtual void testGetUnknownAnimalByType()
        {
            ModelInstanceImpl            modelInstanceImpl = (ModelInstanceImpl)modelInstance;
            ModelElementType             unknownAnimalType = modelInstanceImpl.registerGenericType(MODEL_NAMESPACE, "unknownAnimal");
            IList <ModelElementInstance> unknownAnimals    = new List <ModelElementInstance>(modelInstance.getModelElementsByType(unknownAnimalType));

            assertThat(unknownAnimals).hasSize(2);

            ModelElementInstance wanda = unknownAnimals[0];

            assertThat(wanda.getAttributeValue("id")).isEqualTo("wanda");
            assertThat(wanda.getAttributeValue("gender")).isEqualTo("Female");
            assertThat(wanda.getAttributeValue("species")).isEqualTo("fish");

            ModelElementInstance flipper = unknownAnimals[1];

            assertThat(flipper.getAttributeValue("id")).isEqualTo("flipper");
            assertThat(flipper.getAttributeValue("gender")).isEqualTo("Male");
            assertThat(flipper.getAttributeValue("species")).isEqualTo("dolphin");
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testAddUnknownAnimal()
        public virtual void testAddUnknownAnimal()
        {
            ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl)modelInstance;
            ModelElementType  unknownAnimalType = modelInstanceImpl.registerGenericType(MODEL_NAMESPACE, "unknownAnimal");
            ModelElementType  animalsType       = modelInstance.Model.getType(typeof(Animals));
            ModelElementType  animalType        = modelInstance.Model.getType(typeof(Animal));

            ModelElementInstance unknownAnimal = modelInstance.newInstance(unknownAnimalType);

            assertThat(unknownAnimal).NotNull;
            unknownAnimal.setAttributeValue("id", "new-animal", true);
            unknownAnimal.setAttributeValue("gender", "Unknown");
            unknownAnimal.setAttributeValue("species", "unknown");

            ModelElementInstance         animals             = modelInstance.getModelElementsByType(animalsType).GetEnumerator().next();
            IList <ModelElementInstance> childElementsByType = new List <ModelElementInstance>(animals.getChildElementsByType(animalType));

            animals.insertElementAfter(unknownAnimal, childElementsByType[2]);
            assertThat(animals.getChildElementsByType(unknownAnimalType)).hasSize(3);
        }
Beispiel #8
0
 public ModelTypeInstanceContext(DomElement domElement, ModelInstanceImpl model, ModelElementTypeImpl modelType)
 {
     this.domElement = domElement;
     this.model      = model;
     this.modelType  = modelType;
 }
 public ModelInstanceValidator(ModelInstanceImpl modelInstanceImpl, ICollection <IModelElementValidator <IModelElementInstance> > validators)
 {
     this.ModelInstanceImpl = modelInstanceImpl;
     this.Validators        = validators;
 }
Beispiel #10
0
 public ModelElementInstanceImpl(ModelTypeInstanceContext instanceContext)
 {
     this.domElement    = instanceContext.DomElement;
     this.modelInstance = instanceContext.Model;
     this.elementType   = instanceContext.ModelType;
 }
Beispiel #11
0
        protected internal static ModelElementTypeImpl getModelElement(DomElement domElement, ModelInstanceImpl modelInstance, string namespaceUri)
        {
            string localName = domElement.LocalName;
            ModelElementTypeImpl modelType = (ModelElementTypeImpl)modelInstance.Model.getTypeForName(namespaceUri, localName);

            if (modelType == null)
            {
                Model  model = modelInstance.Model;
                string actualNamespaceUri = model.getActualNamespace(namespaceUri);

                if (!string.ReferenceEquals(actualNamespaceUri, null))
                {
                    modelType = getModelElement(domElement, modelInstance, actualNamespaceUri);
                }
                else
                {
                    modelType = (ModelElementTypeImpl)modelInstance.registerGenericType(namespaceUri, localName);
                }
            }
            return(modelType);
        }
Beispiel #12
0
        /// <summary>
        /// Get a collection of all model element instances in a view
        /// </summary>
        /// <param name="view"> the collection of DOM elements to find the model element instances for </param>
        /// <param name="model"> the model of the elements </param>
        /// <returns> the collection of model element instances of the view </returns>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public static <T extends org.camunda.bpm.model.xml.instance.ModelElementInstance> Collection<T> getModelElementCollection(Collection<org.camunda.bpm.model.xml.instance.DomElement> view, org.camunda.bpm.model.xml.impl.ModelInstanceImpl model)
        public static ICollection <T> getModelElementCollection <T>(ICollection <DomElement> view, ModelInstanceImpl model) where T : org.camunda.bpm.model.xml.instance.ModelElementInstance
        {
            IList <ModelElementInstance> resultList = new List <ModelElementInstance>();

            foreach (DomElement element in view)
            {
                resultList.Add(getModelElement(element, model));
            }
            return((ICollection <T>)resultList);
        }
Beispiel #13
0
 /// <summary>
 /// Filter a <seealso cref="NodeList"/> retaining all elements with a specific type
 ///
 /// </summary>
 /// <param name="nodeList">  the <seealso cref="NodeList"/> to filter </param>
 /// <param name="modelInstance">  the model instance </param>
 /// <param name="type">  the type class to filter for </param>
 /// <returns> the list of all Elements which match the filter </returns>
 public static IList <DomElement> filterNodeListByType(NodeList nodeList, ModelInstanceImpl modelInstance, Type type)
 {
     return(filterNodeList(nodeList, new ElementByTypeListFilter(type, modelInstance)));
 }
Beispiel #14
0
 public ElementByTypeListFilter(Type type, ModelInstanceImpl modelInstance)
 {
     this.type  = type;
     this.model = modelInstance;
 }