You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PropertyMap.java 8.0KB

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