1/*
2 * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.jmx.mbeanserver;
27
28import javax.management.MBeanServer;
29import javax.management.MBeanServerDelegate;
30import javax.management.MBeanServerBuilder;
31
32/**
33 * This class represents a builder that creates
34 * {@link javax.management.MBeanServer} implementations.
35 * The JMX {@link javax.management.MBeanServerFactory} allows
36 * for applications to provide their custom MBeanServer
37 * implementation. This class is not used when the whole Sun Reference JMX
38 * Implementation is used. However it may be used to substitute Sun
39 * MBeanServer implementation to another JMX implementation.
40 * <p>
41 * Contrarily to the default {@link javax.management.MBeanServerBuilder
42 * javax.management.MBeanServerBuilder} this MBeanServerBuilder returns
43 * MBeanServers on which
44 * {@link com.sun.jmx.interceptor.MBeanServerInterceptor}s are enabled.
45 *
46 * @since 1.5
47 */
48public class JmxMBeanServerBuilder extends MBeanServerBuilder {
49    /**
50     * This method creates a new MBeanServerDelegate for a new MBeanServer.
51     * When creating a new MBeanServer the
52     * {@link javax.management.MBeanServerFactory} first calls this method
53     * in order to create a new MBeanServerDelegate.
54     * <br>Then it calls
55     * <code>newMBeanServer(defaultDomain,outer,delegate)</code>
56     * passing the <var>delegate</var> that should be used by the MBeanServer
57     * implementation.
58     * <p>Note that the passed <var>delegate</var> might not be directly the
59     * MBeanServerDelegate that was returned by this method. It could
60     * be, for instance, a new object wrapping the previously
61     * returned object.
62     *
63     * @return A new {@link javax.management.MBeanServerDelegate}.
64     **/
65    public MBeanServerDelegate newMBeanServerDelegate() {
66        return JmxMBeanServer.newMBeanServerDelegate();
67    }
68
69    /**
70     * This method creates a new MBeanServer implementation object.
71     * When creating a new MBeanServer the
72     * {@link javax.management.MBeanServerFactory} first calls
73     * <code>newMBeanServerDelegate()</code> in order to obtain a new
74     * {@link javax.management.MBeanServerDelegate} for the new
75     * MBeanServer. Then it calls
76     * <code>newMBeanServer(defaultDomain,outer,delegate)</code>
77     * passing the <var>delegate</var> that should be used by the
78     * MBeanServer  implementation.
79     * <p>Note that the passed <var>delegate</var> might not be directly the
80     * MBeanServerDelegate that was returned by this implementation. It could
81     * be, for instance, a new object wrapping the previously
82     * returned delegate.
83     * <p>The <var>outer</var> parameter is a pointer to the MBeanServer that
84     * should be passed to the {@link javax.management.MBeanRegistration}
85     * interface when registering MBeans inside the MBeanServer.
86     * If <var>outer</var> is <code>null</code>, then the MBeanServer
87     * implementation is free to use its own <code>this</code> pointer when
88     * invoking the {@link javax.management.MBeanRegistration} interface.
89     * <p>This makes it possible for a MBeanServer implementation to wrap
90     * another MBeanServer implementation, in order to implement, e.g,
91     * security checks, or to prevent access to the actual MBeanServer
92     * implementation by returning a pointer to a wrapping object.
93     * <p>
94     * This MBeanServerBuilder makes it possible to create MBeanServer
95     * which support {@link com.sun.jmx.interceptor.MBeanServerInterceptor}s.
96     *
97     * @param defaultDomain Default domain of the new MBeanServer.
98     * @param outer A pointer to the MBeanServer object that must be
99     *        passed to the MBeans when invoking their
100     *        {@link javax.management.MBeanRegistration} interface.
101     * @param delegate A pointer to the MBeanServerDelegate associated
102     *        with the new MBeanServer. The new MBeanServer must register
103     *        this MBean in its MBean repository.
104     *
105     * @return A new private implementation of an MBeanServer.
106     **/
107    public MBeanServer newMBeanServer(String defaultDomain,
108                                      MBeanServer outer,
109                                      MBeanServerDelegate delegate) {
110        return JmxMBeanServer.newMBeanServer(defaultDomain,outer,delegate,
111                                             true);
112    }
113
114}
115