1. /*
  2. * @(#)LinkRef.java 1.4 00/02/02
  3. *
  4. * Copyright 1999, 2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.naming;
  11. /**
  12. * This class represents a Reference whose contents is a name, called the link name,
  13. * that is bound to an atomic name in a context.
  14. *<p>
  15. * The name is a URL, or a name to be resolved relative to the initial
  16. * context, or if the first character of the name is ".", the name
  17. * is relative to the context in which the link is bound.
  18. *<p>
  19. * Normal resolution of names in context operations always follow links.
  20. * Resolution of the link name itself may cause resolution to pass through
  21. * other links. This gives rise to the possibility of a cycle of links whose
  22. * resolution could not terminate normally. As a simple means to avoid such
  23. * non-terminating resolutions, service providers may define limits on the
  24. * number of links that may be involved in any single operation invoked
  25. * by the caller.
  26. *<p>
  27. * A LinkRef contains a single StringRefAddr, whose type is "LinkAddress",
  28. * and whose contents is the link name. The class name field of the
  29. * Reference is that of this (LinkRef) class.
  30. *<p>
  31. * LinkRef is bound to a name using the normal Context.bind()/rebind(), and
  32. * DirContext.bind()/rebind(). Context.lookupLink() is used to retrieve the link
  33. * itself if the terminal atomic name is bound to a link.
  34. *<p>
  35. * Many naming systems support a native notion of link that may be used
  36. * within the naming system itself. JNDI does not specify whether
  37. * there is any relationship between such native links and JNDI links.
  38. *<p>
  39. * A LinkRef instance is not synchronized against concurrent access by multiple
  40. * threads. Threads that need to access a LinkRef instance concurrently should
  41. * synchronize amongst themselves and provide the necessary locking.
  42. *
  43. * @author Rosanna Lee
  44. * @author Scott Seligman
  45. * @version 1.4 00/02/02
  46. *
  47. * @see LinkException
  48. * @see LinkLoopException
  49. * @see MalformedLinkException
  50. * @see Context#lookupLink
  51. * @since 1.3
  52. */
  53. /*<p>
  54. * The serialized form of a LinkRef object consists of the serialized
  55. * fields of its Reference superclass.
  56. */
  57. public class LinkRef extends Reference {
  58. /* code for link handling */
  59. static final String linkClassName = LinkRef.class.getName();
  60. static final String linkAddrType = "LinkAddress";
  61. /**
  62. * Constructs a LinkRef for a name.
  63. * @param linkName The non-null name for which to create this link.
  64. */
  65. public LinkRef(Name linkName) {
  66. super(linkClassName, new StringRefAddr(linkAddrType, linkName.toString()));
  67. }
  68. /**
  69. * Constructs a LinkRef for a string name.
  70. * @param linkName The non-null name for which to create this link.
  71. */
  72. public LinkRef(String linkName) {
  73. super(linkClassName, new StringRefAddr(linkAddrType, linkName));
  74. }
  75. /**
  76. * Retrieves the name of this link.
  77. *
  78. * @return The non-null name of this link.
  79. * @exception MalformedLinkException If a link name could not be extracted
  80. * @exception NamingException If a naming exception was encountered.
  81. */
  82. public String getLinkName() throws NamingException {
  83. if (className != null && className.equals(linkClassName)) {
  84. RefAddr addr = get(linkAddrType);
  85. if (addr != null && addr instanceof StringRefAddr) {
  86. return (String)((StringRefAddr)addr).getContent();
  87. }
  88. }
  89. throw new MalformedLinkException();
  90. }
  91. /**
  92. * Use serialVersionUID from JNDI 1.1.1 for interoperability
  93. */
  94. private static final long serialVersionUID = -5386290613498931298L;
  95. }