Debian Codegraph @

src/main/java/ezvcard/io/EmbeddedVCardException.java

raw symbols SCIP
1 package ezvcard.io;
2
3 import ezvcard.VCard;
4 import ezvcard.property.VCardProperty;
5
6 /*
7 Copyright (c) 2012-2023, Michael Angstadt
8 All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12
13 1. Redistributions of source code must retain the above copyright notice, this
14 list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 The views and conclusions contained in the software and documentation are those
31 of the authors and should not be interpreted as representing official policies,
32 either expressed or implied, of the FreeBSD Project.
33 */
34
35 /**
36 * Thrown during the marshalling/unmarshalling of a property to signal to the
37 * marshaller that the property's value is a nested (2.1 style) or embedded (3.0
38 * style) vCard.
39 * @author Michael Angstadt
40 */
41 @SuppressWarnings("serial")
42 public class EmbeddedVCardException extends RuntimeException {
43 /*
44 * Serialization note: Not going to bother adding a serialVersionUID, since
45 * VCard is not serializable.
46 */
47 private final VCard vcard;
48 private final InjectionCallback callback;
49
50 /**
51 * Thrown to unmarshal a nested or embedded vCard.
52 * @param callback injects the unmarshalled vCard into the property object
53 */
54 public EmbeddedVCardException(InjectionCallback callback) {
55 this.callback = callback;
56 this.vcard = null;
57 }
58
59 /**
60 * Thrown to marshal a nested or embedded vCard.
61 * @param vcard the vCard to marshal
62 */
63 public EmbeddedVCardException(VCard vcard) {
64 this.callback = null;
65 this.vcard = vcard;
66 }
67
68 /**
69 * Gets the vCard to marshal.
70 * @return the vCard to marshal
71 */
72 public VCard getVCard() {
73 return vcard;
74 }
75
76 /**
77 * Injects the unmarshalled vCard into the property object that threw this
78 * exception.
79 * @param vcard the vCard to inject
80 */
81 public void injectVCard(VCard vcard) {
82 if (callback == null) {
83 return;
84 }
85
86 callback.injectVCard(vcard);
87 }
88
89 /**
90 * Gets the property object that threw the exception.
91 * @return the property object
92 */
93 public VCardProperty getProperty() {
94 if (callback == null) {
95 return null;
96 }
97
98 return callback.getProperty();
99 }
100
101 /**
102 * Injects an unmarshalled vCard into the property object.
103 */
104 public interface InjectionCallback {
105 /**
106 * Injects an unmarshalled vCard into the property object.
107 * @param vcard the vCard to inject
108 */
109 void injectVCard(VCard vcard);
110
111 /**
112 * Gets the property object that threw the
113 * {@link EmbeddedVCardException}.
114 * @return the property object
115 */
116 VCardProperty getProperty();
117 }
118 }