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