/
ProtocolAdapterProvider.java
105 lines (88 loc) · 2.95 KB
/
ProtocolAdapterProvider.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
/*
* Copyright (c) 2017 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
*
* Contributors:
* Bosch Software Innovations GmbH - initial contribution
*/
package org.eclipse.ditto.services.utils.protocol;
import static java.util.Objects.requireNonNull;
import javax.annotation.Nullable;
import org.eclipse.ditto.model.base.headers.HeaderDefinition;
import org.eclipse.ditto.protocoladapter.HeaderTranslator;
import org.eclipse.ditto.protocoladapter.ProtocolAdapter;
import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault;
/**
* Interface for loading protocol adapter at runtime.
*/
public abstract class ProtocolAdapterProvider {
private final ProtocolConfigReader protocolConfigReader;
/**
* This constructor is the obligation of all subclasses of {@code ProtocolAdapterProvider}.
*
* @param protocolConfigReader the argument.
*/
public ProtocolAdapterProvider(final ProtocolConfigReader protocolConfigReader) {
this.protocolConfigReader = requireNonNull(protocolConfigReader);
}
/**
* Retrieve the protocol config reader given by creation of this object.
*
* @return the protocol config reader.
*/
protected ProtocolConfigReader protocolConfigReader() {
return protocolConfigReader;
}
/**
* Gets a protocol adapter which is appropriate for the client specified by the given {@code userAgent}.
*
* @param userAgent the user-agent header provided by the client
* @return the protocol adapter.
*/
public abstract ProtocolAdapter getProtocolAdapter(@Nullable final String userAgent);
/**
* Gets a header translator to filter incoming HTTP headers for the protocol adapter.
*
* @return the header translator.
*/
public abstract HeaderTranslator getHttpHeaderTranslator();
/**
* Header definition for headers ignored by Ditto.
*/
@AllValuesAreNonnullByDefault
protected static final class Ignored implements HeaderDefinition {
private final String key;
/**
* Create an ignored header.
*
* @param key the ignored header key.
*/
public Ignored(final String key) {
this.key = key;
}
@Override
public String getKey() {
return key;
}
@Override
public Class getJavaType() {
return Object.class;
}
@Override
public boolean shouldReadFromExternalHeaders() {
return false;
}
@Override
public boolean shouldWriteToExternalHeaders() {
return false;
}
@Override
public String toString() {
return getKey();
}
}
}