001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.management.j2ee.factory;
023:
024: import org.jboss.deployment.DeploymentInfo;
025: import org.jboss.logging.Logger;
026: import org.jboss.mx.util.ObjectNameMatch;
027:
028: import javax.management.Notification;
029: import javax.management.ObjectName;
030: import java.util.HashMap;
031: import java.util.Iterator;
032:
033: /**
034: * @author Scott.Stark@jboss.org
035: * @version $Revision: 57197 $
036: */
037: public class DefaultManagedObjectFactoryMap implements
038: ManagedObjectFactoryMap {
039: private static Logger log = Logger
040: .getLogger(DefaultManagedObjectFactoryMap.class);
041: private HashMap factoryMap = new HashMap();
042: private HashMap patternFactoryMap = new HashMap();
043:
044: /**
045: * Obtain the ManagedObjectFactory approriate for the event notification
046: * from the core JBoss layer. This method looks to the userData of the
047: * event to figure out how to obtain the JMX ObjectName of the core JBoss
048: * component sending the event. This is the current mechanism by which we
049: * map from the JBoss core layer into JSR-77 managed objects.
050: *
051: * @param createEvent
052: * @return The ManagedObjectFactory if found, null otherwise
053: */
054: public ManagedObjectFactory getFactory(Notification createEvent) {
055: ManagedObjectFactory factory = null;
056:
057: Object data = createEvent.getUserData();
058: ObjectName senderName = null;
059: if (data instanceof ObjectName) {
060: senderName = (ObjectName) data;
061: } else if (data instanceof DeploymentInfo) {
062: DeploymentInfo di = (DeploymentInfo) data;
063: senderName = di.deployer.getServiceName();
064: }
065: factory = (ManagedObjectFactory) factoryMap.get(senderName);
066: if (factory == null) {
067: // Check the pattern to factory mappings
068: Iterator iter = patternFactoryMap.keySet().iterator();
069: while (iter.hasNext()) {
070: ObjectName pattern = (ObjectName) iter.next();
071: if (ObjectNameMatch.match(pattern, senderName))
072: factory = (ManagedObjectFactory) patternFactoryMap
073: .get(pattern);
074: }
075: if (factory == null)
076: log.debug("Failed to find factory for event: "
077: + createEvent);
078: }
079: return factory;
080: }
081:
082: public void setSARDeployer(ObjectName name) {
083: factoryMap.put(name, new ServiceModuleFactory());
084: }
085:
086: public void setEARDeployer(ObjectName name) {
087: factoryMap.put(name, new EARModuleFactory());
088: }
089:
090: public void setEJBDeployer(ObjectName name) {
091: factoryMap.put(name, new EJBModuleFactory());
092: }
093:
094: public void setRARDeployer(ObjectName name) {
095: factoryMap.put(name, new RARModuleFactory());
096: }
097:
098: public void setCMDeployer(ObjectName name) {
099: factoryMap.put(name, new JCAResourceFactory());
100: }
101:
102: public void setWARDeployer(ObjectName name) {
103: factoryMap.put(name, new WebModuleFactory());
104: }
105:
106: public void setJavaMailResource(ObjectName name) {
107: factoryMap.put(name, new JavaMailResourceFactory());
108: }
109:
110: public void setJMSResource(ObjectName name) {
111: factoryMap.put(name, new JMSResourceFactory());
112: }
113:
114: public void setJNDIResource(ObjectName name) {
115: factoryMap.put(name, new JNDIResourceFactory());
116: }
117:
118: public void setJTAResource(ObjectName name) {
119: factoryMap.put(name, new JTAResourceFactory());
120: }
121:
122: public void setRMI_IIOPResource(ObjectName name) {
123: factoryMap.put(name, new RMIIIOPResourceFactory());
124: }
125: }
|