01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.jmx.export.metadata;
18:
19: import javax.management.modelmbean.ModelMBeanNotificationInfo;
20:
21: import org.springframework.util.StringUtils;
22:
23: /**
24: * Utility methods for converting Spring JMX metadata into their plain JMX equivalents.
25: *
26: * @author Rob Harrop
27: * @author Juergen Hoeller
28: * @since 2.0
29: */
30: public abstract class JmxMetadataUtils {
31:
32: /**
33: * Convert the supplied {@link ManagedNotification} into the corresponding
34: * {@link javax.management.modelmbean.ModelMBeanNotificationInfo}.
35: */
36: public static ModelMBeanNotificationInfo convertToModelMBeanNotificationInfo(
37: ManagedNotification notificationInfo) {
38: String name = notificationInfo.getName();
39: if (!StringUtils.hasText(name)) {
40: throw new IllegalArgumentException(
41: "Must specify notification name");
42: }
43:
44: String[] notifTypes = notificationInfo.getNotificationTypes();
45: if (notifTypes == null || notifTypes.length == 0) {
46: throw new IllegalArgumentException(
47: "Must specify at least one notification type");
48: }
49:
50: String description = notificationInfo.getDescription();
51: return new ModelMBeanNotificationInfo(notifTypes, name,
52: description);
53: }
54:
55: }
|