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  
21  /**
22   * Map of properties for a database object.
23   *
24   * @author James Ahlborn
25   * @usage _general_class_
26   */
27  public interface PropertyMap extends Iterable<PropertyMap.Property>
28  {
29    public static final String ACCESS_VERSION_PROP = "AccessVersion";
30    public static final String TITLE_PROP = "Title";
31    public static final String AUTHOR_PROP = "Author";
32    public static final String COMPANY_PROP = "Company";
33  
34    public static final String DEFAULT_VALUE_PROP = "DefaultValue";
35    public static final String REQUIRED_PROP = "Required";
36    public static final String ALLOW_ZERO_LEN_PROP = "AllowZeroLength";
37    public static final String DECIMAL_PLACES_PROP = "DecimalPlaces";
38    public static final String FORMAT_PROP = "Format";
39    public static final String INPUT_MASK_PROP = "InputMask";
40    public static final String CAPTION_PROP = "Caption";
41    public static final String VALIDATION_RULE_PROP = "ValidationRule";
42    public static final String VALIDATION_TEXT_PROP = "ValidationText";
43    public static final String GUID_PROP = "GUID";
44    public static final String DESCRIPTION_PROP = "Description";
45    public static final String RESULT_TYPE_PROP = "ResultType";
46    public static final String EXPRESSION_PROP = "Expression";
47    public static final String ALLOW_MULTI_VALUE_PROP = "AllowMultipleValues";
48    public static final String ROW_SOURCE_TYPE_PROP = "RowSourceType";
49    public static final String ROW_SOURCE_PROP = "RowSource";
50  
51  
52    public String getName();
53  
54    public int getSize();
55  
56    public boolean isEmpty();
57  
58    /**
59     * @return the property with the given name, if any
60     */
61    public Property get(String name);
62  
63    /**
64     * @return the value of the property with the given name, if any
65     */
66    public Object getValue(String name);
67  
68    /**
69     * @return the value of the property with the given name, if any, otherwise
70     *         the given defaultValue
71     */
72    public Object getValue(String name, Object defaultValue);
73  
74    /**
75     * Creates a new (or updates an existing) property in the map.  Attempts to
76     * determine the type of the property based on the name and value (the
77     * property names listed above have their types builtin, otherwise the type
78     * of the value is used).
79     * <p/>
80     * Note, this change will not be persisted until the {@link #save} method
81     * has been called.
82     *
83     * @return the newly created (or updated) property
84     * @throws IllegalArgumentException if the type of the property could not be
85     *                                  determined automatically
86     */
87    public Property put(String name, Object value);
88  
89    /**
90     * Creates a new (or updates an existing) property in the map.
91     * <p/>
92     * Note, this change will not be persisted until the {@link #save} method
93     * has been called.
94     *
95     * @return the newly created (or updated) property
96     */
97    public Property put(String name, DataType type, Object value);
98  
99    /**
100    * Puts all the given properties into this map.
101    *
102    * @param props the properties to put into this map ({@code null} is
103    *              tolerated and ignored).
104    */
105   public void putAll(Iterable<? extends Property> props);
106   
107   /**
108    * Removes the property with the given name
109    *
110    * @return the removed property, or {@code null} if none found
111    */
112   public Property remove(String name);
113 
114   /**
115    * Saves the current state of this map.
116    */
117   public void save() throws IOException;
118 
119   /**
120    * Info about a property defined in a PropertyMap.
121    */ 
122   public interface Property 
123   {
124     public String getName();
125 
126     public DataType getType();
127 
128     public Object getValue();
129 
130     /**
131      * Sets the new value for this property.
132      * <p/>
133      * Note, this change will not be persisted until the {@link
134      * PropertyMap#save} method has been called.
135      */
136     public void setValue(Object newValue);
137   }
138 }