📄 termnode.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;
import issrg.pba.rbac.PolicyParsingException;
import issrg.pba.rbac.xmlpolicy.PolicyXMLNode;
/**
* This abstract class represents XML elements that are Terms of IF-expressions.
* It maintains a registry of Interpreters for each type of operation, which is
* used indirectly by OperationNode and other subclasses.
*
* @author A.Otenko
*/
public abstract class TermNode extends PolicyXMLNode implements Term {
protected int maxOperand;
protected int minOperand;
protected Term [] terms;
private final static java.util.Map interpreters = new java.util.Hashtable();
/**
* This method registers an interpreter for a given type of operation.
*
* @param nodeName - the name of the XML element that represents the
* operation
* @param i - the Interpreter for that operation
*/
protected static void registerInterpreterForNode(String nodeName, Interpreter i){
java.util.Vector v = (java.util.Vector)interpreters.get(nodeName);
if (v==null){
v=new java.util.Vector();
interpreters.put(nodeName, v);
}
v.add(i);
}
/**
* This method retrieves an array of interpreters for a particular kind of
* operation.
*
* @param nodeName - the name of the XML element that represents the
* operation
*
* @return an array of Interpreters for this kind of operation; can be null
* or empty if no Interpreters were registered for that kind of operation
*/
protected static Interpreter[] getInterpretersForNode(String nodeName){
java.util.Vector v = (java.util.Vector)interpreters.get(nodeName);
Interpreter [] result = null;
if (v!=null){
Object [] o = v.toArray();
result = new Interpreter[o.length];
System.arraycopy(o, 0, result, 0, result.length);
}
return result;
}
protected TermNode(){
super();
}
/**
* This constructor builds a TermNode object that will check that the child
* nodes are
* Terms and that there are not more than maxOperandCount of them and not
* less than minOperandCount.
* The negative values of these two parameters mean no restriction on the
* amount of children.
*
* @param name is the name of the XML element for this operator
* @param attr is the set of attributes it has got
* @param maxOperandCount is the maximum amount of children allowed; -1 means
* "don't care"
* @param minOperandCouns is the minimum amount of children allowed; -1 means
* "don't care"
*/
public TermNode(String name, org.xml.sax.Attributes attr, int maxOperandCount, int minOperandCount){
super(name, attr);
maxOperand=maxOperandCount;
minOperand=minOperandCount;
}
/**
* This method ensures the children are Terms and that there are not more
* than maxOperandCount
* and not less than minOperandCount of them, as specified in the
* constructor. It also creates
* an array of Terms that can be used by the sub-classes in their
* evaluations.
*
* @throws PolicyParsingException if one of the above-stated conditions is
* violated
*/
public void construct() throws PolicyParsingException {
java.util.Vector c = getChildren();
if ((minOperand>=0 && c.size()<minOperand) || (maxOperand>=0 && c.size()>maxOperand)){
throw new PolicyParsingException("Illegal number of operands (child nodes) for "+getName()+" node");
}
terms = new Term[c.size()];
for (int i=0; i<c.size(); i++){
if (c.get(i) instanceof Term){
terms[i]=(Term)c.get(i);
continue;
}
throw new PolicyParsingException("Operand ("+i+") "+((PolicyXMLNode)c.get(i)).getName()+" is not a valid term for "+getName()+" node");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -