public CompiledIdentityConstraint(XmlSchemaIdentityConstraint constraint, XmlNamespaceManager nsmgr) {
            this.name = constraint.QualifiedName;

            //public Asttree (string xPath, bool isField, XmlNamespaceManager nsmgr)
            try {
                this.selector = new Asttree(constraint.Selector.XPath, false, nsmgr);
            }
            catch (XmlSchemaException e) {
                e.SetSource(constraint.Selector);
                throw e;
            }
            XmlSchemaObjectCollection fields = constraint.Fields;
            Debug.Assert(fields.Count > 0);
            this.fields = new Asttree[fields.Count];
            for(int idxField = 0; idxField < fields.Count; idxField ++) {
                try {
                    this.fields[idxField] = new Asttree(((XmlSchemaXPath)fields[idxField]).XPath, true, nsmgr);
                }
                catch (XmlSchemaException e) {
                    e.SetSource(constraint.Fields[idxField]);
                    throw e;
                }
            }
            if (constraint is XmlSchemaUnique) {
                this.role = ConstraintRole.Unique;
            } 
            else if (constraint is XmlSchemaKey) {
                this.role = ConstraintRole.Key;
            } 
            else {             // XmlSchemaKeyref
                this.role = ConstraintRole.Keyref;
                this.refer = ((XmlSchemaKeyref)constraint).Refer; 
            }
        }
        private static void WriteConstraintRow(this MamlWriter writer, Context context, ArtItem artItem, string constrainedType, XmlSchemaIdentityConstraint constraint)
        {
            writer.StartTableRow();

            writer.StartTableRowEntry();
            writer.WriteArtItemInline(artItem);
            writer.EndTableRowEntry();

            writer.StartTableRowEntry();
            writer.WriteString(constrainedType);
            writer.EndTableRowEntry();

            writer.StartTableRowEntry();
            writer.WriteSummaryForObject(context, constraint);
            writer.EndTableRowEntry();

            writer.StartTableRowEntry();
            writer.WriteString(constraint.Selector.XPath);
            writer.EndTableRowEntry();

            writer.StartTableRowEntry();
            writer.WriteConstraintFieldList(constraint.Fields);
            writer.EndTableRowEntry();

            writer.EndTableRow();
        }
 internal DataColumn[] BuildKey(XmlSchemaIdentityConstraint keyNode, DataTable table)
 {
     ArrayList list = new ArrayList();
     foreach (XmlSchemaXPath path in keyNode.Fields)
     {
         list.Add(this.FindField(table, path.XPath));
     }
     DataColumn[] array = new DataColumn[list.Count];
     list.CopyTo(array, 0);
     return array;
 }
Ejemplo n.º 4
0
		internal override int Validate (ValidationEventHandler h, XmlSchema schema)
		{
			// Find target key
			XmlSchemaIdentityConstraint target = schema.NamedIdentities [this.Refer] as XmlSchemaIdentityConstraint;
			if (target == null)
				error (h, "Target key was not found.");
			else if (target is XmlSchemaKeyref)
				error (h, "Target identity constraint was keyref.");
			else if (target.Fields.Count != this.Fields.Count)
				error (h, "Target identity constraint has different number of fields.");
			else
				this.target = target;
			return errorCount;
		}
 public CompiledIdentityConstraint(XmlSchemaIdentityConstraint constraint, XmlNamespaceManager nsmgr)
 {
     this.name = XmlQualifiedName.Empty;
     this.refer = XmlQualifiedName.Empty;
     this.name = constraint.QualifiedName;
     try
     {
         this.selector = new Asttree(constraint.Selector.XPath, false, nsmgr);
     }
     catch (XmlSchemaException exception)
     {
         exception.SetSource(constraint.Selector);
         throw exception;
     }
     XmlSchemaObjectCollection fields = constraint.Fields;
     this.fields = new Asttree[fields.Count];
     for (int i = 0; i < fields.Count; i++)
     {
         try
         {
             this.fields[i] = new Asttree(((XmlSchemaXPath) fields[i]).XPath, true, nsmgr);
         }
         catch (XmlSchemaException exception2)
         {
             exception2.SetSource(constraint.Fields[i]);
             throw exception2;
         }
     }
     if (constraint is XmlSchemaUnique)
     {
         this.role = ConstraintRole.Unique;
     }
     else if (constraint is XmlSchemaKey)
     {
         this.role = ConstraintRole.Key;
     }
     else
     {
         this.role = ConstraintRole.Keyref;
         this.refer = ((XmlSchemaKeyref) constraint).Refer;
     }
 }
Ejemplo n.º 6
0
		private XsdKeyTable CreateNewKeyTable (XmlSchemaIdentityConstraint ident)
		{
			XsdKeyTable seq = new XsdKeyTable (ident);
			seq.StartDepth = reader.Depth;
			this.keyTables.Add (seq);
			return seq;
		}
		private void ReserveSelfIdentity (XmlSchemaIdentityConstraint ic)
		{
			string tableName = GetSelectorTarget (ic.Selector.XPath);

			string [] cols = new string [ic.Fields.Count];
			bool [] isAttrSpec = new bool [cols.Length];

			int i = 0;
			foreach (XmlSchemaXPath Field in ic.Fields) {
				string colName = Field.XPath;
				bool isAttr = colName.Length > 0 && colName [0] == '@';
				int index = colName.LastIndexOf (':');
				if (index > 0)
					colName = colName.Substring (index + 1);
				else if (isAttr)
					colName = colName.Substring (1);

				colName = XmlHelper.Decode (colName);
				cols [i] = colName;
				isAttrSpec [i] = isAttr;
				i++;
			}
			
			bool isPK = false;
			// find if there is an attribute with the constraint name
			// if not use the XmlSchemaConstraint's name.
			string constraintName = ic.Name;
			if (ic.UnhandledAttributes != null) {
				foreach (XmlAttribute attr in ic.UnhandledAttributes) {
					if (attr.NamespaceURI != XmlConstants.MsdataNamespace)
						continue;
					switch (attr.LocalName) {
					case XmlConstants.ConstraintName:
						constraintName = attr.Value;
						break;
					case XmlConstants.PrimaryKey:
						isPK = bool.Parse(attr.Value);
						break;
					}
				}
			}
			reservedConstraints.Add (ic,
				new ConstraintStructure (tableName, cols,
					isAttrSpec, constraintName, isPK, null, false, false));
		}
 private string GetTableNamespace(XmlSchemaIdentityConstraint key)
 {
     string xPath = key.Selector.XPath;
     string[] strArray = xPath.Split(new char[] { '/' });
     string name = string.Empty;
     string str = strArray[strArray.Length - 1];
     if ((str == null) || (str.Length == 0))
     {
         throw ExceptionBuilder.InvalidSelector(xPath);
     }
     if (str.IndexOf(':') != -1)
     {
         name = str.Substring(0, str.IndexOf(':'));
     }
     else
     {
         return GetMsdataAttribute(key, "TableNamespace");
     }
     name = XmlConvert.DecodeName(name);
     return this.GetNamespaceFromPrefix(name);
 }
 internal void HandleConstraint(XmlSchemaIdentityConstraint keyNode)
 {
     string key = null;
     key = XmlConvert.DecodeName(keyNode.Name);
     if ((key == null) || (key.Length == 0))
     {
         throw ExceptionBuilder.MissingAttribute("name");
     }
     if (this.ConstraintNodes.ContainsKey(key))
     {
         throw ExceptionBuilder.DuplicateConstraintRead(key);
     }
     string tableName = this.GetTableName(keyNode);
     string msdataAttribute = GetMsdataAttribute(keyNode, "TableNamespace");
     DataTable tableSmart = this._ds.Tables.GetTableSmart(tableName, msdataAttribute);
     if (tableSmart != null)
     {
         this.ConstraintNodes.Add(key, new ConstraintTable(tableSmart, keyNode));
         bool primaryKey = this.GetBooleanAttribute(keyNode, "PrimaryKey", false);
         key = this.GetStringAttribute(keyNode, "ConstraintName", key);
         DataColumn[] columns = this.BuildKey(keyNode, tableSmart);
         if (0 < columns.Length)
         {
             UniqueConstraint instance = (UniqueConstraint) columns[0].Table.Constraints.FindConstraint(new UniqueConstraint(key, columns));
             if (instance == null)
             {
                 columns[0].Table.Constraints.Add(key, columns, primaryKey);
                 SetExtProperties(columns[0].Table.Constraints[key], keyNode.UnhandledAttributes);
             }
             else
             {
                 columns = instance.ColumnsReference;
                 SetExtProperties(instance, keyNode.UnhandledAttributes);
                 if (primaryKey)
                 {
                     columns[0].Table.PrimaryKey = columns;
                 }
             }
             if (keyNode is XmlSchemaKey)
             {
                 for (int i = 0; i < columns.Length; i++)
                 {
                     columns[i].AllowDBNull = false;
                 }
             }
         }
     }
 }
 void Write48_XmlSchemaIdentityConstraint(XmlSchemaIdentityConstraint o) {
     if ((object)o == null) return;
     System.Type t = o.GetType();
     if (t == typeof(XmlSchemaUnique)) {
         Write51_XmlSchemaUnique((XmlSchemaUnique)o);
         return;
     }
     else if (t == typeof(XmlSchemaKeyref)) {
         Write50_XmlSchemaKeyref((XmlSchemaKeyref)o);
         return;
     }
     else if (t == typeof(XmlSchemaKey)) {
         Write47_XmlSchemaKey((XmlSchemaKey)o);
         return;
     }
 }
        private void CompileIdentityConstraint (XmlSchemaIdentityConstraint xi) { 
            if (xi.IsProcessing) {
                xi.CompiledConstraint = CompiledIdentityConstraint.Empty;       
                SendValidationEvent(Res.Sch_IdentityConstraintCircularRef, xi);
                return;
            }

            if (xi.CompiledConstraint != null) {
                return;
            }
            
            xi.IsProcessing = true;
            CompiledIdentityConstraint compic = null;
            try {
                SchemaNamespaceManager xnmgr = new SchemaNamespaceManager(xi);
                compic = new CompiledIdentityConstraint(xi, xnmgr);
                if (xi is XmlSchemaKeyref) {
                    XmlSchemaIdentityConstraint ic = (XmlSchemaIdentityConstraint)this.identityConstraints[((XmlSchemaKeyref)xi).Refer];
                    if (ic == null) {
                        throw new XmlSchemaException(Res.Sch_UndeclaredIdentityConstraint, ((XmlSchemaKeyref)xi).Refer.ToString(), xi);
                    }     
                    CompileIdentityConstraint(ic);
                    if (ic.CompiledConstraint == null) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidIdentityConstraint, ((XmlSchemaKeyref)xi).Refer.ToString(), xi);
                    }
                    // keyref has the different cardinality with the key it referred
                    if (ic.Fields.Count != xi.Fields.Count) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidCardin, xi.QualifiedName.ToString(), xi);
                    }
                    // keyref can only refer to key/unique
                    if (ic.CompiledConstraint.Role == CompiledIdentityConstraint.ConstraintRole.Keyref) {
                        throw new XmlSchemaException(Res.Sch_ReftoKeyref, xi.QualifiedName.ToString(), xi);
                    }
                }
                xi.CompiledConstraint = compic;
            }
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(xi);
                }
                SendValidationEvent(e);
                xi.CompiledConstraint = CompiledIdentityConstraint.Empty;       
                // empty is better than null here, stop quickly when circle referencing
            } 
            finally {
                xi.IsProcessing = false;
            }

        }
Ejemplo n.º 12
0
		public void Reset (XmlSchemaIdentityConstraint source)
		{
			this.source = source;
			this.selector = source.CompiledSelector;
			this.qname = source.QualifiedName;
			XmlSchemaKeyref kr = source as XmlSchemaKeyref;
			if (kr != null)
				this.refKeyName = kr.Refer;
			StartDepth = 0;
		}
		private void ProcessParentKey (XmlSchemaIdentityConstraint ic)
		{
			// Basic concept came from XmlSchemaMapper.cs

			string tableName = GetSelectorTarget (ic.Selector.XPath);
			
			DataTable dt = dataset.Tables [tableName];
			if (dt == null)
				throw new DataException (String.Format ("Invalid XPath selection inside selector. Cannot find: {0}", tableName));

			DataColumn [] cols = new DataColumn [ic.Fields.Count];
			int i = 0;
			foreach (XmlSchemaXPath Field in ic.Fields) {
				string colName = Field.XPath;
				bool isAttr = colName.Length > 0 && colName [0] == '@';
				int index = colName.LastIndexOf (':');
				if (index > 0)
					colName = colName.Substring (index + 1);
				else if (isAttr)
					colName = colName.Substring (1);

				colName = XmlConvert.DecodeName (colName);
				DataColumn col = dt.Columns [colName];
				if (col == null)
					throw new DataException (String.Format ("Invalid XPath selection inside field. Cannot find: {0}", tableName));
				if (isAttr && col.ColumnMapping != MappingType.Attribute)
					throw new DataException ("The XPath specified attribute field, but mapping type is not attribute.");
				if (!isAttr && col.ColumnMapping != MappingType.Element)
					throw new DataException ("The XPath specified simple element field, but mapping type is not simple element.");

				cols [i] = dt.Columns [colName];
				i++;
			}
			
			bool isPK = false;
			// find if there is an attribute with the constraint name
			// if not use the XmlSchemaConstraint's name.
			string constraintName = ic.Name;
			if (ic.UnhandledAttributes != null) {
				foreach (XmlAttribute attr in ic.UnhandledAttributes) {
					if (attr.NamespaceURI != XmlConstants.MsdataNamespace)
						continue;
					switch (attr.LocalName) {
					case XmlConstants.ConstraintName:
						constraintName = attr.Value;
						break;
					case XmlConstants.PrimaryKey:
						isPK = bool.Parse(attr.Value);
						break;
					}
				}
			}
			UniqueConstraint c = new UniqueConstraint (constraintName, cols, isPK);
			dt.Constraints.Add (c);
		}
