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.test;
017
018import org.ini4j.sample.Dwarf;
019import org.ini4j.sample.Dwarfs;
020
021import java.beans.PropertyChangeListener;
022import java.beans.PropertyVetoException;
023import java.beans.VetoableChangeListener;
024
025import java.net.URI;
026
027public final class DwarfsData implements Dwarfs
028{
029    public static final DwarfData bashful;
030    public static final DwarfData doc;
031    public static final DwarfData dopey;
032    public static final DwarfData grumpy;
033    public static final DwarfData happy;
034    public static final DwarfData sleepy;
035    public static final DwarfData sneezy;
036    public static final Dwarfs dwarfs;
037    public static final String[] dwarfNames;
038    public static final String INI_DOPEY_WEIGHT = "${bashful/weight}";
039    public static final String INI_DOPEY_HEIGHT = "${doc/height}";
040    public static final String INI_GRUMPY_HEIGHT = "${dopey/height}";
041    public static final String INI_SLEEPY_HEIGHT = "${doc/height}8";
042    public static final String INI_SNEEZY_HOME_PAGE = "${happy/homePage}/~sneezy";
043    public static final String OPT_DOPEY_WEIGHT = "${bashful.weight}";
044    public static final String OPT_DOPEY_HEIGHT = "${doc.height}";
045    public static final String OPT_GRUMPY_HEIGHT = "${dopey.height}";
046    public static final String OPT_SLEEPY_HEIGHT = "${doc.height}8";
047    public static final String OPT_SNEEZY_HOME_PAGE = "${happy.homePage}/~sneezy";
048
049    static
050    {
051
052        // age, fortuneNumber, height, homeDir, homePage, weight
053        bashful = new DwarfData(PROP_BASHFUL, 67, null, 98.8, "/home/bashful", "http://snowwhite.tale/~bashful", 45.7);
054        doc = new DwarfData(PROP_DOC, 63, null, 87.7, "c:Documents and Settingsdoc", "http://doc.dwarfs", 49.5);
055        dopey = new DwarfData(PROP_DOPEY, 23, new int[] { 11, 33, 55 }, doc.height, "c:\\Documents and Settings\\dopey", "http://dopey.snowwhite.tale/", bashful.weight);
056        grumpy = new DwarfData(PROP_GRUMPY, 76, null, dopey.height, "/home/grumpy", "http://snowwhite.tale/~grumpy/", 65.3);
057        happy = new DwarfData(PROP_HAPPY, 99, null, 77.66, "/home/happy", "http://happy.smurf", 56.4);
058        sleepy = new DwarfData(PROP_SLEEPY, 121, new int[] { 99 }, doc.height + 0.08, "/home/sleepy", "http://snowwhite.tale/~sleepy", 76.11);
059        sneezy = new DwarfData(PROP_SNEEZY, 64, new int[] { 11, 22, 33, 44 }, 76.88, "/home/sneezy", happy.homePage.toString() + "/~sneezy", 69.7);
060        dwarfs = new DwarfsData();
061        dwarfNames = new String[] { bashful.name, doc.name, dopey.name, grumpy.name, happy.name, sleepy.name, sneezy.name };
062    }
063
064    @SuppressWarnings("empty-statement")
065    private DwarfsData()
066    {
067        ;
068    }
069
070    public Dwarf getBashful()
071    {
072        return bashful;
073    }
074
075    public Dwarf getDoc()
076    {
077        return doc;
078    }
079
080    public Dwarf getDopey()
081    {
082        return dopey;
083    }
084
085    public Dwarf getGrumpy()
086    {
087        return grumpy;
088    }
089
090    public Dwarf getHappy()
091    {
092        return happy;
093    }
094
095    public Dwarf getSleepy()
096    {
097        return sleepy;
098    }
099
100    public Dwarf getSneezy()
101    {
102        return sneezy;
103    }
104
105    public static class DwarfData implements Dwarf
106    {
107        private static final String READ_ONLY_INSTANCE = "Read only instance";
108        public final int age;
109        public final int[] fortuneNumber;
110        public final double height;
111        public final String homeDir;
112        public final URI homePage;
113        public final String name;
114        public final double weight;
115
116        public DwarfData(String name, int age, int[] fortuneNumber, double height, String homeDir, String homePage, double weight)
117        {
118            this.name = name;
119            this.age = age;
120            this.fortuneNumber = fortuneNumber;
121            this.height = height;
122            this.homeDir = homeDir;
123            this.homePage = URI.create(homePage);
124            this.weight = weight;
125        }
126
127        public int getAge()
128        {
129            return age;
130        }
131
132        public void setAge(int age)
133        {
134            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
135        }
136
137        public int[] getFortuneNumber()
138        {
139            return fortuneNumber;
140        }
141
142        public void setFortuneNumber(int[] value)
143        {
144            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
145        }
146
147        public double getHeight()
148        {
149            return height;
150        }
151
152        public void setHeight(double height) throws PropertyVetoException
153        {
154            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
155        }
156
157        public String getHomeDir()
158        {
159            return homeDir;
160        }
161
162        public void setHomeDir(String dir)
163        {
164            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
165        }
166
167        public URI getHomePage()
168        {
169            return homePage;
170        }
171
172        public void setHomePage(URI location)
173        {
174            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
175        }
176
177        public double getWeight()
178        {
179            return weight;
180        }
181
182        public void setWeight(double weight)
183        {
184            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
185        }
186
187        public void addPropertyChangeListener(String property, PropertyChangeListener listener)
188        {
189            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
190        }
191
192        public void addVetoableChangeListener(String property, VetoableChangeListener listener)
193        {
194            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
195        }
196
197        public boolean hasAge()
198        {
199            return age != 0;
200        }
201
202        public boolean hasHeight()
203        {
204            return height != 0.0;
205        }
206
207        public boolean hasHomePage()
208        {
209            return homePage != null;
210        }
211
212        public boolean hasWeight()
213        {
214            return weight != 0.0;
215        }
216
217        public void removePropertyChangeListener(String property, PropertyChangeListener listener)
218        {
219            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
220        }
221
222        public void removeVetoableChangeListener(String property, VetoableChangeListener listener)
223        {
224            throw new UnsupportedOperationException(READ_ONLY_INSTANCE);
225        }
226    }
227}