View Javadoc

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;
18  
19  import net.sf.ehcache.config.generator.model.NodeAttribute;
20  import net.sf.ehcache.config.generator.model.NodeElement;
21  import net.sf.ehcache.config.generator.xsom.XSDAttributeValueFactory;
22  import net.sf.ehcache.config.generator.xsom.XSDAttributeValueType;
23  
24  public class ValidDummyEhcacheConfigAttributesValueFactory implements XSDAttributeValueFactory {
25  
26      public String createValueForAttribute(NodeElement element, NodeAttribute attribute, XSDAttributeValueType xsdAttributeValueType) {
27          if ("terracotta".equals(element.getName())) {
28              if ("coherent".equals(attribute.getName())) {
29                  // returing null will skip this attribute
30                  // can skip "coherent" attribute as its deprecated by consistency attribute
31                  return null;
32              }
33              if ("clustered".equals(attribute.getName())) {
34                  return "false";
35              }
36          }
37          if ("pinning".equals(element.getName())) {
38              if ("storage".equals(attribute.getName())) {
39                  return "inMemory";
40              }
41          }
42          if (("cache".equals(element.getName()) || "defaultCache".equals(element.getName()))
43                  && "transactionalMode".equals(attribute.getName())) {
44              return "off";
45          }
46          // always generate with eternal=false
47          if (("defaultCache".equals(element.getName()) || "cache".equals(element.getName())) && "eternal".equals(attribute.getName())) {
48              return "false";
49          }
50          if ("maxMemoryOffHeap".equals(attribute.getName())) {
51              return "1G";
52          }
53          if ("searchAttribute".equals(element.getName())) {
54              if ("expression".equals(attribute.getName())) {
55                  return "value.toString()";
56              } else if ("name".equals(attribute.getName())) {
57                  return "name";
58              } else {
59                  return null;
60              }
61          }
62  
63          return xsdAttributeValueType.getRandomAllowedValue();
64      }
65  }