KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > embedded > JndiBinder


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.ejb3.embedded;
23
24 import java.util.Hashtable JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26 import javax.naming.NamingException JavaDoc;
27
28 import org.jboss.ejb3.EJB3Util;
29 import org.jboss.ejb3.NonSerializableFactory;
30 import org.jboss.naming.Util;
31
32 /**
33  * Comment
34  *
35  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
36  * @version $Revision: 56518 $
37  */

38 public class JndiBinder
39 {
40    private String JavaDoc bindTo;
41    private Object JavaDoc target;
42    private boolean serializable;
43    private Hashtable JavaDoc properties;
44
45    public void setBindTo(String JavaDoc bindTo)
46    {
47       this.bindTo = bindTo;
48    }
49
50    public void setTarget(Object JavaDoc target)
51    {
52       this.target = target;
53    }
54
55    public void setSerializable(boolean serializable)
56    {
57       this.serializable = serializable;
58    }
59
60    public void setJndiProperties(Hashtable JavaDoc properties)
61    {
62       this.properties = properties;
63    }
64
65    public void start() throws Exception JavaDoc
66    {
67       InitialContext JavaDoc ctx = EJB3Util.getInitialContext(properties);
68       
69       try
70       {
71          if (serializable)
72          {
73             Util.rebind(ctx, bindTo, target);
74          }
75          else
76          {
77             NonSerializableFactory.rebind(ctx, bindTo, target);
78          }
79       } catch (NamingException JavaDoc e)
80       {
81          NamingException JavaDoc namingException = new NamingException JavaDoc("Could not bind JndiBinder service into JNDI under jndiName:" + ctx.getNameInNamespace() + "/" + bindTo);
82          namingException.setRootCause(e);
83          throw namingException;
84       }
85    }
86
87    public void stop() throws Exception JavaDoc
88    {
89       InitialContext JavaDoc ctx = EJB3Util.getInitialContext(properties);
90       if (serializable)
91       {
92          Util.unbind(ctx, bindTo);
93       }
94       else
95       {
96          NonSerializableFactory.unbind(ctx, bindTo);
97       }
98    }
99 }
100
Popular Tags