KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > ElemAttributeSet


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ElemAttributeSet.java,v 1.14 2004/02/16 20:32:32 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22
23 import org.apache.xalan.res.XSLMessages;
24 import org.apache.xalan.res.XSLTErrorResources;
25 import org.apache.xalan.transformer.TransformerImpl;
26 import org.apache.xml.utils.QName;
27
28 /**
29  * Implement xsl:attribute-set.
30  * <pre>
31  * &amp;!ELEMENT xsl:attribute-set (xsl:attribute)*>
32  * &amp;!ATTLIST xsl:attribute-set
33  * name %qname; #REQUIRED
34  * use-attribute-sets %qnames; #IMPLIED
35  * &amp;
36  * </pre>
37  * @see <a HREF="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
38  * @xsl.usage advanced
39  */

40 public class ElemAttributeSet extends ElemUse
41 {
42
43   /**
44    * The name attribute specifies the name of the attribute set.
45    * @serial
46    */

47   public QName m_qname = null;
48
49   /**
50    * Set the "name" attribute.
51    * The name attribute specifies the name of the attribute set.
52    *
53    * @param name Name attribute to set
54    */

55   public void setName(QName name)
56   {
57     m_qname = name;
58   }
59
60   /**
61    * Get the "name" attribute.
62    * The name attribute specifies the name of the attribute set.
63    *
64    * @return The name attribute of the attribute set
65    */

66   public QName getName()
67   {
68     return m_qname;
69   }
70
71   /**
72    * Get an int constant identifying the type of element.
73    * @see org.apache.xalan.templates.Constants
74    *
75    * @return Token ID of the element
76    */

77   public int getXSLToken()
78   {
79     return Constants.ELEMNAME_DEFINEATTRIBUTESET;
80   }
81
82   /**
83    * Return the node name.
84    *
85    * @return The name of this element
86    */

87   public String JavaDoc getNodeName()
88   {
89     return Constants.ELEMNAME_ATTRIBUTESET_STRING;
90   }
91
92   /**
93    * Apply a set of attributes to the element.
94    *
95    * @param transformer non-null reference to the the current transform-time state.
96    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
97    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
98    *
99    * @throws TransformerException
100    */

101   public void execute(
102           TransformerImpl transformer)
103             throws TransformerException JavaDoc
104   {
105
106     if (TransformerImpl.S_DEBUG)
107       transformer.getTraceManager().fireTraceEvent(this);
108
109     if (transformer.isRecursiveAttrSet(this))
110     {
111       throw new TransformerException JavaDoc(
112         XSLMessages.createMessage(
113           XSLTErrorResources.ER_XSLATTRSET_USED_ITSELF,
114           new Object JavaDoc[]{ m_qname.getLocalPart() })); //"xsl:attribute-set '"+m_qname.m_localpart+
115
}
116
117     transformer.pushElemAttributeSet(this);
118     super.execute(transformer);
119
120     ElemAttribute attr = (ElemAttribute) getFirstChildElem();
121
122     while (null != attr)
123     {
124       attr.execute(transformer);
125
126       attr = (ElemAttribute) attr.getNextSiblingElem();
127     }
128
129     transformer.popElemAttributeSet();
130    
131     if (TransformerImpl.S_DEBUG)
132       transformer.getTraceManager().fireTraceEndEvent(this);
133
134   }
135
136   /**
137    * Add a child to the child list.
138    * <!ELEMENT xsl:attribute-set (xsl:attribute)*>
139    * <!ATTLIST xsl:attribute-set
140    * name %qname; #REQUIRED
141    * use-attribute-sets %qnames; #IMPLIED
142    * >
143    *
144    * @param newChild Child to be added to this node's list of children
145    *
146    * @return The child that was just added to the list of children
147    *
148    * @throws DOMException
149    */

150   public ElemTemplateElement appendChildElem(ElemTemplateElement newChild)
151   {
152
153     int type = ((ElemTemplateElement) newChild).getXSLToken();
154
155     switch (type)
156     {
157     case Constants.ELEMNAME_ATTRIBUTE :
158       break;
159     default :
160       error(XSLTErrorResources.ER_CANNOT_ADD,
161             new Object JavaDoc[]{ newChild.getNodeName(),
162                           this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
163

164     //" to " + this.m_elemName);
165
}
166
167     return super.appendChild(newChild);
168   }
169
170   /**
171    * This function is called during recomposition to
172    * control how this element is composed.
173    * @param root The root stylesheet for this transformation.
174    */

175   public void recompose(StylesheetRoot root)
176   {
177     root.recomposeAttributeSets(this);
178   }
179
180 }
181
Popular Tags