Source Code Cross Referenced for DeployerLog.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_lib » deployment » work » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas_lib.deployment.work 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2004 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer(s): Florent BENOIT & Ludovic BERT
022:         * --------------------------------------------------------------------------
023:         * $Id: DeployerLog.java 6673 2005-04-28 16:53:00Z benoitf $
024:         * --------------------------------------------------------------------------
025:         */package org.objectweb.jonas_lib.deployment.work;
026:
027:        //import java
028:        import java.io.BufferedReader;
029:        import java.io.BufferedWriter;
030:        import java.io.File;
031:        import java.io.FileNotFoundException;
032:        import java.io.FileReader;
033:        import java.io.FileWriter;
034:        import java.io.IOException;
035:        import java.io.PrintWriter;
036:        import java.util.Enumeration;
037:        import java.util.StringTokenizer;
038:        import java.util.Vector;
039:
040:        import org.objectweb.util.monolog.api.Logger;
041:        import org.objectweb.util.monolog.api.BasicLevel;
042:
043:        import org.objectweb.jonas.common.Log;
044:
045:        /**
046:         * Class which permits to store or load the association between the name of an
047:         * package and the timestamped work copy associated.
048:         * @author Florent Benoit
049:         * @author Ludovic Bert
050:         */
051:        public class DeployerLog {
052:
053:            /**
054:             * The logger used in JOnAS
055:             */
056:            private static Logger logger = Log
057:                    .getLogger(Log.JONAS_DEPLOY_WORK_PREFIX);
058:
059:            /**
060:             * separator char of a entry in the log file
061:             */
062:            private static final String SEPARATOR_ENTRY = ";";
063:
064:            /**
065:             * File for logging
066:             */
067:            private File logFile;
068:
069:            /**
070:             * the current entries of the logfile
071:             */
072:            private Vector logEntries = null;
073:
074:            /**
075:             * Constructor for the deployerLog.
076:             * @param logFile the file which is used for read/write entries
077:             * @throws DeployerLogException if the loadentries failed.
078:             */
079:            public DeployerLog(File logFile) throws DeployerLogException {
080:                if (getLogger().isLoggable(BasicLevel.DEBUG)) {
081:                    getLogger().log(BasicLevel.DEBUG,
082:                            "logfile=" + logFile.getName());
083:                }
084:
085:                this .logFile = logFile;
086:                logEntries = new Vector();
087:                loadEntries();
088:            }
089:
090:            /**
091:             * @return the logger
092:             */
093:            protected static Logger getLogger() {
094:                return logger;
095:            }
096:
097:            /**
098:             * load the entries of the log file.
099:             * @throws DeployerLogException if the load failed.
100:             */
101:            private synchronized void loadEntries() throws DeployerLogException {
102:
103:                BufferedReader br = null;
104:                try {
105:                    br = new BufferedReader(new FileReader(logFile));
106:                } catch (FileNotFoundException e) {
107:                    throw new DeployerLogException("Can not read the "
108:                            + logFile + " file");
109:                }
110:                String line = null;
111:
112:                String field = null;
113:                File originalField = null;
114:                File copyField = null;
115:                StringTokenizer st = null;
116:
117:                try {
118:                    //Read the text file
119:                    while ((line = br.readLine()) != null) {
120:
121:                        //parse the String
122:                        st = new StringTokenizer(line, SEPARATOR_ENTRY);
123:                        field = st.nextToken();
124:                        if (field == null) {
125:                            throw new DeployerLogException(
126:                                    "Inconsistent line in the file " + logFile);
127:                        }
128:                        originalField = new File(field);
129:
130:                        field = st.nextToken();
131:                        if (field == null) {
132:                            throw new DeployerLogException(
133:                                    "Inconsistent line in the file " + logFile);
134:                        }
135:
136:                        copyField = new File(field);
137:
138:                        getLogger().log(
139:                                BasicLevel.DEBUG,
140:                                "Entry[originalField=" + originalField
141:                                        + ",copyField=" + copyField + "]");
142:                        logEntries.add(new LogEntry(originalField, copyField));
143:                    }
144:                    // Close the input stream
145:                    br.close();
146:                } catch (IOException ioe) {
147:                    throw new DeployerLogException(
148:                            "Error while reading the log file " + logFile
149:                                    + " :" + ioe.getMessage());
150:                }
151:            }
152:
153:            /**
154:             * Dump(save) the entries to the log file.
155:             * @throws DeployerLogException if the save failed.
156:             */
157:            private synchronized void saveEntries() throws DeployerLogException {
158:
159:                PrintWriter pw = null;
160:                try {
161:                    pw = new PrintWriter(new BufferedWriter(new FileWriter(
162:                            logFile)));
163:                } catch (IOException e) {
164:                    throw new DeployerLogException(
165:                            "Problem while trying to get an output stream for the "
166:                                    + logFile + " file");
167:                }
168:
169:                LogEntry logEntry = null;
170:                String original = null;
171:                String copy = null;
172:                String line = null;
173:                for (Enumeration e = logEntries.elements(); e.hasMoreElements();) {
174:                    logEntry = (LogEntry) e.nextElement();
175:
176:                    //get the infos
177:
178:                    try {
179:                        original = logEntry.getOriginal().getCanonicalPath();
180:                        copy = logEntry.getCopy().getCanonicalPath();
181:                    } catch (IOException ioe) {
182:                        throw new DeployerLogException(
183:                                "Problem while trying to get files names ");
184:                    }
185:
186:                    //create the line
187:                    line = original + SEPARATOR_ENTRY + copy;
188:
189:                    //dump the line
190:                    pw.println(line);
191:                }
192:                // Close the stream
193:                pw.close();
194:            }
195:
196:            /**
197:             * Return the entries of the file.
198:             * @return a vector of LogEntry item.
199:             */
200:            public synchronized Vector getEntries() {
201:                return logEntries;
202:            }
203:
204:            /**
205:             * Remove the given entry and return the entries of the file.
206:             * @param entry the LogEntry which must be remove.
207:             * @return the new vector of LogEntry item.
208:             * @throws DeployerLogException if the remove can't be done
209:             */
210:            public synchronized Vector removeEntry(LogEntry entry)
211:                    throws DeployerLogException {
212:                if (logEntries == null) {
213:                    throw new DeployerLogException(
214:                            "Can not remove a entry, the vector is null");
215:                }
216:
217:                if (!logEntries.contains(entry)) {
218:                    throw new DeployerLogException("Can not remove entry "
219:                            + entry + ". There is no such entry");
220:                }
221:
222:                //remove can be done
223:                logEntries.remove(entry);
224:
225:                //write to the file.
226:                saveEntries();
227:
228:                //return the new vector
229:                return logEntries;
230:            }
231:
232:            /**
233:             * Add the entry and return the new entries
234:             * @param original the name of the file
235:             * @param copy the copy of the file
236:             * @return the new vector of LogEntry item.
237:             * @throws DeployerLogException if the add can't be done
238:             */
239:            public synchronized Vector addEntry(File original, File copy)
240:                    throws DeployerLogException {
241:                if (logEntries == null) {
242:                    throw new DeployerLogException(
243:                            "Can not add an entry, the vector is null");
244:                }
245:
246:                //add only if it's not already present
247:                LogEntry logEntry = null;
248:                File originalEntry = null;
249:                File copyEntry = null;
250:
251:                boolean found = false;
252:                Enumeration e = logEntries.elements();
253:
254:                //add only if the entry is not found
255:                while (e.hasMoreElements() && !found) {
256:                    logEntry = (LogEntry) e.nextElement();
257:
258:                    originalEntry = logEntry.getOriginal();
259:                    copyEntry = logEntry.getCopy();
260:
261:                    if (originalEntry.getPath().equals(original.getPath())
262:                            && copyEntry.getName().equals(copy.getName())) {
263:                        found = true;
264:                    }
265:                }
266:                if (found) {
267:                    return logEntries;
268:                }
269:
270:                //add entry
271:                logEntry = new LogEntry(original, copy);
272:
273:                //add can be done
274:                logEntries.add(logEntry);
275:
276:                //write to the file.
277:                saveEntries();
278:
279:                //return the new vector
280:                return logEntries;
281:            }
282:
283:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.