Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
11   126   5   1.83
4   32   0.91   3
6     1.67  
2    
 
 
  NotNode       Line # 49 5 2 75% 0.75
  NotInterpreter       Line # 87 6 4 69.2% 0.6923077
 
No Tests
 
1    /*
2    * Copyright (c) 2000-2005, University of Salford
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * Neither the name of the University of Salford nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    * POSSIBILITY OF SUCH DAMAGE.
30    */
31   
32    package issrg.pba.rbac.xmlpolicy.ifstatement;
33   
34    /**
35    * This is the class for Not node of the IF-statement. Its functionality is
36    * very much determined by OperationNode and NotInterpreter, which are
37    * configured to deliver the following semantics:
38    *
39    * <p>This operation expects one and only one Term of type Types.BOOLEAN_TYPE,
40    * and
41    * returns a
42    * value of type Types.BOOLEAN_TYPE.
43    * The evaluation result is "true", if and only if evaluation of the Term
44    * passed to the evaluate method results in a boolean "false".
45    *
46    * @author A.Otenko
47    */
48   
 
49    public class NotNode extends OperationNode {
50   
51    public final static String NOT_NODE = "NOT";
52   
53    /**
54    * Call this method to register the NotNode with the XMLPolicyParser. It also
55    * registers the default NotInterpreter.
56    */
 
57  21 toggle public static void register(){
58  21 try{
59  21 issrg.pba.rbac.xmlpolicy.XMLPolicyParser.registerXMLNode(NOT_NODE, NotNode.class);
60    }catch (NoSuchMethodException nsme){
61  0 nsme.printStackTrace();
62    }
63   
64  21 OperationNode.registerInterpreterForNode(NOT_NODE, new NotInterpreter());
65    }
66   
 
67  0 toggle protected NotNode() {
68    }
69   
70    /**
71    * This constructor builds a NotNode given the XMLPolicyParser and the set of
72    * attributes of this XML element. It expects that there is one and only one
73    * child node.
74    *
75    * @param p - the XMLPolicyParser that builds this NotNode
76    * @param attrs - the attributes of this XML element
77    */
 
78  8 toggle public NotNode(issrg.pba.rbac.xmlpolicy.XMLPolicyParser p, org.xml.sax.Attributes attrs){
79  8 super(NOT_NODE, attrs, 1, 1);
80    }
81    }
82   
83    /**
84    * This is the default NotInterpreter. It accepts one and only one Term of type
85    * Types.BOOLEAN_TYPE, and returns the boolean inverse of that.
86    */
 
87    class NotInterpreter implements Interpreter {
 
88  21 toggle public NotInterpreter(){}
89   
90    /**
91    * This interpreter can evaluate only one child and that one should be a
92    * of boolean type.
93    *
94    * @param t - the array of Terms of the expression
95    *
96    * @return Types.BOOLEAN_TYPE, if t is an array of 1 element, of which the
97    * type is Types.BOOLEAN_TYPE; otherwise null
98    */
 
99  43 toggle public String canEvaluate(Term[] t){
100  43 if (t.length==1 && t[0].getType().intern()==Types.BOOLEAN_TYPE){
101  43 return Types.BOOLEAN_TYPE;
102    }
103   
104  0 return null;
105    }
106   
107    /**
108    * This method evaluates the first element in the array of Terms and returns
109    * the boolean inverse of it.
110    *
111    * @param env - the Environment in which the evaluation occurs
112    * @param t - the array of Terms; must contain only one element, of which the
113    * getType() method should return Types.BOOLEAN_TYPE
114    *
115    * @return java.lang.Boolean object with the boolean inverse of t[0] as the
116    * value
117    */
 
118  35 toggle public Object evaluate(Environment env, Term[] t) throws EvaluationException {
119  35 if (canEvaluate(t)==null){
120  0 throw new EvaluationException("Cannot evaluate expression");
121    }
122   
123    // t[0] always returns a Boolean (canEvaluate verifies that)
124  35 return new Boolean(!((Boolean)t[0].evaluate(env)).booleanValue());
125    }
126    }