Ejemplo n.º 14
0
		private void EndKeyrefValidation (XsdKeyTable seq, XmlSchemaIdentityConstraint targetIdent)
		{
			for (int i = this.keyTables.Count - 1; i >= 0; i--) {
				XsdKeyTable target = this.keyTables [i] as XsdKeyTable;
				if (target.SourceSchemaIdentity != targetIdent)
					continue;
				seq.ReferencedKey = target;
				for (int j = 0; j < seq.FinishedEntries.Count; j++) {
					XsdKeyEntry entry = (XsdKeyEntry) seq.FinishedEntries [j];
					for (int k = 0; k < target.FinishedEntries.Count; k++) {
						XsdKeyEntry targetEntry = (XsdKeyEntry) target.FinishedEntries [k];
						if (entry.CompareIdentity (targetEntry)) {
							entry.KeyRefFound = true;
							break;
						}
					}
				}
			}
			if (seq.ReferencedKey == null)
				HandleError ("Target key was not found.");
			ArrayList errors = null;
			for (int i = 0; i < seq.FinishedEntries.Count; i++) {
				XsdKeyEntry entry = (XsdKeyEntry) seq.FinishedEntries [i];
				if (!entry.KeyRefFound) {
					if (errors == null)
						errors = new ArrayList ();
					errors.Add (" line " + entry.SelectorLineNumber + ", position " + entry.SelectorLinePosition);
				}
			}
			if (errors != null)
				HandleError ("Invalid identity constraints were found. Referenced key was not found: "
					+ String.Join (" / ", errors.ToArray (typeof (string)) as string []));
		}
Ejemplo n.º 15
0
        private void PreprocessIdentityConstraint(XmlSchemaIdentityConstraint constraint) {
            bool valid = true;
            if (constraint.Name != null) {
                ValidateNameAttribute(constraint);
                constraint.SetQualifiedName(new XmlQualifiedName(constraint.Name, this.targetNamespace));
            }
            else {
                SendValidationEvent(Res.Sch_MissRequiredAttribute, "name", constraint);
                valid = false;
            }

            if (this.identityConstraints[constraint.QualifiedName] != null) {
                SendValidationEvent(Res.Sch_DupIdentityConstraint, constraint.QualifiedName.ToString(), constraint);
                valid = false;
            }
            else {
                this.identityConstraints.Add(constraint.QualifiedName, constraint);
            }

            if (constraint.Selector == null) {
                SendValidationEvent(Res.Sch_IdConstraintNoSelector, constraint);
                valid = false;
            }
            if (constraint.Fields.Count == 0) {
                SendValidationEvent(Res.Sch_IdConstraintNoFields, constraint);
                valid = false;
            }
            if (constraint is XmlSchemaKeyref) {
                XmlSchemaKeyref keyref = (XmlSchemaKeyref)constraint;
                if (keyref.Refer.IsEmpty) {
                    SendValidationEvent(Res.Sch_IdConstraintNoRefer, constraint);
                    valid = false;
                }
                else {
                    ValidateQNameAttribute(keyref, "refer", keyref.Refer);
                }
            }
            if (valid) {
                ValidateIdAttribute(constraint);
                ValidateIdAttribute(constraint.Selector);
                foreach (XmlSchemaXPath field in constraint.Fields) {
                    ValidateIdAttribute(field);
                }
            }
        }
 private void Write48_XmlSchemaIdentityConstraint(XmlSchemaIdentityConstraint o)
 {
     if (o != null)
     {
         Type type = o.GetType();
         if (type == typeof(XmlSchemaUnique))
         {
             this.Write51_XmlSchemaUnique((XmlSchemaUnique) o);
         }
         else if (type == typeof(XmlSchemaKeyref))
         {
             this.Write50_XmlSchemaKeyref((XmlSchemaKeyref) o);
         }
         else if (type == typeof(XmlSchemaKey))
         {
             this.Write47_XmlSchemaKey((XmlSchemaKey) o);
         }
     }
 }
Ejemplo n.º 17
0
        protected virtual void Visit(XmlSchemaIdentityConstraint constraint)
        {
            XmlSchemaKey key;
            XmlSchemaKeyref keyref;
            XmlSchemaUnique unique;

            if (Casting.TryCast(constraint, out key))
                Visit(key);
            else if (Casting.TryCast(constraint, out keyref))
                Visit(keyref);
            else if (Casting.TryCast(constraint, out unique))
                Visit(unique);
            else
                throw ExceptionBuilder.UnexpectedSchemaObjectType(constraint);
        }
 public ConstraintTable(DataTable t, XmlSchemaIdentityConstraint c)
 {
     this.table = t;
     this.constraint = c;
 }
Ejemplo n.º 19
0
		public virtual void Check (ConformanceCheckContext ctx, XmlSchemaIdentityConstraint value) {}
Ejemplo n.º 20
0
		public XsdKeyTable (XmlSchemaIdentityConstraint source)
		{
			Reset (source);
		}
Ejemplo n.º 21
0
 internal DataColumn[] BuildKey(XmlSchemaIdentityConstraint keyNode, DataTable table){
     ArrayList keyColumns = new ArrayList();
  
     foreach (XmlSchemaXPath node in keyNode.Fields) {
         keyColumns.Add(FindField(table, node.XPath));
     }
  
     DataColumn [] key = new DataColumn[keyColumns.Count];
     keyColumns.CopyTo(key, 0);
   
     return key;
 } 
Ejemplo n.º 22
0
        private void PreprocessIdentityConstraint(XmlSchemaIdentityConstraint constraint) {
            bool valid = true;
            PreprocessAnnotation(constraint); //Set parent of annotation child of key/keyref/unique
            if (constraint.Name != null) {
                ValidateNameAttribute(constraint);
                constraint.SetQualifiedName(new XmlQualifiedName(constraint.Name, this.targetNamespace));
            }
            else {
                SendValidationEvent(Res.Sch_MissRequiredAttribute, "name", constraint);
                valid = false;
            }

            if (rootSchema.IdentityConstraints[constraint.QualifiedName] != null) {
                SendValidationEvent(Res.Sch_DupIdentityConstraint, constraint.QualifiedName.ToString(), constraint);
                valid = false;
            }
            else {
                rootSchema.IdentityConstraints.Add(constraint.QualifiedName, constraint);
            }

            if (constraint.Selector == null) {
                SendValidationEvent(Res.Sch_IdConstraintNoSelector, constraint);
                valid = false;
            }
            if (constraint.Fields.Count == 0) {
                SendValidationEvent(Res.Sch_IdConstraintNoFields, constraint);
                valid = false;
            }
            if (constraint is XmlSchemaKeyref) {
                XmlSchemaKeyref keyref = (XmlSchemaKeyref)constraint;
                if (keyref.Refer.IsEmpty) {
                    SendValidationEvent(Res.Sch_IdConstraintNoRefer, constraint);
                    valid = false;
                }
                else {
                    ValidateQNameAttribute(keyref, "refer", keyref.Refer);
                }
            }
            if (valid) {
                ValidateIdAttribute(constraint);
                ValidateIdAttribute(constraint.Selector);
                SetParent(constraint.Selector, constraint);
                for (int i = 0; i < constraint.Fields.Count; ++i) {
                    SetParent(constraint.Fields[i], constraint);
                    ValidateIdAttribute(constraint.Fields[i]);
                }
            }
        }
