KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > classloader > scoping > naming > service > BindingService


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.test.classloader.scoping.naming.service;
23
24 import javax.naming.InitialContext JavaDoc;
25 import javax.naming.Context JavaDoc;
26 import javax.management.MBeanServer JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.management.Attribute JavaDoc;
29
30 import org.jboss.mx.util.MBeanServerLocator;
31
32 /** A service that binds custom serializable objects into jndi for use by
33  * a web app to test the behavior of jndi lookups across class loading
34  * scopes.
35  *
36  * @author Scott.Stark@jboss.org
37  * @version $Revision: 37406 $
38  */

39 public class BindingService
40 {
41    private String JavaDoc[] names = {"Name0", "Name1", "Name2"};
42    private Boolean JavaDoc origCallByValue;
43
44    public String JavaDoc[] getNames()
45    {
46       return names;
47    }
48    public void setNames(String JavaDoc[] names)
49    {
50       this.names = names;
51    }
52
53    public void start() throws Exception JavaDoc
54    {
55       // Put the NamingService into call by value mode
56
MBeanServer JavaDoc server = MBeanServerLocator.locateJBoss();
57       ObjectName JavaDoc namingService = new ObjectName JavaDoc("jboss:service=Naming");
58       origCallByValue = (Boolean JavaDoc) server.getAttribute(namingService, "CallByValue");
59       Attribute JavaDoc callByValue = new Attribute JavaDoc("CallByValue", Boolean.TRUE);
60       server.setAttribute(namingService, callByValue);
61       System.out.println("NamingService.CallByValue set to true");
62
63       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
64       Context JavaDoc testCtx = ctx.createSubcontext("shared-context");
65       System.out.println("Created shared-context");
66       testCtx.bind("KeyCount", new Integer JavaDoc(names.length));
67       System.out.println("Bound KeyCount");
68       for(int n = 0; n < names.length; n ++)
69       {
70          String JavaDoc key = "Key#" + n;
71          BindValue value = new BindValue();
72          value.setValue("Value#"+n);
73          testCtx.bind(key, value);
74          System.out.println("Bound "+key);
75       }
76    }
77
78    public void stop() throws Exception JavaDoc
79    {
80       MBeanServer JavaDoc server = MBeanServerLocator.locateJBoss();
81       ObjectName JavaDoc namingService = new ObjectName JavaDoc("jboss:service=Naming");
82       Attribute JavaDoc callByValue = new Attribute JavaDoc("CallByValue", origCallByValue);
83       server.setAttribute(namingService, callByValue);
84       System.out.println("NamingService.CallByValue restored to: "+origCallByValue);
85
86       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
87       Context JavaDoc testCtx = (Context JavaDoc) ctx.lookup("shared-context");
88       testCtx.unbind("KeyCount");
89       System.out.println("Unbound KeyCount");
90       for(int n = 0; n < names.length; n ++)
91       {
92          String JavaDoc key = "Key#" + n;
93          testCtx.unbind(key);
94          System.out.println("Unbound "+key);
95       }
96       ctx.unbind("shared-context");
97       System.out.println("Destroyed shared-context");
98    }
99 }
100
Popular Tags