KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log > output > io > rotate > RotateStrategyByDate


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.log.output.io.rotate;
18
19 import java.io.File JavaDoc;
20 import java.text.SimpleDateFormat JavaDoc;
21 import java.util.Date JavaDoc;
22
23 /**
24  * Rotation stragety based on SimpleDateFormat.
25  *
26  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
27  * @author <a HREF="mailto:colus@apache.org">Eung-ju Park</a>
28  * @version $Revision: 1.13 $ $Date: 2004/02/28 11:31:24 $
29  */

30 public class RotateStrategyByDate
31     implements RotateStrategy
32 {
33     private SimpleDateFormat JavaDoc m_format;
34     private Date JavaDoc m_date;
35     private String JavaDoc m_current;
36
37     /**
38      * Creation of a new rotation strategy based on a date policy.
39      */

40     public RotateStrategyByDate()
41     {
42         this( "yyyyMMdd" );
43     }
44
45     /**
46      * Creation of a new rotation strategy based on a date policy
47      * using a supplied pattern.
48      * @param pattern the message formatting pattern
49      */

50     public RotateStrategyByDate( final String JavaDoc pattern )
51     {
52         m_format = new SimpleDateFormat JavaDoc( pattern );
53         m_date = new Date JavaDoc();
54         m_current = m_format.format( m_date );
55     }
56
57     /**
58      * Reset the strategy.
59      */

60     public void reset()
61     {
62         m_date.setTime( System.currentTimeMillis() );
63         m_current = m_format.format( m_date );
64     }
65
66     /**
67      * Test is a rotation is required. Documentation pending ??
68      *
69      * @param data not used
70      * @param file not used
71      * @return TRUE if a rotation is required else FALSE
72      */

73     public boolean isRotationNeeded( final String JavaDoc data, final File JavaDoc file )
74     {
75         m_date.setTime( System.currentTimeMillis() );
76         if( m_current.equals( m_format.format( m_date ) ) )
77         {
78             return false;
79         }
80         return true;
81     }
82 }
83
Popular Tags