KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > naming > LinkRefPair


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.naming;
23
24 import javax.naming.MalformedLinkException JavaDoc;
25 import javax.naming.RefAddr JavaDoc;
26 import javax.naming.Reference JavaDoc;
27 import javax.naming.StringRefAddr JavaDoc;
28
29 /**
30  * A pair of addresses, one to be used in the local machine,
31  * the other in remote machines.
32  *
33  * @author Adrian Brock (adrian@jboss.com)
34  * @version $Revision: 41973 $
35  */

36 public class LinkRefPair extends Reference JavaDoc
37 {
38    // Constants -----------------------------------------------------
39

40    /** Serial version UID */
41    private static final long serialVersionUID = 6036946190113161492L;
42
43    /** Our class name */
44    private static final String JavaDoc linkRefPairClassName = LinkRefPair.class.getName();
45
46    /** The remote jndi object */
47    static final String JavaDoc remoteAddress = "remoteAddress";
48
49    /** The local jndi object */
50    static final String JavaDoc localAddress = "localAddress";
51
52    /** The guid used to determine whether we are local to the VM */
53    private static final String JavaDoc guidAddress = "guid";
54
55    // Attributes ----------------------------------------------------
56

57    // Static --------------------------------------------------------
58

59    // Constructors --------------------------------------------------
60

61    /**
62     * Create a new link ref pair with the give remote and local names.
63     *
64     * @param remote the remote name
65     * @param local the local name
66     */

67    public LinkRefPair(String JavaDoc remote, String JavaDoc local)
68    {
69       super(linkRefPairClassName, LinkRefPairObjectFactory.className, null);
70       add(new StringRefAddr JavaDoc(guidAddress, LinkRefPairObjectFactory.guid));
71       add(new StringRefAddr JavaDoc(remoteAddress, remote));
72       add(new StringRefAddr JavaDoc(localAddress, local));
73    }
74
75    // Public --------------------------------------------------------
76

77    /**
78     * Get the guid link name
79     *
80     * @return the guid
81     * @throws MalformedLinkException when the reference is malformed
82     */

83    public String JavaDoc getGUID() throws MalformedLinkException JavaDoc
84    {
85       if (className != null && className.equals(linkRefPairClassName))
86       {
87          RefAddr JavaDoc refAddr = get(guidAddress);
88          if (refAddr != null && refAddr instanceof StringRefAddr JavaDoc)
89          {
90             Object JavaDoc content = refAddr.getContent();
91             if (content != null && content instanceof String JavaDoc)
92                return (String JavaDoc) content;
93             else
94                throw new MalformedLinkException JavaDoc("Content is not a string: " + content);
95          }
96          else
97             throw new MalformedLinkException JavaDoc("RefAddr is not a string reference: " + refAddr);
98       }
99       else
100          throw new MalformedLinkException JavaDoc("Class is not a LinkRefPair: " + className);
101    }
102
103    /**
104     * Get the remote link name
105     *
106     * @return the remote link
107     * @throws MalformedLinkException when the reference is malformed
108     */

109    public String JavaDoc getRemoteLinkName() throws MalformedLinkException JavaDoc
110    {
111       if (className != null && className.equals(linkRefPairClassName))
112       {
113          RefAddr JavaDoc refAddr = get(remoteAddress);
114          if (refAddr != null && refAddr instanceof StringRefAddr JavaDoc)
115          {
116             Object JavaDoc content = refAddr.getContent();
117             if (content != null && content instanceof String JavaDoc)
118                return (String JavaDoc) content;
119             else
120                throw new MalformedLinkException JavaDoc("Content is not a string: " + content);
121          }
122          else
123             throw new MalformedLinkException JavaDoc("RefAddr is not a string reference: " + refAddr);
124       }
125       else
126          throw new MalformedLinkException JavaDoc("Class is not a LinkRefPair: " + className);
127    }
128
129    /**
130     * Get the local link name
131     *
132     * @return the remote link
133     * @throws MalformedLinkException when the reference is malformed
134     */

135    public String JavaDoc getLocalLinkName() throws MalformedLinkException JavaDoc
136    {
137       if (className != null && className.equals(linkRefPairClassName))
138       {
139          RefAddr JavaDoc refAddr = get(localAddress);
140          if (refAddr != null && refAddr instanceof StringRefAddr JavaDoc)
141          {
142             Object JavaDoc content = refAddr.getContent();
143             if (content != null && content instanceof String JavaDoc)
144                return (String JavaDoc) content;
145             else
146                throw new MalformedLinkException JavaDoc("Content is not a string: " + content);
147          }
148          else
149             throw new MalformedLinkException JavaDoc("RefAddr is not a string reference: " + refAddr);
150       }
151       else
152          throw new MalformedLinkException JavaDoc("Class is not a LinkRefPair: " + className);
153    }
154
155    // Package protected ---------------------------------------------
156

157    // Protected -----------------------------------------------------
158

159    // Private -------------------------------------------------------
160

161    // Inner classes -------------------------------------------------
162
}
163
Popular Tags