Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
15   119   4   3.75
8   34   0.47   4
4     1.75  
1    
 
 
  Time       Line # 65 15 4 96.3% 0.962963
 
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;
33   
34    /**
35    * This is an extension for evaluating Time expressions in the XML Policy.
36    *
37    * <p>The Policy must contain Const values of type "Time". The values must
38    * conform to the
39    * following syntax: "ccyy-mm-ddThh:mm:ss" (like in Validity elements in XML
40    * Policy). Thus
41    * the time can be specified up to the seconds.
42    * The year should always have 4 digits. Other fields do not need to have 2
43    * digits, if they represent
44    * numbers less than 10. "*" asterisc can be used as a wildcard to represent
45    * "any value" at that position. Trailing fields can be omitted and their
46    * values will be considered 0.
47    *
48    * <p>Examples:
49    * <p><code>&lt;Constant Type="Time" Value="*-*-*T8:20" /&gt;</code>
50    * <p>The example matches 08:20:00 in the morning any day
51    * <p><code>&lt;Constant Type="Time" Value="*-*-*T8:20:*" /&gt;</code>
52    * <p>The above matches any second after 08:20:00 and before 08:21:00 in the
53    * morning any day. This is
54    * different from the above example in that it matches ANY second, i.e. the
55    * whole minute up to 8:21, whilst
56    * the previous example specifies exact time of day (8:20:00).
57    * <p><code>&lt;Constant Type="Time" Value="*-1-*T20" /&gt;</code>
58    * <p>This example matches 8pm any day throughout January.
59    * <p><code>&lt;Constant Type="Time" Value="*-1" /&gt;</code>
60    * <p>This example matches midnight of every 1st of January.
61    *
62    * <p>The extension has been provided in PBA v1.1.
63    */
64   
 
65    public class Time {
66    public static final String TIME_TYPE="Time";
67   
68    private final int [] time=new int[]{-1, -1, -1,
69    // -1, // the fourth was for the weekday
70    -1, -1, -1};
71   
 
72  21 toggle public static void register(){
73  21 issrg.pba.rbac.xmlpolicy
74    .ifstatement.Types.registerType(TIME_TYPE, Time.class);
75    }
76   
 
77  36 toggle protected Time(){}
78   
79    /**
80    * This constructor builds a Time object out of its string representation
81    *
82    * @param timeString - the String in the format explained above.
83    */
 
84  241 toggle public Time(String timeString) throws IllegalArgumentException {
85  241 String d="--T::\""; // the last character is always there to ensure that the last number is parsed, too
86  241 String s;
87  241 int i;
88   
89  1687 for (int j=0; j<d.length(); j++){
90  1446 s=timeString;
91  1446 i=timeString.indexOf(d.charAt(j));
92  1446 if (i>=0){
93  998 s=timeString.substring(0, i);
94  998 timeString=timeString.substring(i+1);
95    }else{
96  448 timeString=""; // that's it, since no more delimiters found, no more time components are there
97    }
98   
99  1446 try{
100  1386 time[j]=s.intern()=="*"?-1:s.intern()==""?0:Integer.parseInt(s);
101    }catch (NumberFormatException nfe){
102  0 throw new IllegalArgumentException("Date format error: "+nfe.getMessage());
103    }
104    }
105    //System.out.println("parsed time: "+time[0]+"."+time[1]+"."+time[2]+", "+time[3]+":"+time[4]+":"+time[5]);//*************
106   
107    }
108   
109    /**
110    * Returns an array of integers representing the year, month, day
111    * hour, minute, second. If the value of the array element
112    * is -1, then the value is not specified ("don't care" when comparing)
113    *
114    * @return array of integers, each element standing for y,m,d,h,m,s
115    */
 
116  299 toggle public int [] getEvaluationTime(){
117  299 return time;
118    }
119    }