View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.impl.config.cache;
17  
18  import de.smartics.properties.api.config.domain.PropertyStoreAccessor;
19  import de.smartics.properties.api.config.domain.SerializableConfigurationProperties;
20  import de.smartics.properties.api.config.domain.SerializableConfigurationPropertiesManagement;
21  import de.smartics.properties.spi.config.support.ConfigurationPropertiesManagementSpi;
22  import de.smartics.properties.spi.config.support.SerializableConfigurationPropertiesManagementSpi;
23  import de.smartics.util.lang.Arg;
24  
25  /**
26   * A delegate that provides a cache.
27   */
28  public final class SerializableCacheConfigurationPropertiesManagement extends
29      AbstractCacheConfigurationPropertiesManagement implements
30      SerializableConfigurationPropertiesManagementSpi
31  {
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    /**
37     * The class version identifier.
38     */
39    private static final long serialVersionUID = 1L;
40  
41    // --- members --------------------------------------------------------------
42  
43    /**
44     * The wrapped delegate whose properties are to be cached.
45     *
46     * @serial
47     */
48    private final SerializableConfigurationPropertiesManagementSpi delegate;
49  
50    // ****************************** Initializer *******************************
51  
52    // ****************************** Constructors ******************************
53  
54    /**
55     * Default constructor.
56     *
57     * @param delegate the wrapped delegate whose properties are to be cached.
58     * @throws NullPointerException if {@code delegate} is <code>null</code>.
59     */
60    public SerializableCacheConfigurationPropertiesManagement(
61        final SerializableConfigurationPropertiesManagementSpi delegate)
62      throws NullPointerException
63    {
64      this(delegate, new DependencyTrackingCache(delegate.getKey()));
65    }
66  
67    /**
68     * Default constructor.
69     *
70     * @param delegate the wrapped delegate whose properties are to be cached.
71     * @param cache the synchronized cache to use.
72     * @throws NullPointerException if {@code delegate} is <code>null</code>.
73     */
74    SerializableCacheConfigurationPropertiesManagement(
75        final SerializableConfigurationPropertiesManagementSpi delegate,
76        final DependencyTrackingCache cache) throws NullPointerException
77    {
78      super(cache);
79  
80      this.delegate = Arg.checkNotNull("delegate", delegate);
81    }
82  
83    // ****************************** Inner Classes *****************************
84  
85    // ********************************* Methods ********************************
86  
87    // --- init -----------------------------------------------------------------
88  
89    // --- get&set --------------------------------------------------------------
90  
91    @Override
92    public boolean isInAdminMode()
93    {
94      return delegate.isInAdminMode();
95    }
96  
97    @Override
98    public void setToAdminMode(final boolean newMode)
99    {
100     delegate.setToAdminMode(newMode);
101   }
102 
103   @Override
104   protected ConfigurationPropertiesManagementSpi getDelegate()
105   {
106     return delegate;
107   }
108 
109   @Override
110   public <T> T getProperties(final Class<T> propertiesInterface,
111       final SerializableConfigurationProperties configuration)
112   {
113     return delegate.getProperties(propertiesInterface, this);
114   }
115 
116   // --- business -------------------------------------------------------------
117 
118   @Override
119   public SerializableConfigurationPropertiesManagement toSerializable()
120   {
121     return this;
122   }
123 
124   @Override
125   public PropertyStoreAccessor getPropertyStoreAccessor()
126   {
127     return delegate.getPropertyStoreAccessor();
128   }
129 
130   // --- object basics --------------------------------------------------------
131 
132 }