1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
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
17 package net.sf.ehcache.config.generator.model.elements;
18
19 import net.sf.ehcache.config.TerracottaConfiguration;
20 import net.sf.ehcache.config.generator.model.NodeElement;
21 import net.sf.ehcache.config.generator.model.SimpleNodeAttribute;
22 import net.sf.ehcache.config.generator.model.SimpleNodeElement;
23
24 /***
25 * {@link NodeElement} representing the {@link TerracottaConfiguration}
26 *
27 * @author Abhishek Sanoujam
28 *
29 */
30 public class TerracottaConfigurationElement extends SimpleNodeElement {
31
32 private final TerracottaConfiguration tcConfiguration;
33
34 /***
35 * Constructor accepting the parent and the {@link TerracottaConfiguration}
36 *
37 * @param parent
38 * @param tcConfiguration
39 */
40 public TerracottaConfigurationElement(NodeElement parent, TerracottaConfiguration tcConfiguration) {
41 super(parent, "terracotta");
42 this.tcConfiguration = tcConfiguration;
43 init();
44 }
45
46 private void init() {
47 if (tcConfiguration == null) {
48 return;
49 }
50 if (tcConfiguration.getNonstopConfiguration() != null) {
51 this.addChildElement(new NonstopConfigurationElement(this, tcConfiguration.getNonstopConfiguration()));
52 }
53 addAttribute(new SimpleNodeAttribute("clustered", tcConfiguration.isClustered()).optional(true).defaultValue(
54 TerracottaConfiguration.DEFAULT_CLUSTERED));
55 addAttribute(new SimpleNodeAttribute("valueMode", tcConfiguration.getValueMode()).optional(true).defaultValue(
56 TerracottaConfiguration.DEFAULT_VALUE_MODE));
57 addAttribute(new SimpleNodeAttribute("consistency", tcConfiguration.getConsistency().name()).optional(true).defaultValue(
58 TerracottaConfiguration.DEFAULT_CONSISTENCY_TYPE.name()));
59 addAttribute(new SimpleNodeAttribute("synchronousWrites", tcConfiguration.isSynchronousWrites()).optional(true).defaultValue(
60 TerracottaConfiguration.DEFAULT_SYNCHRONOUS_WRITES));
61 addAttribute(new SimpleNodeAttribute("copyOnRead", tcConfiguration.isCopyOnRead()).optional(true).defaultValue(
62 TerracottaConfiguration.DEFAULT_COPY_ON_READ));
63 addAttribute(new SimpleNodeAttribute("localKeyCache", tcConfiguration.getLocalKeyCache()).optional(true).defaultValue(
64 TerracottaConfiguration.DEFAULT_LOCAL_KEY_CACHE));
65 addAttribute(new SimpleNodeAttribute("localKeyCacheSize", tcConfiguration.getLocalKeyCacheSize()).optional(true).defaultValue(
66 TerracottaConfiguration.DEFAULT_LOCAL_KEY_CACHE_SIZE));
67 addAttribute(new SimpleNodeAttribute("orphanEviction", tcConfiguration.getOrphanEviction()).optional(true).defaultValue(
68 TerracottaConfiguration.DEFAULT_ORPHAN_EVICTION));
69 addAttribute(new SimpleNodeAttribute("orphanEvictionPeriod", tcConfiguration.getOrphanEvictionPeriod()).optional(true)
70 .defaultValue(TerracottaConfiguration.DEFAULT_ORPHAN_EVICTION_PERIOD));
71 addAttribute(new SimpleNodeAttribute("coherentReads", tcConfiguration.getCoherentReads()).optional(true).defaultValue(
72 TerracottaConfiguration.DEFAULT_COHERENT_READS));
73 addAttribute(new SimpleNodeAttribute("storageStrategy", tcConfiguration.getStorageStrategy()).optional(true).defaultValue(
74 TerracottaConfiguration.DEFAULT_STORAGE_STRATEGY));
75 addAttribute(new SimpleNodeAttribute("concurrency", tcConfiguration.getConcurrency()).optional(true).defaultValue(
76 TerracottaConfiguration.DEFAULT_CONCURRENCY));
77 addAttribute(new SimpleNodeAttribute("localCacheEnabled", tcConfiguration.isLocalCacheEnabled()).optional(true).defaultValue(
78 TerracottaConfiguration.DEFAULT_LOCAL_CACHE_ENABLED));
79 }
80
81 }