001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.naming;
023:
024: import javax.naming.InitialContext;
025:
026: import org.jboss.deployment.DeploymentException;
027: import org.jboss.logging.Logger;
028: import org.jboss.system.ServiceMBeanSupport;
029:
030: /**
031: * An mbean used to construct a link ref pair
032: *
033: * @author Adrian Brock (adrian@jboss.com)
034: * @version $Revision: 62316 $
035: */
036: public class LinkRefPairService extends ServiceMBeanSupport implements
037: LinkRefPairServiceMBean {
038: /** This is a hack to make sure this class doesn't get garbage collected */
039: protected static final Class HACK = LinkRefPairObjectFactory.class;
040:
041: static {
042: // Make sure the LinkRefPairObjectFactory class is initialized
043: Logger.getLogger(LinkRefPairService.class).debug(
044: "LinkRefPair guid=" + LinkRefPairObjectFactory.guid);
045: }
046:
047: // Constants -----------------------------------------------------
048:
049: // Attributes ----------------------------------------------------
050:
051: /** The jndi binding */
052: private String jndiName;
053:
054: /** The remote jndi binding */
055: private String remoteJndiName;
056:
057: /** The local jndi binding */
058: private String localJndiName;
059:
060: // Static --------------------------------------------------------
061:
062: // Constructors --------------------------------------------------
063:
064: // Public --------------------------------------------------------
065:
066: // LinkRefPairServiceMBean implementation ------------------------
067:
068: public String getJndiName() {
069: return jndiName;
070: }
071:
072: public String getLocalJndiName() {
073: return localJndiName;
074: }
075:
076: public String getRemoteJndiName() {
077: return remoteJndiName;
078: }
079:
080: public void setJndiName(String jndiName) {
081: this .jndiName = jndiName;
082: }
083:
084: public void setLocalJndiName(String jndiName) {
085: this .localJndiName = jndiName;
086: }
087:
088: public void setRemoteJndiName(String jndiName) {
089: this .remoteJndiName = jndiName;
090: }
091:
092: // ServiceMBeanSupport overrides ---------------------------------
093:
094: protected void startService() throws Exception {
095: if (jndiName == null)
096: throw new DeploymentException(
097: "The jndiName is null for LinkRefPair "
098: + getServiceName());
099: if (remoteJndiName == null)
100: throw new DeploymentException(
101: "The remoteJndiName is null for LinkRefPair "
102: + getServiceName());
103: if (localJndiName == null)
104: throw new DeploymentException(
105: "The localJndiName is null for LinkRefPair "
106: + getServiceName());
107:
108: LinkRefPair pair = new LinkRefPair(remoteJndiName,
109: localJndiName);
110: InitialContext ctx = new InitialContext();
111: try {
112: Util.bind(ctx, jndiName, pair);
113: } finally {
114: ctx.close();
115: }
116: }
117:
118: protected void stopService() throws Exception {
119: LinkRefPair pair = new LinkRefPair(remoteJndiName,
120: localJndiName);
121: InitialContext ctx = new InitialContext();
122: try {
123: Util.unbind(ctx, jndiName);
124: } finally {
125: ctx.close();
126: }
127: }
128:
129: // Package protected ---------------------------------------------
130:
131: // Protected -----------------------------------------------------
132:
133: // Private -------------------------------------------------------
134:
135: // Inner classes -------------------------------------------------
136: }
|