001 /*
002 * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.management;
027
028 import com.sun.jmx.mbeanserver.JmxMBeanServer;
029
030 /**
031 * <p>This class represents a builder that creates a default
032 * {@link javax.management.MBeanServer} implementation.
033 * The JMX {@link javax.management.MBeanServerFactory} allows
034 * applications to provide their custom MBeanServer
035 * implementation by providing a subclass of this class.</p>
036 *
037 * @see MBeanServer
038 * @see MBeanServerFactory
039 *
040 * @since 1.5
041 */
042 public class MBeanServerBuilder {
043 /**
044 * Public default constructor.
045 **/
046 public MBeanServerBuilder() {
047 }
048
049 /**
050 * This method creates a new MBeanServerDelegate for a new MBeanServer.
051 * When creating a new MBeanServer the
052 * {@link javax.management.MBeanServerFactory} first calls this method
053 * in order to create a new MBeanServerDelegate.
054 * <br>Then it calls
055 * <code>newMBeanServer(defaultDomain,outer,delegate)</code>
056 * passing the <var>delegate</var> that should be used by the MBeanServer
057 * implementation.
058 * <p>Note that the passed <var>delegate</var> might not be directly the
059 * MBeanServerDelegate that was returned by this method. It could
060 * be, for instance, a new object wrapping the previously
061 * returned object.
062 *
063 * @return A new {@link javax.management.MBeanServerDelegate}.
064 **/
065 public MBeanServerDelegate newMBeanServerDelegate() {
066 return JmxMBeanServer.newMBeanServerDelegate();
067 }
068
069 /**
070 * This method creates a new MBeanServer implementation object.
071 * When creating a new MBeanServer the
072 * {@link javax.management.MBeanServerFactory} first calls
073 * <code>newMBeanServerDelegate()</code> in order to obtain a new
074 * {@link javax.management.MBeanServerDelegate} for the new
075 * MBeanServer. Then it calls
076 * <code>newMBeanServer(defaultDomain,outer,delegate)</code>
077 * passing the <var>delegate</var> that should be used by the MBeanServer
078 * implementation.
079 * <p>Note that the passed <var>delegate</var> might not be directly the
080 * MBeanServerDelegate that was returned by this implementation. It could
081 * be, for instance, a new object wrapping the previously
082 * returned delegate.
083 * <p>The <var>outer</var> parameter is a pointer to the MBeanServer that
084 * should be passed to the {@link javax.management.MBeanRegistration}
085 * interface when registering MBeans inside the MBeanServer.
086 * If <var>outer</var> is <code>null</code>, then the MBeanServer
087 * implementation must use its own <code>this</code> reference when
088 * invoking the {@link javax.management.MBeanRegistration} interface.
089 * <p>This makes it possible for a MBeanServer implementation to wrap
090 * another MBeanServer implementation, in order to implement, e.g,
091 * security checks, or to prevent access to the actual MBeanServer
092 * implementation by returning a pointer to a wrapping object.
093 *
094 * @param defaultDomain Default domain of the new MBeanServer.
095 * @param outer A pointer to the MBeanServer object that must be
096 * passed to the MBeans when invoking their
097 * {@link javax.management.MBeanRegistration} interface.
098 * @param delegate A pointer to the MBeanServerDelegate associated
099 * with the new MBeanServer. The new MBeanServer must register
100 * this MBean in its MBean repository.
101 *
102 * @return A new private implementation of an MBeanServer.
103 **/
104 public MBeanServer newMBeanServer(String defaultDomain,
105 MBeanServer outer, MBeanServerDelegate delegate) {
106 // By default, MBeanServerInterceptors are disabled.
107 // Use com.sun.jmx.mbeanserver.MBeanServerBuilder to obtain
108 // MBeanServers on which MBeanServerInterceptors are enabled.
109 return JmxMBeanServer.newMBeanServer(defaultDomain, outer,
110 delegate, false);
111 }
112 }
|