@Test public void testIPAddress_from_string() { FunctionArgumentAttributeValue attrString1 = null; FunctionArgumentAttributeValue attrStringFull = null; FunctionArgumentAttributeValue attrStringMissingElement = null; FunctionArgumentAttributeValue attrStringTooManyElement = null; FunctionArgumentAttributeValue attrStringIllegalElement = null; FunctionArgumentAttributeValue attrStringOutOfOrder = null; FunctionArgumentAttributeValue attrStringMask = null; FunctionArgumentAttributeValue attrStringMissingMaskElement = null; FunctionArgumentAttributeValue attrStringTooManyMaskElement = null; FunctionArgumentAttributeValue attrStringIllegalMaskElement = null; FunctionArgumentAttributeValue attrStringMaskNoValue = null; FunctionArgumentAttributeValue attrStringMinusPort = null; FunctionArgumentAttributeValue attrStringPortMinus = null; FunctionArgumentAttributeValue attrStringPortPort = null; FunctionArgumentAttributeValue attrStringNoPort = null; FunctionArgumentAttributeValue attrStringBadPort = null; FunctionArgumentAttributeValue attrStringTooManyPorts = null; FunctionArgumentAttributeValue attrStringBadValue = null; FunctionArgumentAttributeValue attrStringBadType = null; short[] addrShorts= {123, 134, 156, 255 }; short[] addrMaskShorts= {255, 255, 255, 255 }; try { attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255")); attrStringFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255/255.255.255.255:123-456")); attrStringMissingElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.255")); attrStringTooManyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.255.111.222")); attrStringIllegalElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.256.255")); attrStringOutOfOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.256.255:123-456/255.255.255.255")); attrStringMask = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255/255.255.255.255")); attrStringMissingMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255/123.134.255")); attrStringTooManyMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255/122.134.155.111.222")); attrStringIllegalMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255/123.134.256.255")); attrStringMaskNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255/")); attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255:-123")); attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255:123-")); attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255:1234567-432")); attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255:")); attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255:12.34")); attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123.134.156.255:-123-456")); attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); } catch (Exception e) { fail("creating attribute e="+ e); } FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_IPADDRESS_FROM_STRING; assertEquals(XACML3.ID_FUNCTION_IPADDRESS_FROM_STRING, fd.getId()); assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); assertEquals(DataTypes.DT_IPADDRESS.getId(), fd.getDataTypeId()); assertFalse(fd.returnsBag()); assertEquals(new Integer(1), fd.getNumArgs()); arguments.clear(); arguments.add(attrString1); ExpressionResult res = fd.evaluate(null, arguments); assertTrue(res.isOk()); IPAddress resValue = (IPAddress)res.getValue().getValue(); assertEquals(new IPv4Address(addrShorts, null, null), resValue); arguments.clear(); arguments.add(attrStringFull); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv4Address(addrShorts, addrMaskShorts, PortRange.newInstance("123-456")), resValue); } catch (Exception e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringMissingElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"123.134.255\": invalid address", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringTooManyElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"123.134.255.111.222\": invalid address", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringIllegalElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"123.134.256.255\": invalid octet: \"256", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringOutOfOrder); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"123.134.256.255:123-456/255.255.255.255\": out of order components", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringMask); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv4Address(addrShorts, addrMaskShorts, null), resValue); } catch (Exception e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringMissingMaskElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"123.134.255\": invalid address", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringTooManyMaskElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"122.134.155.111.222\": invalid address", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringIllegalMaskElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"123.134.256.255\": invalid octet: \"256", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringMaskNoValue); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"\": invalid address", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringMinusPort); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("-123")), resValue); } catch (ParseException e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringPortMinus); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("123-")), resValue); } catch (ParseException e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringPortPort); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("1234567-432")), resValue); } catch (ParseException e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringNoPort); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"123.134.156.255:\": no portrange given after ':'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringBadPort); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid PortRange \"12.34\": invalid port number", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringTooManyPorts); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid PortRange \"-123-456\": too many ranges", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringBadValue); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Unknown IPAddress type for \"not valid obj value\"", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringBadType); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); FunctionArgumentAttributeValue attrStringAlternateFull = null; FunctionArgumentAttributeValue attrStringEmptyElement = null; FunctionArgumentAttributeValue attrString2xEmptyElement = null; FunctionArgumentAttributeValue attrStringNoStartBracket = null; FunctionArgumentAttributeValue attrStringNoEndBracket = null; short[] addrv6Shorts = {(short)0x2001, (short)0xdb8, (short)0x85a3, (short)0x0, (short)0x0, (short)0x8a2e, (short)0x370, (short)0x1}; Short prefix = new Short((short) 121); try { attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]")); attrStringFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/121]:123-456")); attrStringAlternateFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]/121:123-456")); attrStringEmptyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e:370:1]")); attrString2xEmptyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e::1]")); attrStringNoStartBracket = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2002:db8:85a3::8a2e::1]")); attrStringNoEndBracket = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e::1")); attrStringMissingElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:1]")); attrStringTooManyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1:123]")); attrStringIllegalElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:mnop:85a3:0:0:8a2e:370:1]")); attrStringOutOfOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:mnop:85a3:0:0:8a2e:370:1:123-456/121]")); attrStringMask = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/21]")); attrStringIllegalMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/130]")); attrStringMaskNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/]")); attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:-123")); attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:123-")); attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:1234567-432")); attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:")); attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:12.34")); attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:-123-456")); attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); } catch (Exception e) { fail("creating attribute e="+ e); } arguments.clear(); arguments.add(attrString1); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); assertEquals(new IPv6Address(addrv6Shorts, null, null), resValue); arguments.clear(); arguments.add(attrStringFull); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv6Address(addrv6Shorts, new Short(prefix), PortRange.newInstance("123-456")), resValue); } catch (Exception e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringAlternateFull); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv6Address(addrv6Shorts, prefix, PortRange.newInstance("123-456")), resValue); } catch (Exception e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringEmptyElement); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv6Address(addrv6Shorts, prefix, null), resValue); } catch (Exception e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrString2xEmptyElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3::8a2e::1\": multiple zero runs", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringNoStartBracket); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2002:db8:85a3::8a2e::1]\": missing opening bracket", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringNoEndBracket); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"[2001:db8:85a3::8a2e::1\": missing closing bracket", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringMissingElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3:0:0:8a2e:1\": not enough address fields", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringTooManyElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3:0:0:8a2e:370:1:123\"", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringIllegalElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv6Address component \"mnop\": invalid hex", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringOutOfOrder); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:mnop:85a3:0:0:8a2e:370:1:123-456\"", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringMask); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv6Address(addrv6Shorts, prefix, null), resValue); } catch (Exception e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringIllegalMaskElement); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid Ipv6Address string \"[2001:db8:85a3:0:0:8a2e:370:1/130]\": prefix is larger than 128", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringMaskNoValue); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid Ipv6Address string \"[2001:db8:85a3:0:0:8a2e:370:1/]\": prefix designation without value", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringMinusPort); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("-123")), resValue); } catch (ParseException e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringPortMinus); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("123-")), resValue); } catch (ParseException e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringPortPort); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (IPAddress)res.getValue().getValue(); try { assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("1234567-432")), resValue); } catch (ParseException e) { fail("port error e="+e); } arguments.clear(); arguments.add(attrStringNoPort); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid IPv6 address string \"[2001:db8:85a3:0:0:8a2e:370:1]:\": no portrange given after ':'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringBadPort); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid PortRange \"12.34\": invalid port number", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStringTooManyPorts); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:ipAddress-from-string Invalid PortRange \"-123-456\": too many ranges", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); }
@Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (this.getDataTypeId().equals(DataTypes.DT_STRING.getId())) { try { String output = this.getDataTypeArgs().toStringValue(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<String>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } } else { try { O output = this.getDataType().convert(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<O>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " " + message )); } } }
FunctionDefinitionStringConversion extends FunctionDefinitionHomogeneousSimple<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (this.getDataTypeId().equals(DataTypes.DT_STRING.getId())) { try { String output = this.getDataTypeArgs().toStringValue(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<String>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } } else { try { O output = this.getDataType().convert(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<O>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " " + message )); } } } }
FunctionDefinitionStringConversion extends FunctionDefinitionHomogeneousSimple<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (this.getDataTypeId().equals(DataTypes.DT_STRING.getId())) { try { String output = this.getDataTypeArgs().toStringValue(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<String>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } } else { try { O output = this.getDataType().convert(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<O>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " " + message )); } } } FunctionDefinitionStringConversion(Identifier idIn, DataType<O> outputType, DataType<I> argType); }
FunctionDefinitionStringConversion extends FunctionDefinitionHomogeneousSimple<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (this.getDataTypeId().equals(DataTypes.DT_STRING.getId())) { try { String output = this.getDataTypeArgs().toStringValue(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<String>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } } else { try { O output = this.getDataType().convert(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<O>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " " + message )); } } } FunctionDefinitionStringConversion(Identifier idIn, DataType<O> outputType, DataType<I> argType); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionStringConversion extends FunctionDefinitionHomogeneousSimple<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (this.getDataTypeId().equals(DataTypes.DT_STRING.getId())) { try { String output = this.getDataTypeArgs().toStringValue(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<String>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } } else { try { O output = this.getDataType().convert(convertedArguments.get(0)); return ExpressionResult.newSingle(new StdAttributeValue<O>(this.getDataTypeId(), output)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " " + message )); } } } FunctionDefinitionStringConversion(Identifier idIn, DataType<O> outputType, DataType<I> argType); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }