📄 apply.java
字号:
throws ParsingException
{
return getInstance(root, FunctionFactory.getConditionInstance(),
new PolicyMetaData(
PolicyMetaData.XACML_1_0_IDENTIFIER,
xpathVersion),
null);
}
/**
* Returns an instance of <code>Apply</code> based on the given DOM root.
*
* @param root the DOM root of an ApplyType XML type
* @param metaData the meta-data associated with the containing policy
* @param manager <code>VariableManager</code> used to connect references
* and definitions while parsing
*
* @throws ParsingException if this is not a valid ApplyType
*/
public static Apply getInstance(Node root, PolicyMetaData metaData,
VariableManager manager)
throws ParsingException
{
return getInstance(root, FunctionFactory.getGeneralInstance(),
metaData, manager);
}
/**
* Returns an instance of <code>Apply</code> based on the given DOM root.
*
* @deprecated As of 2.0 you should avoid using this method, since it
* does not handle XACML 2.0 policies correctly. If you need
* a similar method you can use the new version that
* accepts a <code>VariableManager</code>. This will return
* an <code>Apply</code> instance for XACML 1.x policies.
*
* @param root the DOM root of an ApplyType XML type
* @param xpathVersion the XPath version to use in any selectors or XPath
* functions, or null if this is unspecified (ie, not
* supplied in the defaults section of the policy)
*
* @throws ParsingException if this is not a valid ApplyType
*/
public static Apply getInstance(Node root, String xpathVersion)
throws ParsingException
{
return getInstance(root, FunctionFactory.getGeneralInstance(),
new PolicyMetaData(
PolicyMetaData.XACML_1_0_IDENTIFIER,
xpathVersion),
null);
}
/**
* This is a helper method that is called by the two getInstance
* methods. It takes a factory so we know that we're getting the right
* kind of function.
*/
private static Apply getInstance(Node root, FunctionFactory factory,
PolicyMetaData metaData,
VariableManager manager)
throws ParsingException
{
Function function =
ExpressionHandler.getFunction(root, metaData, factory);
List xprs = new ArrayList();
NodeList nodes = root.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Expression xpr = ExpressionHandler.
parseExpression(nodes.item(i), metaData, manager);
if (xpr != null)
xprs.add(xpr);
}
return new Apply(function, xprs);
}
/**
* Returns the <code>Function</code> used by this <code>Apply</code>.
*
* @return the <code>Function</code>
*/
public Function getFunction() {
return function;
}
/**
* Returns the <code>List</code> of children for this <code>Apply</code>.
* The <code>List</code> contains <code>Expression</code>s. The list is
* unmodifiable, and may be empty.
*
* @return a <code>List</code> of <code>Expression</code>s
*/
public List getChildren() {
return xprs;
}
/**
* Returns whether or not this ApplyType is actually a ConditionType. As
* of 2.0 this always returns false;
*
* @deprecated As of 2.0 this method should not be used, since an
* <code>Apply</code> is never a Condition.
*
* @return false
*/
public boolean isCondition() {
return false;
}
/**
* Evaluates the apply object using the given function. This will in
* turn call evaluate on all the given parameters, some of which may be
* other <code>Apply</code> objects.
*
* @param context the representation of the request
*
* @return the result of trying to evaluate this apply object
*/
public EvaluationResult evaluate(EvaluationCtx context) {
// Note that prior to the 2.0 codebase, this method was much more
// complex, pre-evaluating the higher-order functions. Because this
// was never really the right behavior (there's no reason that a
// function can only be at the start of an Apply), we no longer make
// assumptions at this point, so the higher order functions are
// left to evaluate their own parameters.
return function.evaluate(xprs, context);
}
/**
* Returns the type of attribute that this object will return on a call
* to <code>evaluate</code>. In practice, this will always be the same as
* the result of calling <code>getReturnType</code> on the function used
* by this object.
*
* @return the type returned by <code>evaluate</code>
*/
public URI getType() {
return function.getReturnType();
}
/**
* Returns whether or not the <code>Function</code> will return a bag
* of values on evaluation.
*
* @return true if evaluation will return a bag of values, false otherwise
*/
public boolean returnsBag() {
return function.returnsBag();
}
/**
* Returns whether or not the <code>Function</code> will return a bag
* of values on evaluation.
*
*
* @deprecated As of 2.0, you should use the <code>returnsBag</code>
* method from the super-interface <code>Expression</code>.
*
* @return true if evaluation will return a bag of values, false otherwise
*/
public boolean evaluatesToBag() {
return function.returnsBag();
}
/**
* Encodes this <code>Apply</code> into its XML representation and
* writes this encoding to the given <code>OutputStream</code> with no
* indentation.
*
* @param output a stream into which the XML-encoded data is written
*/
public void encode(OutputStream output) {
encode(output, new Indenter(0));
}
/**
* Encodes this <code>Apply</code> into its XML representation and
* writes this encoding to the given <code>OutputStream</code> with
* indentation.
*
* @param output a stream into which the XML-encoded data is written
* @param indenter an object that creates indentation strings
*/
public void encode(OutputStream output, Indenter indenter) {
PrintStream out = new PrintStream(output);
String indent = indenter.makeString();
out.println(indent + "<Apply FunctionId=\"" +
function.getIdentifier() + "\">");
indenter.in();
Iterator it = xprs.iterator();
while (it.hasNext()) {
Expression xpr = (Expression)(it.next());
xpr.encode(output, indenter);
}
indenter.out();
out.println(indent + "</Apply>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -