Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
9   109   1   9
0   18   0.11   1
1     1  
1    
 
 
  Clock       Line # 54 9 1 100% 1.0
 
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    import java.util.Calendar;
35   
36    /**
37    * This is the abstract class that provides the RelativeValidityPeriod and
38    * decision with current time.
39    * The simplest implementation just gets the system time. You may wish to
40    * provide a secure
41    * clock, obtaining the time from a time-stamping authority.
42    *
43    * <p>The latch method is used to get current time that will be used in
44    * subsequent calls
45    * to getTime method. This use ensures that the time will remain the same
46    * during long calculations. This is needed when making decisions to ensure
47    * that "current
48    * time" is the same
49    * during the whole process.
50    *
51    * @author A.Otenko
52    */
53   
 
54    public abstract class Clock extends Time {
55   
56    /**
57    * This array is created once at construction time to save time each time
58    * getEvaluationTime is called
59    */
60    private final int [] time = new int[6]; // day of week is not implemented yet, so array size is 6, not 7
61   
62    /**
63    * This method gets the actual time and keeps it for later reference.
64    * Subsequent
65    * calls to getTime will return the same value (needed in operations extended
66    * in time).
67    *
68    * @return the current time
69    */
70    public abstract java.util.Date latch();
71   
72    /**
73    * This method returns the time returned by the last call to latch, so all
74    * calculations
75    * will be consistent.
76    *
77    * @return the time returned by the last call to latch
78    */
79    public abstract java.util.Date getTime();
80   
81    /**
82    * This method calls getTime() and converts it into the array of integers, so
83    * it can
84    * be compared by the TimeInterpreter.
85    *
86    * <p>Returns an array of integers representing the year, month, day
87    * hour, minute, second. If the value of the array element
88    * is -1, then the value is not specified ("don't care" when comparing)
89    *
90    * @return array of integers, each element standing for y,m,d,h,m,s
91    */
 
92  122 toggle public int [] getEvaluationTime(){
93  122 Calendar c=new java.util.GregorianCalendar(); // initialised with current day and time
94  122 c.setTime(getTime());
95   
96  122 time[0]=c.get(Calendar.YEAR);
97  122 time[1]=c.get(Calendar.MONTH);
98  122 time[2]=c.get(Calendar.DAY_OF_MONTH);
99    //time[3]=c.get(Calendar.DAY_OF_WEEK); // day of week not implemented yet
100   
101  122 time[/*4*/3]=c.get(Calendar.HOUR_OF_DAY);
102  122 time[/*5*/4]=c.get(Calendar.MINUTE);
103  122 time[/*6*/5]=c.get(Calendar.SECOND);
104   
105  122 return time;
106    }
107   
108    }
109