}
@SuppressWarnings("unchecked")
private static final RPNStructure_type createRPNStructure(QueryModelNode node, String encoding, String defaultNamespace) throws InvalidQueryException
{
RPNStructure_type rpnStructure = null;
if (node instanceof QueryModel)
{
rpnStructure = createRPNStructure(((QueryModel) node).getRoot(), encoding, defaultNamespace);
}
else if (node instanceof QueryModelNamespaceNode)
{
QueryModelNamespaceNode nsNode = (QueryModelNamespaceNode) node;
rpnStructure = createRPNStructure(nsNode.getRoot(), encoding, nsNode.getAttributeSet());
}
else if (node instanceof QueryModelComplexNode)
{
QueryModelComplexNode complexNode = (QueryModelComplexNode) node;
rpnRpnOp_inline2_type rpnOp = new rpnRpnOp_inline2_type();
rpnOp.rpn1 = createRPNStructure(complexNode.getLhs(), encoding, defaultNamespace);
rpnOp.rpn2 = createRPNStructure(complexNode.getRhs(), encoding, defaultNamespace);
rpnOp.op = new Operator_type();
switch (complexNode.getOp())
{
case QueryModelComplexNode.COMPLEX_OP_AND:
rpnOp.op.which = Operator_type.and_CID;
rpnOp.op.o = new AsnNull();
break;
case QueryModelComplexNode.COMPLEX_OP_OR:
rpnOp.op.which = Operator_type.or_CID;
rpnOp.op.o = new AsnNull();
break;
case QueryModelComplexNode.COMPLEX_OP_ANDNOT:
rpnOp.op.which = Operator_type.and_not_CID;
rpnOp.op.o = new AsnNull();
break;
case QueryModelComplexNode.COMPLEX_OP_PROX:
logger.warn("Prox-Op not yet handled");
break;
default:
break;
}
rpnStructure = new RPNStructure_type();
rpnStructure.which = RPNStructure_type.rpnrpnop_CID;
rpnStructure.o = rpnOp;
}
else if (node instanceof QueryModelAPTNode)
{
QueryModelAPTNode aptNode = (QueryModelAPTNode) node;
AttributesPlusTerm_type attributePlusTerm = new AttributesPlusTerm_type();
attributePlusTerm.attributes = new ArrayList();
for (String attributeId : aptNode.getAttributes().keySet())
{
Type1AttributeTriple attributeTriple = Type1AttributeTriple.parse(aptNode.getAttribute(attributeId).toString());
AttributeElement_type attributeElement = new AttributeElement_type();
attributeElement.attributeValue = new attributeValue_inline3_type();
attributeElement.attributeType = BigInteger.valueOf(attributeTriple.attributeType);
/*
* Use OID registry to lookup attr set oid if one is present. Don't fill out element attrset if it's the
* same as default attrset
*/
String elementAttributeSet = attributeTriple.attributeSet;
if ((null != elementAttributeSet) && (!elementAttributeSet.equals(defaultNamespace)))
{
attributeElement.attributeSet = ProtocolOIDRegister.getInstance().oidByName(elementAttributeSet);
}
if (attributeTriple.attributeValue instanceof BigInteger)
{
attributeElement.attributeValue.which = attributeValue_inline3_type.numeric_CID;
attributeElement.attributeValue.o = BigInteger.valueOf(((BigInteger) attributeTriple.attributeValue).intValue());
}
else if (attributeTriple.attributeValue instanceof String)
{
StringOrNumeric_type son = new StringOrNumeric_type();
son.which = StringOrNumeric_type.string_CID;
son.o = attributeTriple.attributeValue.toString();
complex_inline4_type cit = new complex_inline4_type();
cit.list = new ArrayList();
cit.list.add(son);
attributeElement.attributeValue.which = attributeValue_inline3_type.complex_CID;
attributeElement.attributeValue.o = cit;
}
else
{
logger.warn("Unhandled type (" + attributeTriple.attributeValue.getClass().getName() + ") for attribute value");
}
attributePlusTerm.attributes.add(attributeElement);
}
try
{
/*
* Add new AttributeElement members for each attribute.
*/
attributePlusTerm.term = new Term_type();
attributePlusTerm.term.which = Term_type.general_CID;
attributePlusTerm.term.o = aptNode.getTerm().toString().getBytes(encoding);
}
catch (java.io.UnsupportedEncodingException e)
{
logger.warn("Problem converting search string to requested encoding", e);
attributePlusTerm.term.o = aptNode.getTerm().toString().getBytes();
}
Operand_type operand = new Operand_type();
operand.which = Operand_type.attrterm_CID;
operand.o = attributePlusTerm;
rpnStructure = new RPNStructure_type();
rpnStructure.which = RPNStructure_type.op_CID;
rpnStructure.o = operand;
}
return rpnStructure;