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    * Creates a new (or updates an existing) property in the map.
101    * <p/>
102    * Note, this change will not be persisted until the {@link #save} method
103    * has been called.
104    *
105    * @return the newly created (or updated) property
106    */
107   public Property put(String name, DataType type, Object value, boolean isDdl);
108 
109   /**
110    * Puts all the given properties into this map.
111    *
112    * @param props the properties to put into this map ({@code null} is
113    *              tolerated and ignored).
114    */
115   public void putAll(Iterable<? extends Property> props);
116   
117   /**
118    * Removes the property with the given name
119    *
120    * @return the removed property, or {@code null} if none found
121    */
122   public Property remove(String name);
123 
124   /**
125    * Saves the current state of this map.
126    */
127   public void save() throws IOException;
128 
129   /**
130    * Info about a property defined in a PropertyMap.
131    */ 
132   public interface Property 
133   {
134     public String getName();
135 
136     public DataType getType();
137 
138     /**
139      * Whether or not this property is a DDL object.  If {@code true}, users
140      * can't change or delete the property in access without the dbSecWriteDef
141      * permission.  Additionally, certain properties must be flagged correctly
142      * or the access engine may not recognize them correctly.
143      */
144     public boolean isDdl();
145 
146     public Object getValue();
147 
148     /**
149      * Sets the new value for this property.
150      * <p/>
151      * Note, this change will not be persisted until the {@link
152      * PropertyMap#save} method has been called.
153      */
154     public void setValue(Object newValue);
155   }
156 }