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. package com.sun.corba.se.impl.naming.namingutil;
  8. import java.io.StringWriter;
  9. import org.omg.CORBA.DATA_CONVERSION;
  10. import org.omg.CORBA.CompletionStatus;
  11. import com.sun.corba.se.impl.logging.NamingSystemException;
  12. import com.sun.corba.se.spi.logging.CORBALogDomains;
  13. /**
  14. * Utility methods for Naming.
  15. *
  16. * @Author Hemanth
  17. */
  18. class Utility {
  19. private static NamingSystemException wrapper =
  20. NamingSystemException.get( CORBALogDomains.NAMING ) ;
  21. /**
  22. * cleanEscapes removes URL escapes as per IETF 2386 RFP.
  23. */
  24. static String cleanEscapes( String stringToDecode ) {
  25. StringWriter theStringWithoutEscape = new StringWriter();
  26. for( int i = 0; i < stringToDecode.length(); i++ ) {
  27. char c = stringToDecode.charAt( i ) ;
  28. if( c != '%' ) {
  29. theStringWithoutEscape.write( c );
  30. } else {
  31. // Get the two hexadecimal digits and convert that into int
  32. i++;
  33. int Hex1 = hexOf( stringToDecode.charAt(i) );
  34. i++;
  35. int Hex2 = hexOf( stringToDecode.charAt(i) );
  36. int value = (Hex1 * 16) + Hex2;
  37. // Convert the integer to ASCII
  38. theStringWithoutEscape.write( (char) value );
  39. }
  40. }
  41. return theStringWithoutEscape.toString();
  42. }
  43. /**
  44. * Converts an Ascii Character into Hexadecimal digit
  45. * NOTE: THIS METHOD IS DUPLICATED TO DELIVER NAMING AS A SEPARATE
  46. * COMPONENT TO RI.
  47. **/
  48. static int hexOf( char x )
  49. {
  50. int val;
  51. val = x - '0';
  52. if (val >=0 && val <= 9)
  53. return val;
  54. val = (x - 'a') + 10;
  55. if (val >= 10 && val <= 15)
  56. return val;
  57. val = (x - 'A') + 10;
  58. if (val >= 10 && val <= 15)
  59. return val;
  60. throw new DATA_CONVERSION( );
  61. }
  62. /**
  63. * If GIOP Version is not correct, This method throws a BAD_PARAM
  64. * Exception.
  65. **/
  66. static void validateGIOPVersion( IIOPEndpointInfo endpointInfo ) {
  67. if ((endpointInfo.getMajor() > NamingConstants.MAJORNUMBER_SUPPORTED) ||
  68. (endpointInfo.getMinor() > NamingConstants.MINORNUMBERMAX ) )
  69. {
  70. throw wrapper.insBadAddress() ;
  71. }
  72. }
  73. }