Add local MultivaluedHashMap implementation
[netconf.git] / restconf / restconf-common / src / main / java / org / opendaylight / restconf / common / util / SimpleUriInfo.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.common.util;
9
10 import java.net.URI;
11 import java.util.Collections;
12 import java.util.List;
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 public class SimpleUriInfo implements UriInfo {
24     private final String path;
25     private final MultivaluedMap<String, String> queryParams;
26
27     public SimpleUriInfo(String path) {
28         this(path, new MultivaluedHashMap<>());
29     }
30
31     public SimpleUriInfo(String path, MultivaluedMap<String, String> queryParams) {
32         this.path = path;
33         this.queryParams = queryParams;
34     }
35
36     @Override
37     public String getPath() {
38         return path;
39     }
40
41     @Override
42     public String getPath(boolean decode) {
43         return path;
44     }
45
46     @Override
47     public List<PathSegment> getPathSegments() {
48         throw new UnsupportedOperationException();
49     }
50
51     @Override
52     public List<PathSegment> getPathSegments(boolean decode) {
53         throw new UnsupportedOperationException();
54     }
55
56     @Override
57     public URI getRequestUri() {
58         return URI.create(path);
59     }
60
61     @Override
62     public UriBuilder getRequestUriBuilder() {
63         return UriBuilder.fromUri(getRequestUri());
64     }
65
66     @Override
67     public URI getAbsolutePath() {
68         return getRequestUri();
69     }
70
71     @Override
72     public UriBuilder getAbsolutePathBuilder() {
73         return UriBuilder.fromUri(getAbsolutePath());
74     }
75
76     @Override
77     public URI getBaseUri() {
78         return URI.create("");
79     }
80
81     @Override
82     public UriBuilder getBaseUriBuilder() {
83         return UriBuilder.fromUri(getBaseUri());
84     }
85
86     @Override
87     public MultivaluedMap<String, String> getPathParameters() {
88         return new MultivaluedHashMap<>();
89     }
90
91     @Override
92     public MultivaluedMap<String, String> getPathParameters(boolean decode) {
93         return getPathParameters();
94     }
95
96     @Override
97     public MultivaluedMap<String, String> getQueryParameters() {
98         return queryParams;
99     }
100
101     @Override
102     public MultivaluedMap<String, String> getQueryParameters(boolean decode) {
103         return getQueryParameters();
104     }
105
106     @Override
107     public List<String> getMatchedURIs() {
108         return Collections.emptyList();
109     }
110
111     @Override
112     public List<String> getMatchedURIs(boolean decode) {
113         return getMatchedURIs();
114     }
115
116     @Override
117     public List<Object> getMatchedResources() {
118         return Collections.emptyList();
119     }
120
121     @Override
122     public URI resolve(URI uri) {
123         return uri;
124     }
125
126     @Override
127     public URI relativize(URI uri) {
128         return uri;
129     }
130 }