public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs)
            {
                System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
                System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
                Dataset1 ds = new Dataset1();

                xs.Add(ds.GetSchemaSerializable());
                System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "ProductsDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                return(type);
            }
Exemple #2
0
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            ParentChildDataSet ds = new ParentChildDataSet();

            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            xs.Add(ds.GetSchemaSerializable());
            if (PublishLegacyWSDL())
            {
                System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
                any.Namespace = ds.Namespace;
                sequence.Items.Add(any);
            }
            else
            {
                System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(0);
                any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                sequence.MaxOccurs = decimal.MaxValue;
                System.Xml.Schema.XmlSchemaAttribute attribute = new System.Xml.Schema.XmlSchemaAttribute();
                attribute.Name       = "namespace";
                attribute.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute);
            }
            type.Particle = sequence;
            return(type);
        }
        /// <summary>
        /// Load the schema attribute
        /// </summary>
        /// <param name="a">The attribute to load</param>
        public void Load(System.Xml.Schema.XmlSchemaAttribute a)
        {
            base.Load(a);

            // First setup name, optionality, etc.
            this.Name       = a.Name;
            this.Namespace  = a.QualifiedName != null ? a.QualifiedName.Namespace : Schema.TargetNamespace;
            this.Required   = (a.Use == System.Xml.Schema.XmlSchemaUse.Required);
            this.prohibited = (a.Use == System.Xml.Schema.XmlSchemaUse.Prohibited);
            this.fixedValue = a.FixedValue;

            // Setup the type
            //this.attType = System.Xml.Schema.XmlSchemaType. a.SchemaTypeName.Name
            if (!a.SchemaTypeName.IsEmpty)
            {
                this.attType = Schema.FindType(a.SchemaTypeName.Name) as XmlSchemaSimpleType;
            }
            else
            {
                // Look for a built in type

                SchemaType = new XmlSchemaSimpleType(Schema, this);
                SchemaType.Load(a.SchemaType);
            }
        }
        /// <summary> Tells if the attribute can take any object (easier to write/maintain and compile-time checking). </summary>
        public static bool IsSystemObject(string parentEltName, System.Xml.Schema.XmlSchemaAttribute attribMember, string attribType)
        {
            if (attribType != "System.String")
            {
                return(false);
            }

            return(attribMember.Name == "unsaved-value" ||
                   IsSystemEnum(parentEltName, attribMember, attribType));
        }
        /// <summary> Tells if the attribute's type must be convert to System.Type (easier to write/maintain and compile-time checking). </summary>
        public static bool IsSystemType(string parentEltName, System.Xml.Schema.XmlSchemaAttribute attribMember, string attribType)
        {
            if (attribType != "System.String")
            {
                return(false);
            }

            if (attribMember.Name == "name" || attribMember.Name == "proxy")
            {
                return(parentEltName == "class" || parentEltName == "subclass" ||
                       parentEltName == "joined-subclass" || parentEltName == "union-subclass" || parentEltName == "type");
            }

            if (attribMember.Name == "extends")
            {
                return(parentEltName == "subclass" || parentEltName == "joined-subclass" || parentEltName == "union-subclass");
            }

            // Note : Easier to write and it can't hurt :D (and ATM they are all System.Type)
            if (attribMember.Name == "access" || attribMember.Name == "default-access" ||
                attribMember.Name == "extends" || attribMember.Name == "id-type" ||
                attribMember.Name == "meta-type" || attribMember.Name == "persister" ||
                attribMember.Name == "collection-type")
            {
                return(true);
            }

            if (attribMember.Name == "class")
            {
                return(parentEltName == "component" || parentEltName == "composite-element" || parentEltName == "composite-id" ||
                       parentEltName == "composite-index" || parentEltName == "index-many-to-many" || parentEltName == "key-many-to-one" ||
                       parentEltName == "many-to-many" || parentEltName == "many-to-one" || parentEltName == "meta-value" ||
                       parentEltName == "nested-composite-element" || parentEltName == "one-to-many" || parentEltName == "one-to-one" ||
                       parentEltName == "import" || parentEltName == "definition" || parentEltName == "tuplizer");
            }

            if (attribMember.Name == "type")
            {
                return(parentEltName == "collection-id" || parentEltName == "discriminator" || parentEltName == "element" ||
                       parentEltName == "id" || parentEltName == "index" || parentEltName == "key-property" ||
                       parentEltName == "property" || parentEltName == "version");
            }

            if (attribMember.Name == "sort")
            {
                return(parentEltName == "map" || parentEltName == "set");
            }

            return(false);            // Default
        }
