KickJava   Java API By Example, From Geeks To Geeks.

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


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.InitialContext JavaDoc;
25
26 import org.jboss.deployment.DeploymentException;
27 import org.jboss.system.ServiceMBeanSupport;
28
29 /**
30  * An mbean used to construct a link ref pair
31  *
32  * @author Adrian Brock (adrian@jboss.com)
33  * @version $Revision: 37459 $
34  */

35 public class LinkRefPairService extends ServiceMBeanSupport
36    implements LinkRefPairServiceMBean
37 {
38    // Constants -----------------------------------------------------
39

40    // Attributes ----------------------------------------------------
41

42    /** The jndi binding */
43    private String JavaDoc jndiName;
44
45    /** The remote jndi binding */
46    private String JavaDoc remoteJndiName;
47
48    /** The local jndi binding */
49    private String JavaDoc localJndiName;
50    
51    // Static --------------------------------------------------------
52

53    // Constructors --------------------------------------------------
54

55    // Public --------------------------------------------------------
56

57    // LinkRefPairServiceMBean implementation ------------------------
58

59    public String JavaDoc getJndiName()
60    {
61       return jndiName;
62    }
63
64    public String JavaDoc getLocalJndiName()
65    {
66       return localJndiName;
67    }
68
69    public String JavaDoc getRemoteJndiName()
70    {
71       return remoteJndiName;
72    }
73
74    public void setJndiName(String JavaDoc jndiName)
75    {
76       this.jndiName = jndiName;
77    }
78
79    public void setLocalJndiName(String JavaDoc jndiName)
80    {
81       this.localJndiName = jndiName;
82    }
83    
84    public void setRemoteJndiName(String JavaDoc jndiName)
85    {
86       this.remoteJndiName = jndiName;
87    }
88    
89    // ServiceMBeanSupport overrides ---------------------------------
90

91    protected void startService() throws Exception JavaDoc
92    {
93       if (jndiName == null)
94          throw new DeploymentException("The jndiName is null for LinkRefPair " + getServiceName());
95       if (remoteJndiName == null)
96          throw new DeploymentException("The remoteJndiName is null for LinkRefPair " + getServiceName());
97       if (localJndiName == null)
98          throw new DeploymentException("The localJndiName is null for LinkRefPair " + getServiceName());
99
100       LinkRefPair pair = new LinkRefPair(remoteJndiName, localJndiName);
101       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
102       try
103       {
104          Util.bind(ctx, jndiName, pair);
105       }
106       finally
107       {
108          ctx.close();
109       }
110    }
111    
112    protected void stopService() throws Exception JavaDoc
113    {
114       LinkRefPair pair = new LinkRefPair(remoteJndiName, localJndiName);
115       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
116       try
117       {
118          Util.unbind(ctx, jndiName);
119       }
120       finally
121       {
122          ctx.close();
123       }
124    }
125    
126    // Package protected ---------------------------------------------
127

128    // Protected -----------------------------------------------------
129

130    // Private -------------------------------------------------------
131

132    // Inner classes -------------------------------------------------
133
}
134
Popular Tags