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  {
18      private final PluginPersistentState pluginPersistentState;
19  
20      public LoadOnlyPluginPersistentStateStore()
21      {
22          this(PluginPersistentState.Builder.create().toState());
23      }
24  
25      public LoadOnlyPluginPersistentStateStore(final PluginPersistentState pluginPersistentState)
26      {
27          this.pluginPersistentState = pluginPersistentState;
28      }
29  
30      /**
31       * This implementation ignores the provided state and throws.
32       *
33       * @param state ignored
34       * @throws IllegalStateException always
35       */
36      @Override
37      public void save(final PluginPersistentState state)
38      {
39          throw new IllegalStateException("Cannot save state to " + LoadOnlyPluginPersistentStateStore.class);
40      }
41  
42      @Override
43      public PluginPersistentState load()
44      {
45          return pluginPersistentState;
46      }
47  }