New SAVE_TO option
[jvcard.git] / src / be / nikiroo / jvcard / launcher / CardResult.java
... / ...
CommitLineData
1package be.nikiroo.jvcard.launcher;
2
3import java.io.IOException;
4
5import be.nikiroo.jvcard.Card;
6
7/**
8 * This class is a placeholder for a {@link Card} result and some information
9 * about it.
10 *
11 * @author niki
12 *
13 */
14public class CardResult {
15 /**
16 * This interface represents the merge callback when the {@link Card}
17 * synchronisation is not able to process fully automatically.
18 *
19 * @author niki
20 *
21 */
22 public interface MergeCallback {
23 /**
24 * This method will be called when the local cache and the server both
25 * have changes. You need to review the proposed changes, or do your own
26 * merge, and return the final result. You can also cancel the merge
27 * operation by returning NULL.
28 *
29 * @param previous
30 * the previous version of the {@link Card}
31 * @param local
32 * the local cache version of the {@link Card}
33 * @param server
34 * the remote server version of the {@link Card}
35 * @param autoMerged
36 * the automatic merge result you should manually check
37 *
38 * @return the final merged result, or NULL for cancel
39 */
40 public Card merge(Card previous, Card local, Card server,
41 Card autoMerged);
42 }
43
44 private Card card;
45 private boolean remote;
46 private boolean synced;
47 private boolean changed;
48 private IOException exception;
49
50 /**
51 * Create a new {@link CardResult}.
52 *
53 * @param card
54 * the target {@link Card}
55 * @param remtote
56 * TRUE if it is linked to a remote server
57 * @param synced
58 * TRUE if it was synchronised
59 */
60 public CardResult(Card card, boolean remote, boolean synced, boolean changed) {
61 this.card = card;
62 this.remote = remote;
63 this.synced = synced;
64 this.changed = changed;
65 }
66
67 /**
68 * Create a new {@link CardResult}.
69 *
70 * @param exception
71 * the synchronisation exception that occurred
72 */
73 public CardResult(IOException exception) {
74 this(null, true, false, false);
75 this.exception = exception;
76 }
77
78 /**
79 * Check if this {@link Card} is linked to a remote jVCard server.
80 *
81 * @return TRUE if it is
82 */
83 public boolean isRemote() {
84 return remote;
85 }
86
87 /**
88 * Check if the {@link Card} was synchronised.
89 *
90 * @return TRUE if it was
91 */
92 public boolean isSynchronised() {
93 return synced;
94 }
95
96 /**
97 * Check if this {@link Card} changed after the synchronisation.
98 *
99 * @return TRUE if it has
100 */
101 public boolean isChanged() {
102 return remote && changed;
103 }
104
105 /**
106 * Return the {@link Card}
107 *
108 * @return the {@link Card}
109 *
110 * @throws IOException
111 * in case of synchronisation issues
112 */
113 public Card getCard() throws IOException {
114 if (exception != null)
115 throw exception;
116
117 return card;
118 }
119}