/// <summary>
 /// Initializes a new instance of the SdbSchemaType.
 /// </summary>
 /// <param name="particleIndex"></param>
 /// <param name="simpleTypeIndex"></param>
 /// <param name="attributeCount"></param>
 /// <param name="startAttribute"></param>
 public SdbSchemaType(SdbIndex particleIndex, SdbIndex simpleTypeIndex, SdbIndex attributeCount, SdbIndex startAttribute)
 {
     this.ParticleIndex          = particleIndex;
     this.SimpleTypeIndex        = simpleTypeIndex;
     this.AttributesCount        = attributeCount;
     this.StartIndexOfAttributes = startAttribute;
 }
Beispiel #2
0
        /// <summary>
        /// Load the data in the binary database into SchemaTypeData object.
        /// </summary>
        /// <param name="openxmlTypeId">The id of the type (the OpenXmlElement class).</param>
        /// <returns>The SchemaTypeData object.</returns>
        private SchemaTypeData LoadSchemaTypeData(OpenXmlTypeId openxmlTypeId)
        {
            Debug.Assert(openxmlTypeId >= this.SdbDataHead.StartClassId);
            Debug.Assert(openxmlTypeId < this.SdbDataHead.StartClassId + this.SdbDataHead.ClassIdsCount);

            SdbIndex index                = (SdbIndex)(openxmlTypeId - this.SdbDataHead.StartClassId);
            var      sdbSchemaType        = this.SdbSchemaTypes[this.SdbClassIdMap[index].SchemaTypeIndex];
            var      attributeConstraints = BuildAttributeConstraint(sdbSchemaType);

            var particleConstraint = BuildParticleConstraint(sdbSchemaType);

            if (particleConstraint != null)
            {
                return(new SchemaTypeData(openxmlTypeId, attributeConstraints, particleConstraint));
            }
            else if (sdbSchemaType.IsSimpleContent)
            {
                Debug.Assert(sdbSchemaType.SimpleTypeIndex != SdbData.InvalidId);
                // simple content
                var simpleTypeConstraint = this.SimpleTypeRestrictions[sdbSchemaType.SimpleTypeIndex];
                return(new SchemaTypeData(openxmlTypeId, attributeConstraints, simpleTypeConstraint));
            }
            else
            {
                // leaf element
                Debug.Assert(sdbSchemaType.SimpleTypeIndex == SdbData.InvalidId);
                return(new SchemaTypeData(openxmlTypeId, attributeConstraints));
            }
        }
        public static SdbIndex LoadSdbIndex(byte[] bytes, ref int startIndex)
        {
            SdbIndex result = BitConverter.ToUInt16(bytes, startIndex);

            startIndex += sizeof(SdbIndex);
            return(result);
        }
        public SdbParticleChildrenIndex(int index)
        {
            if (index >= SdbData.MaxSdbIndex)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            this.ParticleIndex = (SdbIndex)index;
        }
Beispiel #5
0
        /// <summary>
        /// Load the attribute constraints and simple type constraint for attributes for the schema type.
        /// </summary>
        /// <param name="sdbSchemaTpye"></param>
        /// <returns></returns>
        private AttributeConstraint[] BuildAttributeConstraint(SdbSchemaType sdbSchemaTpye)
        {
            Debug.Assert(sdbSchemaTpye != null);
            if (sdbSchemaTpye.AttributesCount > 0)
            {
                int count = sdbSchemaTpye.AttributesCount;
                var attributeConstraints = new AttributeConstraint[count];

                SdbIndex sdbIndex = sdbSchemaTpye.StartIndexOfAttributes;
                for (int i = 0; i < count; i++)
                {
                    var sdbAttributeData = this.SdbAttributes[sdbIndex + i];
                    // then load the simple type constraint for this attribute
                    var simpleTypeIndex      = sdbAttributeData.SimpleTypeIndex;
                    var simpleTypeConstraint = this.SimpleTypeRestrictions[simpleTypeIndex];
                    attributeConstraints[i] = new AttributeConstraint(sdbAttributeData.AttributeUse, simpleTypeConstraint, (FileFormatVersions)(sdbAttributeData.FileFormatVersion));
                }
                return(attributeConstraints);
            }

            return(null);
        }
