KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > namingutil > Utility


1 /*
2  * @(#)Utility.java 1.6 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.namingutil;
9
10 import java.io.StringWriter JavaDoc;
11
12 import org.omg.CORBA.DATA_CONVERSION JavaDoc;
13 import org.omg.CORBA.CompletionStatus JavaDoc;
14
15 import com.sun.corba.se.impl.logging.NamingSystemException;
16 import com.sun.corba.se.spi.logging.CORBALogDomains;
17
18 /**
19  * Utility methods for Naming.
20  *
21  * @Author Hemanth
22  */

23 class Utility {
24     private static NamingSystemException wrapper =
25     NamingSystemException.get( CORBALogDomains.NAMING ) ;
26
27     /**
28      * cleanEscapes removes URL escapes as per IETF 2386 RFP.
29      */

30     static String JavaDoc cleanEscapes( String JavaDoc stringToDecode ) {
31         StringWriter JavaDoc theStringWithoutEscape = new StringWriter JavaDoc();
32         for( int i = 0; i < stringToDecode.length(); i++ ) {
33             char c = stringToDecode.charAt( i ) ;
34             if( c != '%' ) {
35                 theStringWithoutEscape.write( c );
36             } else {
37                 // Get the two hexadecimal digits and convert that into int
38
i++;
39                 int Hex1 = hexOf( stringToDecode.charAt(i) );
40                 i++;
41                 int Hex2 = hexOf( stringToDecode.charAt(i) );
42                 int value = (Hex1 * 16) + Hex2;
43                 // Convert the integer to ASCII
44
theStringWithoutEscape.write( (char) value );
45             }
46         }
47         return theStringWithoutEscape.toString();
48     }
49
50     /**
51      * Converts an Ascii Character into Hexadecimal digit
52      * NOTE: THIS METHOD IS DUPLICATED TO DELIVER NAMING AS A SEPARATE
53      * COMPONENT TO RI.
54      **/

55     static int hexOf( char x )
56     {
57         int val;
58
59         val = x - '0';
60         if (val >=0 && val <= 9)
61             return val;
62
63         val = (x - 'a') + 10;
64         if (val >= 10 && val <= 15)
65             return val;
66
67         val = (x - 'A') + 10;
68         if (val >= 10 && val <= 15)
69             return val;
70
71         throw new DATA_CONVERSION JavaDoc( );
72     }
73
74     /**
75      * If GIOP Version is not correct, This method throws a BAD_PARAM
76      * Exception.
77      **/

78     static void validateGIOPVersion( IIOPEndpointInfo endpointInfo ) {
79         if ((endpointInfo.getMajor() > NamingConstants.MAJORNUMBER_SUPPORTED) ||
80         (endpointInfo.getMinor() > NamingConstants.MINORNUMBERMAX ) )
81         {
82         throw wrapper.insBadAddress() ;
83         }
84     }
85 }
86
Popular Tags