Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Bean2XmlOptions |
|
| 0.0;0 |
1 | // Copyright 2008-2014 severally by the contributors | |
2 | // | |
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 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package net.sf.practicalxml.converter.bean; | |
16 | ||
17 | ||
18 | /** | |
19 | * Options used by {@link Bean2XmlConverter} to control the structure of the | |
20 | * generated DOM tree. | |
21 | * | |
22 | * @since 1.1 | |
23 | */ | |
24 | 17 | public enum Bean2XmlOptions |
25 | { | |
26 | /** | |
27 | * Outputs byte arrays as a Base64-encoded string | |
28 | * | |
29 | * @since 1.1.18 | |
30 | */ | |
31 | 1 | BYTE_ARRAYS_AS_BASE64, |
32 | ||
33 | /** | |
34 | * Outputs byte arrays as a hex-encoded string | |
35 | * | |
36 | * @since 1.1.18 | |
37 | */ | |
38 | 1 | BYTE_ARRAYS_AS_HEX, |
39 | ||
40 | /** | |
41 | * Will use a shared static introspection cache for all conversions. | |
42 | * <p> | |
43 | * <strong>Warning</strong>: if you use this option, do not store this | |
44 | * library in a shared app-server classpath. If you do, the cache will | |
45 | * prevent class unloading, and you will run out of permgen space. | |
46 | */ | |
47 | 1 | CACHE_INTROSPECTIONS, |
48 | ||
49 | /** | |
50 | * Defer exception processing. When an exception occurs during conversion, | |
51 | * the node causing that exception is skipped and the exception is added | |
52 | * to a list. The caller can then examine that list and take appropriate | |
53 | * action. | |
54 | * <p> | |
55 | * Note: all deferred exceptions will be of type | |
56 | * {@link net.sf.practicalxml.converter.ConversionException}, and will wrap | |
57 | * an underlying cause. Because the converter works by reflection, in many | |
58 | * cases this cause will be an <code>InvocationTargetException</code> with | |
59 | * its own cause. | |
60 | * | |
61 | * @since 1.1.15 | |
62 | */ | |
63 | 1 | DEFER_EXCEPTIONS, |
64 | ||
65 | ||
66 | /** | |
67 | * Output enum instances with an attribute containing the enum's name, and | |
68 | * the text value containing the enum's <code>toString()</code>. Default is | |
69 | * to output the enum's name as the element value. | |
70 | * <p> | |
71 | * This option is useful when the enum contains descriptive text, and you | |
72 | * want to use that text in further output. | |
73 | * | |
74 | * @since 1.1.17 | |
75 | */ | |
76 | 1 | ENUM_AS_NAME_AND_VALUE, |
77 | ||
78 | /** | |
79 | * Output maps in an "introspected" format, where the name of each item | |
80 | * is the map key (rather than "data"), and the "key" attribute is omitted. | |
81 | * If any key is not a valid XML identifier, the converter will throw. | |
82 | */ | |
83 | 1 | MAP_KEYS_AS_ELEMENT_NAME, |
84 | ||
85 | /** | |
86 | * If the value is <code>null</code>, add an element containing a single | |
87 | * text child holding an empty string. | |
88 | * <p> | |
89 | * This may make life easier when processing data from a certain DBMS | |
90 | * designed in the mid-1980s when disk space was too expensive to create | |
91 | * a separate null flag for VARCHAR fields. However, be aware that it | |
92 | * may cause parsing problems. | |
93 | */ | |
94 | 1 | NULL_AS_EMPTY, |
95 | ||
96 | /** | |
97 | * If the value is <code>null</code>, add an element without content, with | |
98 | * the attribute <code>xsi:nil</code> set to "true". | |
99 | */ | |
100 | 1 | NULL_AS_XSI_NIL, |
101 | ||
102 | /** | |
103 | * Will create sequences (arrays, lists, and sets) as repeated elements | |
104 | * rather than a parent-children construct. This option is invalid when | |
105 | * converting an array as the top-level object, as it would cause the | |
106 | * creation of multiple root elements. It also produces output that can | |
107 | * not, at this time, be processed correctly by {@link Xml2BeanConverter}. | |
108 | */ | |
109 | 1 | SEQUENCE_AS_REPEATED_ELEMENTS, |
110 | ||
111 | /** | |
112 | * When introspecting, call <code>setAccessible(true)</code> on accessor | |
113 | * methods. This allows use with instances of private classes that have | |
114 | * public methods, but will cause an exception in any environment that has | |
115 | * a security manager that denies this operation. | |
116 | * | |
117 | * @since 1.1.15 | |
118 | */ | |
119 | 1 | SET_ACCESSIBLE, |
120 | ||
121 | /** | |
122 | * Omits circular references from the output. By default, the converter | |
123 | * will throw if it discovers a circular reference. When this option is | |
124 | * in effect, it simply skips over the reference. This is useful when | |
125 | * converting objects managed by an ORM, where you normally don't care | |
126 | * about backlinks. | |
127 | * | |
128 | * @since 1.1.14 | |
129 | */ | |
130 | 1 | SKIP_CIRCULAR_REFERENCES, |
131 | ||
132 | /** | |
133 | * Sequences (arrays, lists, sets) will name their elements according to | |
134 | * the parent element, with any trailing "s" removed. For example, if the | |
135 | * parent is named "products", each child will be named "product", rather | |
136 | * than the default "data". If the parent is named "foo", each child will | |
137 | * also be named "foo" (since there's no "s" to remove). | |
138 | */ | |
139 | 1 | SEQUENCE_NAMED_BY_PARENT, |
140 | ||
141 | /** | |
142 | * Will add an <code>index</code> attribute to the child elements of | |
143 | * sequences (arrays, lists, sets); the value of this attribute is the | |
144 | * element's position in the sequence (numbered from 0). This index is | |
145 | * not terribly useful, so is no longer default behavior. | |
146 | */ | |
147 | 1 | USE_INDEX_ATTR, |
148 | ||
149 | /** | |
150 | * Will add a <code>type</code> attribute to each element; see package | |
151 | * docs for more details. | |
152 | * <p> | |
153 | * <em>This option implies {@link #XSD_FORMAT}</em>. | |
154 | */ | |
155 | 1 | USE_TYPE_ATTR, |
156 | ||
157 | /** | |
158 | * Outputs values using formats defined by XML Schema, rather than Java's | |
159 | * <code>String.valueOf()</code> method. Note that these formats are not | |
160 | * flagged in the element, so sender and receiver will have to agree on | |
161 | * the format. | |
162 | */ | |
163 | 1 | XSD_FORMAT |
164 | } |