Ejemplo n.º 23
0
        internal void HandleConstraint(XmlSchemaIdentityConstraint keyNode){
            String name = null;
            
            name = XmlConvert.DecodeName(keyNode.Name);
            if (name==null || name.Length==0)
                throw ExceptionBuilder.MissingAttribute(Keywords.NAME);

            if (ConstraintNodes.ContainsKey(name))
                throw ExceptionBuilder.DuplicateConstraintRead(name);

            // we do not process key defined outside the current node
            String tableName = GetTableName(keyNode);
            string tableNs = GetMsdataAttribute(keyNode,Keywords.MSD_TABLENS);
            
            DataTable table =  _ds.Tables.GetTableSmart(tableName,tableNs);

            if (table == null)
                return;

            ConstraintNodes.Add(name, new ConstraintTable(table, keyNode));

            bool   fPrimaryKey = GetBooleanAttribute(keyNode, Keywords.MSD_PRIMARYKEY,  /*default:*/ false);
            name        = GetStringAttribute(keyNode, "ConstraintName", /*default:*/ name);



            DataColumn[] key = BuildKey(keyNode, table);

            if (0 < key.Length) {
                UniqueConstraint found = (UniqueConstraint) key[0].Table.Constraints.FindConstraint(new UniqueConstraint(name, key));

                if (found == null) {
                    key[0].Table.Constraints.Add(name, key, fPrimaryKey);
                    SetExtProperties(key[0].Table.Constraints[name], keyNode.UnhandledAttributes);
                }
                else {
                        key = found.ColumnsReference;
                        SetExtProperties(found, keyNode.UnhandledAttributes);
                        if (fPrimaryKey)
                            key[0].Table.PrimaryKey = key;
                    }
                if (keyNode is XmlSchemaKey) {
                    for (int i=0; i<key.Length; i++)
                        key[i].AllowDBNull = false;
                }
            }
        }
Ejemplo n.º 24
0
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
Ejemplo n.º 25
0
        private String GetTableNamespace(XmlSchemaIdentityConstraint key) {
            string xpath = key.Selector.XPath;
            string [] split = xpath.Split('/');
            string prefix =string.Empty;
            
            string QualifiedTableName = split[split.Length - 1]; //get the last string after '/' and ':'
            
            if ((QualifiedTableName == null) || (QualifiedTableName.Length == 0))
                throw ExceptionBuilder.InvalidSelector(xpath);

            if (QualifiedTableName.IndexOf(':') != -1)
                prefix = QualifiedTableName.Substring(0, QualifiedTableName.IndexOf(':'));
            else
                return GetMsdataAttribute(key, Keywords.MSD_TABLENS);

            prefix  = XmlConvert.DecodeName(prefix );

            return GetNamespaceFromPrefix(prefix);
        }
 private void CompileIdentityConstraint(XmlSchemaIdentityConstraint xi)
 {
     if (xi.IsProcessing)
     {
         xi.CompiledConstraint = CompiledIdentityConstraint.Empty;
         base.SendValidationEvent("Sch_IdentityConstraintCircularRef", xi);
     }
     else if (xi.CompiledConstraint == null)
     {
         xi.IsProcessing = true;
         CompiledIdentityConstraint constraint = null;
         try
         {
             SchemaNamespaceManager nsmgr = new SchemaNamespaceManager(xi);
             constraint = new CompiledIdentityConstraint(xi, nsmgr);
             if (xi is XmlSchemaKeyref)
             {
                 XmlSchemaIdentityConstraint constraint2 = (XmlSchemaIdentityConstraint) this.schema.IdentityConstraints[((XmlSchemaKeyref) xi).Refer];
                 if (constraint2 == null)
                 {
                     throw new XmlSchemaException("Sch_UndeclaredIdentityConstraint", ((XmlSchemaKeyref) xi).Refer.ToString(), xi);
                 }
                 this.CompileIdentityConstraint(constraint2);
                 if (constraint2.CompiledConstraint == null)
                 {
                     throw new XmlSchemaException("Sch_RefInvalidIdentityConstraint", ((XmlSchemaKeyref) xi).Refer.ToString(), xi);
                 }
                 if (constraint2.Fields.Count != xi.Fields.Count)
                 {
                     throw new XmlSchemaException("Sch_RefInvalidCardin", xi.QualifiedName.ToString(), xi);
                 }
                 if (constraint2.CompiledConstraint.Role == CompiledIdentityConstraint.ConstraintRole.Keyref)
                 {
                     throw new XmlSchemaException("Sch_ReftoKeyref", xi.QualifiedName.ToString(), xi);
                 }
             }
             xi.CompiledConstraint = constraint;
         }
         catch (XmlSchemaException exception)
         {
             if (exception.SourceSchemaObject == null)
             {
                 exception.SetSource(xi);
             }
             base.SendValidationEvent(exception);
             xi.CompiledConstraint = CompiledIdentityConstraint.Empty;
         }
         finally
         {
             xi.IsProcessing = false;
         }
     }
 }
