KickJava   Java API By Example, From Geeks To Geeks.

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


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.mx.util.ObjectNameMatch;
27
28 import javax.management.Notification JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 /**
34  * @author Scott.Stark@jboss.org
35  * @version $Revision: 37459 $
36  */

37 public class DefaultManagedObjectFactoryMap
38         implements ManagedObjectFactoryMap
39 {
40    private static Logger log = Logger.getLogger(DefaultManagedObjectFactoryMap.class);
41    private HashMap JavaDoc factoryMap = new HashMap JavaDoc();
42    private HashMap JavaDoc patternFactoryMap = new HashMap JavaDoc();
43
44    /**
45     * Obtain the ManagedObjectFactory approriate for the event notification
46     * from the core JBoss layer. This method looks to the userData of the
47     * event to figure out how to obtain the JMX ObjectName of the core JBoss
48     * component sending the event. This is the current mechanism by which we
49     * map from the JBoss core layer into JSR-77 managed objects.
50     *
51     * @param createEvent
52     * @return The ManagedObjectFactory if found, null otherwise
53     */

54    public ManagedObjectFactory getFactory(Notification JavaDoc createEvent)
55    {
56       ManagedObjectFactory factory = null;
57
58       Object JavaDoc data = createEvent.getUserData();
59       ObjectName JavaDoc senderName = null;
60       if (data instanceof ObjectName JavaDoc)
61       {
62          senderName = (ObjectName JavaDoc) data;
63       }
64       else if (data instanceof DeploymentInfo)
65       {
66          DeploymentInfo di = (DeploymentInfo) data;
67          senderName = di.deployer.getServiceName();
68       }
69       factory = (ManagedObjectFactory) factoryMap.get(senderName);
70       if (factory == null)
71       {
72          // Check the pattern to factory mappings
73
Iterator JavaDoc iter = patternFactoryMap.keySet().iterator();
74          while (iter.hasNext())
75          {
76             ObjectName JavaDoc pattern = (ObjectName JavaDoc) iter.next();
77             if (ObjectNameMatch.match(pattern, senderName))
78                factory = (ManagedObjectFactory) patternFactoryMap.get(pattern);
79          }
80          if (factory == null)
81             log.debug("Failed to find factory for event: " + createEvent);
82       }
83       return factory;
84    }
85
86    public void setSARDeployer(ObjectName JavaDoc name)
87    {
88       factoryMap.put(name, new ServiceModuleFactory());
89    }
90
91    public void setEARDeployer(ObjectName JavaDoc name)
92    {
93       factoryMap.put(name, new EARModuleFactory());
94    }
95
96    public void setEJBDeployer(ObjectName JavaDoc name)
97    {
98       factoryMap.put(name, new EJBModuleFactory());
99    }
100
101    public void setRARDeployer(ObjectName JavaDoc name)
102    {
103       factoryMap.put(name, new RARModuleFactory());
104    }
105
106    public void setCMDeployer(ObjectName JavaDoc name)
107    {
108       factoryMap.put(name, new JCAResourceFactory());
109    }
110
111    public void setWARDeployer(ObjectName JavaDoc name)
112    {
113       factoryMap.put(name, new WebModuleFactory());
114    }
115
116    public void setJavaMailResource(ObjectName JavaDoc name)
117    {
118       factoryMap.put(name, new JavaMailResourceFactory());
119    }
120
121    public void setJMSResource(ObjectName JavaDoc name)
122    {
123       factoryMap.put(name, new JMSResourceFactory());
124    }
125
126    public void setJNDIResource(ObjectName JavaDoc name)
127    {
128       factoryMap.put(name, new JNDIResourceFactory());
129    }
130
131    public void setJTAResource(ObjectName JavaDoc name)
132    {
133       factoryMap.put(name, new JTAResourceFactory());
134    }
135
136    public void setRMI_IIOPResource(ObjectName JavaDoc name)
137    {
138       factoryMap.put(name, new RMIIIOPResourceFactory());
139    }
140 }
141
Popular Tags