Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
31   162   8   5.17
12   53   0.42   6
6     2.17  
1    
 
 
  SimpleObligations       Line # 61 31 8 26.5% 0.26530612
 
No Tests
 
1   
2    /*
3    * Copyright (c) 2006, University of Kent
4    * All rights reserved.
5    *
6    * Redistribution and use in source and binary forms, with or without
7    * modification, are permitted provided that the following conditions are met:
8    *
9    * Redistributions of source code must retain the above copyright notice, this
10    * list of conditions and the following disclaimer.
11    *
12    * Redistributions in binary form must reproduce the above copyright notice,
13    * this list of conditions and the following disclaimer in the documentation
14    * and/or other materials provided with the distribution.
15    *
16    * 1. Neither the name of the University of Kent nor the names of its
17    * contributors may be used to endorse or promote products derived from this
18    * software without specific prior written permission.
19    *
20    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23    * PURPOSE ARE DISCLAIMED.
24    *
25    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32    * POSSIBILITY OF SUCH DAMAGE.
33    *
34    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
35    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
36    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
37    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
38    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
39    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
40    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
41    * SERIOUS FAULTS, IN THIS SOFTWARE.
42    *
43    * 5. This license is governed, except to the extent that local laws
44    * necessarily apply, by the laws of England and Wales.
45    *
46    * Author : Gansen Zhao
47    * Email: gz7@kent.ac.uk
48    */
49   
50    package issrg.pba;
51   
52    import issrg.pba.rbac.xmlpolicy.PolicyXMLNode;
53    import java.util.Vector;
54   
55    /**
56    * This class implements the interface Obligations, and provides a constructor
57    * to construct an instance based on a PolicyXMLNode object.
58    *
59    * @author gansen
60    */
 
61    public class SimpleObligations implements issrg.pba.Obligations{
62   
63    //a vector holding all the obligations.
64    Vector m_vObligations;
65   
66    /** Creates a new instance of SimpleObligations */
 
67  0 toggle public SimpleObligations() {
68  0 m_vObligations=null;
69    }
70   
71   
72    /**
73    * check if the Obligations Object contains no obligations.
74    */
 
75  0 toggle public boolean isEmpty(){
76    //return false;
77  0 if(m_vObligations==null)
78  0 return true;
79  0 if(m_vObligations.size()<1)
80  0 return true;
81  0 return false;
82    }
83   
84    /**
85    * Construct a SimpleObligations Object using an XMLPolicyNode. <br>
86    *
87    * This constructor constructs an instance based on the PolicyXMLNode constructed
88    * when by the xml policy parser. The PolcyXMLNode corresponses to the xml node of the
89    * obligations object in the xml tree.
90    *
91    * @param ObligationsNode The corresponding PolicyXMLNode object of the Obligations in
92    * the target access rule.
93    *
94    */
 
95  2 toggle public SimpleObligations(PolicyXMLNode ObligationsNode){
96    //build the obligations node
97  2 Obligation oblg;
98  2 if(ObligationsNode==null)
99  0 return;
100  2 Vector vObligations=ObligationsNode.getChildren();
101  2 PolicyXMLNode obligationNode;
102   
103  2 m_vObligations=new Vector();
104   
105    //acquire obligation nodes from the vector, and then
106    //create obligation objects from obligation nodes
107  6 for(int i =0;i<vObligations.size();i++){
108  4 obligationNode=(PolicyXMLNode)vObligations.get(i);
109  4 oblg=new SimpleObligation(obligationNode);
110  4 m_vObligations.add(oblg);
111    }
112    }
113   
114    /**
115    * This function converts the internal structure into XML text string.
116    * It generates the tags for the highest level (OBLIGATIONS). The tags
117    * are <Obligations> and </Olibgations>
118    *
119    * <p>No Attributes are iterated and inserts into the XML text as the XML DTD
120    * of Obligations contains no attributes. All children nodes
121    * are converted to XML by their own (which is implemented by the xmlpolicynode).
122    */
 
123  0 toggle public String toXML(){
124  0 String xml;
125  0 SimpleObligation so;
126  0 xml=new String("");
127  0 if((m_vObligations!=null)&&(m_vObligations.size()>0)){
128  0 xml+=new String("<Obligations>");
129  0 for(int i=0;i <m_vObligations.size();i++){
130  0 so=(SimpleObligation) m_vObligations.get(i);
131  0 xml+=new String("\r\n");
132  0 xml+=so.toXML();
133    }
134  0 xml+=new String("\r\n");
135  0 xml+=new String("</Obligations>");
136    }else{
137  0 xml+=new String("<Obligations />");
138    }
139  0 return xml;
140    }
141   
142    /**
143    * This function retrieves a vector which contains the obligations
144    *
145    * @return a vector containing the obligations objects that are children of the OBLIGATIONS object.
146    * when the current OBLIGATIONS object has no children, the return value might be a null pointer.
147    */
 
148  0 toggle public Vector getObligations(){
149  0 return m_vObligations;
150    }
151   
152    /**
153    * This function acts the same as the toXML function. It overrides the default implementation of the
154    * java's object class.
155    *
156    * @return the XML string representing the current object.
157    */
 
158  0 toggle public String toString(){
159  0 return toXML();
160    }
161   
162    }