Exemple #6
0
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs) {
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     IBDataset ds = new IBDataset();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
     any1.Namespace = "http://www.w3.org/2001/XMLSchema";
     any1.MinOccurs = new decimal(0);
     any1.MaxOccurs = decimal.MaxValue;
     any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any1);
     System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
     any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     any2.MinOccurs = new decimal(1);
     any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any2);
     System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute1.Name = "namespace";
     attribute1.FixedValue = ds.Namespace;
     type.Attributes.Add(attribute1);
     System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute2.Name = "tableTypeName";
     attribute2.FixedValue = "SPR_TOVDataTable";
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     return type;
 }
Exemple #7
0
		private void AssessAttributeLocallyValidUse (XsAttribute attr)
		{
			// This is extra check than spec 3.5.4
			if (attr.ValidatedUse == XmlSchemaUse.Prohibited)
				HandleError ("Attribute " + attr.QualifiedName + " is prohibited in this context.");
		}
Exemple #8
0
		// 3.2.4 Attribute Locally Valid and 3.4.4
		private object AssessAttributeLocallyValid (XsAttribute attr, XmlSchemaInfo info, XmlValueGetter getter)
		{
			if (info != null) {
				info.SchemaAttribute = attr;
				info.SchemaType = attr.AttributeSchemaType;
			}

			// 2. - 4.
			if (attr.AttributeType == null)
				HandleError ("Attribute type is missing for " + attr.QualifiedName);
			XsDatatype dt = attr.AttributeType as XsDatatype;
			if (dt == null)
				dt = ((SimpleType) attr.AttributeType).Datatype;

			object parsedValue = null;

			// It is a bit heavy process, so let's omit as long as possible ;-)
			if (dt != SimpleType.AnySimpleType || attr.ValidatedFixedValue != null) {
				try {
					CurrentAttributeType = dt;
					parsedValue = getter ();
				} catch (Exception ex) { // It is inevitable and bad manner.
					HandleError (String.Format ("Attribute value is invalid against its data type {0}", dt != null ? dt.TokenizedType : default (XmlTokenizedType)), ex);
				}

				// check part of 3.14.4 StringValid
				SimpleType st = attr.AttributeSchemaType;
				if (st != null) {
					string xav = null;
					try {
						xav = new XmlAtomicValue (parsedValue, attr.AttributeSchemaType).Value;
					} catch (Exception ex) {
						HandleError (String.Format ("Failed to convert attribute value to type {0}", st.QualifiedName), ex);
					}
					if (xav != null)
						ValidateRestrictedSimpleTypeValue (st, ref dt, xav);
				}

				if (attr.ValidatedFixedValue != null) {
					if (!XmlSchemaUtil.AreSchemaDatatypeEqual (attr.AttributeSchemaType, attr.ValidatedFixedTypedValue, attr.AttributeSchemaType, parsedValue))
						HandleError (String.Format ("The value of the attribute {0} does not match with its fixed value '{1}' in the space of type {2}", attr.QualifiedName, attr.ValidatedFixedValue, dt));
					parsedValue = attr.ValidatedFixedTypedValue;
				}
			}

#region ID Constraints
			if (!IgnoreIdentity) {
				string error = idManager.AssessEachAttributeIdentityConstraint (dt, parsedValue, ((QName) elementQNameStack [elementQNameStack.Count - 1]).Name);
				if (error != null)
					HandleError (error);
			}
#endregion

#region Key Constraints
			if (!IgnoreIdentity)
				ValidateKeyFieldsAttribute (attr, parsedValue);
#endregion

			return parsedValue;
		}
