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 */
020 package org.sonar.api.config;
021
022 import org.sonar.api.ServerExtension;
023
024 import javax.annotation.Nullable;
025
026 /**
027 * Observe changes of global properties done from web application. It does not support :
028 * <ul>
029 * <li>changes done by end-users from the page "Project Settings"</li>
030 * <li>changes done programmatically on the component org.sonar.api.config.Settings</li>
031 * </ul>
032 *
033 * @since 3.0
034 */
035 public abstract class GlobalPropertyChangeHandler implements ServerExtension {
036
037 public static final class PropertyChange {
038 private String key;
039 private String newValue;
040
041 private PropertyChange(String key, @Nullable String newValue) {
042 this.key = key;
043 this.newValue = newValue;
044 }
045
046 public static PropertyChange create(String key, @Nullable String newValue) {
047 return new PropertyChange(key, newValue);
048 }
049
050 public String getKey() {
051 return key;
052 }
053
054 public String getNewValue() {
055 return newValue;
056 }
057
058 @Override
059 public String toString() {
060 return String.format("[key=%s, newValue=%s]", key, newValue);
061 }
062 }
063
064 /**
065 * This method gets called when a property is changed.
066 */
067 public abstract void onChange(PropertyChange change);
068 }