org.glassfish.jersey.message.internal
Class HeadersFactory

java.lang.Object
  extended by org.glassfish.jersey.message.internal.HeadersFactory

public final class HeadersFactory
extends Object

Utility class supporting the processing of message headers.

Author:
Marek Potociar (marek.potociar at oracle.com), Michal Gajdos (michal.gajdos at oracle.com)

Method Summary
static String asHeaderString(List<Object> values, RuntimeDelegate rd)
          Converts a list of message header values to a single string value (with individual values separated by ',').
static String asString(Object headerValue, RuntimeDelegate rd)
          Convert a message header value, represented as a general object, to it's string representation.
static MultivaluedMap<String,String> asStringHeaders(MultivaluedMap<String,Object> headers)
          Returns string view of passed headers.
static List<String> asStringList(List<Object> headerValues, RuntimeDelegate rd)
          Returns string view of list of header values.
static AbstractMultivaluedMap<String,String> createInbound()
          Create an empty inbound message headers container.
static AbstractMultivaluedMap<String,Object> createOutbound()
          Create an empty outbound message headers container.
static
<V> MultivaluedMap<String,V>
empty()
          Get immutable empty message headers container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createInbound

public static AbstractMultivaluedMap<String,String> createInbound()
Create an empty inbound message headers container. Created container is mutable.

Returns:
a new empty mutable container for storing inbound message headers.

empty

public static <V> MultivaluedMap<String,V> empty()
Get immutable empty message headers container. The factory method can be used to for both message header container types  –  inbound as well as outbound.

Type Parameters:
V - header value type. Typically Object in case of the outbound headers and String in case of the inbound headers.
Returns:
an immutable empty message headers container.

createOutbound

public static AbstractMultivaluedMap<String,Object> createOutbound()
Create an empty outbound message headers container. Created container is mutable.

Returns:
a new empty mutable container for storing outbound message headers.

asString

public static String asString(Object headerValue,
                              RuntimeDelegate rd)
Convert a message header value, represented as a general object, to it's string representation. If the supplied header value is null, this method returns null.

This method defers to RuntimeDelegate.createHeaderDelegate(java.lang.Class) to obtain a RuntimeDelegate.HeaderDelegate to convert the value to a String. If a RuntimeDelegate.HeaderDelegate is not found then the toString() method on the header object is utilized.

Parameters:
headerValue - the header value represented as an object.
rd - runtime delegate instance to be used for header delegate retrieval. If null, a default RuntimeDelegate instance will be obtained and used.
Returns:
the string representation of the supplied header value or null if the supplied header value is null.

asStringList

public static List<String> asStringList(List<Object> headerValues,
                                        RuntimeDelegate rd)
Returns string view of list of header values. Any modifications to the underlying list are visible to the view, the view also supports removal of elements. Does not support other modifications.

Parameters:
headerValues - header values.
rd - RuntimeDelegate instance or null (in that case RuntimeDelegate.getInstance() will be called for before element conversion.
Returns:
String view of header values.

asStringHeaders

public static MultivaluedMap<String,String> asStringHeaders(MultivaluedMap<String,Object> headers)
Returns string view of passed headers. Any modifications to the headers are visible to the view, the view also supports removal of elements. Does not support other modifications.

Parameters:
headers - headers.
Returns:
String view of headers or null if {code headers} input parameter is null.

asHeaderString

public static String asHeaderString(List<Object> values,
                                    RuntimeDelegate rd)
Converts a list of message header values to a single string value (with individual values separated by ','). Each single header value is converted to String using a RuntimeDelegate.HeaderDelegate if one is available via RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the header value class or using its toString() method if a header delegate is not available.

Parameters:
values - list of individual header values.
rd - RuntimeDelegate instance or null (in that case RuntimeDelegate.getInstance() will be called for before conversion of elements).
Returns:
single string consisting of all the values passed in as a parameter. If values parameter is null, null is returned. If the list of values is empty, an empty string is returned.


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.