Removal of NET_1_1 defines and some NET_2_0; Both defines are true these days in...
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaCollection.cs
old mode 100755 (executable)
new mode 100644 (file)
index 033d527..e572e06
@@ -56,6 +56,7 @@ namespace System.Xml.Schema
                public XmlSchemaCollection (XmlNameTable nameTable)
                        : this (new XmlSchemaSet (nameTable))
                {
+                       schemaSet.ValidationEventHandler += new ValidationEventHandler (OnValidationError);
                }
 
                internal XmlSchemaCollection (XmlSchemaSet schemaSet)
@@ -98,23 +99,24 @@ namespace System.Xml.Schema
                        return Add (ns, reader, new XmlUrlResolver ());
                }
 
-#if NET_1_1
                public XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
-#else
-               internal XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
-#endif
                {
                        XmlSchema schema = XmlSchema.Read (reader, ValidationEventHandler);
-                       schema.Compile (ValidationEventHandler, schemaSet, resolver);
-                       lock (schemaSet) {
-                               return schemaSet.Add (schema);
-                       }
+                       if (schema.TargetNamespace == null)
+                               schema.TargetNamespace = ns;
+                       else if (ns != null && schema.TargetNamespace != ns)
+                               throw new XmlSchemaException ("The actual targetNamespace in the schema does not match the parameter.");
+
+                       return Add (schema);
                }
 
                public XmlSchema Add (string ns, string uri)
                {
-                       lock (schemaSet) {
-                               return schemaSet.Add (ns, uri);
+                       XmlReader reader = new XmlTextReader (uri);
+                       try {
+                               return Add (ns, reader);
+                       } finally {
+                               reader.Close ();
                        }
                }
 
@@ -128,18 +130,19 @@ namespace System.Xml.Schema
                        if (schema == null)
                                throw new ArgumentNullException ("schema");
 
-                       // XmlSchemaCollection.Add() compiles, while XmlSchemaSet.Add() does not
-                       if (!schema.IsCompiled)
-                               schema.Compile (ValidationEventHandler, schemaSet, resolver);
-                       // compilation error -> returns null (and don't add to the collection).
-                       if (!schema.IsCompiled)
-                               return null;
+                       XmlSchemaSet xss = new XmlSchemaSet (schemaSet.NameTable);
+                       xss.Add (schemaSet);
 
-                       lock (schemaSet) {
-                               // consider imported schemas.
-                               schemaSet.Add (schema.Schemas);
-                               return schema;
-                       }
+                       // FIXME: maybe it requires Reprocess()
+                       xss.Add (schema);
+                       xss.ValidationEventHandler += ValidationEventHandler;
+                       xss.XmlResolver = resolver;
+                       xss.Compile ();
+                       if (!xss.IsCompiled)
+                               return null;
+                       // It is set only when the compilation was successful.
+                       schemaSet = xss;
+                       return schema;
                }
 
                public void Add (XmlSchemaCollection schema)
@@ -147,9 +150,18 @@ namespace System.Xml.Schema
                        if (schema == null)
                                throw new ArgumentNullException ("schema");
 
-                       lock (schemaSet) {
-                               schemaSet.Add (schema.schemaSet);
-                       }
+                       XmlSchemaSet xss = new XmlSchemaSet (schemaSet.NameTable);
+                       xss.Add (schemaSet);
+
+                       // FIXME: maybe it requires Reprocess()
+                       xss.Add (schema.schemaSet);
+                       xss.ValidationEventHandler += ValidationEventHandler;
+                       xss.XmlResolver = schemaSet.XmlResolver;
+                       xss.Compile ();
+                       if (!xss.IsCompiled)
+                               return;
+                       // It is set only when the compilation was successful.
+                       schemaSet = xss;
                }
 
                public bool Contains (string ns)
@@ -179,6 +191,10 @@ namespace System.Xml.Schema
                        return new XmlSchemaCollectionEnumerator(schemaSet.Schemas());
                }
 
+               int ICollection.Count {
+                       get { return Count; }
+               }
+
                // interface Methods
                void ICollection.CopyTo (Array array, int index)
                {
@@ -202,7 +218,7 @@ namespace System.Xml.Schema
                        get { return this; }
                }
 
-               internal void OnValidationError (object o, ValidationEventArgs e)
+               void OnValidationError (object o, ValidationEventArgs e)
                {
                        if (ValidationEventHandler != null)
                                ValidationEventHandler (o, e);