KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > util > UniqueNameGenerator


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics.util;
24
25 import java.util.Calendar JavaDoc;
26 import java.util.Date JavaDoc;
27 /**
28  *
29  * @author mu125243
30  */

31 public class UniqueNameGenerator {
32     
33     private static final String JavaDoc AM = "AM";
34     private static final String JavaDoc PM = "PM";
35     private static final char SEPARATOR = '-';
36     private static final char DATE_SEPARATOR = '_';
37     private static final String JavaDoc REPORT_JAR = "report.jar";
38     
39     /** Creates a new instance of UniqueNameGenerator */
40     public UniqueNameGenerator() {
41     }
42     
43     /**
44      * @param defaultDir directory in which report is stored
45      * @name name of the target for which report is being generated
46      * @return name of diagnostic report
47      */

48     public static String JavaDoc getName(String JavaDoc target) {
49         Date JavaDoc dateObj = new Date JavaDoc();
50         Calendar JavaDoc calendar = Calendar.getInstance();
51         String JavaDoc am_pm = calendar.get(Calendar.AM_PM) == 0? AM : PM;
52         int month = calendar.get(Calendar.MONTH) + 1;
53         String JavaDoc dateValue = "" + month +
54                 calendar.get(Calendar.DAY_OF_MONTH) +
55                 calendar.get(Calendar.YEAR);
56         String JavaDoc dateTime = ""+calendar.get(Calendar.HOUR_OF_DAY) +
57                SEPARATOR + calendar.get(Calendar.MINUTE) + am_pm;
58         String JavaDoc fileName = target + SEPARATOR +
59                 dateValue + DATE_SEPARATOR + dateTime + SEPARATOR + REPORT_JAR;
60  
61         return fileName;
62     }
63 }
64
Popular Tags