/**
* JOnAS: Java(TM) Open Application Server
* Copyright (C) 2004 Bull S.A.
* Contact: jonas-team@objectweb.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
* USA
*
* --------------------------------------------------------------------------
* $Id$
* --------------------------------------------------------------------------
*/
package org.objectweb.jonas.management.j2eemanagement;

import javax.management.MBeanServerNotification;
import javax.management.Notification;
import javax.management.NotificationFilter;
import javax.management.ObjectName;

/**
* @author Adriana Danes
*
* NotificationFilter that accepts only management notifications
*/
public class ManagementMBeanFilter implements NotificationFilter {

   /**
     *
     */
    private static final long serialVersionUID = 1L;

/**
    * Returns true if the notification is a REGISTRATION or UNREGISTRETION
    * JOnAS management MBean notification
    * @param notif notification to filter
    * @return true if this is a discovery notification, false otherwise
    */
    public boolean isNotificationEnabled(Notification notif) {
        boolean result = false;
        if (notif instanceof MBeanServerNotification) {
            ObjectName name = ((MBeanServerNotification) notif).getMBeanName();
            String onType = name.getKeyProperty("type");
            String onServer = name.getKeyProperty("server");
            if (onType != null && onType.equals("management")
                    && onServer != null && onServer.equals("JOnAS")) {
                return true;
            }
        }
        return result;
    }
}