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.SerializableConfigurationProperties;
19 import de.smartics.properties.api.config.domain.SerializableConfigurationPropertiesManagement;
20 import de.smartics.properties.spi.config.support.ConfigurationPropertiesManagementSpi;
21 import de.smartics.properties.spi.config.support.SerializableConfigurationPropertiesManagementSpi;
22 import de.smartics.util.lang.Arguments;
23
24 /**
25 * A delegate that provides a cache.
26 */
27 public final class SerializableCacheConfigurationPropertiesManagement extends
28 AbstractCacheConfigurationPropertiesManagement implements
29 SerializableConfigurationPropertiesManagementSpi
30 {
31 // ********************************* Fields *********************************
32
33 // --- constants ------------------------------------------------------------
34
35 /**
36 * The class version identifier.
37 */
38 private static final long serialVersionUID = 1L;
39
40 // --- members --------------------------------------------------------------
41
42 /**
43 * The wrapped delegate whose properties are to be cached.
44 *
45 * @serial
46 */
47 private final SerializableConfigurationPropertiesManagementSpi delegate;
48
49 // ****************************** Initializer *******************************
50
51 // ****************************** Constructors ******************************
52
53 /**
54 * Default constructor.
55 *
56 * @param delegate the wrapped delegate whose properties are to be cached.
57 * @throws NullPointerException if {@code delegate} is <code>null</code>.
58 */
59 public SerializableCacheConfigurationPropertiesManagement(
60 final SerializableConfigurationPropertiesManagementSpi delegate)
61 throws NullPointerException
62 {
63 this(delegate, new DependencyTrackingCache());
64 }
65
66 /**
67 * Default constructor.
68 *
69 * @param delegate the wrapped delegate whose properties are to be cached.
70 * @param cache the synchronized cache to use.
71 * @throws NullPointerException if {@code delegate} is <code>null</code>.
72 */
73 SerializableCacheConfigurationPropertiesManagement(
74 final SerializableConfigurationPropertiesManagementSpi delegate,
75 final DependencyTrackingCache cache) throws NullPointerException
76 {
77 super(cache);
78 Arguments.checkNotNull("delegate", delegate);
79
80 this.delegate = delegate;
81 }
82
83 // ****************************** Inner Classes *****************************
84
85 // ********************************* Methods ********************************
86
87 // --- init -----------------------------------------------------------------
88
89 // --- get&set --------------------------------------------------------------
90
91 @Override
92 protected ConfigurationPropertiesManagementSpi getDelegate()
93 {
94 return delegate;
95 }
96
97 @Override
98 public <T> T getProperties(final Class<T> propertiesInterface,
99 final SerializableConfigurationProperties configuration)
100 {
101 return delegate.getProperties(propertiesInterface, this);
102 }
103
104 // --- business -------------------------------------------------------------
105
106 @Override
107 public SerializableConfigurationPropertiesManagement toSerializable()
108 {
109 return this;
110 }
111
112 // --- object basics --------------------------------------------------------
113
114 }