Example #1
0
        public virtual void RegisterType(IModelElementType modelElementType, Type instanceType)
        {
            var qName = ModelUtil.GetQName(modelElementType.TypeNamespace, modelElementType.TypeName);

            _typesByName[qName]         = modelElementType;
            _typesByClass[instanceType] = modelElementType;
        }
        public virtual IValidationResults Validate()
        {
            ValidationResultsCollectorImpl resultsCollector = new ValidationResultsCollectorImpl();

            foreach (var validator in Validators)
            {
                IModelElementType elementType = validator.ElementType;
                IEnumerable <IModelElementInstance> modelElementsByType = ModelInstanceImpl.GetModelElementsByType(elementType);

                foreach (IModelElementInstance element in modelElementsByType)
                {
                    resultsCollector.CurrentElement = element;

                    try
                    {
                        validator.Validate(element, resultsCollector);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Validator " + validator + " threw an exception while validating " + element, e);
                    }
                }
            }
            return(resultsCollector.Results);
        }
Example #3
0
 public virtual void RegisterChildElementType(IModelElementType childElementType)
 {
     if (!_childElementTypes.Contains(childElementType))
     {
         _childElementTypes.Add(childElementType);
     }
 }
Example #4
0
        public virtual T NewInstance <T>(IModelElementType type) where T : IModelElementInstance
        {
            IModelElementInstance modelElementInstance = type.NewInstance(this);

            ModelUtil.SetGeneratedUniqueIdentifier(type, modelElementInstance);
            return((T)modelElementInstance);
        }
Example #5
0
 public virtual void RegisterExtendingType(IModelElementType modelType)
 {
     if (!_extendingTypes.Contains(modelType))
     {
         _extendingTypes.Add(modelType);
     }
 }
Example #6
0
        public virtual IModelElementInstance AddExtensionElement(string namespaceUri, string localName)
        {
            IModelElementType     extensionElementType = ((ModelInstanceImpl)modelInstance).RegisterGenericType(namespaceUri, localName);
            IModelElementInstance extensionElement     = extensionElementType.NewInstance(modelInstance);

            AddChildElement(extensionElement);
            return(extensionElement);
        }
Example #7
0
        /// <summary>
        /// Calculate a collection of all base types for the given type
        /// </summary>
        public static ICollection <IModelElementType> CalculateAllBaseTypes(IModelElementType type)
        {
            IList <IModelElementType> baseTypes = new List <IModelElementType>();
            ModelElementTypeImpl      typeImpl  = (ModelElementTypeImpl)type;

            typeImpl.ResolveBaseTypes(baseTypes);
            return(baseTypes);
        }
Example #8
0
        public virtual T NewInstance <T>(Type type) where T : IModelElementInstance
        {
            IModelElementType modelElementType = model.GetType(type);

            if (modelElementType != null)
            {
                return(NewInstance <T>(modelElementType));
            }
            throw new ModelException("Cannot create instance of ModelType " + type + ": no such type registered.");
        }
Example #9
0
        public virtual IModelElementType RegisterGenericType(string namespaceUri, string localName)
        {
            IModelElementType elementType = model.GetTypeForName(namespaceUri, localName);

            if (elementType == null)
            {
                elementType = ModelBuilder.DefineGenericType <IModelElementInstance>(localName, namespaceUri);
                model       = (ModelImpl)ModelBuilder.Build();
            }
            return(elementType);
        }
Example #10
0
        //TODO 可能又类型判断错误 设置ModelElementId id.DefaultValue is string
        /// <summary>
        /// Set unique identifier if the type has a String id attribute
        /// </summary>
        /// <param name="type"> the type of the model element </param>
        /// <param name="modelElementInstance"> the model element instance to set the id </param>
        public static void SetGeneratedUniqueIdentifier(IModelElementType type, IModelElementInstance modelElementInstance)
        {
            //AttributeBox id = type.GetAttribute("id");
            IAttribute /*<String>*/ id = type.GetAttribute("id");

            //if (id != null && id.ValueType ==typeof(string) && id.IdAttribute)
            if (id != null && id.IdAttribute)
            {
                ((StringAttribute)id).SetValue(modelElementInstance, ModelUtil.GetUniqueIdentifier(type));
            }
        }
