1. /*
  2. * @(#)CorbanameURL.java 1.7 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 com.sun.corba.se.impl.logging.NamingSystemException;
  9. import com.sun.corba.se.spi.logging.CORBALogDomains;
  10. /**
  11. * The corbaname: URL definitions from the -ORBInitDef and -ORBDefaultInitDef's
  12. * will be stored in this object. This object is capable of storing CorbaLoc
  13. * profiles as defined in the CorbaName grammer.
  14. *
  15. * @Author Hemanth
  16. */
  17. public class CorbanameURL extends INSURLBase
  18. {
  19. private static NamingSystemException wrapper =
  20. NamingSystemException.get( CORBALogDomains.NAMING ) ;
  21. /**
  22. * This constructor takes a corbaname: url with 'corbaname:' prefix stripped
  23. * and initializes all the variables accordingly. If there are any parsing
  24. * errors then BAD_PARAM exception is raised.
  25. */
  26. public CorbanameURL( String aURL ) {
  27. String url = aURL;
  28. // First Clean the URL Escapes if there are any
  29. try {
  30. url = Utility.cleanEscapes( url );
  31. } catch( Exception e ) {
  32. badAddress( e );
  33. }
  34. int delimiterIndex = url.indexOf( '#' );
  35. String corbalocString = null;
  36. if( delimiterIndex != -1 ) {
  37. // Append corbaloc: for Grammar check, Get the string between
  38. // corbaname: and # which forms the corbaloc string
  39. corbalocString = "corbaloc:" +
  40. url.substring( 0, delimiterIndex ) + "/";
  41. } else {
  42. // Build a corbaloc string to check the grammar.
  43. // 10 is the length of corbaname:
  44. corbalocString = "corbaloc:" + url.substring( 0, url.length() );
  45. // If the string doesnot end with a / then add one to end the
  46. // URL correctly
  47. if( corbalocString.endsWith( "/" ) != true ) {
  48. corbalocString = corbalocString + "/";
  49. }
  50. }
  51. try {
  52. // Check the corbaloc grammar and set the returned corbaloc
  53. // object to the CorbaName Object
  54. INSURL insURL =
  55. INSURLHandler.getINSURLHandler().parseURL( corbalocString );
  56. copyINSURL( insURL );
  57. // String after '#' is the Stringified name used to resolve
  58. // the Object reference from the rootnaming context. If
  59. // the String is null then the Root Naming context is passed
  60. // back
  61. if((delimiterIndex > -1) &&
  62. (delimiterIndex < (aURL.length() - 1)))
  63. {
  64. int start = delimiterIndex + 1 ;
  65. String result = url.substring(start) ;
  66. theStringifiedName = result ;
  67. }
  68. } catch( Exception e ) {
  69. badAddress( e );
  70. }
  71. }
  72. /**
  73. * A Utility method to throw BAD_PARAM exception.
  74. */
  75. private void badAddress( java.lang.Throwable e )
  76. throws org.omg.CORBA.BAD_PARAM
  77. {
  78. throw wrapper.insBadAddress( e ) ;
  79. }
  80. /**
  81. * A Utility method to copy all the variables from CorbalocURL object to
  82. * this instance.
  83. */
  84. private void copyINSURL( INSURL url ) {
  85. rirFlag = url.getRIRFlag( );
  86. theEndpointInfo = (java.util.ArrayList) url.getEndpointInfo( );
  87. theKeyString = url.getKeyString( );
  88. theStringifiedName = url.getStringifiedName( );
  89. }
  90. public boolean isCorbanameURL( ) {
  91. return true;
  92. }
  93. }