|
|
|
|
|
*/ |
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
* (the "License"); you may not use this file except in compliance with |
|
* the License. You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.sun.org.apache.xpath.internal.functions; |
|
|
|
import com.sun.org.apache.xalan.internal.res.XSLMessages; |
|
import com.sun.org.apache.xml.internal.utils.QName; |
|
import com.sun.org.apache.xpath.internal.Expression; |
|
import com.sun.org.apache.xpath.internal.ExpressionNode; |
|
import com.sun.org.apache.xpath.internal.ExpressionOwner; |
|
import com.sun.org.apache.xpath.internal.ExtensionsProvider; |
|
import com.sun.org.apache.xpath.internal.XPathContext; |
|
import com.sun.org.apache.xpath.internal.XPathVisitor; |
|
import com.sun.org.apache.xpath.internal.objects.XNull; |
|
import com.sun.org.apache.xpath.internal.objects.XObject; |
|
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; |
|
import com.sun.org.apache.xpath.internal.res.XPATHMessages; |
|
import java.util.ArrayList; |
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class FuncExtFunction extends Function |
|
{ |
|
static final long serialVersionUID = 5196115554693708718L; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
String m_namespace; |
|
|
|
|
|
|
|
|
|
*/ |
|
String m_extensionName; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
Object m_methodKey; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
List<Expression> m_argVec = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void fixupVariables(List<QName> vars, int globalsSize) |
|
{ |
|
|
|
if (null != m_argVec) |
|
{ |
|
int nArgs = m_argVec.size(); |
|
|
|
for (int i = 0; i < nArgs; i++) |
|
{ |
|
Expression arg = m_argVec.get(i); |
|
|
|
arg.fixupVariables(vars, globalsSize); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public String getNamespace() |
|
{ |
|
return m_namespace; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public String getFunctionName() |
|
{ |
|
return m_extensionName; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Object getMethodKey() |
|
{ |
|
return m_methodKey; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Expression getArg(int n) { |
|
if (n >= 0 && n < m_argVec.size()) |
|
return m_argVec.get(n); |
|
else |
|
return null; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public int getArgCount() { |
|
return m_argVec.size(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public FuncExtFunction(java.lang.String namespace, |
|
java.lang.String extensionName, Object methodKey) |
|
{ |
|
|
|
m_namespace = namespace; |
|
m_extensionName = extensionName; |
|
m_methodKey = methodKey; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public XObject execute(XPathContext xctxt) |
|
throws javax.xml.transform.TransformerException |
|
{ |
|
if (xctxt.isSecureProcessing()) |
|
throw new javax.xml.transform.TransformerException( |
|
XPATHMessages.createXPATHMessage( |
|
XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED, |
|
new Object[] {toString()})); |
|
|
|
XObject result; |
|
List<XObject> argVec = new ArrayList<>(); |
|
int nArgs = m_argVec.size(); |
|
|
|
for (int i = 0; i < nArgs; i++) |
|
{ |
|
Expression arg = m_argVec.get(i); |
|
|
|
XObject xobj = arg.execute(xctxt); |
|
|
|
|
|
*/ |
|
xobj.allowDetachToRelease(false); |
|
argVec.add(xobj); |
|
} |
|
|
|
ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject(); |
|
Object val = extProvider.extFunction(this, argVec); |
|
|
|
if (null != val) |
|
{ |
|
result = XObject.create(val, xctxt); |
|
} |
|
else |
|
{ |
|
result = new XNull(); |
|
} |
|
|
|
return result; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setArg(Expression arg, int argNum) |
|
throws WrongNumberArgsException |
|
{ |
|
m_argVec.add(arg); |
|
arg.exprSetParent(this); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void checkNumberArgs(int argNum) throws WrongNumberArgsException{} |
|
|
|
|
|
class ArgExtOwner implements ExpressionOwner |
|
{ |
|
|
|
Expression m_exp; |
|
|
|
ArgExtOwner(Expression exp) |
|
{ |
|
m_exp = exp; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public Expression getExpression() |
|
{ |
|
return m_exp; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void setExpression(Expression exp) |
|
{ |
|
exp.exprSetParent(FuncExtFunction.this); |
|
m_exp = exp; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void callArgVisitors(XPathVisitor visitor) |
|
{ |
|
for (int i = 0; i < m_argVec.size(); i++) |
|
{ |
|
Expression exp = m_argVec.get(i); |
|
exp.callVisitors(new ArgExtOwner(exp), visitor); |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void exprSetParent(ExpressionNode n) |
|
{ |
|
|
|
super.exprSetParent(n); |
|
|
|
int nArgs = m_argVec.size(); |
|
|
|
for (int i = 0; i < nArgs; i++) |
|
{ |
|
Expression arg = m_argVec.get(i); |
|
|
|
arg.exprSetParent(n); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected void reportWrongNumberArgs() throws WrongNumberArgsException { |
|
String fMsg = XSLMessages.createXPATHMessage( |
|
XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION, |
|
new Object[]{ "Programmer's assertion: the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." }); |
|
|
|
throw new RuntimeException(fMsg); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public String toString() |
|
{ |
|
if (m_namespace != null && m_namespace.length() > 0) |
|
return "{" + m_namespace + "}" + m_extensionName; |
|
else |
|
return m_extensionName; |
|
} |
|
} |