View Javadoc

1   /*
2    * Copyright 2005,2009 Ivan SZKIBA
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 org.ini4j;
17  
18  import org.ini4j.Profile.Section;
19  
20  import org.ini4j.spi.IniHandler;
21  import org.ini4j.spi.RegEscapeTool;
22  import org.ini4j.spi.TypeValuesPair;
23  
24  public class BasicRegistry extends BasicProfile implements Registry
25  {
26      private static final long serialVersionUID = -6432826330714504802L;
27      private String _version;
28  
29      public BasicRegistry()
30      {
31          _version = VERSION;
32      }
33  
34      @Override public String getVersion()
35      {
36          return _version;
37      }
38  
39      @Override public void setVersion(String value)
40      {
41          _version = value;
42      }
43  
44      @Override public Key add(String name)
45      {
46          return (Key) super.add(name);
47      }
48  
49      @Override public Key get(Object key)
50      {
51          return (Key) super.get(key);
52      }
53  
54      @Override public Key get(Object key, int index)
55      {
56          return (Key) super.get(key, index);
57      }
58  
59      @Override public Key put(String key, Section value)
60      {
61          return (Key) super.put(key, value);
62      }
63  
64      @Override public Key put(String key, Section value, int index)
65      {
66          return (Key) super.put(key, value, index);
67      }
68  
69      @Override public Key remove(Section section)
70      {
71          return (Key) super.remove(section);
72      }
73  
74      @Override public Key remove(Object key)
75      {
76          return (Key) super.remove(key);
77      }
78  
79      @Override public Key remove(Object key, int index)
80      {
81          return (Key) super.remove(key, index);
82      }
83  
84      @Override Key newSection(String name)
85      {
86          return new BasicRegistryKey(this, name);
87      }
88  
89      @Override void store(IniHandler formatter, Section section, String option)
90      {
91          store(formatter, section.getComment(option));
92          Type type = ((Key) section).getType(option, Type.REG_SZ);
93          String rawName = option.equals(Key.DEFAULT_NAME) ? option : RegEscapeTool.getInstance().quote(option);
94          String[] values = new String[section.length(option)];
95  
96          for (int i = 0; i < values.length; i++)
97          {
98              values[i] = section.get(option, i);
99          }
100 
101         String rawValue = RegEscapeTool.getInstance().encode(new TypeValuesPair(type, values));
102 
103         formatter.handleOption(rawName, rawValue);
104     }
105 }