View Javadoc
1   /*
2   Copyright (c) 2013 James Ahlborn
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  
17  package com.healthmarketscience.jackcess;
18  
19  import java.io.IOException;
20  import java.util.stream.Stream;
21  import java.util.stream.StreamSupport;
22  
23  /**
24   * Map of properties for a database object.
25   *
26   * @author James Ahlborn
27   * @usage _general_class_
28   */
29  public interface PropertyMap extends Iterable<PropertyMap.Property>
30  {
31    public static final String ACCESS_VERSION_PROP = "AccessVersion";
32    public static final String TITLE_PROP = "Title";
33    public static final String AUTHOR_PROP = "Author";
34    public static final String COMPANY_PROP = "Company";
35  
36    public static final String DEFAULT_VALUE_PROP = "DefaultValue";
37    public static final String REQUIRED_PROP = "Required";
38    public static final String ALLOW_ZERO_LEN_PROP = "AllowZeroLength";
39    public static final String DECIMAL_PLACES_PROP = "DecimalPlaces";
40    public static final String FORMAT_PROP = "Format";
41    public static final String INPUT_MASK_PROP = "InputMask";
42    public static final String CAPTION_PROP = "Caption";
43    public static final String VALIDATION_RULE_PROP = "ValidationRule";
44    public static final String VALIDATION_TEXT_PROP = "ValidationText";
45    public static final String GUID_PROP = "GUID";
46    public static final String DESCRIPTION_PROP = "Description";
47    public static final String RESULT_TYPE_PROP = "ResultType";
48    public static final String EXPRESSION_PROP = "Expression";
49    public static final String ALLOW_MULTI_VALUE_PROP = "AllowMultipleValues";
50    public static final String ROW_SOURCE_TYPE_PROP = "RowSourceType";
51    public static final String ROW_SOURCE_PROP = "RowSource";
52    public static final String DISPLAY_CONTROL_PROP = "DisplayControl";
53    public static final String TEXT_FORMAT_PROP = "TextFormat";
54    public static final String IME_MODE_PROP = "IMEMode";
55    public static final String IME_SENTENCE_MODE_PROP = "IMESentenceMode";
56  
57  
58    public String getName();
59  
60    public int getSize();
61  
62    public boolean isEmpty();
63  
64    /**
65     * @return the property with the given name, if any
66     */
67    public Property get(String name);
68  
69    /**
70     * @return the value of the property with the given name, if any
71     */
72    public Object getValue(String name);
73  
74    /**
75     * @return the value of the property with the given name, if any, otherwise
76     *         the given defaultValue
77     */
78    public Object getValue(String name, Object defaultValue);
79  
80    /**
81     * Creates a new (or updates an existing) property in the map.  Attempts to
82     * determine the type of the property based on the name and value (the
83     * property names listed above have their types builtin, otherwise the type
84     * of the value is used).
85     * <p>
86     * Note, this change will not be persisted until the {@link #save} method
87     * has been called.
88     *
89     * @return the newly created (or updated) property
90     * @throws IllegalArgumentException if the type of the property could not be
91     *                                  determined automatically
92     */
93    public Property put(String name, Object value);
94  
95    /**
96     * Creates a new (or updates an existing) property in the map.
97     * <p>
98     * Note, this change will not be persisted until the {@link #save} method
99     * has been called.
100    *
101    * @return the newly created (or updated) property
102    */
103   public Property put(String name, DataType type, Object value);
104 
105   /**
106    * Creates a new (or updates an existing) property in the map.
107    * <p>
108    * Note, this change will not be persisted until the {@link #save} method
109    * has been called.
110    *
111    * @return the newly created (or updated) property
112    */
113   public Property put(String name, DataType type, Object value, boolean isDdl);
114 
115   /**
116    * Puts all the given properties into this map.
117    *
118    * @param props the properties to put into this map ({@code null} is
119    *              tolerated and ignored).
120    */
121   public void putAll(Iterable<? extends Property> props);
122 
123   /**
124    * Removes the property with the given name
125    *
126    * @return the removed property, or {@code null} if none found
127    */
128   public Property remove(String name);
129 
130   /**
131    * Saves the current state of this map.
132    */
133   public void save() throws IOException;
134 
135   /**
136    * @return a Stream using the default Iterator.
137    */
138   default public Stream<PropertyMap.Property> stream() {
139     return StreamSupport.stream(spliterator(), false);
140   }
141 
142   /**
143    * Info about a property defined in a PropertyMap.
144    */
145   public interface Property
146   {
147     public String getName();
148 
149     public DataType getType();
150 
151     /**
152      * Whether or not this property is a DDL object.  If {@code true}, users
153      * can't change or delete the property in access without the dbSecWriteDef
154      * permission.  Additionally, certain properties must be flagged correctly
155      * or the access engine may not recognize them correctly.
156      */
157     public boolean isDdl();
158 
159     public Object getValue();
160 
161     /**
162      * Sets the new value for this property.
163      * <p>
164      * Note, this change will not be persisted until the {@link
165      * PropertyMap#save} method has been called.
166      */
167     public void setValue(Object newValue);
168   }
169 
170   /**
171    * Interface for enums which can be used as property values.
172    */
173   public interface EnumValue
174   {
175     /**
176      * @return the property value which should be stored in the db
177      */
178     public Object getValue();
179   }
180 
181   /**
182    * Enum value constants for the DisplayControl property
183    */
184   public enum DisplayControl implements EnumValue
185   {
186     BOUND_OBJECT_FRAME(108),
187     CHECK_BOX(106),
188     COMBO_BOX(111),
189     COMMAND_BUTTON(104),
190     CUSTOM_CONTROL(119),
191     EMPTY_CELL(127),
192     IMAGE(103),
193     LABEL(100),
194     LINE(102),
195     LIST_BOX(110),
196     NAVIGATION_BUTTON(130),
197     NAVIGATION_CONTROL(129),
198     OBJECT_FRAME(114),
199     OPTION_BUTTON(105),
200     OPTION_GROUP(107),
201     PAGE(124),
202     PAGE_BREAK(118),
203     RECTANGLE(101),
204     SUB_FORM(112),
205     TAB_CTL(123),
206     TEXT_BOX(109),
207     TOGGLE_BUTTON(122),
208     WEB_BROWSER(128);
209 
210     private final Short _value;
211 
212     private DisplayControl(int value) {
213       _value = (short)value;
214     }
215 
216     @Override
217     public Short getValue() {
218       return _value;
219     }
220 
221     @Override
222     public String toString() {
223       return name() + "[" + _value + "]";
224     }
225   }
226 
227   /**
228    * Enum value constants for the TextFormat property
229    */
230   public enum TextFormat implements EnumValue
231   {
232     HTMLRICHTEXT(1),
233     PLAIN(0);
234 
235     private final Byte _value;
236 
237     private TextFormat(int value) {
238       _value = (byte)value;
239     }
240 
241     @Override
242     public Byte getValue() {
243       return _value;
244     }
245 
246     @Override
247     public String toString() {
248       return name() + "[" + _value + "]";
249     }
250   }
251 
252   /**
253    * Enum value constants for the IMEMode property
254    */
255   public enum IMEMode implements EnumValue
256   {
257     NOCONTROL(0),
258     ON(1),
259     OFF(2),
260     DISABLE(3),
261     HIRAGANA(4),
262     KATAKANA(5),
263     KATAKANAHALF(6),
264     ALPHAFULL(7),
265     ALPHA(8),
266     HANGULFULL(9),
267     HANGUL(10);
268 
269     private final Byte _value;
270 
271     private IMEMode(int value) {
272       _value = (byte)value;
273     }
274 
275     @Override
276     public Byte getValue() {
277       return _value;
278     }
279 
280     @Override
281     public String toString() {
282       return name() + "[" + _value + "]";
283     }
284   }
285 
286   /**
287    * Enum value constants for the IMESentenceMode property
288    */
289   public enum IMESentenceMode implements EnumValue
290   {
291     NORMAL(0),
292     PLURAL(1),
293     SPEAKING(2),
294     NONE(3);
295 
296     private final Byte _value;
297 
298     private IMESentenceMode(int value) {
299       _value = (byte)value;
300     }
301 
302     @Override
303     public Byte getValue() {
304       return _value;
305     }
306 
307     @Override
308     public String toString() {
309       return name() + "[" + _value + "]";
310     }
311   }
312 
313 }