📄 constantnode.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 the class that represents a Constant node and evaluates the contant
* specified
* in the policy XML.
*
* <p>If the policy contains the constant of type for which there is no
* constructor provided
* by the AEF (not registered with the Types), an EvaluationException will
* occur at construction-time.
*
* @author A.Otenko
*/
public class ConstantNode extends TermNode {
/**
* This is the name of the node that represents the Constant - a static value specified in
* the policy.
*/
public final static String CONSTANT_NODE = "Constant";
/**
* This method should be called to register the node with the XML Parser
*/
public static void register(){
try{
issrg.pba.rbac.xmlpolicy.XMLPolicyParser.registerXMLNode(CONSTANT_NODE, ConstantNode.class);
}catch (NoSuchMethodException nsme){
nsme.printStackTrace();
}
}
protected String type;
protected Object value;
protected ConstantNode() {}
/**
* This constructor builds an ConstantNode, given a XMLPolicyParser and the
* set of attributes of this XML element. It expects that a
* issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE and
* issrg.pba.rbac.xmlpolicy.XMLTags.VALUE_ATTRIBUTE ("Type" and "Value") are
* present in this XML element. The value is converted from string into a
* Java object using the Types.construct() method, so the type of the value
* must be registered there.
*
* @param p - the XMLPolicyParser that builds this ConstantNode
* @param attr - the attributes of this XML element
*
* @throws EvaluationException, if the value could not be decoded using
* available types
* @see Types#construct
*/
public ConstantNode(issrg.pba.rbac.xmlpolicy.XMLPolicyParser p, org.xml.sax.Attributes attr) throws EvaluationException, issrg.pba.rbac.PolicyParsingException{
super(CONSTANT_NODE, attr, -1, 0);
type=((String)getAttributes().get(issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE)).intern();
if (type==null) throw new issrg.pba.rbac.PolicyParsingException(issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE+" attribute was expected in "+CONSTANT_NODE);
value = getAttributes().get(issrg.pba.rbac.xmlpolicy.XMLTags.VALUE_ATTRIBUTE);
if (value==null) throw new issrg.pba.rbac.PolicyParsingException(issrg.pba.rbac.xmlpolicy.XMLTags.VALUE_ATTRIBUTE+" attribute was expected in "+CONSTANT_NODE);
value = Types.construct(type, (String)value);
}
/**
* This method returns the Type of the constant as determined at construction
* time.
*/
public String getType(){
return type;
}
/**
* This method returns the value of the constant evaluated at construction
* time. It doesn't actually throw EvaluationExceptions, but the clause is
* kept for subclasses, if there will be any.
*/
public Object evaluate(Environment env) throws EvaluationException{
return value;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -