corba/src/java.corba/share/classes/com/sun/corba/se/impl/naming/cosnaming/NamingUtils.java
author avstepan
Tue, 05 May 2015 15:17:13 +0400
changeset 30383 45960fdbe465
parent 25862 a5e25d68f971
permissions -rw-r--r--
8079075: some docs cleanup for CORBA - part 1 Summary: some fix for CORBA docs Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.naming.cosnaming;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.io.*;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import org.omg.CosNaming.NameComponent;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
public class NamingUtils {
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
    // Do not instantiate this class
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
    private NamingUtils() {};
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
     * Debug flag which must be true for debug streams to be created and
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
     * dprint output to be generated.
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
    public static boolean debug = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
     * Prints the message to the debug stream if debugging is enabled.
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
     * @param msg the debug message to print.
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
    public static void dprint(String msg) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
        if (debug && debugStream != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
            debugStream.println(msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
     * Prints the message to the error stream (System.err is default).
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
     * @param msg the error message to print.
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    public static void errprint(String msg) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
        if (errStream != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
            errStream.println(msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
            System.err.println(msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
     * Prints the stacktrace of the supplied exception to the error stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
     * @param e any Java exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
    public static void printException(java.lang.Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        if (errStream != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
            e.printStackTrace(errStream);
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
            e.printStackTrace();
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
     * Create a debug print stream to the supplied log file.
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
     * @param logFile the file to which debug output will go.
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
     * @exception IOException thrown if the file cannot be opened for output.
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    public static void makeDebugStream(File logFile)
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
        throws java.io.IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        // Create an outputstream for debugging
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
        java.io.OutputStream logOStream =
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
            new java.io.FileOutputStream(logFile);
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        java.io.DataOutputStream logDStream =
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            new java.io.DataOutputStream(logOStream);
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
        debugStream = new java.io.PrintStream(logDStream);
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        // Emit first message
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
        debugStream.println("Debug Stream Enabled.");
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
     * Create a error print stream to the supplied file.
30383
45960fdbe465 8079075: some docs cleanup for CORBA - part 1
avstepan
parents: 25862
diff changeset
    93
     * @param errFile the file to which error messages will go.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
     * @exception IOException thrown if the file cannot be opened for output.
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    public static void makeErrStream(File errFile)
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        throws java.io.IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            // Create an outputstream for errors
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
            java.io.OutputStream errOStream =
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
                new java.io.FileOutputStream(errFile);
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
            java.io.DataOutputStream errDStream =
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
                new java.io.DataOutputStream(errOStream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
            errStream = new java.io.PrintStream(errDStream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
            dprint("Error stream setup completed.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
     * A utility method that takes Array of NameComponent and converts
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
     * into a directory structured name in the format of /id1.kind1/id2.kind2..
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
     * This is used mainly for Logging.
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    static String getDirectoryStructuredName( NameComponent[] name ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        StringBuffer directoryStructuredName = new StringBuffer("/");
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        for( int i = 0; i < name.length; i++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
            directoryStructuredName.append( name[i].id + "." + name[i].kind );
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        return directoryStructuredName.toString( );
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
     * The debug printstream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    public static java.io.PrintStream debugStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
     * The error printstream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    public static java.io.PrintStream errStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
}