001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jmx.export.metadata; 018 019import javax.management.modelmbean.ModelMBeanNotificationInfo; 020 021import org.springframework.util.ObjectUtils; 022import org.springframework.util.StringUtils; 023 024/** 025 * Utility methods for converting Spring JMX metadata into their plain JMX equivalents. 026 * 027 * @author Rob Harrop 028 * @author Juergen Hoeller 029 * @since 2.0 030 */ 031public abstract class JmxMetadataUtils { 032 033 /** 034 * Convert the supplied {@link ManagedNotification} into the corresponding 035 * {@link javax.management.modelmbean.ModelMBeanNotificationInfo}. 036 */ 037 public static ModelMBeanNotificationInfo convertToModelMBeanNotificationInfo(ManagedNotification notificationInfo) { 038 String[] notifTypes = notificationInfo.getNotificationTypes(); 039 if (ObjectUtils.isEmpty(notifTypes)) { 040 throw new IllegalArgumentException("Must specify at least one notification type"); 041 } 042 043 String name = notificationInfo.getName(); 044 if (!StringUtils.hasText(name)) { 045 throw new IllegalArgumentException("Must specify notification name"); 046 } 047 048 String description = notificationInfo.getDescription(); 049 return new ModelMBeanNotificationInfo(notifTypes, name, description); 050 } 051 052}