Source Code Cross Referenced for PluginFileAppender.java in  » Workflow-Engines » osbl-1_0 » logging » 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 » Workflow Engines » osbl 1_0 » logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package logging;
002:
003:        import java.io.IOException;
004:
005:        import org.apache.log4j.Layout;
006:        import org.apache.log4j.RollingFileAppender;
007:        import org.eclipse.core.runtime.IPath;
008:
009:        /**
010:         * PluginFileAppender
011:         * This class is a custom Log4J appender that sends Log4J events to 
012:         * the Eclipse plug-in state location. It extends the RollingFileAppender class.
013:         * @author Manoel Marques
014:         */
015:        public class PluginFileAppender extends RollingFileAppender {
016:
017:            private IPath stateLocation;
018:            private boolean activateOptionsPending;
019:            private boolean translatePath = true;
020:
021:            /**
022:             * Creates a new PluginFileAppender.
023:             */
024:            public PluginFileAppender() {
025:                super ();
026:            }
027:
028:            /**
029:             * Creates a new PluginFileAppender.
030:             * @param layout layout instance.
031:             * @param stateLocation IPath containing the plug-in state location 
032:             */
033:            public PluginFileAppender(Layout layout, IPath stateLocation) {
034:                super ();
035:                setLayout(layout);
036:                setStateLocation(stateLocation);
037:            }
038:
039:            /**
040:             * Creates a new PluginFileAppender.
041:             * @param layout layout instance.
042:             * @param stateLocation IPath containing the plug-in state location 
043:             * @param file file name
044:             * @param append true if file is to be appended
045:             */
046:            public PluginFileAppender(Layout layout, IPath stateLocation,
047:                    String file, boolean append) throws IOException {
048:                super ();
049:                setLayout(layout);
050:                setStateLocation(stateLocation);
051:                setFile(file);
052:                setAppend(append);
053:                activateOptions();
054:            }
055:
056:            /**
057:             * Creates a new PluginFileAppender.
058:             * @param layout layout instance.
059:             * @param stateLocation IPath containing the plug-in state location 
060:             * @param file file name
061:             */
062:            public PluginFileAppender(Layout layout, IPath stateLocation,
063:                    String file) throws IOException {
064:                super ();
065:                setLayout(layout);
066:                setStateLocation(stateLocation);
067:                setFile(file);
068:                activateOptions();
069:            }
070:
071:            /**
072:             * Sets the state location. If activateOptions call is pending, translate the file name
073:             * and call activateOptions 
074:             * @param stateLocation IPath containing the plug-in state location 
075:             */
076:            void setStateLocation(IPath stateLocation) {
077:                this .stateLocation = stateLocation;
078:                if (this .stateLocation != null && this .activateOptionsPending) {
079:                    this .activateOptionsPending = false;
080:                    setFile(getFile());
081:                    activateOptions();
082:                }
083:            }
084:
085:            /**
086:             * Sets the file name.Translate it before setting. 
087:             * @param file file name
088:             */
089:            public void setFile(String file) {
090:                super .setFile(getTranslatedFileName(file));
091:            }
092:
093:            /**
094:             * Set file options and opens it, leaving ready to write.
095:             * @param file file name
096:             * @param append true if file is to be appended
097:             * @param bufferedIO true if file is to buffered
098:             * @param bufferSize buffer size
099:             * @throws IOException - IO Error happend or the state location was not set   
100:             */
101:            public void setFile(String fileName, boolean append,
102:                    boolean bufferedIO, int bufferSize) throws IOException {
103:                if (this .stateLocation == null)
104:                    throw new IOException("Missing Plugin State Location.");
105:
106:                fileName = (this .translatePath) ? getTranslatedFileName(fileName)
107:                        : fileName;
108:                super .setFile(fileName, append, bufferedIO, bufferSize);
109:            }
110:
111:            /**
112:             * Finishes instance initialization. If state location was not set, set activate as 
113:             * pending and does nothing.
114:             */
115:            public void activateOptions() {
116:                if (this .stateLocation == null) {
117:                    this .activateOptionsPending = true;
118:                    return;
119:                }
120:
121:                // base class will call setFile, don't translate the name
122:                // because it was already translated
123:                this .translatePath = false;
124:                super .activateOptions();
125:                this .translatePath = true;
126:            }
127:
128:            /**
129:             * Any path part of a file is removed and the state location is added to the name
130:             * to form a new path. If there is not state location, returns the name unmodified.
131:             * @param file file name
132:             * @return translated file name 
133:             */
134:            private String getTranslatedFileName(String file) {
135:
136:                if (this .stateLocation == null || file == null)
137:                    return file;
138:
139:                file = file.trim();
140:                if (file.length() == 0)
141:                    return file;
142:
143:                int index = file.lastIndexOf('/');
144:                if (index == -1)
145:                    index = file.lastIndexOf('\\');
146:
147:                if (index != -1)
148:                    file = file.substring(index + 1);
149:
150:                IPath newPath = this.stateLocation.append(file);
151:                return newPath.toString();
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.