Exemple #9
0
		private void ValidateKeyFieldsAttribute (XsAttribute attr, object value)
		{
			ValidateKeyFields (true, false, attr.AttributeType, attr.QualifiedName.Name, attr.QualifiedName.Namespace, value);
		}
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs) {
     NorthwindDataSet ds = new NorthwindDataSet();
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     xs.Add(ds.GetSchemaSerializable());
     if (PublishLegacyWSDL()) {
         System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
         any.Namespace = ds.Namespace;
         sequence.Items.Add(any);
     }
     else {
         System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
         any1.Namespace = "http://www.w3.org/2001/XMLSchema";
         any1.MinOccurs = new decimal(0);
         any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
         sequence.Items.Add(any1);
         System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
         any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
         any2.MinOccurs = new decimal(0);
         any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
         sequence.Items.Add(any2);
         sequence.MaxOccurs = decimal.MaxValue;
         System.Xml.Schema.XmlSchemaAttribute attribute = new System.Xml.Schema.XmlSchemaAttribute();
         attribute.Name = "namespace";
         attribute.FixedValue = ds.Namespace;
         type.Attributes.Add(attribute);
     }
     type.Particle = sequence;
     return type;
 }
        /// <summary> Return the C# type of this XmlSchemaAttribute. </summary>
        public static string GetAttributeTypeName(System.Xml.Schema.XmlSchemaElement parentElt, System.Xml.Schema.XmlSchemaAttribute attrib)
        {
            string attribTypeName = attrib.SchemaTypeName.Name;

            switch (attribTypeName)
            {
            case "":                      // => Dynamically generated enumeration
                return(Capitalize(parentElt.Name)
                       + Capitalize(attrib.Name));

            case "boolean": return("System.Boolean");

            case "int": return("System.Int64");

            case "nonNegativeInteger":
            case "positiveInteger": return("System.Int32");

            case "string": return("System.String");

            default:
                if (!KnowEnums.Contains(attribTypeName) && attribTypeName.Length > 0)
                {
                    log.Warn("\n\nUnknow TYPE (can be an enum): " + attribTypeName + "\n\n");
                }
                return(Program.Conformer.ToCapitalized(attribTypeName));
            }
        }
        /// <summary> Returns the unspecified value of the type of this attribute. </summary>
        public static string GetUnspecifiedValue(System.Xml.Schema.XmlSchemaElement parentElt, System.Xml.Schema.XmlSchemaAttribute attrib)
        {
            // The unspecified value is used to know if the user set a value
            // (in this case, we should write it; even if it is the default value)
            switch (attrib.SchemaTypeName.Name)
            {
            case "boolean": return(attrib.DefaultValue == null ? "false" : attrib.DefaultValue); // This value is meaningless because of its "bool XXXIsSpecified" property

            case "int": return(long.MinValue.ToString());                                        // Use a value outside the range of integers

            case "nonNegativeInteger":
            case "positiveInteger": return("-1");                     // value should be positive (so we can use -1 as unspecified value)

            case "string": return("null");

            default:                     // => Treat it as Enumeration
                return(GetAttributeTypeName(parentElt, attrib) + ".Unspecified");
            }
        }
 /// <summary> Tells if the attribute's type must be convert from a System.Enum value (easier to write/maintain and compile-time checking). </summary>
 public static bool IsSystemEnum(string parentEltName, System.Xml.Schema.XmlSchemaAttribute attribMember, string attribType)
 {
     return(attribMember.Name == "discriminator-value");
 }
Exemple #14
0
        private static string AttributeToXmlValue(System.Xml.Schema.XmlSchemaElement schemaElt, System.Xml.Schema.XmlSchemaAttribute attrib, string attribName, bool isRoot)
        {
            string fieldType = Utils.GetAttributeTypeName(schemaElt, attrib);
            string val       = "attribute." + Utils.Capitalize(attribName);

            switch (fieldType)
            {
            case "System.Boolean": return(val + " ? \"true\" : \"false\"");

            case "System.Int32": return(val + ".ToString()");

            case "System.Int64": return(val + ".ToString()");

            case "System.String": return("GetAttributeValue(" + val + (isRoot? ", type)" : ", mappedClass)"));

            default:                     // => Enum
                return("GetXmlEnumValue(typeof(" + fieldType + "), " + val + ")");
            }
        }