KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 /**
22  * Hierarchical rotation strategy.
23  * This object is initialised with several rotation strategy objects.
24  * The <code>isRotationNeeded</code> method checks the first rotation
25  * strategy object. If a rotation is needed, this result is returned.
26  * If not, the next rotation strategy object is checked, and so on.
27  *
28  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
29  */

30 public class OrRotateStrategy
31     implements RotateStrategy
32 {
33     private RotateStrategy[] m_strategies;
34
35     /** The rotation strategy used. This marker is required for the reset()
36      * method.
37      */

38     private int m_usedRotation = -1;
39
40     /**
41      * Constructor
42      * @param strategies the set of rotation strategies
43      */

44     public OrRotateStrategy( final RotateStrategy[] strategies )
45     {
46         this.m_strategies = strategies;
47     }
48
49     /**
50      * reset.
51      */

52     public void reset()
53     {
54         for( int i = 0; i < m_strategies.length; i++ )
55         {
56             m_strategies[ i ].reset();
57         }
58     }
59
60     /**
61      * check if now a log rotation is neccessary.
62      * This object is initialised with several rotation strategy objects.
63      * The <code>isRotationNeeded</code> method checks the first rotation
64      * strategy object. If a rotation is needed, this result is returned.
65      * If not the next rotation strategy object is asked and so on.
66      * @param data the last message written to the log system
67      * @param file ???
68      * @return boolean return true if log rotation is neccessary, else false
69      */

70     public boolean isRotationNeeded( final String JavaDoc data, final File JavaDoc file )
71     {
72         m_usedRotation = -1;
73
74         if( null != m_strategies )
75         {
76             final int length = m_strategies.length;
77             for( int i = 0; i < length; i++ )
78             {
79                 if( true == m_strategies[ i ].isRotationNeeded( data, file ) )
80                 {
81                     m_usedRotation = i;
82                     return true;
83                 }
84             }
85         }
86
87         return false;
88     }
89 }
90
91
Popular Tags