001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: ElemAttributeSet.java,v 1.17 2005/01/23 00:27:29 mcnamara Exp $
018: */
019: package org.apache.xalan.templates;
020:
021: import javax.xml.transform.TransformerException;
022:
023: import org.apache.xalan.res.XSLMessages;
024: import org.apache.xalan.res.XSLTErrorResources;
025: import org.apache.xalan.transformer.TransformerImpl;
026: import org.apache.xml.utils.QName;
027:
028: /**
029: * Implement xsl:attribute-set.
030: * <pre>
031: * &!ELEMENT xsl:attribute-set (xsl:attribute)*>
032: * &!ATTLIST xsl:attribute-set
033: * name %qname; #REQUIRED
034: * use-attribute-sets %qnames; #IMPLIED
035: * &
036: * </pre>
037: * @see <a href="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
038: * @xsl.usage advanced
039: */
040: public class ElemAttributeSet extends ElemUse {
041: static final long serialVersionUID = -426740318278164496L;
042:
043: /**
044: * The name attribute specifies the name of the attribute set.
045: * @serial
046: */
047: public QName m_qname = null;
048:
049: /**
050: * Set the "name" attribute.
051: * The name attribute specifies the name of the attribute set.
052: *
053: * @param name Name attribute to set
054: */
055: public void setName(QName name) {
056: m_qname = name;
057: }
058:
059: /**
060: * Get the "name" attribute.
061: * The name attribute specifies the name of the attribute set.
062: *
063: * @return The name attribute of the attribute set
064: */
065: public QName getName() {
066: return m_qname;
067: }
068:
069: /**
070: * Get an int constant identifying the type of element.
071: * @see org.apache.xalan.templates.Constants
072: *
073: * @return Token ID of the element
074: */
075: public int getXSLToken() {
076: return Constants.ELEMNAME_DEFINEATTRIBUTESET;
077: }
078:
079: /**
080: * Return the node name.
081: *
082: * @return The name of this element
083: */
084: public String getNodeName() {
085: return Constants.ELEMNAME_ATTRIBUTESET_STRING;
086: }
087:
088: /**
089: * Apply a set of attributes to the element.
090: *
091: * @param transformer non-null reference to the the current transform-time state.
092: *
093: * @throws TransformerException
094: */
095: public void execute(TransformerImpl transformer)
096: throws TransformerException {
097:
098: if (transformer.getDebug())
099: transformer.getTraceManager().fireTraceEvent(this );
100:
101: if (transformer.isRecursiveAttrSet(this )) {
102: throw new TransformerException(XSLMessages.createMessage(
103: XSLTErrorResources.ER_XSLATTRSET_USED_ITSELF,
104: new Object[] { m_qname.getLocalPart() })); //"xsl:attribute-set '"+m_qname.m_localpart+
105: }
106:
107: transformer.pushElemAttributeSet(this );
108: super .execute(transformer);
109:
110: ElemAttribute attr = (ElemAttribute) getFirstChildElem();
111:
112: while (null != attr) {
113: attr.execute(transformer);
114:
115: attr = (ElemAttribute) attr.getNextSiblingElem();
116: }
117:
118: transformer.popElemAttributeSet();
119:
120: if (transformer.getDebug())
121: transformer.getTraceManager().fireTraceEndEvent(this );
122:
123: }
124:
125: /**
126: * Add a child to the child list.
127: * <!ELEMENT xsl:attribute-set (xsl:attribute)*>
128: * <!ATTLIST xsl:attribute-set
129: * name %qname; #REQUIRED
130: * use-attribute-sets %qnames; #IMPLIED
131: * >
132: *
133: * @param newChild Child to be added to this node's list of children
134: *
135: * @return The child that was just added to the list of children
136: *
137: * @throws DOMException
138: */
139: public ElemTemplateElement appendChildElem(
140: ElemTemplateElement newChild) {
141:
142: int type = ((ElemTemplateElement) newChild).getXSLToken();
143:
144: switch (type) {
145: case Constants.ELEMNAME_ATTRIBUTE:
146: break;
147: default:
148: error(XSLTErrorResources.ER_CANNOT_ADD, new Object[] {
149: newChild.getNodeName(), this .getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
150:
151: //" to " + this.m_elemName);
152: }
153:
154: return super .appendChild(newChild);
155: }
156:
157: /**
158: * This function is called during recomposition to
159: * control how this element is composed.
160: * @param root The root stylesheet for this transformation.
161: */
162: public void recompose(StylesheetRoot root) {
163: root.recomposeAttributeSets(this);
164: }
165:
166: }
|