/
JavaScriptMessageMapperConfiguration.java
127 lines (113 loc) · 4.38 KB
/
JavaScriptMessageMapperConfiguration.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright (c) 2017 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.services.connectivity.mapping.javascript;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
import org.eclipse.ditto.services.connectivity.mapping.MessageMapperConfiguration;
/**
* Configuration properties for JavaScript MassageMapper.
*/
public interface JavaScriptMessageMapperConfiguration extends MessageMapperConfiguration {
/**
* @return the mappingScript responsible for mapping incoming messages.
*/
default Optional<String> getIncomingScript() {
return findProperty(JavaScriptMessageMapperConfigurationProperties.INCOMING_SCRIPT);
}
/**
* @return the mappingScript responsible for mapping outgoing messages.
*/
default Optional<String> getOutgoingScript() {
return findProperty(JavaScriptMessageMapperConfigurationProperties.OUTGOING_SCRIPT);
}
/**
* @return whether to load "bytebuffer.js" library.
*/
default boolean isLoadBytebufferJS() {
final Map<String, String> properties = getProperties();
@Nullable final String v = properties.get(JavaScriptMessageMapperConfigurationProperties.LOAD_BYTEBUFFER_JS);
if (null != v) {
return Boolean.parseBoolean(v);
}
return false;
}
/**
* @return whether to load "long.js" library.
*/
default boolean isLoadLongJS() {
final Map<String, String> properties = getProperties();
@Nullable final String v = properties.get(JavaScriptMessageMapperConfigurationProperties.LOAD_LONG_JS);
if (null != v) {
return Boolean.parseBoolean(v);
}
return false;
}
/**
* Specific builder for {@link JavaScriptMessageMapperConfiguration}.
*/
interface Builder extends MessageMapperConfiguration.Builder<JavaScriptMessageMapperConfiguration> {
/**
* Configures the mappingScript responsible for mapping incoming messages.
*
* @param mappingScript the incoming mapping script.
* @return this builder for chaining.
*/
default Builder incomingScript(@Nullable final String mappingScript) {
if (mappingScript != null) {
getProperties().put(JavaScriptMessageMapperConfigurationProperties.INCOMING_SCRIPT,
mappingScript);
} else {
getProperties().remove(JavaScriptMessageMapperConfigurationProperties.INCOMING_SCRIPT);
}
return this;
}
/**
* Configures the mappingScript responsible for mapping outgoing messages.
*
* @param mappingScript the outgoing mapping script.
* @return this builder for chaining.
*/
default Builder outgoingScript(@Nullable final String mappingScript) {
if (mappingScript != null) {
getProperties().put(JavaScriptMessageMapperConfigurationProperties.OUTGOING_SCRIPT,
mappingScript);
} else {
getProperties().remove(JavaScriptMessageMapperConfigurationProperties.OUTGOING_SCRIPT);
}
return this;
}
/**
* Configures whether to load "bytebuffer.js" library.
*
* @param load whether to load "bytebuffer.js" library.
* @return this builder for chaining.
*/
default Builder loadBytebufferJS(final boolean load) {
getProperties().put(JavaScriptMessageMapperConfigurationProperties.LOAD_BYTEBUFFER_JS,
Boolean.toString(load));
return this;
}
/**
* Configures whether to load "long.js" library.
*
* @param load whether to load "long.js" library.
* @return this builder for chaining.
*/
default Builder loadLongJS(final boolean load) {
getProperties().put(JavaScriptMessageMapperConfigurationProperties.LOAD_LONG_JS,
Boolean.toString(load));
return this;
}
}
}