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]);
}
Aggregations