Source Code Cross Referenced for MessageLoggerEngine.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » util » 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 » Code Analyzer » apache ivy » org.apache.ivy.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.ivy.util;
019:
020:        import java.util.ArrayList;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Stack;
024:
025:        /**
026:         * A {@link MessageLogger} implementation delegating the work to the current top logger on a stack.
027:         * <p>
028:         * When the logger stack is empty, it delegates the work to a default logger, which by default is
029:         * the {@link Message#getDefaultLogger()}.
030:         * </p>
031:         * <p>
032:         * {@link #pushLogger(MessageLogger)} should be called to delegate to a new logger, and
033:         * {@link #popLogger()} should be called when the context of this logger is finished.
034:         * </p>
035:         */
036:        public class MessageLoggerEngine implements  MessageLogger {
037:            private final Stack/*<MessageLogger>*/loggerStack = new Stack();
038:
039:            private MessageLogger defaultLogger = null;
040:
041:            private List problems = new ArrayList();
042:
043:            private List warns = new ArrayList();
044:
045:            private List errors = new ArrayList();
046:
047:            public MessageLoggerEngine() {
048:            }
049:
050:            /**
051:             * Sets the logger used when the stack is empty.
052:             * 
053:             * @param defaultLogger the logger to use when the stack is empty.
054:             */
055:            public void setDefaultLogger(MessageLogger defaultLogger) {
056:                this .defaultLogger = defaultLogger;
057:            }
058:
059:            /**
060:             * Push a logger on the stack.
061:             * 
062:             * @param logger
063:             *            the logger to push. Must not be <code>null</code>.
064:             */
065:            public void pushLogger(MessageLogger logger) {
066:                Checks.checkNotNull(logger, "logger");
067:                loggerStack.push(logger);
068:            }
069:
070:            /**
071:             * Pops a logger from the logger stack.
072:             * <p>
073:             * Does nothing if the logger stack is empty
074:             * </p>
075:             */
076:            public void popLogger() {
077:                if (!loggerStack.isEmpty()) {
078:                    loggerStack.pop();
079:                }
080:            }
081:
082:            /**
083:             * Returns the current logger, or the default one if there is no logger in the stack
084:             * @return the current logger, or the default one if there is no logger in the stack
085:             */
086:            private MessageLogger peekLogger() {
087:                if (loggerStack.isEmpty()) {
088:                    return getDefaultLogger();
089:                }
090:                return (MessageLogger) loggerStack.peek();
091:            }
092:
093:            private MessageLogger getDefaultLogger() {
094:                // we don't store the logger returned by Message.getDefaultLogger() to always stay in sync
095:                // as long as our default logger has not been set explicitly with setDefaultLogger()
096:                return defaultLogger == null ? Message.getDefaultLogger()
097:                        : defaultLogger;
098:            }
099:
100:            // consolidated methods
101:            public void warn(String msg) {
102:                peekLogger().warn(msg);
103:                problems.add("WARN:  " + msg);
104:                warns.add(msg);
105:            }
106:
107:            public void error(String msg) {
108:                peekLogger().error(msg);
109:                problems.add("\tERROR: " + msg);
110:                errors.add(msg);
111:            }
112:
113:            public List getErrors() {
114:                return errors;
115:            }
116:
117:            public List getProblems() {
118:                return problems;
119:            }
120:
121:            public List getWarns() {
122:                return warns;
123:            }
124:
125:            public void sumupProblems() {
126:                MessageLoggerHelper.sumupProblems(this );
127:                clearProblems();
128:            }
129:
130:            public void clearProblems() {
131:                getDefaultLogger().clearProblems();
132:                for (Iterator iter = loggerStack.iterator(); iter.hasNext();) {
133:                    MessageLogger l = (MessageLogger) iter.next();
134:                    l.clearProblems();
135:                }
136:                problems.clear();
137:                errors.clear();
138:                warns.clear();
139:            }
140:
141:            public void setShowProgress(boolean progress) {
142:                getDefaultLogger().setShowProgress(progress);
143:                // updates all loggers in the stack
144:                for (Iterator iter = loggerStack.iterator(); iter.hasNext();) {
145:                    MessageLogger l = (MessageLogger) iter.next();
146:                    l.setShowProgress(progress);
147:                }
148:            }
149:
150:            public boolean isShowProgress() {
151:                // testing the default logger is enough, all loggers should be in sync
152:                return getDefaultLogger().isShowProgress();
153:            }
154:
155:            // delegation methods
156:
157:            public void debug(String msg) {
158:                peekLogger().debug(msg);
159:            }
160:
161:            public void deprecated(String msg) {
162:                peekLogger().deprecated(msg);
163:            }
164:
165:            public void endProgress() {
166:                peekLogger().endProgress();
167:            }
168:
169:            public void endProgress(String msg) {
170:                peekLogger().endProgress(msg);
171:            }
172:
173:            public void info(String msg) {
174:                peekLogger().info(msg);
175:            }
176:
177:            public void rawinfo(String msg) {
178:                peekLogger().rawinfo(msg);
179:            }
180:
181:            public void log(String msg, int level) {
182:                peekLogger().log(msg, level);
183:            }
184:
185:            public void progress() {
186:                peekLogger().progress();
187:            }
188:
189:            public void rawlog(String msg, int level) {
190:                peekLogger().rawlog(msg, level);
191:            }
192:
193:            public void verbose(String msg) {
194:                peekLogger().verbose(msg);
195:            }
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.