Example #11
0
        //TODO 入口 IModelElementInstance解析
        /// <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>
        /// <returns> the child model element </returns>
        public static IModelElementInstance GetModelElement(IDomElement domElement, IModelInstance modelInstance)
        {
            IModelElementInstance modelElement = domElement.ModelElementInstance;

            if (modelElement == null)
            {
                IModelElementType modelType = GetModelElement(domElement, modelInstance, domElement.NamespaceUri);
                modelElement = ((ModelElementTypeImpl)modelType).NewInstance(modelInstance, domElement);
                domElement.ModelElementInstance = modelElement;
            }
            return(modelElement);
        }
Example #12
0
        public IQuery <T> FilterByType <T>(IModelElementType elementClass) where T : IModelElementInstance
        {
            IList <T> filtered = new List <T>();

            foreach (var instance in _collection)
            {
                if (elementClass.InstanceType == instance.GetType())
                {
                    //filtered.Add((T)instance);
                }
            }
            return(new QueryImpl <T>(filtered));
        }
Example #13
0
        public virtual void PerformModelBuild(IModel model)
        {
            IModelElementType elementType = model.GetType(typeof(TSource));

            if (elementType == null)
            {
                throw new ModelException(parentElementType + " declares undefined child element of type " + typeof(TSource) + ".");
            }
            parentElementType.RegisterChildElementType(elementType);
            parentElementType.RegisterChildElementCollection(_collection);
            foreach (IModelBuildOperation modelBuildOperation in _modelBuildOperations)
            {
                modelBuildOperation.PerformModelBuild(model);
            }
        }
Example #14
0
        public virtual IEnumerable <IModelElementInstance> GetModelElementsByType(IModelElementType type)
        {
            IEnumerable <IModelElementType> extendingTypes = type.AllExtendingTypes;

            List <IModelElementInstance> instances = new List <IModelElementInstance>();

            foreach (IModelElementType modelElementType in extendingTypes)
            {
                if (!modelElementType.Abstract)
                {
                    instances.AddRange(modelElementType.GetInstances(this));
                }
            }
            return(instances);
        }
Example #15
0
 public NamedEnumAttribute(IModelElementType owningElementType)
     : base(owningElementType)
 {
     if (changedNames == null)
     {
         changedNames = new Dictionary <string, string>();
         var type = typeof(HitPolicy);
         foreach (var item in type.GetFields())
         {
             if (item.GetCustomAttributes(false).Length > 0)
             {
                 var cus = (DescriptionAttribute)item.GetCustomAttributes(false)[0];
                 changedNames.Add(cus.Description, item.Name);
             }
         }
     }
 }
Example #16
0
        //public virtual ICollection<IDiagramElement> GetIncomingReferencesByType(Type referenceSourceTypeClass)
        //{
        //    ICollection<IDiagramElement> references = new List<IDiagramElement>();
        //    // we traverse all incoming references in reverse direction
        //    foreach (IReference reference in IdAttribute.IncomingReferences)
        //    {

        //        IModelElementType sourceElementType = reference.ReferenceSourceElementType;
        //        Type sourceInstanceType = sourceElementType.InstanceType;

        //        // if the referencing element (source element) is a BPMNDI element, dig deeper
        //        if (referenceSourceTypeClass.IsAssignableFrom(sourceInstanceType))
        //        {
        //            references.Add((IDiagramElement)reference);
        //        }
        //    }
        //    return references;
        //}

        public ICollection <IReference> GetIncomingReferencesByType(Type referenceSourceTypeClass)
        {
            ICollection <IReference> references = new List <IReference>();

            // we traverse all incoming references in reverse direction
            foreach (IReference reference in IdAttribute.IncomingReferences)
            {
                IModelElementType sourceElementType = reference.ReferenceSourceElementType;
                Type sourceInstanceType             = sourceElementType.InstanceType;

                // if the referencing element (source element) is a BPMNDI element, dig deeper
                if (referenceSourceTypeClass.IsAssignableFrom(sourceInstanceType))
                {
                    references.Add(reference);
                }
            }
            return(references);
        }
