use of org.apache.xpath.Expression in project j2objc by google.
the class TemplateList method setTemplate.
/**
* Add a template to the table of named templates and/or the table of templates
* with match patterns. This routine should
* be called in decreasing order of precedence but it checks nonetheless.
*
* @param template
*/
public void setTemplate(ElemTemplate template) {
XPath matchXPath = template.getMatch();
if (null == template.getName() && null == matchXPath) {
template.error(XSLTErrorResources.ER_NEED_NAME_OR_MATCH_ATTRIB, new Object[] { "xsl:template" });
}
if (null != template.getName()) {
ElemTemplate existingTemplate = (ElemTemplate) m_namedTemplates.get(template.getName());
if (null == existingTemplate) {
m_namedTemplates.put(template.getName(), template);
} else {
int existingPrecedence = existingTemplate.getStylesheetComposed().getImportCountComposed();
int newPrecedence = template.getStylesheetComposed().getImportCountComposed();
if (newPrecedence > existingPrecedence) {
// This should never happen
m_namedTemplates.put(template.getName(), template);
} else if (newPrecedence == existingPrecedence)
template.error(XSLTErrorResources.ER_DUPLICATE_NAMED_TEMPLATE, new Object[] { template.getName() });
}
}
if (null != matchXPath) {
Expression matchExpr = matchXPath.getExpression();
if (matchExpr instanceof StepPattern) {
insertPatternInTable((StepPattern) matchExpr, template);
} else if (matchExpr instanceof UnionPattern) {
UnionPattern upat = (UnionPattern) matchExpr;
StepPattern[] pats = upat.getPatterns();
int n = pats.length;
for (int i = 0; i < n; i++) {
insertPatternInTable(pats[i], template);
}
} else {
// TODO: assert error
}
}
}
use of org.apache.xpath.Expression in project j2objc by google.
the class XUnresolvedVariableSimple method execute.
/**
* For support of literal objects in xpaths.
*
* @param xctxt The XPath execution context.
*
* @return This object.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
Expression expr = ((ElemVariable) m_obj).getSelect().getExpression();
XObject xobj = expr.execute(xctxt);
xobj.allowDetachToRelease(false);
return xobj;
}
use of org.apache.xpath.Expression in project j2objc by google.
the class WalkerFactory method createDefaultStepPattern.
/**
* Create a StepPattern that is contained within a LocationPath.
*
*
* @param compiler The compiler that holds the syntax tree/op map to
* construct from.
* @param stepOpCodePos The current op code position within the opmap.
* @param mpi The MatchPatternIterator to which the steps will be attached.
* @param analysis 32 bits of analysis, from which the type of AxesWalker
* may be influenced.
* @param tail The step that is the first step analyzed, but the last
* step in the relative match linked list, i.e. the tail.
* May be null.
* @param head The step that is the current head of the relative
* match step linked list.
* May be null.
*
* @return the head of the list.
*
* @throws javax.xml.transform.TransformerException
*/
private static StepPattern createDefaultStepPattern(Compiler compiler, int opPos, MatchPatternIterator mpi, int analysis, StepPattern tail, StepPattern head) throws javax.xml.transform.TransformerException {
int stepType = compiler.getOp(opPos);
boolean simpleInit = false;
boolean prevIsOneStepDown = true;
int whatToShow = compiler.getWhatToShow(opPos);
StepPattern ai = null;
int axis, predicateAxis;
switch(stepType) {
case OpCodes.OP_VARIABLE:
case OpCodes.OP_EXTFUNCTION:
case OpCodes.OP_FUNCTION:
case OpCodes.OP_GROUP:
prevIsOneStepDown = false;
Expression expr;
switch(stepType) {
case OpCodes.OP_VARIABLE:
case OpCodes.OP_EXTFUNCTION:
case OpCodes.OP_FUNCTION:
case OpCodes.OP_GROUP:
expr = compiler.compile(opPos);
break;
default:
expr = compiler.compile(opPos + 2);
}
axis = Axis.FILTEREDLIST;
predicateAxis = Axis.FILTEREDLIST;
ai = new FunctionPattern(expr, axis, predicateAxis);
simpleInit = true;
break;
case OpCodes.FROM_ROOT:
whatToShow = DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT;
axis = Axis.ROOT;
predicateAxis = Axis.ROOT;
ai = new StepPattern(DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT, axis, predicateAxis);
break;
case OpCodes.FROM_ATTRIBUTES:
whatToShow = DTMFilter.SHOW_ATTRIBUTE;
axis = Axis.PARENT;
predicateAxis = Axis.ATTRIBUTE;
// ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);
break;
case OpCodes.FROM_NAMESPACE:
whatToShow = DTMFilter.SHOW_NAMESPACE;
axis = Axis.PARENT;
predicateAxis = Axis.NAMESPACE;
// ai = new StepPattern(whatToShow, axis, predicateAxis);
break;
case OpCodes.FROM_ANCESTORS:
axis = Axis.DESCENDANT;
predicateAxis = Axis.ANCESTOR;
break;
case OpCodes.FROM_CHILDREN:
axis = Axis.PARENT;
predicateAxis = Axis.CHILD;
break;
case OpCodes.FROM_ANCESTORS_OR_SELF:
axis = Axis.DESCENDANTORSELF;
predicateAxis = Axis.ANCESTORORSELF;
break;
case OpCodes.FROM_SELF:
axis = Axis.SELF;
predicateAxis = Axis.SELF;
break;
case OpCodes.FROM_PARENT:
axis = Axis.CHILD;
predicateAxis = Axis.PARENT;
break;
case OpCodes.FROM_PRECEDING_SIBLINGS:
axis = Axis.FOLLOWINGSIBLING;
predicateAxis = Axis.PRECEDINGSIBLING;
break;
case OpCodes.FROM_PRECEDING:
axis = Axis.FOLLOWING;
predicateAxis = Axis.PRECEDING;
break;
case OpCodes.FROM_FOLLOWING_SIBLINGS:
axis = Axis.PRECEDINGSIBLING;
predicateAxis = Axis.FOLLOWINGSIBLING;
break;
case OpCodes.FROM_FOLLOWING:
axis = Axis.PRECEDING;
predicateAxis = Axis.FOLLOWING;
break;
case OpCodes.FROM_DESCENDANTS_OR_SELF:
axis = Axis.ANCESTORORSELF;
predicateAxis = Axis.DESCENDANTORSELF;
break;
case OpCodes.FROM_DESCENDANTS:
axis = Axis.ANCESTOR;
predicateAxis = Axis.DESCENDANT;
break;
default:
//"Programmer's assertion: unknown opcode: "
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[] { Integer.toString(stepType) }));
}
if (null == ai) {
// %REVIEW%
whatToShow = compiler.getWhatToShow(opPos);
ai = new StepPattern(whatToShow, compiler.getStepNS(opPos), compiler.getStepLocalName(opPos), axis, predicateAxis);
}
if (false || DEBUG_PATTERN_CREATION) {
System.out.print("new step: " + ai);
System.out.print(", axis: " + Axis.getNames(ai.getAxis()));
System.out.print(", predAxis: " + Axis.getNames(ai.getAxis()));
System.out.print(", what: ");
System.out.print(" ");
ai.debugWhatToShow(ai.getWhatToShow());
}
int argLen = compiler.getFirstPredicateOpPos(opPos);
ai.setPredicates(compiler.getCompiledPredicates(argLen));
return ai;
}
use of org.apache.xpath.Expression in project j2objc by google.
the class Compiler method compile.
/**
* Execute the XPath object from a given opcode position.
* @param opPos The current position in the xpath.m_opMap array.
* @return The result of the XPath.
*
* @throws TransformerException if there is a syntax or other error.
* @xsl.usage advanced
*/
public Expression compile(int opPos) throws TransformerException {
int op = getOp(opPos);
Expression expr = null;
// System.out.println(getPatternString()+"op: "+op);
switch(op) {
case OpCodes.OP_XPATH:
expr = compile(opPos + 2);
break;
case OpCodes.OP_OR:
expr = or(opPos);
break;
case OpCodes.OP_AND:
expr = and(opPos);
break;
case OpCodes.OP_NOTEQUALS:
expr = notequals(opPos);
break;
case OpCodes.OP_EQUALS:
expr = equals(opPos);
break;
case OpCodes.OP_LTE:
expr = lte(opPos);
break;
case OpCodes.OP_LT:
expr = lt(opPos);
break;
case OpCodes.OP_GTE:
expr = gte(opPos);
break;
case OpCodes.OP_GT:
expr = gt(opPos);
break;
case OpCodes.OP_PLUS:
expr = plus(opPos);
break;
case OpCodes.OP_MINUS:
expr = minus(opPos);
break;
case OpCodes.OP_MULT:
expr = mult(opPos);
break;
case OpCodes.OP_DIV:
expr = div(opPos);
break;
case OpCodes.OP_MOD:
expr = mod(opPos);
break;
// expr = quo(opPos); break;
case OpCodes.OP_NEG:
expr = neg(opPos);
break;
case OpCodes.OP_STRING:
expr = string(opPos);
break;
case OpCodes.OP_BOOL:
expr = bool(opPos);
break;
case OpCodes.OP_NUMBER:
expr = number(opPos);
break;
case OpCodes.OP_UNION:
expr = union(opPos);
break;
case OpCodes.OP_LITERAL:
expr = literal(opPos);
break;
case OpCodes.OP_VARIABLE:
expr = variable(opPos);
break;
case OpCodes.OP_GROUP:
expr = group(opPos);
break;
case OpCodes.OP_NUMBERLIT:
expr = numberlit(opPos);
break;
case OpCodes.OP_ARGUMENT:
expr = arg(opPos);
break;
case OpCodes.OP_EXTFUNCTION:
expr = compileExtension(opPos);
break;
case OpCodes.OP_FUNCTION:
expr = compileFunction(opPos);
break;
case OpCodes.OP_LOCATIONPATH:
expr = locationPath(opPos);
break;
case OpCodes.OP_PREDICATE:
expr = null;
// should never hit this here.
break;
case OpCodes.OP_MATCHPATTERN:
expr = matchPattern(opPos + 2);
break;
case OpCodes.OP_LOCATIONPATHPATTERN:
expr = locationPathPattern(opPos);
break;
case OpCodes.OP_QUO:
error(XPATHErrorResources.ER_UNKNOWN_OPCODE, //"ERROR! Unknown op code: "+m_opMap[opPos]);
new Object[] { "quo" });
break;
default:
error(XPATHErrorResources.ER_UNKNOWN_OPCODE, //"ERROR! Unknown op code: "+m_opMap[opPos]);
new Object[] { Integer.toString(getOp(opPos)) });
}
return expr;
}
use of org.apache.xpath.Expression in project j2objc by google.
the class FuncExtFunction method exprSetParent.
/**
* Set the parent node.
* For an extension function, we also need to set the parent
* node for all argument expressions.
*
* @param n The parent node
*/
public void exprSetParent(ExpressionNode n) {
super.exprSetParent(n);
int nArgs = m_argVec.size();
for (int i = 0; i < nArgs; i++) {
Expression arg = (Expression) m_argVec.elementAt(i);
arg.exprSetParent(n);
}
}
Aggregations