01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.jbi.management;
18:
19: import java.util.concurrent.ExecutorService;
20:
21: import javax.management.DynamicMBean;
22: import javax.management.JMException;
23: import javax.management.StandardMBean;
24:
25: /**
26: * Builds a DynamicMBean wrappers for existing objects
27: *
28: * @version $Revision: 564607 $
29: */
30: public final class MBeanBuilder {
31:
32: private MBeanBuilder() {
33: }
34:
35: /**
36: * Build an MBean
37: *
38: * @param theObject
39: * @param interfaceMBean
40: * @param description
41: * @param executorService
42: * @return the MBean wrapper
43: * @throws JMException
44: */
45: static DynamicMBean buildStandardMBean(Object theObject,
46: Class interfaceMBean, String description,
47: ExecutorService executorService) throws JMException {
48: DynamicMBean result = null;
49: if (theObject != null) {
50: if (theObject instanceof MBeanInfoProvider) {
51: MBeanInfoProvider info = (MBeanInfoProvider) theObject;
52: result = new BaseStandardMBean(
53: info.getObjectToManage(), interfaceMBean,
54: description, info.getAttributeInfos(), info
55: .getOperationInfos(), executorService);
56: info
57: .setPropertyChangeListener((BaseStandardMBean) result);
58: } else {
59: return new StandardMBean(theObject, interfaceMBean);
60: }
61: }
62: return result;
63: }
64: }
|