001: /**
002: * EasyBeans
003: * Copyright (C) 2006-2007 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: J2EEDeployedObjectMBean.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.jsr77;
025:
026: import javax.management.MBeanException;
027: import javax.management.MalformedObjectNameException;
028: import javax.management.ObjectName;
029:
030: import org.ow2.util.log.Log;
031: import org.ow2.util.log.LogFactory;
032:
033: /**
034: * J2EEDeployedObject JSR77 MBean.
035: * @param <T> ManagedObject type
036: * @author Guillaume Sauthier
037: * @author Florent BENOIT
038: */
039: public class J2EEDeployedObjectMBean<T> extends
040: J2EEManagedObjectMBean<T> {
041:
042: /**
043: * Logger.
044: */
045: private static Log logger = LogFactory
046: .getLog(J2EEDeployedObjectMBean.class);
047:
048: /**
049: * J2EE server key.
050: */
051: public static final String J2EESERVER_KEY = "J2EEServer";
052:
053: /**
054: * Creates a J2EEDeployedObject.
055: * @throws MBeanException if creation fails.
056: */
057: public J2EEDeployedObjectMBean() throws MBeanException {
058: super ();
059: }
060:
061: /**
062: * @return Returns the XML Deployment Descriptors of the Module.
063: */
064: public String getDeploymentDescriptor() {
065: // TODO implement it !
066: throw new UnsupportedOperationException("Not implemented yet !");
067: }
068:
069: /**
070: * @return Returns the J2EEServer ObjectName.
071: */
072: public String getServer() {
073: String serverName = null;
074: // Read ObjectName of this MBean
075: try {
076: ObjectName on = new ObjectName(getObjectName());
077: // build ObjectName
078: serverName = getJ2EEServer(on.getDomain(),
079: on.getKeyProperty(J2EESERVER_KEY)).toString();
080: } catch (MalformedObjectNameException e) {
081: throw new IllegalStateException(
082: "Cannot build Server object name", e);
083: }
084: return serverName;
085: }
086:
087: /**
088: * Gets ObjectName for a J2EEServer MBean.
089: * @param domainName domain name
090: * @param serverName server name
091: * @return the created ObjectName
092: */
093: public static ObjectName getJ2EEServer(final String domainName,
094: final String serverName) {
095: try {
096: StringBuffer sb = new StringBuffer(domainName);
097: sb.append(":j2eeType=J2EEServer");
098: sb.append(",name=");
099: sb.append(serverName);
100: return new ObjectName(sb.toString());
101: } catch (javax.management.MalformedObjectNameException e) {
102: logger.error("Cannot build ObjectName for the J2EEServer",
103: e);
104: return null;
105: }
106: }
107:
108: }
|