KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > services > loggingmonitor > RolloverPeriod


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.services.loggingmonitor;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26
27 /**
28  * This class encapsulates the specification of a log file's rollover period.
29  *
30  * @author <a HREF="mailto:jimmy.wilson@acxiom.com">James Wilson</a>
31  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
32  * @version $Revision: 37459 $
33  */

34 class RolloverPeriod
35 {
36    private static final Map JavaDoc periodFormatsMap;
37    static
38    {
39       periodFormatsMap = new HashMap JavaDoc();
40       periodFormatsMap.put("MONTH", "\'.\'yyyy-MM");
41       periodFormatsMap.put("MONTHLY", "\'.\'yyyy-MM");
42       periodFormatsMap.put("WEEK", "\'.\'yyyy-ww");
43       periodFormatsMap.put("WEEKLY", "\'.\'yyyy-ww");
44       periodFormatsMap.put("DAY", "\'.\'yyyy-MM-dd");
45       periodFormatsMap.put("DAILY", "\'.\'yyyy-MM-dd");
46       periodFormatsMap.put("HALFDAY", "\'.\'yyyy-MM-dd-a");
47       periodFormatsMap.put("HALFDAILY", "\'.\'yyyy-MM-dd-a");
48       periodFormatsMap.put("HOUR", "\'.\'yyyy-MM-dd-HH");
49       periodFormatsMap.put("HOURLY", "\'.\'yyyy-MM-dd-HH");
50       periodFormatsMap.put("MINUTE", "\'.\'yyyy-MM-dd-HH-mm");
51    }
52
53    private String JavaDoc rolloverPeriod;
54    private String JavaDoc rolloverFormat;
55
56    /**
57     * Constructor.
58     *
59     * @param rolloverPeriod a rollover period specification.
60     */

61    public RolloverPeriod(String JavaDoc rolloverPeriod)
62    {
63       this.rolloverFormat = (String JavaDoc)periodFormatsMap.get(rolloverPeriod.toUpperCase());
64
65       if (this.rolloverFormat == null)
66       {
67          throw new IllegalArgumentException JavaDoc("Unknown rollover period: " + rolloverPeriod);
68       }
69       this.rolloverPeriod = rolloverPeriod;
70    }
71
72    /**
73     * Returns the rollover format specification associated with the rollover
74     * period specification used to construct this class.
75     */

76    public String JavaDoc getRolloverFormat()
77    {
78       return rolloverFormat;
79    }
80
81    /**
82     * Returns the rollover period specification used to construct this class.
83     */

84    public String JavaDoc toString()
85    {
86       return rolloverPeriod;
87    }
88 }
89
Popular Tags