KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > LinkRef


1 /*
2  * @(#)LinkRef.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
8 package javax.naming;
9
10 /**
11   * This class represents a Reference whose contents is a name, called the link name,
12   * that is bound to an atomic name in a context.
13   *<p>
14   * The name is a URL, or a name to be resolved relative to the initial
15   * context, or if the first character of the name is ".", the name
16   * is relative to the context in which the link is bound.
17   *<p>
18   * Normal resolution of names in context operations always follow links.
19   * Resolution of the link name itself may cause resolution to pass through
20   * other links. This gives rise to the possibility of a cycle of links whose
21   * resolution could not terminate normally. As a simple means to avoid such
22   * non-terminating resolutions, service providers may define limits on the
23   * number of links that may be involved in any single operation invoked
24   * by the caller.
25   *<p>
26   * A LinkRef contains a single StringRefAddr, whose type is "LinkAddress",
27   * and whose contents is the link name. The class name field of the
28   * Reference is that of this (LinkRef) class.
29   *<p>
30   * LinkRef is bound to a name using the normal Context.bind()/rebind(), and
31   * DirContext.bind()/rebind(). Context.lookupLink() is used to retrieve the link
32   * itself if the terminal atomic name is bound to a link.
33   *<p>
34   * Many naming systems support a native notion of link that may be used
35   * within the naming system itself. JNDI does not specify whether
36   * there is any relationship between such native links and JNDI links.
37   *<p>
38   * A LinkRef instance is not synchronized against concurrent access by multiple
39   * threads. Threads that need to access a LinkRef instance concurrently should
40   * synchronize amongst themselves and provide the necessary locking.
41   *
42   * @author Rosanna Lee
43   * @author Scott Seligman
44   * @version 1.7 03/12/19
45   *
46   * @see LinkException
47   * @see LinkLoopException
48   * @see MalformedLinkException
49   * @see Context#lookupLink
50   * @since 1.3
51   */

52
53   /*<p>
54   * The serialized form of a LinkRef object consists of the serialized
55   * fields of its Reference superclass.
56   */

57
58 public class LinkRef extends Reference JavaDoc {
59     /* code for link handling */
60     static final String JavaDoc linkClassName = LinkRef JavaDoc.class.getName();
61     static final String JavaDoc linkAddrType = "LinkAddress";
62
63     /**
64       * Constructs a LinkRef for a name.
65       * @param linkName The non-null name for which to create this link.
66       */

67     public LinkRef(Name JavaDoc linkName) {
68     super(linkClassName, new StringRefAddr JavaDoc(linkAddrType, linkName.toString()));
69     }
70
71     /**
72       * Constructs a LinkRef for a string name.
73       * @param linkName The non-null name for which to create this link.
74       */

75     public LinkRef(String JavaDoc linkName) {
76     super(linkClassName, new StringRefAddr JavaDoc(linkAddrType, linkName));
77     }
78
79     /**
80       * Retrieves the name of this link.
81       *
82       * @return The non-null name of this link.
83       * @exception MalformedLinkException If a link name could not be extracted
84       * @exception NamingException If a naming exception was encountered.
85       */

86     public String JavaDoc getLinkName() throws NamingException JavaDoc {
87     if (className != null && className.equals(linkClassName)) {
88         RefAddr JavaDoc addr = get(linkAddrType);
89         if (addr != null && addr instanceof StringRefAddr JavaDoc) {
90         return (String JavaDoc)((StringRefAddr JavaDoc)addr).getContent();
91         }
92     }
93     throw new MalformedLinkException JavaDoc();
94     }
95     /**
96      * Use serialVersionUID from JNDI 1.1.1 for interoperability
97      */

98     private static final long serialVersionUID = -5386290613498931298L;
99 }
100
Popular Tags