KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > managers > DefaultDeploymentLogger


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library 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 library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Briclet Frédéric.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers;
27
28 import java.io.File JavaDoc;
29 import java.io.FileWriter JavaDoc;
30 import java.io.PrintWriter JavaDoc;
31 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeploymentLogger;
32
33 /**
34  * The default Deployment logger implementation, which log the event message into
35  * a file.
36  *
37  * @author <a HREF="mailto:briclet@lifl.fr">Briclet Frédéric</a>
38  *
39  * @version 0.1
40  */

41 public class DefaultDeploymentLogger
42        implements DeploymentLogger
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49
private PrintWriter JavaDoc print;
50     private File JavaDoc file;
51     // ==================================================================
52
//
53
// Constructors.
54
//
55
// ==================================================================
56
/**
57      * The onstructor precising the text file to
58      * write in
59      */

60     public DefaultDeploymentLogger(String JavaDoc filepath)
61     throws Exception JavaDoc
62     {
63             File JavaDoc file=new File JavaDoc(filepath);
64             file.createNewFile();
65             print= new PrintWriter JavaDoc(new FileWriter JavaDoc(file));
66     }
67     /**
68      * The default constructor
69      */

70     public DefaultDeploymentLogger()
71     {
72     }
73     // ==================================================================
74
//
75
// Internal methods.
76
//
77
// ==================================================================
78
private void
79     setTemporaryLogFile()
80     {
81         try{
82             file=File.createTempFile("DeploymentLog"+System.currentTimeMillis(),".log");
83             file.createNewFile();
84             print= new PrintWriter JavaDoc(new FileWriter JavaDoc(file));
85         }
86         catch(Exception JavaDoc e){
87             e.printStackTrace();
88         }
89
90     }
91     // ==================================================================
92
//
93
// Public methods.
94
//
95
// ==================================================================
96
public void
97     setLogFile(String JavaDoc filepath)
98     throws Exception JavaDoc
99     {
100         file=new File JavaDoc(filepath);
101         file.createNewFile();
102         print= new PrintWriter JavaDoc(new FileWriter JavaDoc(file));
103     }
104     
105     
106     public void
107     removeLogFile()
108     {
109         try{
110             print.close();
111             file.delete();
112         }
113         catch(Exception JavaDoc e)
114         {
115             System.err.println("A problem occured during log file removing");
116         }
117     }
118     /**
119      * Log the given mesage @param ch in the current open file
120      * @param ch the message to log
121      */

122     public void
123     log(String JavaDoc ch)
124     {
125         if(print==null)
126             setTemporaryLogFile();
127         else
128         {
129             print.println(ch);
130             print.flush();
131         }
132     }
133 }
134
Popular Tags