Ejemplo n.º 27
0
 private String GetTableName(XmlSchemaIdentityConstraint key) {
     string xpath = key.Selector.XPath;
     string [] split = xpath.Split('/',':');
     String tableName = split[split.Length - 1]; //get the last string after '/' and ':'
     
     if ((tableName == null) || (tableName.Length == 0))
         throw ExceptionBuilder.InvalidSelector(xpath);
         
     tableName = XmlConvert.DecodeName(tableName);
     return tableName;            
 }
 private void PreprocessIdentityConstraint(XmlSchemaIdentityConstraint constraint)
 {
     bool flag = true;
     this.PreprocessAnnotation(constraint);
     if (constraint.Name != null)
     {
         this.ValidateNameAttribute(constraint);
         constraint.SetQualifiedName(new XmlQualifiedName(constraint.Name, this.targetNamespace));
     }
     else
     {
         base.SendValidationEvent("Sch_MissRequiredAttribute", "name", constraint);
         flag = false;
     }
     if (this.rootSchema.IdentityConstraints[constraint.QualifiedName] != null)
     {
         base.SendValidationEvent("Sch_DupIdentityConstraint", constraint.QualifiedName.ToString(), constraint);
         flag = false;
     }
     else
     {
         this.rootSchema.IdentityConstraints.Add(constraint.QualifiedName, constraint);
     }
     if (constraint.Selector == null)
     {
         base.SendValidationEvent("Sch_IdConstraintNoSelector", constraint);
         flag = false;
     }
     if (constraint.Fields.Count == 0)
     {
         base.SendValidationEvent("Sch_IdConstraintNoFields", constraint);
         flag = false;
     }
     if (constraint is XmlSchemaKeyref)
     {
         XmlSchemaKeyref xso = (XmlSchemaKeyref) constraint;
         if (xso.Refer.IsEmpty)
         {
             base.SendValidationEvent("Sch_IdConstraintNoRefer", constraint);
             flag = false;
         }
         else
         {
             this.ValidateQNameAttribute(xso, "refer", xso.Refer);
         }
     }
     if (flag)
     {
         this.ValidateIdAttribute(constraint);
         this.ValidateIdAttribute(constraint.Selector);
         this.SetParent(constraint.Selector, constraint);
         for (int i = 0; i < constraint.Fields.Count; i++)
         {
             this.SetParent(constraint.Fields[i], constraint);
             this.ValidateIdAttribute(constraint.Fields[i]);
         }
     }
 }
 private string GetTableName(XmlSchemaIdentityConstraint key)
 {
     string xPath = key.Selector.XPath;
     string[] strArray = xPath.Split(new char[] { '/', ':' });
     string name = strArray[strArray.Length - 1];
     if ((name == null) || (name.Length == 0))
     {
         throw ExceptionBuilder.InvalidSelector(xPath);
     }
     return XmlConvert.DecodeName(name);
 }