📄 operationnode.java
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Salford nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package issrg.pba.rbac.xmlpolicy.ifstatement;
/**
* This is an abstract class which is a base to other operations. The
* sub-classes would only
* need to have a valid constructor, so the XMLParser will be able to
* instantiate a working
* copy of it, and perhaps a static registration method to update the collection
* of interpreters.
*
* <p>This class maintains a registry of Interpreters for each type of
* operation. During evaluation time an Interpreter will be found in the
* registry for the
* required type of operation and it will be used to perform the evaluation.
* If no Interpreter can be found for the specific set of Terms,
* EvaluationException occurs.
*
* @see Interpreter
*/
public class OperationNode extends TermNode {
protected String type;
protected Interpreter interpreter;
protected OperationNode() {}
/**
* This constructor builds an OperationNode given the name and the attributes
* of the XML element, and the acceptable numbers of operands.
*
* @param nodeName - the name of the XML element this OperationNode represents
* @param attrs - the attributes of this XML element
* @param maxOperandCount - the maximum acceptable number of operands; if
* "-1", any number of operands is acceptable
* @param minOperandCount - the minimum acceptable number of operands
*/
public OperationNode(String nodeName, org.xml.sax.Attributes attrs, int maxOperandCount, int minOperandCount){
super(nodeName, attrs, maxOperandCount, minOperandCount);
}
/**
* The method builds a usual TermNode and then checks if an interpreter can
* be found that
* would agree to interpret the relevant terms (children nodes) and deliver a
* definite result.
* If no such interpreter is found, a PolicyParsingException is thrown;
* otherwise, the
* interpreter will be used by the evaluate method, and the result type
* reported by the canEvaluate
* method of the interpreter will be returned by the getType method.
*/
public void construct() throws issrg.pba.rbac.PolicyParsingException {
super.construct();
Interpreter[] ints = TermNode.getInterpretersForNode(getName());
if (ints!=null){
for (int i=0; i<ints.length; i++){
if ((type=ints[i].canEvaluate(terms))!=null){ // can evaluate; terms has been set by the super.construct(); this automatically sets the type of the result, too
interpreter=ints[i];
break;
}
}
}
if (interpreter==null){
throw new issrg.pba.rbac.PolicyParsingException("No interpreter for such combination of operands has been found for node "+getName());
}
}
public String getType(){
return type; // evaluated during the call to construct()
}
/**
* This method evaluates the expression given the environment. It uses the
* Interpreter found during the call to construct();
*
* @param env - the Environment with the variables in it
*
* @return the Interpreter-specific object, guaranteed to be of type returned
* by getType()
*
* @throws EvaluationException, if there was a problem evaluating the
* expression
*/
public Object evaluate(Environment env) throws EvaluationException{
try{
return interpreter.evaluate(env, terms);
}catch (EvaluationException ee){
throw ee;
}catch (Throwable th){
throw new EvaluationException("Run-time error", th);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -