1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.common.lib;
20
21 import java.util.HashSet;
22 import java.util.Set;
23 import org.apache.syncope.common.lib.types.ClientExceptionType;
24
25 public class SyncopeClientException extends RuntimeException {
26
27 private static final long serialVersionUID = 3380920886511913475L;
28
29 private ClientExceptionType type;
30
31 private final Set<String> elements = new HashSet<>();
32
33 public static SyncopeClientException build(final ClientExceptionType type) {
34 if (type == ClientExceptionType.Composite) {
35 throw new IllegalArgumentException("Composite exceptions must be obtained via buildComposite()");
36 }
37 return new SyncopeClientException(type);
38 }
39
40 public static SyncopeClientCompositeException buildComposite() {
41 return new SyncopeClientCompositeException();
42 }
43
44 protected SyncopeClientException(final ClientExceptionType type) {
45 super();
46 setType(type);
47 }
48
49 public boolean isComposite() {
50 return getType() == ClientExceptionType.Composite;
51 }
52
53 public SyncopeClientCompositeException asComposite() {
54 if (!isComposite()) {
55 throw new IllegalArgumentException("This is not a composite exception");
56 }
57
58 return (SyncopeClientCompositeException) this;
59 }
60
61 public ClientExceptionType getType() {
62 return type;
63 }
64
65 public final void setType(final ClientExceptionType type) {
66 this.type = type;
67 }
68
69 public Set<String> getElements() {
70 return elements;
71 }
72
73 public boolean isEmpty() {
74 return elements.isEmpty();
75 }
76
77 public int size() {
78 return elements.size();
79 }
80
81 @Override
82 public String getMessage() {
83 return new StringBuilder().
84 append(getType()).
85 append(' ').
86 append(getElements()).
87 toString();
88 }
89
90 @Override
91 public String getLocalizedMessage() {
92 return getMessage();
93 }
94 }