Source Code Cross Referenced for AndroMDALogger.java in  » UML » AndroMDA-3.2 » org » andromda » core » common » 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 » UML » AndroMDA 3.2 » org.andromda.core.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.core.common;
002:
003:        import java.io.InputStream;
004:
005:        import java.net.URL;
006:
007:        import org.andromda.core.configuration.Namespaces;
008:        import org.apache.commons.lang.StringUtils;
009:        import org.apache.log4j.BasicConfigurator;
010:        import org.apache.log4j.LogManager;
011:        import org.apache.log4j.Logger;
012:        import org.apache.log4j.xml.DOMConfigurator;
013:
014:        /**
015:         * This is the logger used to write <em>AndroMDA</em> prefixed messages so that our informational logging is nice
016:         * looking.
017:         *
018:         * @author <a href="http://www.mbohlen.de">Matthias Bohlen </a>
019:         * @author Chad Brandon
020:         * @since 26.11.2003
021:         */
022:        public class AndroMDALogger {
023:            /**
024:             * The default name to give the logger (if one isn't set)
025:             */
026:            private static final String DEFAULT_LOGGER_NAME = "AndroMDA";
027:            private static Logger logger = Logger
028:                    .getLogger(DEFAULT_LOGGER_NAME);
029:
030:            /**
031:             * Configures logging for the AndroMDA application from the the xml resource "log4j.xml" found within the same
032:             * package as this class.
033:             */
034:            public static void initialize() {
035:                String defaultConfiguration = "log4j.xml";
036:                URL url = null;
037:                final String configuration = loggingConfigurationUri;
038:                if (StringUtils.isNotEmpty(configuration)) {
039:                    try {
040:                        url = new URL(configuration);
041:                        InputStream stream = url.openStream();
042:                        stream.close();
043:                        stream = null;
044:                        configure(url);
045:                        logger
046:                                .info("Logging configured from external source --> '"
047:                                        + configuration + "'");
048:                    } catch (Throwable throwable) {
049:                        url = AndroMDALogger.class
050:                                .getResource(defaultConfiguration);
051:                        configure(url);
052:                        logger.warn("Invalid logging configuration uri --> '"
053:                                + configuration + "'");
054:                    }
055:                }
056:                if (url == null) {
057:                    url = AndroMDALogger.class
058:                            .getResource(defaultConfiguration);
059:                    configure(url);
060:                }
061:                if (url == null) {
062:                    throw new RuntimeException(
063:                            "Could not find default logging configuration file '"
064:                                    + defaultConfiguration + "'");
065:                }
066:            }
067:
068:            /**
069:             * The URI to an external logging configuration file.
070:             */
071:            private static String loggingConfigurationUri = null;
072:
073:            /**
074:             * Sets the URI to an external logging configuration file. This will override the default log4j.xml.
075:             *
076:             * @param loggingConfigurationUri the URI to the logging configuraiton file.
077:             */
078:            public static void setLoggingConfigurationUri(
079:                    final String loggingConfigurationUri) {
080:                AndroMDALogger.loggingConfigurationUri = loggingConfigurationUri;
081:            }
082:
083:            /**
084:             * Configures the Logger from the passed in logConfigurationXml
085:             *
086:             * @param logConfigurationXml
087:             */
088:            protected static void configure(final URL logConfigurationXml) {
089:                try {
090:                    DOMConfigurator.configure(logConfigurationXml);
091:                } catch (Exception ex) {
092:                    System.err.println("Unable to initialize logging system "
093:                            + "with configuration file '" + logConfigurationXml
094:                            + "' --> using basic configuration.");
095:                    BasicConfigurator.configure();
096:                }
097:            }
098:
099:            /**
100:             * Retrieves the namespace logger (if one is available) otherwise returns the root logger.
101:             *
102:             * @param namespaceName the name of the namespace for which we'll retrieve the logger instance.
103:             * @return the namespace or root logger instance.
104:             */
105:            public static Logger getNamespaceLogger(final String namespaceName) {
106:                Logger logger;
107:                if (namespaceName != null
108:                        && !Namespaces.DEFAULT.equals(namespaceName)) {
109:                    logger = Logger
110:                            .getLogger(getNamespaceLoggerName(namespaceName));
111:                } else {
112:                    logger = Logger.getRootLogger();
113:                }
114:                return logger;
115:            }
116:
117:            /**
118:             * Gets the name of the logger.
119:             *
120:             * @param namespace the name of the namespace for which this logger is used.
121:             * @return the logger name.
122:             */
123:            public static String getNamespaceLoggerName(final String namespace) {
124:                return "org.andromda.namespaces." + namespace;
125:            }
126:
127:            /**
128:             * Gets the name of the file to which namespace logging output will be written.
129:             *
130:             * @param namespace the name of the namespace for which this logger is used.
131:             * @return the namespace logging file name.
132:             */
133:            public static String getNamespaceLogFileName(final String namespace) {
134:                return "andromda-" + namespace + ".log";
135:            }
136:
137:            /**
138:             * Allows us to add a suffix to the logger name.
139:             *
140:             * @param suffix the suffix to append to the logger name.
141:             */
142:            public static void setSuffix(final String suffix) {
143:                logger = Logger.getLogger(DEFAULT_LOGGER_NAME + ':' + suffix);
144:            }
145:
146:            /**
147:             * Resets the logger to the default name.
148:             */
149:            public static void reset() {
150:                logger = Logger.getLogger(DEFAULT_LOGGER_NAME);
151:            }
152:
153:            /**
154:             * Shuts down the logger and releases any resources.
155:             */
156:            public static void shutdown() {
157:                LogManager.shutdown();
158:            }
159:
160:            public static void debug(Object object) {
161:                logger.debug(object);
162:            }
163:
164:            public static void info(Object object) {
165:                logger.info(object);
166:            }
167:
168:            public static void warn(Object object) {
169:                logger.warn(object);
170:            }
171:
172:            public static void error(Object object) {
173:                logger.error(object);
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.