Example #17
0
        /// <summary>
        /// Find the index of the type of a model element in a list of element types
        /// </summary>
        /// <param name="modelElement"> the model element which type is searched for </param>
        /// <param name="childElementTypes"> the list to search the type </param>
        /// <returns> the index of the model element type in the list or -1 if it is not found </returns>
        public static int GetIndexOfElementType(IModelElementInstance modelElement, IList <IModelElementType> childElementTypes)
        {
            for (int index = 0; index < childElementTypes.Count; index++)
            {
                IModelElementType childElementType = childElementTypes[index];
                Type instanceType = childElementType.InstanceType;
                if (instanceType.IsAssignableFrom(modelElement.GetType()))
                {
                    return(index);
                }
            }
            ICollection <string> childElementTypeNames = new List <string>();

            foreach (IModelElementType childElementType in childElementTypes)
            {
                childElementTypeNames.Add(childElementType.TypeName);
            }
            throw new ModelException("New child is not a valid child element type: " + modelElement.ElementType.TypeName + "; valid types are: " + childElementTypeNames);
        }
Example #18
0
        protected internal static IModelElementType GetModelElement(IDomElement domElement, IModelInstance modelInstance, string namespaceUri)
        {
            string            localName = domElement.LocalName;
            IModelElementType modelType = modelInstance.Model.GetTypeForName(namespaceUri, localName);

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

                if (!string.ReferenceEquals(actualNamespaceUri, null))
                {
                    modelType = GetModelElement(domElement, modelInstance, actualNamespaceUri);
                }
                else
                {
                    modelType = ((ModelInstanceImpl)modelInstance).RegisterGenericType(namespaceUri, localName);
                }
            }
            return(modelType);
        }
Example #19
0
 public StringAttribute(IModelElementType owningElementType)
     : base(owningElementType)
 {
 }
Example #20
0
 public ChildElementCollectionImpl(ModelElementTypeImpl parentElementType)
 {
     //this.childElementTypeClass = childElementTypeClass;
     this._parentElementType = parentElementType;
 }
Example #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public <V extends org.camunda.bpm.model.xml.instance.ModelElementInstance> org.camunda.bpm.model.bpmn.Query<V> filterByType(org.camunda.bpm.model.xml.type.ModelElementType elementType)
        public virtual IQuery <TV> FilterByType <TV>(IModelElementType elementType) where TV : IModelElementInstance
        {
            Type elementClass = (Type)elementType.InstanceType;

            return(FilterByType <TV>(elementClass));
        }
 public virtual T NewInstance <T>(IModelElementType type) where T : IModelElementInstance
 {
     return(modelInstance.NewInstance <T>(type));
 }
Example #23
0
 public ObjectAttribute(IModelElementType owningElementType) : base(owningElementType)
 {
 }
Example #24
0
 public ChildElementCollectionBuilderImpl(IModelElementType parentElementType)
 {
     this.parentElementType = (ModelElementTypeImpl)parentElementType;
     this._collection       = CreateCollectionInstance();
 }
Example #25
0
 public ChildElementBuilderImpl(IModelElementType parentElementType)
     : base(parentElementType)
 {
 }
Example #26
0
 internal DoubleAttribute(IModelElementType owningElementType) : base(owningElementType)
 {
 }
Example #27
0
 internal IntegerAttribute(IModelElementType owningElementType)
     : base(owningElementType)
 {
 }
Example #28
0
 internal AttributeImpl(IModelElementType owningElementType)
 {
     this._owningElementType = owningElementType;
 }
Example #29
0
 public static string GetUniqueIdentifier(IModelElementType type)
 {
     return(type.TypeName + "_" + Guid.NewGuid());
 }
 public virtual IEnumerable <IModelElementInstance> GetModelElementsByType(IModelElementType referencingType)
 {
     return(modelInstance.GetModelElementsByType(referencingType));
 }