org.wso2.balana.attr.IntegerAttribute Java Examples
The following examples show how to use
org.wso2.balana.attr.IntegerAttribute.
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
Source File: MobiAttributeFinder.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
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 File: NOfFunction.java From balana with Apache License 2.0 | 6 votes |
/** * */ public void checkInputsNoBag(List inputs) throws IllegalArgumentException { Object[] list = inputs.toArray(); // check that there is at least one arg if (list.length == 0) throw new IllegalArgumentException("n-of requires an argument"); // check that the first element is an Integer Evaluatable eval = (Evaluatable) (list[0]); if (!eval.getType().toString().equals(IntegerAttribute.identifier)) throw new IllegalArgumentException("first argument to n-of must" + " be an integer"); // now check that the rest of the args are booleans for (int i = 1; i < list.length; i++) { if (!((Evaluatable) (list[i])).getType().toString().equals(BooleanAttribute.identifier)) throw new IllegalArgumentException("invalid parameter in n-of" + ": expected boolean"); } }
Example #3
Source File: MultiplyFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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 File: XPathFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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. * * @param functionName function name * @return identifier of the Data type */ private static String getReturnType(String functionName) { if (functionName.equals(NAME_XPATH_NODE_COUNT)){ return IntegerAttribute.identifier; } else { return BooleanAttribute.identifier; } }
Example #5
Source File: AddFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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 File: AbsFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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 File: NumericConvertFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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 File: NumericConvertFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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 File: ModFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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 mod operation long arg0 = ((IntegerAttribute) argValues[0]).getValue(); long arg1 = ((IntegerAttribute) argValues[1]).getValue(); return new EvaluationResult(new IntegerAttribute(arg0 % arg1)); }
Example #10
Source File: DivideFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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 #11
Source File: SubtractFunction.java From balana with Apache License 2.0 | 5 votes |
/** * 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 #12
Source File: NOfFunction.java From balana with Apache License 2.0 | 4 votes |
/** * 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 one by one. As soon as we can return // a result, do so. Return Indeterminate if any argument // evaluated is indeterminate. Iterator it = inputs.iterator(); Evaluatable eval = (Evaluatable) (it.next()); // Evaluate the first argument EvaluationResult result = eval.evaluate(context); if (result.indeterminate()) return result; // if there were no problems, we know 'n' long n = ((IntegerAttribute) (result.getAttributeValue())).getValue(); // If the number of trues needed is less than zero, report an error. if (n < 0) return makeProcessingError("First argument to " + getFunctionName() + " cannot be negative."); // If the number of trues needed is zero, return true. if (n == 0) return EvaluationResult.getTrueInstance(); // make sure it's possible to find n true values long remainingArgs = inputs.size() - 1; if (n > remainingArgs) return makeProcessingError("not enough arguments to n-of to " + "find " + n + " true values"); // loop through the inputs, trying to find at least n trues while (remainingArgs >= n) { eval = (Evaluatable) (it.next()); // evaluate the next argument result = eval.evaluate(context); if (result.indeterminate()) return result; // get the next value, and see if it's true if (((BooleanAttribute) (result.getAttributeValue())).getValue()) { // we're one closer to our goal...see if we met it if (--n == 0) return EvaluationResult.getTrueInstance(); } // we're still looking, but we've got one fewer arguments remainingArgs--; } // if we got here then we didn't meet our quota return EvaluationResult.getFalseInstance(); }
Example #13
Source File: IntegerAttributeProxy.java From balana with Apache License 2.0 | 4 votes |
public AttributeValue getInstance(Node root) throws Exception { return IntegerAttribute.getInstance(root); }
Example #14
Source File: IntegerAttributeProxy.java From balana with Apache License 2.0 | 4 votes |
public AttributeValue getInstance(String value) throws Exception { return IntegerAttribute.getInstance(value); }
Example #15
Source File: ModFunction.java From balana with Apache License 2.0 | 3 votes |
/** * Creates a new <code>ModFunction</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 ModFunction(String functionName) { super(NAME_INTEGER_MOD, 0, IntegerAttribute.identifier, false, 2, IntegerAttribute.identifier, false); if (!functionName.equals(NAME_INTEGER_MOD)) throw new IllegalArgumentException("unknown mod function: " + functionName); }