Search in sources :

Example 1 with ElementOperand

use of org.eclipse.milo.opcua.stack.core.types.structured.ElementOperand in project milo by eclipse.

the class EventContentFilter method validateFilterElement.

private static ContentFilterElementResult validateFilterElement(@NotNull FilterContext context, @NotNull ContentFilterElement filterElement) {
    FilterOperator filterOperator = filterElement.getFilterOperator();
    if (!Operators.SUPPORTED_OPERATORS.contains(filterOperator)) {
        return new ContentFilterElementResult(new StatusCode(StatusCodes.Bad_FilterOperatorUnsupported), new StatusCode[0], new DiagnosticInfo[0]);
    }
    ExtensionObject[] xos = filterElement.getFilterOperands();
    if (xos == null || xos.length == 0) {
        return new ContentFilterElementResult(new StatusCode(StatusCodes.Bad_FilterOperandCountMismatch), new StatusCode[0], new DiagnosticInfo[0]);
    }
    FilterOperand[] operands = new FilterOperand[xos.length];
    StatusCode[] operandStatusCodes = new StatusCode[xos.length];
    for (int i = 0; i < xos.length; i++) {
        Object operand = xos[i].decodeOrNull(context.getServer().getSerializationContext());
        if (operand instanceof FilterOperand) {
            operands[i] = (FilterOperand) operand;
            if (operand instanceof SimpleAttributeOperand) {
                try {
                    validateSimpleOperand(context, (SimpleAttributeOperand) operand);
                    operandStatusCodes[i] = StatusCode.GOOD;
                } catch (ValidationException e) {
                    operandStatusCodes[i] = e.getStatusCode();
                }
            } else if (operand instanceof ElementOperand) {
                operandStatusCodes[i] = StatusCode.GOOD;
            } else if (operand instanceof LiteralOperand) {
                operandStatusCodes[i] = StatusCode.GOOD;
            } else {
                // includes AttributeOperand and any unknown/unhandle subclasses
                operandStatusCodes[i] = new StatusCode(StatusCodes.Bad_FilterOperandInvalid);
            }
        } else {
            operandStatusCodes[i] = new StatusCode(StatusCodes.Bad_FilterOperandInvalid);
        }
    }
    StatusCode operatorStatus = StatusCode.GOOD;
    try {
        Operator<?> operator = getOperator(filterOperator);
        operator.validate(context, operands);
    } catch (ValidationException e) {
        operatorStatus = e.getStatusCode();
    }
    return new ContentFilterElementResult(operatorStatus, operandStatusCodes, new DiagnosticInfo[0]);
}
Also used : LiteralOperand(org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) ElementOperand(org.eclipse.milo.opcua.stack.core.types.structured.ElementOperand) FilterOperator(org.eclipse.milo.opcua.stack.core.types.enumerated.FilterOperator) SimpleAttributeOperand(org.eclipse.milo.opcua.stack.core.types.structured.SimpleAttributeOperand) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) ContentFilterElementResult(org.eclipse.milo.opcua.stack.core.types.structured.ContentFilterElementResult)

Aggregations

ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 FilterOperator (org.eclipse.milo.opcua.stack.core.types.enumerated.FilterOperator)1 ContentFilterElementResult (org.eclipse.milo.opcua.stack.core.types.structured.ContentFilterElementResult)1 ElementOperand (org.eclipse.milo.opcua.stack.core.types.structured.ElementOperand)1 FilterOperand (org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand)1 LiteralOperand (org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand)1 SimpleAttributeOperand (org.eclipse.milo.opcua.stack.core.types.structured.SimpleAttributeOperand)1