KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > style > XSLAttributeSet


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.om.Name;
5 import com.icl.saxon.om.NamespaceException;
6
7 import com.icl.saxon.handlers.*;
8 import com.icl.saxon.expr.*;
9
10 import org.w3c.dom.Node JavaDoc;
11 import javax.xml.transform.*;
12
13
14 /**
15 * An xsl:attribute-set element in the stylesheet.<BR>
16 */

17
18 public class XSLAttributeSet extends StyleElement {
19
20     int fingerprint; // the name of this attribute set, as a Name object
21
String JavaDoc use; // the value of the use-attribute-sets attribute, as supplied
22
Procedure procedure = new Procedure(); // needed if there are variables
23

24     public int getAttributeSetFingerprint() {
25         return fingerprint;
26     }
27
28     public void prepareAttributes() throws TransformerConfigurationException {
29
30         String JavaDoc name = null;
31         use = null;
32         
33         StandardNames sn = getStandardNames();
34         AttributeCollection atts = getAttributeList();
35         
36         for (int a=0; a<atts.getLength(); a++) {
37             int nc = atts.getNameCode(a);
38             int f = nc & 0xfffff;
39             if (f==sn.NAME) {
40                 name = atts.getValue(a);
41             } else if (f==sn.USE_ATTRIBUTE_SETS) {
42                 use = atts.getValue(a);
43             } else {
44                 checkUnknownAttribute(nc);
45             }
46         }
47
48         if (name==null) {
49             reportAbsence("name");
50             return;
51         }
52         
53         if (!Name.isQName(name)) {
54             compileError("Attribute set name must be a valid QName");
55         }
56         
57         try {
58             fingerprint = makeNameCode(name, false) & 0xfffff;
59         } catch (NamespaceException err) {
60             compileError(err.getMessage());
61         }
62
63     }
64
65     public void validate() throws TransformerConfigurationException {
66         checkTopLevel();
67
68         Node JavaDoc child = getFirstChild();
69         while (child!=null) {
70             if (!(child instanceof XSLAttribute)) {
71                 compileError("Only xsl:attribute is allowed within xsl:attribute-set");
72             }
73             child = child.getNextSibling();
74         }
75
76         if (use!=null) {
77             findAttributeSets(use); // identify any attribute sets that this one refers to
78
}
79     }
80
81     /**
82     * Get associated Procedure (for details of stack frame)
83     */

84
85     public Procedure getProcedure() {
86         return procedure;
87     }
88
89     public void preprocess() throws TransformerConfigurationException {
90         getPrincipalStyleSheet().allocateLocalSlots(procedure.getNumberOfVariables());
91     }
92
93     public void process(Context context) throws TransformerException {
94
95         // do nothing until the attribute set is expanded
96
}
97
98     public void expand(Context context) throws TransformerException {
99         processAttributeSets(context);
100         if (procedure.getNumberOfVariables()==0) {
101             processChildren(context);
102         } else {
103             Bindery bindery = context.getController().getBindery();
104             bindery.openStackFrame(null);
105             processChildren(context);
106             bindery.closeStackFrame();
107         }
108     }
109
110 }
111
112 //
113
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
114
// you may not use this file except in compliance with the License. You may obtain a copy of the
115
// License at http://www.mozilla.org/MPL/
116
//
117
// Software distributed under the License is distributed on an "AS IS" basis,
118
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
119
// See the License for the specific language governing rights and limitations under the License.
120
//
121
// The Original Code is: all this file.
122
//
123
// The Initial Developer of the Original Code is
124
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
125
//
126
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
127
//
128
// Contributor(s): none.
129
//
130
Popular Tags