KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > cosnaming > NamingUtils


1 /*
2  * @(#)NamingUtils.java 1.18 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.naming.cosnaming;
9
10 import java.io.*;
11 import org.omg.CosNaming.NameComponent JavaDoc;
12
13
14 public class NamingUtils {
15     // Do not instantiate this class
16
private NamingUtils() {};
17
18     /**
19      * Debug flag which must be true for debug streams to be created and
20      * dprint output to be generated.
21      */

22     public static boolean debug = false;
23
24     /**
25      * Prints the message to the debug stream if debugging is enabled.
26      * @param msg the debug message to print.
27      */

28     public static void dprint(String JavaDoc msg) {
29     if (debug && debugStream != null)
30         debugStream.println(msg);
31     }
32
33     /**
34      * Prints the message to the error stream (System.err is default).
35      * @param msg the error message to print.
36      */

37     public static void errprint(String JavaDoc msg) {
38     if (errStream != null)
39         errStream.println(msg);
40     else
41         System.err.println(msg);
42     }
43
44     /**
45      * Prints the stacktrace of the supplied exception to the error stream.
46      * @param e any Java exception.
47      */

48     public static void printException(java.lang.Exception JavaDoc e) {
49     if (errStream != null)
50         e.printStackTrace(errStream);
51     else
52         e.printStackTrace();
53     }
54
55     /**
56      * Create a debug print stream to the supplied log file.
57      * @param logFile the file to which debug output will go.
58      * @exception IOException thrown if the file cannot be opened for output.
59      */

60     public static void makeDebugStream(File logFile)
61     throws java.io.IOException JavaDoc {
62     // Create an outputstream for debugging
63
java.io.OutputStream JavaDoc logOStream =
64         new java.io.FileOutputStream JavaDoc(logFile);
65     java.io.DataOutputStream JavaDoc logDStream =
66         new java.io.DataOutputStream JavaDoc(logOStream);
67     debugStream = new java.io.PrintStream JavaDoc(logDStream);
68       
69     // Emit first message
70
debugStream.println("Debug Stream Enabled.");
71     }
72   
73     /**
74      * Create a error print stream to the supplied file.
75      * @param logFile the file to which error messages will go.
76      * @exception IOException thrown if the file cannot be opened for output.
77      */

78     public static void makeErrStream(File errFile)
79     throws java.io.IOException JavaDoc {
80     if (debug) {
81         // Create an outputstream for errors
82
java.io.OutputStream JavaDoc errOStream =
83         new java.io.FileOutputStream JavaDoc(errFile);
84         java.io.DataOutputStream JavaDoc errDStream =
85         new java.io.DataOutputStream JavaDoc(errOStream);
86         errStream = new java.io.PrintStream JavaDoc(errDStream);
87         dprint("Error stream setup completed.");
88     }
89     }
90
91
92     /**
93      * A utility method that takes Array of NameComponent and converts
94      * into a directory structured name in the format of /id1.kind1/id2.kind2..
95      * This is used mainly for Logging.
96      */

97     static String JavaDoc getDirectoryStructuredName( NameComponent JavaDoc[] name ) {
98         StringBuffer JavaDoc directoryStructuredName = new StringBuffer JavaDoc("/");
99         for( int i = 0; i < name.length; i++ ) {
100             directoryStructuredName.append( name[i].id + "." + name[i].kind );
101         }
102         return directoryStructuredName.toString( );
103     }
104
105     /**
106      * The debug printstream.
107      */

108     public static java.io.PrintStream JavaDoc debugStream;
109
110     /**
111      * The error printstream.
112      */

113     public static java.io.PrintStream JavaDoc errStream;
114 }
115
Popular Tags