/
ExpressionResolver.java
57 lines (51 loc) · 2.35 KB
/
ExpressionResolver.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
/*
* Copyright (c) 2017-2018 Bosch Software Innovations GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/index.php
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.model.placeholders;
import java.util.Optional;
/**
* The ExpressionResolver is able to:
* <ul>
* <li>resolve {@link Placeholder}s in a passed {@code template} (based on {@link PlaceholderResolver}</li>
* <li>execute optional pipeline stages in a passed {@code template}</li>
* </ul>
* As a result, a resolved String is returned.
* For example, following expressions can be resolved:
* <ul>
* <li>{@code {{ thing:id }} }</li>
* <li>{@code {{ header:device_id }} }</li>
* <li>{@code {{ topic:full }} }</li>
* <li>{@code {{ thing:name | fn:substring-before(':') | fn:default(thing:name) }} }</li>
* <li>{@code {{ header:unknown | fn:default('fallback') }} }</li>
* </ul>
*/
public interface ExpressionResolver {
/**
* Resolves a complete expression template starting with a {@link Placeholder} followed by optional pipeline stages
* (e.g. functions).
*
* @param expressionTemplate the expressionTemplate to resolve {@link Placeholder}s and and execute optional
* pipeline stages
* @param allowUnresolved whether it should be allowed that unresolved placeholder may be present after processing
* @return the resolved String or the original {@code expressionTemplate} if {@code allowUnresolved} was set to
* {@code true} and placeholders could not be resolved.
* @throws org.eclipse.ditto.model.connectivity.UnresolvedPlaceholderException thrown if {@code allowUnresolved} was
* set to {@code false} and the passed in {@code expressionTemplate} could not be resolved
*/
String resolve(String expressionTemplate, boolean allowUnresolved);
/**
* Resolves a single {@link Placeholder} with the passed full {@code placeholder} name (e.g.: {@code thing:id} or
* {@code header:correlation-id}.
*
* @param placeholder the placeholder to resolve.
* @return the resolved placeholder if it could be resolved, empty Optional otherwise.
*/
Optional<String> resolveSinglePlaceholder(String placeholder);
}