001/* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2012 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020package org.sonar.api.notifications; 021 022import com.google.common.collect.Maps; 023import org.sonar.api.ServerExtension; 024 025import java.util.Map; 026 027/** 028 * <p> 029 * Notification dispatchers (see {@link NotificationDispatcher}) can define their own metadata class in order 030 * to tell more about them. 031 * <br/> 032 * Instances of those classes must be passed to Pico container (generally in the 033 * {@link SonarPlugin#getExtensions()} method implementation). 034 * </p> 035 * 036 * @since 3.5 037 */ 038public final class NotificationDispatcherMetadata implements ServerExtension { 039 040 public static final String GLOBAL_NOTIFICATION = "globalNotification"; 041 public static final String PER_PROJECT_NOTIFICATION = "perProjectNotification"; 042 043 private String dispatcherKey; 044 private Map<String, String> properties; 045 046 private NotificationDispatcherMetadata(String dispatcherKey) { 047 this.dispatcherKey = dispatcherKey; 048 this.properties = Maps.newHashMap(); 049 } 050 051 /** 052 * Creates a new metadata instance for the given dispatcher. 053 */ 054 public static NotificationDispatcherMetadata create(String dispatcherKey) { 055 return new NotificationDispatcherMetadata(dispatcherKey); 056 } 057 058 /** 059 * Sets a property on this metadata object. 060 */ 061 public NotificationDispatcherMetadata setProperty(String key, String value) { 062 properties.put(key, value); 063 return this; 064 } 065 066 /** 067 * Gives the property for the given key. 068 */ 069 public String getProperty(String key) { 070 return properties.get(key); 071 } 072 073 /** 074 * Returns the unique key of the dispatcher. 075 */ 076 public String getDispatcherKey() { 077 return dispatcherKey; 078 } 079 080}