SettingScope.java

  1. /*
  2.  * Copyright (C) 2003-2012 eXo Platform SAS.
  3.  *
  4.  * This program is free software: you can redistribute it and/or modify
  5.  * it under the terms of the GNU Affero General Public License as published by
  6.  * the Free Software Foundation, either version 3 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU Affero General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU Affero General Public License
  15.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17. package org.exoplatform.commons.api.settings.data;


  18. /**
  19.  * Associates setting properties with a specified scope (for example, GLOBAL/PORTAL/APPLICATION).
  20.  * SettingScope is composed by [context, scope] and is used to
  21.  * specify context of setting properties at the Scope level when working with database, cache or dispatching the setting event.
  22.  * @LevelAPI Experimental
  23.  */
  24. public class SettingScope extends SettingContext {

  25.   /**
  26.    *
  27.    */
  28.   private static final long serialVersionUID = -8617975143175631988L;

  29.   protected Scope           scope;

  30.   protected String          scopePath;

  31.   /**
  32.    * Creates a setting scope object with a composite key [context, scope].
  33.    * @param context The context value.
  34.    * @param scope The scope value.
  35.    * @LevelAPI Experimental
  36.    */
  37.   public SettingScope(Context context, Scope scope) {
  38.     super(context);
  39.     this.scope = scope;
  40.     scopePath = Tools.buildScopePath(context, scope);
  41.   }
  42.   /**
  43.    * Compares a specified object with the SettingScope for equality.
  44.    */
  45.   @Override
  46.   public boolean equals(Object obj) {
  47.     if (obj == null) {
  48.       return false;
  49.     }
  50.     if (this == obj) {
  51.       return true;
  52.     }
  53.     if (!super.equals(obj)) {
  54.       return false;
  55.     }

  56.     if (obj instanceof SettingScope) {
  57.       SettingScope dest = (SettingScope) obj;
  58.       return this.getScopePath().equals(dest.getScopePath());
  59.     }
  60.     return false;
  61.   }
  62.   /**
  63.    * Returns the hash code value for the SettingScope object.
  64.    */
  65.   @Override
  66.   public int hashCode() {
  67.     int result = super.repositoryName.hashCode();
  68.     result = 31 * result + scopePath.hashCode();
  69.     return result;
  70.   }
  71.   /**
  72.    * Gets a scope value of the SettingScope object.
  73.    * @return The value of key.
  74.    * @LevelAPI Experimental
  75.    */
  76.   public Scope getScope() {
  77.     return scope;
  78.   }
  79.   /**
  80.    * Gets a path to the SettingScope object.
  81.    * @return The SettingScope path in the database.
  82.    * @LevelAPI Experimental
  83.    */
  84.   public String getScopePath() {
  85.     return scopePath;
  86.   }

  87. }