2
* Copyright 2005-2012 Restlet S.A.S.
4
* The contents of this file are subject to the terms of one of the following
5
* open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
6
* 1.0 (the "Licenses"). You can select the license that you prefer but you may
7
* not use this file except in compliance with one of these Licenses.
9
* You can obtain a copy of the Apache 2.0 license at
10
* http://www.opensource.org/licenses/apache-2.0
12
* You can obtain a copy of the LGPL 3.0 license at
13
* http://www.opensource.org/licenses/lgpl-3.0
15
* You can obtain a copy of the LGPL 2.1 license at
16
* http://www.opensource.org/licenses/lgpl-2.1
18
* You can obtain a copy of the CDDL 1.0 license at
19
* http://www.opensource.org/licenses/cddl1
21
* You can obtain a copy of the EPL 1.0 license at
22
* http://www.opensource.org/licenses/eclipse-1.0
24
* See the Licenses for the specific language governing permissions and
25
* limitations under the Licenses.
27
* Alternatively, you can obtain a royalty free commercial license with less
28
* limitations, transferable or non-transferable, directly at
29
* http://www.restlet.com/products/restlet-framework
31
* Restlet is a registered trademark of Restlet S.A.S.
34
package org.restlet.ext.jaxrs.internal.spi;
36
import java.util.List;
38
import javax.ws.rs.core.CacheControl;
39
import javax.ws.rs.ext.RuntimeDelegate;
40
import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
42
import org.restlet.data.CacheDirective;
43
import org.restlet.engine.http.header.CacheDirectiveReader;
44
import org.restlet.engine.http.header.CacheDirectiveWriter;
45
import org.restlet.ext.jaxrs.internal.util.Converter;
48
* {@link HeaderDelegate} for {@link CacheControl}.
50
* @author Stephan Koops
52
public class CacheControlHeaderDelegate implements HeaderDelegate<CacheControl> {
55
* Obtain an instance of a HeaderDelegate for the CacheControl class.
57
* @see RuntimeDelegate#createHeaderDelegate(Class)
59
CacheControlHeaderDelegate() {
63
* Parse the supplied value and create an instance of <code>T</code>.
67
* @return the newly created instance of <code>T</code>
68
* @throws IllegalArgumentException
69
* if the supplied string cannot be parsed
70
* @see javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate#fromString(java.lang.String)
72
public CacheControl fromString(String value)
73
throws IllegalArgumentException {
74
CacheDirectiveReader ccr = new CacheDirectiveReader(value);
75
List<CacheDirective> cacheDirectives = ccr.readValues();
76
return Converter.toJaxRsCacheControl(cacheDirectives);
80
* Convert the supplied value to a String.
83
* the value of type <code>T</code>
84
* @return a String representation of the value
85
* @throws IllegalArgumentException
86
* if the supplied object cannot be serialized
87
* @see javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate#toString(java.lang.Object)
89
public String toString(CacheControl cacheControl) {
90
List<CacheDirective> directives = Converter
91
.toRestletCacheDirective(cacheControl);
92
return CacheDirectiveWriter.write(directives);