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.spi;
17  
18  import org.ini4j.Config;
19  import org.ini4j.Profile;
20  import org.ini4j.Reg;
21  
22  import org.ini4j.Registry.Key;
23  import org.ini4j.Registry.Type;
24  
25  public class RegBuilder extends AbstractProfileBuilder
26  {
27      private Reg _reg;
28  
29      public static RegBuilder newInstance(Reg reg)
30      {
31          RegBuilder instance = newInstance();
32  
33          instance.setReg(reg);
34  
35          return instance;
36      }
37  
38      public void setReg(Reg value)
39      {
40          _reg = value;
41      }
42  
43      @Override public void handleOption(String rawName, String rawValue)
44      {
45          String name = (rawName.charAt(0) == EscapeTool.DOUBLE_QUOTE) ? RegEscapeTool.getInstance().unquote(rawName) : rawName;
46          TypeValuesPair tv = RegEscapeTool.getInstance().decode(rawValue);
47  
48          if (tv.getType() != Type.REG_SZ)
49          {
50              ((Key) getCurrentSection()).putType(name, tv.getType());
51          }
52  
53          for (String value : tv.getValues())
54          {
55              super.handleOption(name, value);
56          }
57      }
58  
59      @Override Config getConfig()
60      {
61          return _reg.getConfig();
62      }
63  
64      @Override Profile getProfile()
65      {
66          return _reg;
67      }
68  
69      private static RegBuilder newInstance()
70      {
71          return ServiceFinder.findService(RegBuilder.class);
72      }
73  }