-
Notifications
You must be signed in to change notification settings - Fork 215
/
AbstractSecuritySchemeBuilder.java
96 lines (83 loc) · 3.35 KB
/
AbstractSecuritySchemeBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.wot.model;
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;
import javax.annotation.Nullable;
import org.eclipse.ditto.json.JsonObjectBuilder;
/**
* Abstract implementation of {@link org.eclipse.ditto.wot.model.SecurityScheme.Builder}.
*/
abstract class AbstractSecuritySchemeBuilder<B extends SecurityScheme.Builder<B, S>, S extends SecurityScheme>
extends AbstractTypedJsonObjectBuilder<B, S>
implements SecurityScheme.Builder<B, S> {
protected final String securitySchemeName;
protected AbstractSecuritySchemeBuilder(final String securitySchemeName,
final JsonObjectBuilder wrappedObjectBuilder,
final Class<?> selfType) {
super(wrappedObjectBuilder, selfType);
this.securitySchemeName = checkNotNull(securitySchemeName, "securitySchemeName");
setScheme(getSecuritySchemeScheme());
}
abstract SecuritySchemeScheme getSecuritySchemeScheme();
@Override
public B setAtType(@Nullable final AtType atType) {
if (atType != null) {
if (atType instanceof MultipleAtType) {
putValue(SecurityScheme.SecuritySchemeJsonFields.AT_TYPE_MULTIPLE, ((MultipleAtType) atType).toJson());
} else if (atType instanceof SingleAtType) {
putValue(SecurityScheme.SecuritySchemeJsonFields.AT_TYPE, atType.toString());
} else {
throw new IllegalArgumentException("Unsupported @type: " + atType.getClass().getSimpleName());
}
} else {
remove(SecurityScheme.SecuritySchemeJsonFields.AT_TYPE);
}
return myself;
}
@Override
public B setScheme(@Nullable final SecuritySchemeScheme scheme) {
if (scheme != null) {
putValue(SecurityScheme.SecuritySchemeJsonFields.SCHEME, scheme.toString());
} else {
remove(SecurityScheme.SecuritySchemeJsonFields.SCHEME);
}
return myself;
}
@Override
public B setDescription(@Nullable final Description description) {
if (description != null) {
putValue(SecurityScheme.SecuritySchemeJsonFields.DESCRIPTION, description.toString());
} else {
remove(SecurityScheme.SecuritySchemeJsonFields.DESCRIPTION);
}
return myself;
}
@Override
public B setDescriptions(@Nullable final Descriptions descriptions) {
if (descriptions != null) {
putValue(SecurityScheme.SecuritySchemeJsonFields.DESCRIPTIONS, descriptions.toJson());
} else {
remove(SecurityScheme.SecuritySchemeJsonFields.DESCRIPTIONS);
}
return myself;
}
@Override
public B setProxy(@Nullable final IRI proxy) {
if (proxy != null) {
putValue(SecurityScheme.SecuritySchemeJsonFields.PROXY, proxy.toString());
} else {
remove(SecurityScheme.SecuritySchemeJsonFields.PROXY);
}
return myself;
}
}