Beispiel #6
0
        private void CheckParticle(int particleIndex)
        {
            var particle = this.SdbParticles[particleIndex];

            switch (particle.ParticleType)
            {
            case ParticleType.Element:
                Debug.Assert(particle.ChildrenCount == 0);
                // element type ID must be a valid ID in the class ID map.
                Debug.Assert(particle.ElementTypeId >= SdbClassIdToSchemaTypeIndex.StartClassId);
                Debug.Assert(particle.ElementTypeId < SdbClassIdToSchemaTypeIndex.StartClassId + this.SdbDataHead.ClassIdsCount);
                break;

            case ParticleType.All:
            case ParticleType.Choice:
            case ParticleType.Group:
            case ParticleType.Sequence:
                Debug.Assert(particle.ChildrenCount >= 0);     // CT_Ink has an empty <xsd:sequence></xsd:sequence>
                for (int i = 0; i < particle.ChildrenCount; i++)
                {
                    var childIndex = this.SdbParticleIndexs[particle.ChildrenStartIndex + i];
                    CheckParticle(childIndex.ParticleIndex);
                }
                break;

            case ParticleType.Any:
            case ParticleType.AnyWithUri:
                SdbIndex namespaceId = particle.XsdAnyNamespaceId;
                Debug.Assert(namespaceId != SdbData.InvalidId);
                break;

            case ParticleType.Invalid:
            default:
                Debug.Assert(false);
                break;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Get corresponding namespace string for Any, Other, Local and TargetNamespace.
        /// </summary>
        /// <param name="value">One of the Any, Other, Local and TargetNamespace.</param>
        /// <returns>##any, ##other, ##local or ##targetNamespace.</returns>
        internal static string GetNamespaceString(SdbIndex value)
        {
            switch (value)
            {
                case XsdAnyPrefidefinedValue.Any:
                    // Elements from any namespace can be present.
                    return "##any";

                case XsdAnyPrefidefinedValue.Local:
                    // Elements that are not qualified with a namespace can be present.
                    return "##local";

                case XsdAnyPrefidefinedValue.Other:
                    // Elements from any namespace that is not the target namespace of the parent element containing this element can be present.
                    return "##other";

                case XsdAnyPrefidefinedValue.TargetNamespace:
                    return "##targetNamespace";

                default:
                    Debug.Assert(false);
                    return string.Empty;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Load the particle constraint from the specified data in binary database.
        /// </summary>
        /// <param name="particleIndex">The index of the particle constraint data in the binary database.</param>
        /// <returns>The particle constraint in ParticleConstraint.</returns>
        private ParticleConstraint BuildParticleConstraint(SdbIndex particleIndex)
        {
            Debug.Assert(particleIndex >= 0);
            Debug.Assert(particleIndex < this.SdbDataHead.ParticleCount);

            SdbParticleConstraint sdbParticleConstraint = this.SdbParticles[particleIndex];
            var particleConstraint = ParticleConstraint.CreateParticleConstraint(sdbParticleConstraint.ParticleType);

            particleConstraint.ParticleType = sdbParticleConstraint.ParticleType;
            particleConstraint.MaxOccurs    = sdbParticleConstraint.MaxOccurs;
            particleConstraint.MinOccurs    = sdbParticleConstraint.MinOccurs;
            particleConstraint.ElementId    = sdbParticleConstraint.ElementTypeId;

            if (sdbParticleConstraint.ChildrenCount > 0)
            {
                Debug.Assert(sdbParticleConstraint.ParticleType == ParticleType.All ||
                             sdbParticleConstraint.ParticleType == ParticleType.Choice ||
                             sdbParticleConstraint.ParticleType == ParticleType.Group ||
                             sdbParticleConstraint.ParticleType == ParticleType.Sequence);
                particleConstraint.ChildrenParticles = new ParticleConstraint[sdbParticleConstraint.ChildrenCount];
                for (SdbIndex i = 0; i < sdbParticleConstraint.ChildrenCount; i++)
                {
                    SdbIndex childIndex = this.SdbParticleIndexs[(SdbIndex)(sdbParticleConstraint.ChildrenStartIndex + i)].ParticleIndex;
                    particleConstraint.ChildrenParticles[i] = this.BuildParticleConstraint(childIndex);
                }
            }
            else if (sdbParticleConstraint.ParticleType == ParticleType.All ||
                     sdbParticleConstraint.ParticleType == ParticleType.Choice ||
                     sdbParticleConstraint.ParticleType == ParticleType.Group ||
                     sdbParticleConstraint.ParticleType == ParticleType.Sequence)
            {
                particleConstraint.ChildrenParticles = EmptyChildrenParticles;
            }

            return(particleConstraint);
        }
        /// <summary>
        /// Get corresponding namespace string for Any, Other, Local and TargetNamespace.
        /// </summary>
        /// <param name="value">One of the Any, Other, Local and TargetNamespace.</param>
        /// <returns>##any, ##other, ##local or ##targetNamespace.</returns>
        internal static string GetNamespaceString(SdbIndex value)
        {
            switch (value)
            {
            case XsdAnyPrefidefinedValue.Any:
                // Elements from any namespace can be present.
                return("##any");

            case XsdAnyPrefidefinedValue.Local:
                // Elements that are not qualified with a namespace can be present.
                return("##local");

            case XsdAnyPrefidefinedValue.Other:
                // Elements from any namespace that is not the target namespace of the parent element containing this element can be present.
                return("##other");

            case XsdAnyPrefidefinedValue.TargetNamespace:
                return("##targetNamespace");

            default:
                Debug.Assert(false);
                return(string.Empty);
            }
        }
Beispiel #10
0
 public SdbParticleChildrenIndex()
 {
     this.ParticleIndex = SdbData.InvalidId;
 }
 /// <summary>
 /// Return the index of the data in the data array. The data array is sorted by the class ID and the class ID is continuous.
 /// </summary>
 /// <param name="classId"></param>
 /// <returns></returns>
 public static SdbIndex ArrayIndexFromClassId(SdbIndex classId)
 {
     Debug.Assert(classId >= StartClassId);
     return((SdbIndex)(classId - StartClassId));
 }
 /// <summary>
 /// Initializes a new instance of the SdbClassIdToSchemaTypeIndex.
 /// </summary>
 /// <param name="classId"></param>
 /// <param name="schemaTypeIndex"></param>
 public SdbClassIdToSchemaTypeIndex(SdbIndex classId, SdbIndex schemaTypeIndex)
 {
     this.ClassId         = classId;
     this.SchemaTypeIndex = schemaTypeIndex;
 }
 public SdbParticleChildrenIndex()
 {
     this.ParticleIndex = SdbData.InvalidId;
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the SdbSchemaType.
 /// </summary>
 /// <param name="particleIndex"></param>
 /// <param name="simpleTypeIndex"></param>
 /// <param name="attributeCount"></param>
 /// <param name="startAttribute"></param>
 public SdbSchemaType(SdbIndex particleIndex, SdbIndex simpleTypeIndex, SdbIndex attributeCount, SdbIndex startAttribute)
 {
     this.ParticleIndex = particleIndex;
     this.SimpleTypeIndex = simpleTypeIndex;
     this.AttributesCount = attributeCount;
     this.StartIndexOfAttributes = startAttribute;
 }
Beispiel #15
0
 /// <summary>
 /// Return the index of the data in the data array. The data array is sorted by the class ID and the class ID is continuous.
 /// </summary>
 /// <param name="classId"></param>
 /// <returns></returns>
 public static SdbIndex ArrayIndexFromClassId(SdbIndex classId)
 {
     Debug.Assert(classId >= StartClassId);
     return (SdbIndex)(classId - StartClassId);
 }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the SdbClassIdToSchemaTypeIndex.
 /// </summary>
 /// <param name="classId"></param>
 /// <param name="schemaTypeIndex"></param>
 public SdbClassIdToSchemaTypeIndex(SdbIndex classId, SdbIndex schemaTypeIndex)
 {
     this.ClassId = classId;
     this.SchemaTypeIndex = schemaTypeIndex;
 }
Beispiel #17
0
        /// <summary>
        /// Get a SdbClassIdToSchemaTypeIndex data for the sepcified class ID.
        /// </summary>
        /// <param name="classId">The class ID.</param>
        /// <returns>A SdbClassIdToSchemaTypeIndex data.</returns>
        private SdbClassIdToSchemaTypeIndex GetClassIdData(SdbIndex classId)
        {
            int index = SdbClassIdToSchemaTypeIndex.ArrayIndexFromClassId(classId);

            return(this.SdbClassIdMap[index]);
        }
 public SdbParticleChildrenIndex(SdbIndex index)
 {
     this.ParticleIndex = index;
 }
Beispiel #19
0
 public SdbParticleChildrenIndex(SdbIndex index)
 {
     this.ParticleIndex = index;
 }
 public SdbAttributeConstraint(XsdAttributeUse xsdAttributeUse, SdbIndex simpleTypeIndex, byte fileFormatVersion)
 {
     this.AttributeUse      = xsdAttributeUse;
     this.SimpleTypeIndex   = simpleTypeIndex;
     this.FileFormatVersion = fileFormatVersion;
 }
Beispiel #21
0
 public SdbParticleChildrenIndex(int index)
 {
     if (index >= SdbData.MaxSdbIndex)
     {
         throw new ArgumentOutOfRangeException("index");
     }
      
     this.ParticleIndex = (SdbIndex)index;
 }
 public static byte[] Bytes(this SdbIndex value)
 {
     return(BitConverter.GetBytes(value));
 }
Beispiel #23
0
 public SdbAttributeConstraint(XsdAttributeUse xsdAttributeUse, SdbIndex simpleTypeIndex, byte fileFormatVersion)
 {
     this.AttributeUse = xsdAttributeUse;
     this.SimpleTypeIndex = simpleTypeIndex;
     this.FileFormatVersion = fileFormatVersion;
 }