return node;
}
private static QueryModelAPTNode visitQueryNode(StreamTokenizer tokenizer, int currentToken, String namespaceId) throws InvalidQueryException
{
QueryModelAPTNode attributePlusTermNode = new QueryModelAPTNode();
List<String> terms = new ArrayList<String>();
while (currentToken == PrefixQuery.TOKEN_ATTR)
{
int attributeType = 0;
Object attributeValue = null;
String localAttributeSet = null;
// Consume the @attr and see what's next
currentToken = readToken(tokenizer);
// See if there is an attrset, as in "@attr gils 1=2016"
if (currentToken == PrefixQuery.TOKEN_TERM)
{
// It must be an attribute set identifier, since attr types are always numeric
localAttributeSet = tokenizer.sval;
currentToken = readToken(tokenizer);
}
// Process the attribute
if (currentToken == PrefixQuery.TOKEN_NUMBER)
{
attributeType = (int) tokenizer.nval;
// Consume the attribute token
currentToken = readToken(tokenizer);
}
else
{
throw new InvalidQueryException("Unexpected error processing RPN query, expected attribute type");
}
// Ensure that there is an equals
if (currentToken == PrefixQuery.TOKEN_EQUALS)
{
// Consume it
currentToken = readToken(tokenizer);
}
else
{
throw new InvalidQueryException("Unexpected error processing RPN query, expected =");
}
// Ensure there is a value
if (currentToken == PrefixQuery.TOKEN_NUMBER)
{
attributeValue = java.math.BigInteger.valueOf((int) tokenizer.nval);
// Consume It
currentToken = readToken(tokenizer);
}
else if (currentToken == PrefixQuery.TOKEN_TERM)
{
// With the new attribute set architecture we will start to get string values... Deal here
attributeValue = tokenizer.sval;
// Consume It
currentToken = readToken(tokenizer);
}
else
{
throw new InvalidQueryException("Unexpected error processing RPN query, expected str or num attribute");
}
if (localAttributeSet == null)
{
localAttributeSet = namespaceId;
}
attributePlusTermNode.setAttribute(localAttributeSet + "." + attributeType, new AttributeValue(localAttributeSet, attributeType + "." + attributeValue));
}
// See if we have an element name
if (currentToken == PrefixQuery.TOKEN_ELEMENTNAME)
{
// Consume the element name token and move on to the actual element name
currentToken = readToken(tokenizer);
// Consume the actual element name
currentToken = readToken(tokenizer);
}
// Process any terms following the attrs
while ((currentToken == PrefixQuery.TOKEN_TERM) || (currentToken == PrefixQuery.TOKEN_NUMBER))
{
if (currentToken == PrefixQuery.TOKEN_TERM)
{
terms.add(tokenizer.sval);
}
else
{
terms.add("" + tokenizer.nval);
}
currentToken = readToken(tokenizer);
}
if (terms.size() > 1)
{
attributePlusTermNode.setTerm(terms);
}
else if (terms.size() == 1)
{
attributePlusTermNode.setTerm(terms.get(0));
}
else
{
throw new InvalidQueryException("No Terms");
}