001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: ElemApplyImport.java 468643 2006-10-28 06:56:03Z minchau $
020     */
021    package org.apache.xalan.templates;
022    
023    import javax.xml.transform.TransformerException;
024    
025    import org.apache.xalan.res.XSLTErrorResources;
026    import org.apache.xalan.transformer.TransformerImpl;
027    import org.apache.xml.dtm.DTM;
028    
029    /**
030     * Implement xsl:apply-imports.
031     * <pre>
032     * <!ELEMENT xsl:apply-imports EMPTY>
033     * </pre>
034     * @see <a href="http://www.w3.org/TR/xslt#apply-imports">apply-imports in XSLT Specification</a>
035     * @xsl.usage advanced
036     */
037    public class ElemApplyImport extends ElemTemplateElement
038    {
039        static final long serialVersionUID = 3764728663373024038L;
040    
041      /**
042       * Get an int constant identifying the type of element.
043       * @see org.apache.xalan.templates.Constants
044       *
045       * @return Token ID for xsl:apply-imports element types
046       */
047      public int getXSLToken()
048      {
049        return Constants.ELEMNAME_APPLY_IMPORTS;
050      }
051    
052      /**
053       * Return the node name.
054       *
055       * @return Element name
056       */
057      public String getNodeName()
058      {
059        return Constants.ELEMNAME_APPLY_IMPORTS_STRING;
060      }
061    
062      /**
063       * Execute the xsl:apply-imports transformation.
064       *
065       * @param transformer non-null reference to the the current transform-time state.
066       *
067       * @throws TransformerException
068       */
069      public void execute(
070              TransformerImpl transformer)
071                throws TransformerException
072      {
073    
074        if (transformer.currentTemplateRuleIsNull())
075        {
076          transformer.getMsgMgr().error(this,
077            XSLTErrorResources.ER_NO_APPLY_IMPORT_IN_FOR_EACH);  //"xsl:apply-imports not allowed in a xsl:for-each");
078        }
079    
080        if (transformer.getDebug())
081          transformer.getTraceManager().fireTraceEvent(this);
082    
083        int sourceNode = transformer.getXPathContext().getCurrentNode();
084        if (DTM.NULL != sourceNode)
085        {
086          // supply the current templated (matched, not named)        
087          ElemTemplate matchTemplate = transformer.getMatchedTemplate();
088          transformer.applyTemplateToNode(this, matchTemplate, sourceNode);
089        }
090        else  // if(null == sourceNode)
091        {
092          transformer.getMsgMgr().error(this,
093            XSLTErrorResources.ER_NULL_SOURCENODE_APPLYIMPORTS);  //"sourceNode is null in xsl:apply-imports!");
094        }
095        if (transformer.getDebug())
096          transformer.getTraceManager().fireTraceEndEvent(this);
097      }
098    
099      /**
100       * Add a child to the child list.
101       * <!ELEMENT xsl:apply-imports EMPTY>
102       *
103       * @param newChild New element to append to this element's children list
104       *
105       * @return null, xsl:apply-Imports cannot have children 
106       */
107      public ElemTemplateElement appendChild(ElemTemplateElement newChild)
108      {
109    
110        error(XSLTErrorResources.ER_CANNOT_ADD,
111              new Object[]{ newChild.getNodeName(),
112                            this.getNodeName() });  //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
113    
114        //" to " + this.m_elemName);
115        return null;
116      }
117    }