⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notnode.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 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 for Not node of the IF-statement. Its functionality is
 * very much determined by OperationNode and NotInterpreter, which are 
 * configured to deliver the following semantics:
 *
 * <p>This operation expects one and only one Term of type Types.BOOLEAN_TYPE, 
 * and 
 * returns a 
 * value of type Types.BOOLEAN_TYPE.
 * The evaluation result is "true", if and only if evaluation of the Term 
 * passed to the evaluate method results in a boolean "false".
 *
 * @author A.Otenko
 */

public class NotNode extends OperationNode {

  public final static String NOT_NODE = "NOT";

  /**
   * Call this method to register the NotNode with the XMLPolicyParser. It also
   * registers the default NotInterpreter.
   */
  public static void register(){
    try{
      issrg.pba.rbac.xmlpolicy.XMLPolicyParser.registerXMLNode(NOT_NODE, NotNode.class);
    }catch (NoSuchMethodException nsme){
      nsme.printStackTrace();
    }

    OperationNode.registerInterpreterForNode(NOT_NODE, new NotInterpreter());
  }

  protected NotNode() {
  }

  /**
   * This constructor builds a NotNode given the XMLPolicyParser and the set of
   * attributes of this XML element. It expects that there is one and only one
   * child node.
   *
   * @param p - the XMLPolicyParser that builds this NotNode
   * @param attrs - the attributes of this XML element
   */
  public NotNode(issrg.pba.rbac.xmlpolicy.XMLPolicyParser p, org.xml.sax.Attributes attrs){
    super(NOT_NODE, attrs, 1, 1);
  }
}

/**
 * This is the default NotInterpreter. It accepts one and only one Term of type
 * Types.BOOLEAN_TYPE, and returns the boolean inverse of that.
 */
class NotInterpreter implements Interpreter {
  public NotInterpreter(){}

  /**
   * This interpreter can evaluate only one child and that one should be a 
   * of boolean type.
   *
   * @param t - the array of Terms of the expression
   *
   * @return Types.BOOLEAN_TYPE, if t is an array of 1 element, of which the
   *   type is Types.BOOLEAN_TYPE; otherwise null
   */
  public String canEvaluate(Term[] t){
    if (t.length==1 && t[0].getType().intern()==Types.BOOLEAN_TYPE){
      return Types.BOOLEAN_TYPE;
    }

    return null;
  }

  /**
   * This method evaluates the first element in the array of Terms and returns
   * the boolean inverse of it.
   *
   * @param env - the Environment in which the evaluation occurs
   * @param t - the array of Terms; must contain only one element, of which the
   *   getType() method should return Types.BOOLEAN_TYPE
   *
   * @return java.lang.Boolean object with the boolean inverse of t[0] as the
   *   value
   */
  public Object evaluate(Environment env, Term[] t) throws EvaluationException {
    if  (canEvaluate(t)==null){
      throw new EvaluationException("Cannot evaluate expression");
    }

    // t[0] always returns a Boolean (canEvaluate verifies that)
    return new Boolean(!((Boolean)t[0].evaluate(env)).booleanValue());
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -