001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2013 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube 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 * SonarQube 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 License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.config;
021
022import org.sonar.api.ServerExtension;
023
024import 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 * <li>changes done when restoring settings from XML using backup/restore feature</li>
032 * </ul>
033 *
034 * @since 3.0
035 */
036public abstract class GlobalPropertyChangeHandler implements ServerExtension {
037
038  public static final class PropertyChange {
039    private String key;
040    private String newValue;
041
042    private PropertyChange(String key, @Nullable String newValue) {
043      this.key = key;
044      this.newValue = newValue;
045    }
046
047    public static PropertyChange create(String key, @Nullable String newValue) {
048      return new PropertyChange(key, newValue);
049    }
050
051    public String getKey() {
052      return key;
053    }
054
055    public String getNewValue() {
056      return newValue;
057    }
058
059    @Override
060    public String toString() {
061      return String.format("[key=%s, newValue=%s]", key, newValue);
062    }
063  }
064
065  /**
066   * This method gets called when a property is changed.
067   */
068  public abstract void onChange(PropertyChange change);
069
070}