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 */ 016package org.ini4j; 017 018import org.ini4j.Profile.Section; 019 020import org.ini4j.spi.IniHandler; 021import org.ini4j.spi.RegEscapeTool; 022import org.ini4j.spi.TypeValuesPair; 023 024public class BasicRegistry extends BasicProfile implements Registry 025{ 026 private static final long serialVersionUID = -6432826330714504802L; 027 private String _version; 028 029 public BasicRegistry() 030 { 031 _version = VERSION; 032 } 033 034 @Override public String getVersion() 035 { 036 return _version; 037 } 038 039 @Override public void setVersion(String value) 040 { 041 _version = value; 042 } 043 044 @Override public Key add(String name) 045 { 046 return (Key) super.add(name); 047 } 048 049 @Override public Key get(Object key) 050 { 051 return (Key) super.get(key); 052 } 053 054 @Override public Key get(Object key, int index) 055 { 056 return (Key) super.get(key, index); 057 } 058 059 @Override public Key put(String key, Section value) 060 { 061 return (Key) super.put(key, value); 062 } 063 064 @Override public Key put(String key, Section value, int index) 065 { 066 return (Key) super.put(key, value, index); 067 } 068 069 @Override public Key remove(Section section) 070 { 071 return (Key) super.remove(section); 072 } 073 074 @Override public Key remove(Object key) 075 { 076 return (Key) super.remove(key); 077 } 078 079 @Override public Key remove(Object key, int index) 080 { 081 return (Key) super.remove(key, index); 082 } 083 084 @Override Key newSection(String name) 085 { 086 return new BasicRegistryKey(this, name); 087 } 088 089 @Override void store(IniHandler formatter, Section section, String option) 090 { 091 store(formatter, section.getComment(option)); 092 Type type = ((Key) section).getType(option, Type.REG_SZ); 093 String rawName = option.equals(Key.DEFAULT_NAME) ? option : RegEscapeTool.getInstance().quote(option); 094 String[] values = new String[section.length(option)]; 095 096 for (int i = 0; i < values.length; i++) 097 { 098 values[i] = section.get(option, i); 099 } 100 101 String rawValue = RegEscapeTool.getInstance().encode(new TypeValuesPair(type, values)); 102 103 formatter.handleOption(rawName, rawValue); 104 } 105}