001 /*
002 * Copyright 2005,2009 Ivan SZKIBA
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.ini4j.spi;
017
018 import org.ini4j.Config;
019 import org.ini4j.Profile;
020 import org.ini4j.Reg;
021
022 import org.ini4j.Registry.Key;
023 import org.ini4j.Registry.Type;
024
025 public class RegBuilder extends AbstractProfileBuilder
026 {
027 private Reg _reg;
028
029 public static RegBuilder newInstance(Reg reg)
030 {
031 RegBuilder instance = newInstance();
032
033 instance.setReg(reg);
034
035 return instance;
036 }
037
038 public void setReg(Reg value)
039 {
040 _reg = value;
041 }
042
043 @Override public void handleOption(String rawName, String rawValue)
044 {
045 String name = (rawName.charAt(0) == EscapeTool.DOUBLE_QUOTE) ? RegEscapeTool.getInstance().unquote(rawName) : rawName;
046 TypeValuesPair tv = RegEscapeTool.getInstance().decode(rawValue);
047
048 if (tv.getType() != Type.REG_SZ)
049 {
050 ((Key) getCurrentSection()).putType(name, tv.getType());
051 }
052
053 for (String value : tv.getValues())
054 {
055 super.handleOption(name, value);
056 }
057 }
058
059 @Override Config getConfig()
060 {
061 return _reg.getConfig();
062 }
063
064 @Override Profile getProfile()
065 {
066 return _reg;
067 }
068
069 private static RegBuilder newInstance()
070 {
071 return ServiceFinder.findService(RegBuilder.class);
072 }
073 }