compliance work: attribset
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl / XslAttributeSet.cs
1 //
2 // XslAttributeSet.cs
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //      Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 //      
8 // (C) 2003 Ben Maurer
9 // (C) 2003 Atsushi Enomoto
10 //
11
12 using System;
13 using System.CodeDom;
14 using System.Collections;
15 using System.Collections.Specialized;
16 using System.Xml;
17 using System.Xml.Schema;
18 using System.Xml.XPath;
19 using System.Xml.Xsl;
20 using Mono.Xml.Xsl.Operations;
21
22 using QName = System.Xml.XmlQualifiedName;
23
24 namespace Mono.Xml.Xsl {
25         public class XslAttributeSet : XslCompiledElement {
26                 QName name;
27                 // [QName]=>XslAttributeSet
28                 ArrayList usedAttributeSets = new ArrayList ();
29                 
30                 // [QName]=>XslAttribute
31                 ArrayList attributes = new ArrayList ();
32                 
33                 public XslAttributeSet (Compiler c) : base (c) {}
34                 
35                 public QName Name {
36                         get { return name; }
37                 }
38
39                 protected override void Compile (Compiler c)
40                 {
41                         this.name = c.ParseQNameAttribute ("name");
42                         
43                         QName [] attrSets = c.ParseQNameListAttribute ("use-attribute-sets");
44                         if (attrSets != null)
45                                 foreach (QName q in c.ParseQNameListAttribute ("use-attribute-sets"))
46                                         usedAttributeSets.Add (q);
47
48                         
49                         if (!c.Input.MoveToFirstChild ()) return;
50                                 
51                         do {
52                                 if (c.Input.NodeType != XPathNodeType.Element) continue;
53                                         
54                                 if (c.Input.NamespaceURI != XsltNamespace || c.Input.LocalName != "attribute")
55                                         throw new Exception ("Invalid attr set content");
56                                 attributes.Add (new XslAttribute (c));
57                         } while (c.Input.MoveToNext ());
58                         
59                         c.Input.MoveToParent ();
60                         
61                 }
62                 
63                 public void Merge (XslAttributeSet s)
64                 {
65                         attributes.AddRange (s.attributes);
66                         
67                         foreach (QName q in s.usedAttributeSets)
68                                 if (!usedAttributeSets.Contains (q))
69                                         usedAttributeSets.Add (q);
70                 }
71                 
72                 public override void Evaluate (XslTransformProcessor p) {
73                         p.SetBusy (this);
74                         
75                         if (usedAttributeSets != null) {
76                                 foreach (QName set in usedAttributeSets)
77                                 {
78                                         XslAttributeSet s = p.ResolveAttributeSet (set);
79                                         if (s == null)
80                                                 throw new Exception ("Could not resolve attribute set");
81                                         
82                                         if (p.IsBusy (s))
83                                                 throw new Exception ("circular dependency");
84                                         
85                                         s.Evaluate (p);
86                                 }
87                         }
88                                                 
89                         foreach (Operations.XslAttribute a in attributes)
90                                 a.Evaluate (p);
91                         
92                         p.SetFree (this);
93                 }
94         }
95 }