View Javadoc
1   package com.atlassian.plugin.manager.store;
2   
3   import com.atlassian.annotations.ExperimentalApi;
4   import com.atlassian.plugin.manager.PluginPersistentState;
5   import com.atlassian.plugin.manager.PluginPersistentStateStore;
6   
7   /**
8    * A read-only implementation of {@link PluginPersistentStateStore} which returns a state provided on construction.
9    * <p>
10   * The held {@link PluginPersistentState} is not read-only - external modification to it is not prevented, and will be reflected
11   * in the state returned from {@link #load()}.
12   *
13   * @since 3.2.0
14   */
15  @ExperimentalApi
16  public class LoadOnlyPluginPersistentStateStore implements PluginPersistentStateStore {
17      private final PluginPersistentState pluginPersistentState;
18  
19      public LoadOnlyPluginPersistentStateStore() {
20          this(PluginPersistentState.Builder.create().toState());
21      }
22  
23      public LoadOnlyPluginPersistentStateStore(final PluginPersistentState pluginPersistentState) {
24          this.pluginPersistentState = pluginPersistentState;
25      }
26  
27      /**
28       * This implementation ignores the provided state and throws.
29       *
30       * @param state ignored
31       * @throws IllegalStateException always
32       */
33      @Override
34      public void save(final PluginPersistentState state) {
35          throw new IllegalStateException("Cannot save state to " + LoadOnlyPluginPersistentStateStore.class);
36      }
37  
38      @Override
39      public PluginPersistentState load() {
40          return pluginPersistentState;
41      }
42  }