📄 clock.java
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Salford nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package issrg.pba.rbac;
import java.util.Calendar;
/**
* This is the abstract class that provides the RelativeValidityPeriod and
* decision with current time.
* The simplest implementation just gets the system time. You may wish to
* provide a secure
* clock, obtaining the time from a time-stamping authority.
*
* <p>The latch method is used to get current time that will be used in
* subsequent calls
* to getTime method. This use ensures that the time will remain the same
* during long calculations. This is needed when making decisions to ensure
* that "current
* time" is the same
* during the whole process.
*
* @author A.Otenko
*/
public abstract class Clock extends Time {
/**
* This array is created once at construction time to save time each time
* getEvaluationTime is called
*/
private final int [] time = new int[6]; // day of week is not implemented yet, so array size is 6, not 7
/**
* This method gets the actual time and keeps it for later reference.
* Subsequent
* calls to getTime will return the same value (needed in operations extended
* in time).
*
* @return the current time
*/
public abstract java.util.Date latch();
/**
* This method returns the time returned by the last call to latch, so all
* calculations
* will be consistent.
*
* @return the time returned by the last call to latch
*/
public abstract java.util.Date getTime();
/**
* This method calls getTime() and converts it into the array of integers, so
* it can
* be compared by the TimeInterpreter.
*
* <p>Returns an array of integers representing the year, month, day
* hour, minute, second. If the value of the array element
* is -1, then the value is not specified ("don't care" when comparing)
*
* @return array of integers, each element standing for y,m,d,h,m,s
*/
public int [] getEvaluationTime(){
Calendar c=new java.util.GregorianCalendar(); // initialised with current day and time
c.setTime(getTime());
time[0]=c.get(Calendar.YEAR);
time[1]=c.get(Calendar.MONTH);
time[2]=c.get(Calendar.DAY_OF_MONTH);
//time[3]=c.get(Calendar.DAY_OF_WEEK); // day of week not implemented yet
time[/*4*/3]=c.get(Calendar.HOUR_OF_DAY);
time[/*5*/4]=c.get(Calendar.MINUTE);
time[/*6*/5]=c.get(Calendar.SECOND);
return time;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -