2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
* $Id: ElementAvailableCall.java,v 1.2 2009/12/10 03:18:18 matthewoliver Exp $
22
package org.apache.xalan.xsltc.compiler;
24
import java.util.Vector;
26
import org.apache.bcel.generic.ConstantPoolGen;
27
import org.apache.bcel.generic.PUSH;
28
import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
29
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
30
import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
31
import org.apache.xalan.xsltc.compiler.util.Type;
32
import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
35
* @author Jacek Ambroziak
36
* @author Santiago Pericas-Geertsen
38
final class ElementAvailableCall extends FunctionCall {
40
public ElementAvailableCall(QName fname, Vector arguments) {
41
super(fname, arguments);
45
* Force the argument to this function to be a literal string.
47
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
48
if (argument() instanceof LiteralExpr) {
49
return _type = Type.Boolean;
51
ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
52
"element-available", this);
53
throw new TypeCheckError(err);
57
* Returns an object representing the compile-time evaluation
58
* of an expression. We are only using this for function-available
59
* and element-available at this time.
61
public Object evaluateAtCompileTime() {
62
return getResult() ? Boolean.TRUE : Boolean.FALSE;
66
* Returns the result that this function will return
68
public boolean getResult() {
70
final LiteralExpr arg = (LiteralExpr) argument();
71
final String qname = arg.getValue();
72
final int index = qname.indexOf(':');
73
final String localName = (index > 0) ?
74
qname.substring(index + 1) : qname;
75
return getParser().elementSupported(arg.getNamespace(),
78
catch (ClassCastException e) {
84
* Calls to 'element-available' are resolved at compile time since
85
* the namespaces declared in the stylsheet are not available at run
86
* time. Consequently, arguments to this function must be literals.
88
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
89
final ConstantPoolGen cpg = classGen.getConstantPool();
90
final boolean result = getResult();
91
methodGen.getInstructionList().append(new PUSH(cpg, result));