KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > system > controller > support > ContainedMBeanService


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, 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.system.controller.support;
23
24 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
25 import java.util.Hashtable JavaDoc;
26
27 import javax.management.ObjectName JavaDoc;
28
29 import org.jboss.system.ServiceMBeanSupport;
30
31 /**
32  * An mbean that creates and starts mbeans outside of the SARDeployer.
33  *
34  * @author Scott.Stark@jboss.org
35  * @version $Revision:$
36  */

37 public class ContainedMBeanService extends ServiceMBeanSupport
38    implements ContainedMBeanServiceMBean
39 {
40    private String JavaDoc aString;
41    private ObjectName JavaDoc simpleName;
42    private Simple simpleMBean;
43
44    /** Pass through AString for the container SimpleMBean */
45    public String JavaDoc getAString()
46    {
47       return this.aString;
48    }
49    /** Pass through AString for the container SimpleMBean */
50    public void setAString(String JavaDoc string)
51    {
52       this.aString = string;
53    }
54
55    /**
56     * Create and register the contained SimpleMBean
57     */

58    @Override JavaDoc
59    protected void createService() throws Exception JavaDoc
60    {
61       simpleMBean = new Simple();
62       simpleMBean.setAString(aString);
63       Hashtable JavaDoc props = serviceName.getKeyPropertyList();
64       props.put("contained", "SimpleMBean");
65       simpleName = new ObjectName JavaDoc(serviceName.getDomain(), props);
66       server.registerMBean(simpleMBean, simpleName);
67       boolean expectError = "ERRORINCREATE".equals(aString);
68       // Invoke create on simpleName
69
Object JavaDoc[] params = {};
70       String JavaDoc[] signature = {};
71       server.invoke(simpleName, "create", params, signature);
72       if( expectError )
73          throw new Error JavaDoc("Did not see expected ERRORINCREATE from: "+simpleName);
74    }
75
76    @Override JavaDoc
77    protected void startService() throws Exception JavaDoc
78    {
79       if( simpleName != null )
80       {
81          // Invoke start on simpleName
82
boolean expectError = "ERRORINSTART".equals(aString);
83          Object JavaDoc[] params = {};
84          String JavaDoc[] signature = {};
85          server.invoke(simpleName, "start", params, signature);
86          if( expectError )
87             throw new Error JavaDoc("Did not see expected ERRORINSTART from: "+simpleName);
88       }
89    }
90
91    @Override JavaDoc
92    protected void stopService() throws Exception JavaDoc
93    {
94       if( simpleName != null )
95       {
96          boolean expectError = "ERRORINSTOP".equals(aString);
97          Object JavaDoc[] params = {};
98          String JavaDoc[] signature = {};
99          server.invoke(simpleName, "stop", params, signature);
100          if( expectError )
101             throw new Error JavaDoc("Did not see expected ERRORINSTOP from: "+simpleName);
102       }
103    }
104
105    @Override JavaDoc
106    protected void destroyService() throws Exception JavaDoc
107    {
108       if( simpleName != null )
109       {
110          boolean expectError = "ERRORINDESTROY".equals(aString);
111          Object JavaDoc[] params = {};
112          String JavaDoc[] signature = {};
113          try
114          {
115             server.invoke(simpleName, "destroy", params, signature);
116             if( expectError )
117                throw new Error JavaDoc("Did not see expected ERRORINDESTROY from: "+simpleName);
118          }
119          catch(Throwable JavaDoc e)
120          {
121             if( expectError == false )
122                throw new UndeclaredThrowableException JavaDoc(e);
123          }
124          server.unregisterMBean(simpleName);
125       }
126       simpleName = null;
127    }
128
129 }
130
Popular Tags