jaxp/src/com/sun/org/apache/xpath/internal/objects/XRTreeFragSelectWrapper.java
author lana
Tue, 18 Mar 2014 17:49:48 -0700
changeset 23377 2af1ddf102a4
parent 12457 c348e06f0e82
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: XRTreeFragSelectWrapper.java,v 1.2.4.1 2005/09/15 02:02:35 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal.objects;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xalan.internal.res.XSLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.utils.XMLString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.Expression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xpath.internal.XPathContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * This class makes an select statement act like an result tree fragment.
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
public class XRTreeFragSelectWrapper extends XRTreeFrag implements Cloneable
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
    static final long serialVersionUID = -6526177905590461251L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
  public XRTreeFragSelectWrapper(Expression expr)
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
    super(expr);
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
   * This function is used to fixup variables from QNames to stack frame
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
   * indexes at stylesheet build time.
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
   * @param vars List of QNames that correspond to variables.  This list
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
   * should be searched backwards for the first qualified name that
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * corresponds to the variable reference qname.  The position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   * QName in the vector from the start of the vector will be its position
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   * in the stack frame (but variables above the globalsTop value will need
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   * to be offset to the current stack frame).
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  public void fixupVariables(java.util.Vector vars, int globalsSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    ((Expression)m_obj).fixupVariables(vars, globalsSize);
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
   * For support of literal objects in xpaths.
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * @param xctxt The XPath execution context.
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   * @return the result of executing the select expression
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
  public XObject execute(XPathContext xctxt)
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
         XObject m_selected;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     m_selected = ((Expression)m_obj).execute(xctxt);
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     m_selected.allowDetachToRelease(m_allowRelease);
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
     if (m_selected.getType() == CLASS_STRING)
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
       return m_selected;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
     else
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
       return new XString(m_selected.str());
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * Detaches the <code>DTMIterator</code> from the set which it iterated
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * over, releasing any computational resources and placing the iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * in the INVALID state. After <code>detach</code> has been invoked,
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   * calls to <code>nextNode</code> or <code>previousNode</code> will
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * raise a runtime exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   * In general, detach should only be called once on the object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
  public void detach()
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_DETACH_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"detach() not supported by XRTreeFragSelectWrapper!");
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * Cast result object to a number.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   * @return The result tree fragment as a number or NaN
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  public double num()
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NUM_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"num() not supported by XRTreeFragSelectWrapper!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
   * Cast result object to an XMLString.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * @return The document fragment node data or the empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
  public XMLString xstr()
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XSTR_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"xstr() not supported by XRTreeFragSelectWrapper!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   * Cast result object to a string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
   * @return The document fragment node data or the empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
  public String str()
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_STR_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"str() not supported by XRTreeFragSelectWrapper!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   * Tell what kind of class this is.
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   * @return the string type
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
  public int getType()
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    return CLASS_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
   * Cast result object to a result tree fragment.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
   * @return The document fragment this wraps
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
  public int rtf()
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"rtf() not supported by XRTreeFragSelectWrapper!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   * Cast result object to a DTMIterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   * @return The document fragment as a DTMIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
  public DTMIterator asNodeIterator()
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"asNodeIterator() not supported by XRTreeFragSelectWrapper!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
}