Source Code Cross Referenced for Log.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » core » support » umlsupport » 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 » IDE Netbeans » uml » org.netbeans.modules.uml.core.support.umlsupport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        /*
043:         * File         : Log.java
044:         * Version      : 2.0
045:         * Description  : Provides basic logging services for Describe IDE integrations.
046:         * Author       : Sumitabh Kansal
047:         */
048:        package org.netbeans.modules.uml.core.support.umlsupport;
049:
050:        import java.io.File;
051:        import java.io.FileWriter;
052:        import java.io.PrintWriter;
053:        import java.util.Date;
054:
055:        import org.netbeans.modules.uml.common.ETSystem;
056:        import org.netbeans.modules.uml.core.coreapplication.IPreferenceManager2;
057:        import org.netbeans.modules.uml.ui.products.ad.applicationcore.IADProduct;
058:        import org.netbeans.modules.uml.ui.support.ProductHelper;
059:
060:        /**
061:         *  Provides basic logging services for Describe IDE integrations.
062:         *
063:         * @author Sumitabh Kansal
064:         */
065:        public class Log {
066:            //kris richards - all LoggingInformation prefs have been expunged and set to empty or false.
067:            // Therefore, most methods do nothing effectual (no writing).
068:            /**
069:             *  An autoflushing writer to the logfile.
070:             */
071:            private static PrintWriter output = null;
072:
073:            private static boolean initialized = false;
074:
075:            private static final String LOG_PATH = "LoggingInformation";
076:            private static final String PREF_YES = "PSK_YES";
077:
078:            // bit masks used to reveal the MDR event type being passed in
079:            public final static int MDR_EVENT_MASK_UNKNOWN = 0; // 00000000
080:            public final static int MDR_EVENT_MASK_GENERAL = 7; // 00000111 
081:            public final static int MDR_EVENT_MASK_SPECIFIC = 248; // 11111000
082:
083:            // bit masks for the 3 general types of MDR events
084:            public final static int MDR_EVENT_MASK_PLANNED = 1; // 00000001
085:            public final static int MDR_EVENT_MASK_CANCELED = 2; // 00000010
086:            public final static int MDR_EVENT_MASK_CHANGE = 4; // 00000100
087:
088:            // bit masks for the 5 specific types of event
089:            public final static int MDR_EVENT_MASK_ATTRIBUTE = 8; // 00001000
090:            public final static int MDR_EVENT_MASK_ASSOCIATE = 16; // 00010000
091:            public final static int MDR_EVENT_MASK_EXTENT = 32; // 00100000
092:            public final static int MDR_EVENT_MASK_INSTANCE = 64; // 01000000
093:            public final static int MDR_EVENT_MASK_TRANSACTION = 128; // 10000000
094:
095:            public final static int MDR_EVENT_FLAG_RESET = 0;
096:            // bitwise flags indicating the 5 specific MDR events being logged
097:            // for each of the 3 general event types
098:            public static int mdrPlannedEventLogFlag = 0;
099:            public static int mdrCanceledEventLogFlag = 0;
100:            public static int mdrChangeEventLogFlag = 0;
101:
102:            /**
103:             *  Forces Log to reinitialize when the next Log request is made.
104:             */
105:            public static void reset() {
106:                mdrPlannedEventLogFlag = MDR_EVENT_FLAG_RESET;
107:                mdrCanceledEventLogFlag = MDR_EVENT_FLAG_RESET;
108:                mdrChangeEventLogFlag = MDR_EVENT_FLAG_RESET;
109:            }
110:
111:            /**
112:             *  Initializes Log.
113:             */
114:            public static void init() {
115:                setPropertyFlags();
116:            }
117:
118:            private static boolean initialized() {
119:                if (initialized)
120:                    return true;
121:                init();
122:                return initialized;
123:            }
124:
125:            /**
126:             *  Writes a string to the logfile, with an ending newline.
127:             */
128:            public static void write(String s) {
129:                write(s, true);
130:            }
131:
132:            /**
133:             *  Writes a string to the logfile, with an ending newline.
134:             */
135:            public static void write(String s, boolean newline) {
136:                try {
137:                    if (!initialized)
138:                        init();
139:
140:                    if (output != null) {
141:                        if (newline)
142:                            output.println(s);
143:                        else
144:                            output.print(s);
145:                    }
146:                }
147:
148:                catch (Exception e) {
149:                    e.printStackTrace();
150:                }
151:            }
152:
153:            /**
154:             *  Writes a string to the logfile, prefixed by the current date and a
155:             * [Debug] tag, and terminated by a newline. Suitable for debugging log
156:             * messages.
157:             * @param s The String to write.
158:             */
159:            public static void out(String s) {
160:                if (!initialized)
161:                    init();
162:            }
163:
164:            /**
165:             * Writes a string to the logfile, boxed by banner lines. Use sparingly...
166:             * @param s The String to write.
167:             * @deprecated This method is extremely noisy in the logfile and should not
168:             *             be used in production code.
169:             */
170:            public static void banner(String s) {
171:            }
172:
173:            /**
174:             * Dumps a stack trace of the current thread to the logfile.
175:             * @param s The String (or null) that will be used to describe the stack
176:             *          trace.
177:             * @deprecated This method is extremely noisy in the logfile, and should not
178:             *             be used in production code.
179:             */
180:            public static void dumpStack(String s) {
181:                Log.stackTrace(new Throwable(s).fillInStackTrace());
182:            }
183:
184:            /**
185:             *  Writes a string to the logfile, prefixed by the current date and an
186:             * [Entry] tag, and terminated by a newline. Suitable for function entry
187:             * logs.
188:             *
189:             * @param s The String to write.
190:             */
191:            public static void entry(String s) {
192:                if (!initialized)
193:                    init();
194:
195:            }
196:
197:            /**
198:             *  Writes a string to the logfile, prefixed by the current date and an
199:             * [Exit] tag, and terminated by a newline. Suitable for function exit
200:             * logs.
201:             *
202:             * @param s The String to write.
203:             */
204:            public static void exit(String s) {
205:
206:            }
207:
208:            /**
209:             *  Writes a string to the logfile, prefixed by the current date and an
210:             * [Error] tag, and terminated by a newline. Suitable for error
211:             * notifications.
212:             *
213:             * @param s The String to write.
214:             */
215:            public static void err(String s) {
216:                if (!initialized)
217:                    init();
218:
219:            }
220:
221:            /**
222:             * Writes a stack trace to the logfile.
223:             * @param t The Throwable object that holds the stack trace.
224:             */
225:            public static void stackTrace(Throwable t) {
226:                if (!initialized)
227:                    init();
228:
229:            }
230:
231:            /**
232:             * Writes a stack trace to the log file, with the error message
233:             * given. Suitable for logging conditions that should never occur.
234:             *
235:             * @param mess The error message.
236:             */
237:            public static void impossible(String mess) {
238:                dumpStack(mess);
239:            }
240:
241:            /**
242:             *  Writes a string to the logfile, prefixed by a [DescribeLog] tag.
243:             *
244:             * @param s The String to write.
245:             */
246:            public static void writeDescribeLogs(String s) {
247:                try {
248:                    if (!initialized)
249:                        init();
250:                } catch (Exception e) {
251:                    e.printStackTrace();
252:                }
253:            }
254:
255:            /**
256:             *  Writes a string to the logfile, prefixed by the current date and an
257:             * [Error] tag, and terminated by a newline. Suitable for error
258:             * notifications.
259:             *
260:             * @param s The String to write.
261:             */
262:            public static void mdrEventTrace(int mdrEventID, String s,
263:                    boolean newline) {
264:                if (!initialized)
265:                    init();
266:
267:                if (isMDREventEnabled(mdrEventID)) {
268:                    // actual miliseconds are more useful than formatted 
269:                    // date/time for event logging (the precision is desired)
270:                    write(System.currentTimeMillis() + " [MDR Event] " + s,
271:                            newline);
272:                    //         write(new Date(System.currentTimeMillis()) 
273:                    //            + " [MDR Event] " + s, newline);
274:                }
275:            }
276:
277:            /**
278:             *  Sets Log properties by asking Describe's preference manager. Aborts
279:             * if Describe is not connected.
280:             */
281:            private static void setPropertyFlags() {
282:                IPreferenceManager2 prefMan = ProductHelper
283:                        .getPreferenceManager();
284:                if (prefMan == null)
285:                    return;
286:
287:                String mdrLogPath = LOG_PATH
288:                        + "|LogMDREvents|LogMDRPlannedChangeEvents";
289:                String prefLogMDRPlannedAssocEvent = prefMan
290:                        .getPreferenceValue(mdrLogPath,
291:                                "LogMDRAssociationEvents");
292:                String prefLogMDRPlannedAttrEvent = prefMan.getPreferenceValue(
293:                        mdrLogPath, "LogMDRAttributeEvents");
294:                String prefLogMDRPlannedExtentEvent = prefMan
295:                        .getPreferenceValue(mdrLogPath, "LogMDRExtentEvents");
296:                String prefLogMDRPlannedInstanceEvent = prefMan
297:                        .getPreferenceValue(mdrLogPath, "LogMDRInstanceEvents");
298:                String prefLogMDRPlannedTransEvent = prefMan
299:                        .getPreferenceValue(mdrLogPath,
300:                                "LogMDRTransactionEvents");
301:
302:                mdrLogPath = LOG_PATH
303:                        + "|LogMDREvents|LogMDRCanceledChangeEvents";
304:                String prefLogMDRCanceledAssocEvent = prefMan
305:                        .getPreferenceValue(mdrLogPath,
306:                                "LogMDRAssociationEvents");
307:                String prefLogMDRCanceledAttrEvent = prefMan
308:                        .getPreferenceValue(mdrLogPath, "LogMDRAttributeEvents");
309:                String prefLogMDRCanceledExtentEvent = prefMan
310:                        .getPreferenceValue(mdrLogPath, "LogMDRExtentEvents");
311:                String prefLogMDRCanceledInstanceEvent = prefMan
312:                        .getPreferenceValue(mdrLogPath, "LogMDRInstanceEvents");
313:                String prefLogMDRCanceledTransEvent = prefMan
314:                        .getPreferenceValue(mdrLogPath,
315:                                "LogMDRTransactionEvents");
316:
317:                mdrLogPath = LOG_PATH + "|LogMDREvents|LogMDRChangeEvents";
318:                String prefLogMDRChangeAssocEvent = prefMan.getPreferenceValue(
319:                        mdrLogPath, "LogMDRAssociationEvents");
320:                String prefLogMDRChangeAttrEvent = prefMan.getPreferenceValue(
321:                        mdrLogPath, "LogMDRAttributeEvents");
322:                String prefLogMDRChangeExtentEvent = prefMan
323:                        .getPreferenceValue(mdrLogPath, "LogMDRExtentEvents");
324:                String prefLogMDRChangeInstanceEvent = prefMan
325:                        .getPreferenceValue(mdrLogPath, "LogMDRInstanceEvents");
326:                String prefLogMDRChangeTransEvent = prefMan.getPreferenceValue(
327:                        mdrLogPath, "LogMDRTransactionEvents");
328:
329:                if (PREF_YES.equals(prefLogMDRPlannedAssocEvent))
330:                    mdrPlannedEventLogFlag |= MDR_EVENT_MASK_ASSOCIATE;
331:                if (PREF_YES.equals(prefLogMDRPlannedAttrEvent))
332:                    mdrPlannedEventLogFlag |= MDR_EVENT_MASK_ATTRIBUTE;
333:                if (PREF_YES.equals(prefLogMDRPlannedExtentEvent))
334:                    mdrPlannedEventLogFlag |= MDR_EVENT_MASK_EXTENT;
335:                if (PREF_YES.equals(prefLogMDRPlannedInstanceEvent))
336:                    mdrPlannedEventLogFlag |= MDR_EVENT_MASK_INSTANCE;
337:                if (PREF_YES.equals(prefLogMDRPlannedTransEvent))
338:                    mdrPlannedEventLogFlag |= MDR_EVENT_MASK_TRANSACTION;
339:
340:                if (PREF_YES.equals(prefLogMDRCanceledAssocEvent))
341:                    mdrCanceledEventLogFlag |= MDR_EVENT_MASK_ASSOCIATE;
342:                if (PREF_YES.equals(prefLogMDRCanceledAttrEvent))
343:                    mdrCanceledEventLogFlag |= MDR_EVENT_MASK_ATTRIBUTE;
344:                if (PREF_YES.equals(prefLogMDRCanceledExtentEvent))
345:                    mdrCanceledEventLogFlag |= MDR_EVENT_MASK_EXTENT;
346:                if (PREF_YES.equals(prefLogMDRCanceledInstanceEvent))
347:                    mdrCanceledEventLogFlag |= MDR_EVENT_MASK_INSTANCE;
348:                if (PREF_YES.equals(prefLogMDRCanceledTransEvent))
349:                    mdrCanceledEventLogFlag |= MDR_EVENT_MASK_TRANSACTION;
350:
351:                if (PREF_YES.equals(prefLogMDRChangeAssocEvent))
352:                    mdrChangeEventLogFlag |= MDR_EVENT_MASK_ASSOCIATE;
353:                if (PREF_YES.equals(prefLogMDRChangeAttrEvent))
354:                    mdrChangeEventLogFlag |= MDR_EVENT_MASK_ATTRIBUTE;
355:                if (PREF_YES.equals(prefLogMDRChangeExtentEvent))
356:                    mdrChangeEventLogFlag |= MDR_EVENT_MASK_EXTENT;
357:                if (PREF_YES.equals(prefLogMDRChangeInstanceEvent))
358:                    mdrChangeEventLogFlag |= MDR_EVENT_MASK_INSTANCE;
359:                if (PREF_YES.equals(prefLogMDRChangeTransEvent))
360:                    mdrChangeEventLogFlag |= MDR_EVENT_MASK_TRANSACTION;
361:
362:                ETSystem.out.println("Log file not specified");
363:
364:                if (output != null) {
365:                    output.close();
366:                    output = null;
367:                }
368:
369:            }
370:
371:            private static boolean isMDREventEnabled(int mdrEventID) {
372:                int generalType = mdrEventID & MDR_EVENT_MASK_GENERAL;
373:                int specificType = (mdrEventID & MDR_EVENT_MASK_SPECIFIC);
374:
375:                if (generalType == MDR_EVENT_MASK_PLANNED) {
376:                    if ((mdrPlannedEventLogFlag & specificType) > 0)
377:                        return true;
378:                }
379:
380:                else if (generalType == MDR_EVENT_MASK_CANCELED) {
381:                    if ((mdrCanceledEventLogFlag & specificType) > 0)
382:                        return true;
383:                }
384:
385:                else if (generalType == MDR_EVENT_MASK_CHANGE) {
386:                    if ((mdrChangeEventLogFlag & specificType) > 0)
387:                        return true;
388:                }
389:
390:                return false;
391:            }
392:        }
ww__w___.j___a__v_a__2__s.___c_om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.