Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
17   126   7   3.4
6   35   0.65   5
5     2.2  
1    
 
 
  ArgNode       Line # 52 17 7 46.4% 0.4642857
 
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 that represents an Arg node and evaluates the arguments of
36    * an
37    * action at run-time.
38    *
39    * <p>If the policy contains the arguments of types for which there is no
40    * constructor provided
41    * by the AEF (not registered with the Types), or the AEF failed to provide the
42    * argument with the name
43    * stated in the policy, an EvaluationException will occur at run-time.
44    *
45    * <p>Note that if the evaluation does not reach the point where the argument
46    * is needed, no
47    * exception will be thrown.
48    *
49    * @author A.Otenko
50    */
51   
 
52    public class ArgNode extends TermNode {
53    /**
54    * This is the name of the node that represents the Arg - a reference to an
55    * argument of the
56    * action being authorised.
57    */
58    public final static String ARG_NODE = "Arg";
59   
60    /**
61    * This method should be called to register the node with the XML Parser
62    */
 
63  21 toggle public static void register(){
64  21 try{
65  21 issrg.pba.rbac.xmlpolicy.XMLPolicyParser.registerXMLNode(ARG_NODE, ArgNode.class);
66    }catch (NoSuchMethodException nsme){
67  0 nsme.printStackTrace();
68    }
69    }
70   
71    protected String type;
72    protected String parameter_name;
73   
 
74  0 toggle protected ArgNode() {}
75   
76    /**
77    * This constructor builds an ArgNode, given a XMLPolicyParser and the
78    * set of attributes of this XML element. It expects that a
79    * issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE and
80    * issrg.pba.rbac.xmlpolicy.XMLTags.NAME_ATTRIBUTE ("Type" and "Name") are
81    * present in this XML element.
82    *
83    * @param p - the XMLPolicyParser that builds this ArgNode
84    * @param attr - the attributes of this XML element
85    */
 
86  67 toggle public ArgNode(issrg.pba.rbac.xmlpolicy.XMLPolicyParser p, org.xml.sax.Attributes attr) throws issrg.pba.rbac.PolicyParsingException {
87  67 super(ARG_NODE, attr, -1, 0);
88   
89  67 type=((String)getAttributes().get(issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE)).intern();
90  0 if (type==null) throw new issrg.pba.rbac.PolicyParsingException(issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE+" attribute was expected in "+ARG_NODE);
91  67 parameter_name=(String)getAttributes().get(issrg.pba.rbac.xmlpolicy.XMLTags.NAME_ATTRIBUTE);
92  0 if (type==null) throw new issrg.pba.rbac.PolicyParsingException(issrg.pba.rbac.xmlpolicy.XMLTags.NAME_ATTRIBUTE+" attribute was expected in "+ARG_NODE);
93    }
94   
95    /**
96    * This method returns the type of this argument.
97    */
 
98  207 toggle public String getType(){
99  207 return type;
100    }
101   
102    /**
103    * This method returns the value of the action argument that this element
104    * refers to. Types.construct() method is used to convert the String
105    * representation of the argument value in the Environment into a Java object.
106    *
107    * @param env - the Environment of the evaluation, including the arguments
108    * of the Action
109    *
110    * @return the Object, constructed from the String representation of the
111    * argument value
112    */
 
113  0 toggle public Object evaluate(Environment env) throws EvaluationException{
114  0 try{
115  0 issrg.pba.rbac.Argument arg = (issrg.pba.rbac.Argument)env.getArgs().get(parameter_name);
116   
117  0 if (arg==null || arg.getType().intern()!=type){
118  0 throw new EvaluationException("No such argument to the action: "+parameter_name+" of type "+type);
119    }
120   
121  0 return Types.construct(type, arg.getValue());
122    }catch (Throwable th){
123  0 throw new EvaluationException("Evaluation run-time error", th);
124    }
125    }
126    }