KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > factory > ServiceModuleFactory


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.management.j2ee.factory;
23
24 import org.jboss.deployment.DeploymentInfo;
25 import org.jboss.logging.Logger;
26 import org.jboss.management.j2ee.MBean;
27 import org.jboss.management.j2ee.ServiceModule;
28
29 import javax.management.MBeanServer JavaDoc;
30 import javax.management.ObjectName JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.ListIterator JavaDoc;
33
34 /**
35  * @author Scott.Stark@jboss.org
36  * @version $Revision: 37459 $
37  */

38 public class ServiceModuleFactory
39         implements ManagedObjectFactory
40 {
41    private static Logger log = Logger.getLogger(ServiceModuleFactory.class);
42
43    /**
44     * Create JSR-77 SAR-Module
45     *
46     * @param server the MBeanServer context
47     * @param data arbitrary data associated with the creation context
48     */

49    public ObjectName JavaDoc create(MBeanServer JavaDoc server, Object JavaDoc data)
50    {
51       if ((data instanceof DeploymentInfo) == false)
52          return null;
53
54       DeploymentInfo di = (DeploymentInfo) data;
55       String JavaDoc moduleName = di.shortName;
56       ObjectName JavaDoc sarName = ServiceModule.create(server, moduleName, di.localUrl);
57       if (sarName != null)
58       {
59          log.debug("Created ServiceModule: " + sarName);
60       }
61
62       try
63       {
64          List JavaDoc mbeans = di.mbeans;
65          for (int i = 0; i < mbeans.size(); i++)
66          {
67             ObjectName JavaDoc mbeanName = (ObjectName JavaDoc) mbeans.get(i);
68             // Create JSR-77 MBean
69
MBean.create(server, sarName.toString(), mbeanName);
70             log.debug("Create MBean, name: " + mbeanName + ", SAR Module: " + sarName);
71          }
72       }
73       catch (Throwable JavaDoc e)
74       {
75          log.debug("Failed to create MBean, sarName:" + sarName, e);
76       }
77
78       return sarName;
79    }
80
81    public void destroy(MBeanServer JavaDoc server, Object JavaDoc data)
82    {
83       if ((data instanceof DeploymentInfo) == false)
84          return;
85
86       DeploymentInfo di = (DeploymentInfo) data;
87       List JavaDoc services = di.mbeans;
88       int lastService = services.size();
89
90       for (ListIterator JavaDoc i = services.listIterator(lastService); i.hasPrevious();)
91       {
92          ObjectName JavaDoc name = (ObjectName JavaDoc) i.previous();
93          try
94          {
95             // Destroy JSR-77 MBean
96
MBean.destroy(server, name.toString());
97             log.debug("Destroy MBean, name: " + name);
98          }
99          catch (Throwable JavaDoc e)
100          {
101             log.debug("Failed to remove remove JSR-77 MBean", e);
102          } // end of try-catch
103
}
104
105       // Remove JSR-77 SAR-Module
106
String JavaDoc moduleName = di.shortName;
107       try
108       {
109          ServiceModule.destroy(server, moduleName);
110          log.debug("Removed JSR-77 SAR: " + moduleName);
111       }
112       catch (Throwable JavaDoc e)
113       {
114          log.debug("Failed to remove JSR-77 SAR: " + moduleName);
115       }
116    }
117 }
118
Popular Tags