Move SimpleUriInfo
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / LocalUriInfo.java
1 /*
2  * Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
9
10 import java.net.URI;
11 import java.util.List;
12 import javax.ws.rs.core.MultivaluedHashMap;
13 import javax.ws.rs.core.MultivaluedMap;
14 import javax.ws.rs.core.PathSegment;
15 import javax.ws.rs.core.UriBuilder;
16 import javax.ws.rs.core.UriInfo;
17
18 /**
19  * Simple implementation of the {@link UriInfo} interface.
20  *
21  * @author Thomas Pantelis
22  */
23 final class LocalUriInfo implements UriInfo {
24     private final MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
25     private final String path;
26
27     LocalUriInfo() {
28         path = "/";
29     }
30
31     @Override
32     public String getPath() {
33         return path;
34     }
35
36     @Override
37     public String getPath(final boolean decode) {
38         return path;
39     }
40
41     @Override
42     public List<PathSegment> getPathSegments() {
43         throw new UnsupportedOperationException();
44     }
45
46     @Override
47     public List<PathSegment> getPathSegments(final boolean decode) {
48         throw new UnsupportedOperationException();
49     }
50
51     @Override
52     public URI getRequestUri() {
53         return URI.create(path);
54     }
55
56     @Override
57     public UriBuilder getRequestUriBuilder() {
58         return UriBuilder.fromUri(getRequestUri());
59     }
60
61     @Override
62     public URI getAbsolutePath() {
63         return getRequestUri();
64     }
65
66     @Override
67     public UriBuilder getAbsolutePathBuilder() {
68         return UriBuilder.fromUri(getAbsolutePath());
69     }
70
71     @Override
72     public URI getBaseUri() {
73         return UriBuilder.fromUri("http://localhost:8181").build();
74     }
75
76     @Override
77     public UriBuilder getBaseUriBuilder() {
78         return UriBuilder.fromUri(getBaseUri());
79     }
80
81     @Override
82     public MultivaluedMap<String, String> getPathParameters() {
83         return new MultivaluedHashMap<>();
84     }
85
86     @Override
87     public MultivaluedMap<String, String> getPathParameters(final boolean decode) {
88         return getPathParameters();
89     }
90
91     @Override
92     public MultivaluedMap<String, String> getQueryParameters() {
93         return queryParams;
94     }
95
96     @Override
97     public MultivaluedMap<String, String> getQueryParameters(final boolean decode) {
98         return getQueryParameters();
99     }
100
101     @Override
102     public List<String> getMatchedURIs() {
103         return List.of();
104     }
105
106     @Override
107     public List<String> getMatchedURIs(final boolean decode) {
108         return getMatchedURIs();
109     }
110
111     @Override
112     public List<Object> getMatchedResources() {
113         return List.of();
114     }
115
116     @Override
117     public URI resolve(final URI uri) {
118         return uri;
119     }
120
121     @Override
122     public URI relativize(final URI uri) {
123         return uri;
124     }
125 }