Java Code Examples for org.wso2.balana.attr.DoubleAttribute

The following examples show how to use org.wso2.balana.attr.DoubleAttribute. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private AttributeValue getAttributeValue(Literal literal) {
    IRI datatype = literal.getDatatype();
    switch (datatype.stringValue()) {
        case "http://www.w3.org/2001/XMLSchema#string":
            return new StringAttribute(literal.stringValue());
        case "http://www.w3.org/2001/XMLSchema#boolean":
            return BooleanAttribute.getInstance(literal.booleanValue());
        case "http://www.w3.org/2001/XMLSchema#double":
            return new DoubleAttribute(literal.doubleValue());
        case "http://www.w3.org/2001/XMLSchema#integer":
            return new IntegerAttribute(literal.longValue());
        case "http://www.w3.org/2001/XMLSchema#anyURI":
            try {
                return new AnyURIAttribute(new URI(literal.stringValue()));
            } catch (URISyntaxException e) {
                throw new ProcessingException("Not a valid URI");
            }
        case "https://www.w3.org/2001/XMLSchema#dateTime":
            return new DateTimeAttribute(new Date(literal.dateTimeValue().toInstant().toEpochMilli()));
        default:
            throw new ProcessingException("Datatype " + datatype + " is not supported");
    }
}
 
Example 2
Source Project: balana   Source File: FloorFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Evaluate the function, using the specified parameters.
 * 
 * @param inputs a <code>List</code> of <code>Evaluatable</code> objects representing the
 *            arguments passed to the function
 * @param context an <code>EvaluationCtx</code> so that the <code>Evaluatable</code> objects can
 *            be evaluated
 * @return an <code>EvaluationResult</code> representing the function's result
 */
public EvaluationResult evaluate(List inputs, EvaluationCtx context) {

    // Evaluate the arguments
    AttributeValue[] argValues = new AttributeValue[inputs.size()];
    EvaluationResult result = evalArgs(inputs, context, argValues);
    if (result != null)
        return result;

    // Now that we have real values, perform the floor operation
    double arg = ((DoubleAttribute) argValues[0]).getValue();

    return new EvaluationResult(new DoubleAttribute(Math.floor(arg)));
}
 
Example 3
Source Project: balana   Source File: MultiplyFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_INTEGER_MULTIPLY))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example 4
Source Project: balana   Source File: RoundFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Evaluate the function, using the specified parameters.
 * 
 * @param inputs a <code>List</code> of <code>Evaluatable</code> objects representing the
 *            arguments passed to the function
 * @param context an <code>EvaluationCtx</code> so that the <code>Evaluatable</code> objects can
 *            be evaluated
 * @return an <code>EvaluationResult</code> representing the function's result
 */
public EvaluationResult evaluate(List inputs, EvaluationCtx context) {

    // Evaluate the arguments
    AttributeValue[] argValues = new AttributeValue[inputs.size()];
    EvaluationResult result = evalArgs(inputs, context, argValues);
    if (result != null)
        return result;

    // Now that we have real values, perform the round operation
    double arg = ((DoubleAttribute) argValues[0]).getValue();
    BigDecimal roundValue = new BigDecimal(arg);

    return new EvaluationResult(new DoubleAttribute(roundValue.setScale(0, RoundingMode.HALF_EVEN).doubleValue()));
}
 
Example 5
Source Project: balana   Source File: AddFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
	if (functionName.equals(NAME_INTEGER_ADD))
		return IntegerAttribute.identifier;
	else
		return DoubleAttribute.identifier;
}
 
Example 6
Source Project: balana   Source File: AbsFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_INTEGER_ABS))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example 7
Source Project: balana   Source File: NumericConvertFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_DOUBLE_TO_INTEGER))
        return DoubleAttribute.identifier;
    else
        return IntegerAttribute.identifier;
}
 
Example 8
Source Project: balana   Source File: NumericConvertFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the return type for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getReturnType(String functionName) {
    if (functionName.equals(NAME_DOUBLE_TO_INTEGER))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example 9
Source Project: balana   Source File: DivideFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_INTEGER_DIVIDE))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example 10
Source Project: balana   Source File: SubtractFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_INTEGER_SUBTRACT))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example 11
Source Project: balana   Source File: DoubleAttributeProxy.java    License: Apache License 2.0 4 votes vote down vote up
public AttributeValue getInstance(Node root) throws Exception {
    return DoubleAttribute.getInstance(root);
}
 
Example 12
Source Project: balana   Source File: DoubleAttributeProxy.java    License: Apache License 2.0 4 votes vote down vote up
public AttributeValue getInstance(String value) throws Exception {
    return DoubleAttribute.getInstance(value);
}
 
Example 13
Source Project: balana   Source File: FloorFunction.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new <code>FloorFunction</code> object.
 * 
 * @param functionName the standard XACML name of the function to be handled by this object,
 *            including the full namespace
 * 
 * @throws IllegalArgumentException if the function is unknown
 */
public FloorFunction(String functionName) {
    super(NAME_FLOOR, 0, DoubleAttribute.identifier, false, 1, DoubleAttribute.identifier,
            false);

    if (!functionName.equals(NAME_FLOOR))
        throw new IllegalArgumentException("unknown floor function: " + functionName);
}
 
Example 14
Source Project: balana   Source File: RoundFunction.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new <code>RoundFunction</code> object.
 * 
 * @param functionName the standard XACML name of the function to be handled by this object,
 *            including the full namespace
 * 
 * @throws IllegalArgumentException if the function is unknown
 */
public RoundFunction(String functionName) {
    super(NAME_ROUND, 0, DoubleAttribute.identifier, false, 1, DoubleAttribute.identifier,
            false);

    if (!functionName.equals(NAME_ROUND))
        throw new IllegalArgumentException("unknown round function: " + functionName);
}