Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    *
    * Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
    *
    * The contents of this file are subject to the terms of either the GNU
    * General Public License Version 2 only ("GPL") or the Common Development
    * and Distribution License("CDDL") (collectively, the "License").  You
    * may not use this file except in compliance with the License.  You can
   * obtain a copy of the License at
   * http://glassfish.java.net/public/CDDL+GPL_1_1.html
   * or packager/legal/LICENSE.txt.  See the License for the specific
   * language governing permissions and limitations under the License.
   *
   * When distributing the software, include this License Header Notice in each
   * file and include the License file at packager/legal/LICENSE.txt.
   *
   * GPL Classpath Exception:
   * Oracle designates this particular file as subject to the "Classpath"
   * exception as provided by Oracle in the GPL Version 2 section of the License
   * file that accompanied this code.
   *
   * Modifications:
   * If applicable, add the following below the License Header, with the fields
   * enclosed by brackets [] replaced by your own identifying information:
   * "Portions Copyright [year] [name of copyright owner]"
   *
   * Contributor(s):
   * If you wish your version of this file to be governed by only the CDDL or
   * only the GPL Version 2, indicate your decision by adding "[Contributor]
   * elects to include this software in this distribution under the [CDDL or GPL
   * Version 2] license."  If you don't indicate a single choice of license, a
   * recipient has the option to distribute your version of this file under
   * either the CDDL, the GPL Version 2 or to extend the choice of license to
   * its licensees as provided above.  However, if you add GPL Version 2 code
   * and therefore, elected the GPL Version 2 license, then the option applies
   * only if the new code is made subject to such option by the copyright
   * holder.
   */
  package com.sun.jersey.api;
  
  import java.net.URI;
  import java.util.Date;
  import java.util.List;
  import java.util.Locale;
Defines the contract between a returned instance and the runtime when an application needs to provide metadata to the runtime.

JResponse is a type safe alternative to javax.ws.rs.core.Response that preserves the type information of response entity thus it is not necessary to utilize javax.ws.rs.core.GenericEntity. It provides equivalent functionality to javax.ws.rs.core.Response.

JResponse may be extended in combination with JResponse.AJResponseBuilder specialization when building responses.

Several methods have parameters of type URI, javax.ws.rs.core.UriBuilder provides convenient methods to create such values as does href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html.create(java.lang.String)">URI.create().

Parameters:
<E> The entity type
Author(s):
Paul.Sandoz@Sun.Com
See also:
JResponse.JResponseBuilder
javax.ws.rs.core.Response
  
  public class JResponse<E> {
      private final StatusType statusType;
  
      private final E entity;
  
      private final OutBoundHeaders headers;

    
Construct given a status type, entity and metadata.

Parameters:
statusType the status type
headers the metadata, it is the callers responsibility to copy the metadata if necessary.
entity the entity
  
      public JResponse(StatusType statusTypeOutBoundHeaders headers, E entity) {
          this. = statusType;
         this. = entity;
         this. = headers;
     }

    
Construct given a status, entity and metadata.

Parameters:
status the status
headers the metadata, it is the callers responsibility to copy the metadata if necessary.
entity the entity
 
     public JResponse(int statusOutBoundHeaders headers, E entity) {
         this(ResponseImpl.toStatusType(status), headersentity);
     }

    
Construct a shallow copy. The metadata map will be copied but not the key/value references.

Parameters:
that the JResponse to copy from.
 
     public JResponse(JResponse<E> that) {
         this(that.statusType,
                 that.headers != null ? new OutBoundHeaders(that.headers) : null,
                 that.entity);
     }

    
Construct from a JResponse.AJResponseBuilder.

Parameters:
b the builder.
 
     protected JResponse(AJResponseBuilder<E, ?> b) {
         this. = b.getStatusType();
         this. = b.getEntity();
         this. = b.getMetadata();
     }

    
Convert to a javax.ws.rs.core.Response compatible instance.

Returns:
the javax.ws.rs.core.Response compatible instance.
 
     public JResponseAsResponse toResponse() {
         return new JResponseAsResponse(this);
     }

    
Convert to a javax.ws.rs.core.Response compatible instance.

Parameters:
type the entity type
Returns:
the javax.ws.rs.core.Response compatible instance.
 
     public JResponseAsResponse toResponse(Type type) {
         return new JResponseAsResponse(thistype);
     }

    
Get the status type associated with the response.

Returns:
the response status type.
 
     public StatusType getStatusType() {
         return ;
     }

    
Get the status code associated with the response.

Returns:
the response status code.
 
     public int getStatus() {
         return .getStatusCode();
     }

    
Get metadata associated with the response as a map. The returned map may be subsequently modified by the JAX-RS runtime. Values will be serialized using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the class of the value or using the values toString method if a header delegate is not available.

Returns:
response metadata as a map
 
     public OutBoundHeaders getMetadata() {
         return ;
     }
    
    
Get the response entity. The response will be serialized using a MessageBodyWriter for the class and type the entity E.

Returns:
the response entity.
See also:
javax.ws.rs.ext.MessageBodyWriter
 
     public E getEntity() {
         return ;
     }

    
Get the type of the entity.

Returns:
the type of the entity.
 
     public Type getType() {
         return getSuperclassTypeParameter(getClass());
     }
     
     private static Type getSuperclassTypeParameter(Class<?> subclass) {
         Type superclass = subclass.getGenericSuperclass();
         if (!(superclass instanceof ParameterizedType)) {
             return Object.class;
         }
         ParameterizedType parameterized = (ParameterizedTypesuperclass;
         return parameterized.getActualTypeArguments()[0];
     }


    
Create a new JResponse.JResponseBuilder by performing a shallow copy of an existing javax.ws.rs.core.Response. The returned builder has its own metadata map but entries are simply references to the keys and values contained in the supplied Response metadata map.

Parameters:
<E> The entity type
response a Response from which the status code, entity and metadata will be copied
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> fromResponse(Response response) {
         JResponseBuilder b = status(response.getStatus());
         b.entity(response.getEntity());
         for (String headerNameresponse.getMetadata().keySet()) {
             List<ObjectheaderValues = response.getMetadata().get(headerName);
             for (Object headerValueheaderValues) {
                 b.header(headerNameheaderValue);
             }
         }
         return b;
     }

    
Create a new JResponse.JResponseBuilder by performing a shallow copy of an existing JResponse. The returned builder has its own metadata map but entries are simply references to the keys and values contained in the supplied Response metadata map.

Parameters:
<E> The entity type
response a JResponse from which the status code, entity and metadata will be copied
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> fromResponse(JResponse<E> response) {
         JResponseBuilder<E> b = status(response.getStatus());
         b.entity(response.getEntity());
         for (String headerNameresponse.getMetadata().keySet()) {
             List<ObjectheaderValues = response.getMetadata().get(headerName);
             for (Object headerValueheaderValues) {
                 b.header(headerNameheaderValue);
             }
         }
         return b;
     }
    
    
Create a new JResponse.JResponseBuilder with the supplied status.

Parameters:
<E> The entity type
status the response status
Returns:
a new JResponseBuilder
Throws:
java.lang.IllegalArgumentException if status is null
 
     public static <E> JResponseBuilder<E> status(StatusType status) {
         JResponseBuilder<E> b = new JResponseBuilder<E>();
         b.status(status);
         return b;
     }

    
Create a new JResponse.JResponseBuilder with the supplied status.

Parameters:
<E> The entity type
status the response status
Returns:
a new JResponseBuilder
Throws:
java.lang.IllegalArgumentException if status is null
 
     public static <E> JResponseBuilder<E> status(Response.Status status) {
         return status((StatusType)status);
     }

    
Create a new JResponse.JResponseBuilder with the supplied status.

Parameters:
<E> The entity type
status the response status
Returns:
a new JResponseBuilder
Throws:
java.lang.IllegalArgumentException if status is less than 100 or greater than 599.
 
     public static <E> JResponseBuilder<E> status(int status) {
         JResponseBuilder<E> b = new JResponseBuilder<E>();
         b.status(status);
         return b;
     }

    
Create a new JResponse.JResponseBuilder with an OK status.

Parameters:
<E> The entity type
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> ok() {
         JResponseBuilder b = status(.);
         return b;
     }

    
Create a new JResponse.JResponseBuilder that contains a representation.

Parameters:
<E> The entity type
entity the representation entity data
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> ok(E entity) {
         JResponseBuilder<E> b = ok();
         b.entity(entity);
         return b;
     }

    
Create a new JResponse.JResponseBuilder that contains a representation.

Parameters:
<E> The entity type
entity the representation entity data
type the media type of the entity
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> ok(E entityMediaType type) {
         JResponseBuilder<E> b = ok();
         b.entity(entity);
         b.type(type);
         return b;
     }

    
Create a new JResponse.JResponseBuilder that contains a representation.

Parameters:
<E> The entity type
entity the representation entity data
type the media type of the entity
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> ok(E entityString type) {
         JResponseBuilder<E> b = ok();
         b.entity(entity);
         b.type(type);
         return b;
     }

    
Create a new JResponse.JResponseBuilder that contains a representation.

Parameters:
<E> The entity type
entity the representation entity data
variant representation metadata
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> ok(E entityVariant variant) {
         JResponseBuilder<E> b = ok();
         b.entity(entity);
         b.variant(variant);
         return b;
     }

    
Create a new JResponse.JResponseBuilder with an server error status.

Parameters:
<E> The entity type
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> serverError() {
         return b;
     }

    
Create a new JResponse.JResponseBuilder for a created resource, set the location header using the supplied value.

Parameters:
<E> The entity type
location the URI of the new resource. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the request URI (see UriInfo).
Returns:
a new JResponseBuilder
Throws:
java.lang.IllegalArgumentException if location is null
 
     public static <E> JResponseBuilder<E> created(URI location) {
         JResponseBuilder<E> b = JResponse.<E>status(.).location(location);
         return b;
     }

    
Create a new JResponse.JResponseBuilder for an empty response.

Parameters:
<E> The entity type
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> noContent() {
         JResponseBuilder<E> b = status(.);
         return b;
     }

    
Create a new JResponse.JResponseBuilder with a not-modified status.

Parameters:
<E> The entity type
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> notModified() {
         JResponseBuilder<E> b = status(.);
         return b;
     }

    
Create a new JResponse.JResponseBuilder with a not-modified status.

Parameters:
<E> The entity type
tag a tag for the unmodified entity
Returns:
a new JResponseBuilder
Throws:
java.lang.IllegalArgumentException if tag is null
 
     public static <E> JResponseBuilder<E> notModified(EntityTag tag) {
         JResponseBuilder<E> b = notModified();
         b.tag(tag);
         return b;
     }

    
Create a new JResponse.JResponseBuilder with a not-modified status and a strong entity tag. This is a shortcut for notModified(new EntityTag(value)).

Parameters:
<E> The entity type
tag the string content of a strong entity tag. The JAX-RS runtime will quote the supplied value when creating the header.
Returns:
a new JResponseBuilder
Throws:
java.lang.IllegalArgumentException if tag is null
 
     public static <E> JResponseBuilder<E> notModified(String tag) {
         JResponseBuilder b = notModified();
         b.tag(tag);
         return b;
     }

    
Create a new JResponse.JResponseBuilder for a redirection. Used in the redirect-after-POST (aka POST/redirect/GET) pattern.

Parameters:
<E> The entity type
location the redirection URI. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the base URI of the application (see UriInfo).
Returns:
a new JResponseBuilder
Throws:
java.lang.IllegalArgumentException if location is null
 
     public static <E> JResponseBuilder<E> seeOther(URI location) {
         JResponseBuilder<E> b = JResponse.<E>status(.).location(location);
         return b;
     }

    
Create a new JResponse.JResponseBuilder for a temporary redirection.

Parameters:
<E> The entity type
location the redirection URI. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the base URI of the application (see UriInfo).
Returns:
a new JResponseBuilder
Throws:
java.lang.IllegalArgumentException if location is null
 
     public static <E> JResponseBuilder<E> temporaryRedirect(URI location) {
         JResponseBuilder<E> b = JResponse.<E>status(.).location(location);
         return b;
     }

    
Create a new JResponse.JResponseBuilder for a not acceptable response.

Parameters:
<E> The entity type
variants list of variants that were available, a null value is equivalent to an empty list.
Returns:
a new JResponseBuilder
 
     public static <E> JResponseBuilder<E> notAcceptable(List<Variantvariants) {
         JResponseBuilder<E> b = JResponse.<E>status(.).variants(variants);
         return b;
     }

    
A class used to build JResponse instances that contain metadata instead of or in addition to an entity. An initial instance may be obtained via static methods of the JResponse class, instance methods provide the ability to set metadata. E.g. to create a response that indicates the creation of a new resource:
@POST
 JResponse addWidget(...) {
   Widget w = ...
   URI widgetId = UriBuilder.fromResource(Widget.class)...
   return JResponse.created(widgetId).build();
 }

Several methods have parameters of type URI, javax.ws.rs.core.UriBuilder provides convenient methods to create such values as does URI.create().

Where multiple variants of the same method are provided, the type of the supplied parameter is retained in the metadata of the built JResponse.

Parameters:
<E> The entity type
 
     public static final class JResponseBuilder<E> extends AJResponseBuilder<E, JResponseBuilder<E>> {
        
Default constructor.
 
         public JResponseBuilder() {}

        
Construct a shallow copy. The metadata map will be copied but not the key/value references.

Parameters:
that the JResponseBuilder to copy from.
 
         public JResponseBuilder(JResponseBuilder<E> that) {
             super(that);
         }
        
        
Create a shallow copy preserving state. The metadata map will be copied but not the key/value references.

Returns:
the copy.
 
         @Override
         public JResponseBuilder<E> clone() {
             return new JResponseBuilder<E>(this);
         }

        
Create a JResponse instance from the current JResponseBuilder. The builder is reset to a blank state equivalent to calling .

Returns:
a JResponse instance
 
         public JResponse<E> build() {
             JResponse<E> r = new JResponse<E>(this);
             reset();
             return r;
         }
     }

    
An abstract response builder that may be utilized to extend response building and the construction of JResponse instances.

Parameters:
<E> The entity type
<B> The builder type
 
     public static abstract class AJResponseBuilder<E, B extends AJResponseBuilder> {
        
The status type.
 
         protected StatusType statusType = .;

        
The response metadata.
 
         protected OutBoundHeaders headers;

        
The entity.
 
         protected E entity;

        
Default constructor.
 
         protected AJResponseBuilder() {}

        
Construct a shallow copy. The metadata map will be copied but not the key/value references.

Parameters:
that the AJResponseBuilder to copy from.
 
         protected AJResponseBuilder(AJResponseBuilder<E, ?> that) {
             this. = that.statusType;
             this. = that.entity;
             if (that.headers != null) {
                 this. = new OutBoundHeaders(that.headers);
             } else {
                 this. = null;
             }
         }

        
Reset to the default state.
 
         protected void reset() {
              = .;
              = null;
              = null;
         }

        
Get the status type associated with the response.

Returns:
the response status type.
 
         protected StatusType getStatusType() {
             return ;
         }

        
Get the status code associated with the response.

Returns:
the response status code.
 
         protected int getStatus() {
             return .getStatusCode();
         }

        
Get the metadata associated with the response.

Returns:
response metadata as a map
 
         protected OutBoundHeaders getMetadata() {
             if ( == null)
                  = new OutBoundHeaders();
             return ;
         }

        
Get the response entity.

Returns:
the response entity.
 
         protected E getEntity() {
             return ;
         }

        
Set the status.

Parameters:
status the response status
Returns:
the updated instance
Throws:
java.lang.IllegalArgumentException if status is less than 100 or greater than 599.
 
         public B status(int status) {
             return status(ResponseImpl.toStatusType(status));
         }

        
Set the status.

Parameters:
status the response status
Returns:
the updated instance.
Throws:
java.lang.IllegalArgumentException if status is null
 
         public B status(StatusType status) {
             if (status == null)
                 throw new IllegalArgumentException();
             this. = status;
             return (B)this;
         };

        
Set the status.

Parameters:
status the response status
Returns:
the updated instance.
Throws:
java.lang.IllegalArgumentException if status is null
 
         public B status(Status status) {
             return status((StatusType)status);
         };

        
Set the entity.

Parameters:
entity the response entity
Returns:
the updated instance
 
         public B entity(E entity) {
             this. = entity;
             return (B)this;
         }

        
Set the response media type.

Parameters:
type the media type of the response entity, if null any existing value for type will be removed
Returns:
the updated instance
 
         public B type(MediaType type) {
             headerSingle(.type);
             return (B)this;
         }

        
Set the response media type.

Parameters:
type the media type of the response entity, if null any existing value for type will be removed
Returns:
the updated instance
Throws:
java.lang.IllegalArgumentException if type cannot be parsed
 
         public B type(String type) {
             return type(type == null ? null : MediaType.valueOf(type));
         }

        
Set representation metadata. Equivalent to setting the values of content type, content language, and content encoding separately using the values of the variant properties.

Parameters:
variant metadata of the response entity, a null value is equivalent to a variant with all null properties.
Returns:
the updated instance
 
         public B variant(Variant variant) {
             if (variant == null) {
                 type((MediaType)null);
                 language((String)null);
                 encoding(null);
                 return (B)this;
             }
 
             type(variant.getMediaType());
             // TODO set charset
             language(variant.getLanguage());
             encoding(variant.getEncoding());
 
             return (B)this;
         }

        
Add a Vary header that lists the available variants.

Parameters:
variants a list of available representation variants, a null value will remove an existing value for vary.
Returns:
the updated instance
 
         public B variants(List<Variantvariants) {
             if (variants == null) {
                 header(.null);
                 return (B)this;
             }
 
             if (variants.isEmpty())
                 return (B)this;
 
             MediaType accept = variants.get(0).getMediaType();
             boolean vAccept = false;
 
             Locale acceptLanguage = variants.get(0).getLanguage();
             boolean vAcceptLanguage = false;
 
             String acceptEncoding = variants.get(0).getEncoding();
             boolean vAcceptEncoding = false;
 
             for (Variant v : variants) {
                 vAccept |= !vAccept && vary(v.getMediaType(), accept);
                 vAcceptLanguage |= !vAcceptLanguage && vary(v.getLanguage(), acceptLanguage);
                 vAcceptEncoding |= !vAcceptEncoding && vary(v.getEncoding(), acceptEncoding);
             }
 
             StringBuilder vary = new StringBuilder();
             append(varyvAccept.);
             append(varyvAcceptLanguage.);
             append(varyvAcceptEncoding.);
 
             if (vary.length() > 0)
                 header(.vary.toString());
             return (B)this;
         }
 
         private boolean vary(MediaType vMediaType vary) {
             return v != null && !v.equals(vary);
         }
 
         private boolean vary(Locale vLocale vary) {
             return v != null && !v.equals(vary);
         }
 
         private boolean vary(String vString vary) {
             return v != null && !v.equalsIgnoreCase(vary);
         }
 
         private void append(StringBuilder sbboolean vString s) {
             if (v) {
                 if (sb.length() > 0)
                     sb.append(',');
                 sb.append(s);
             }
         }

        
Set the language.

Parameters:
language the language of the response entity, if null any existing value for language will be removed
Returns:
the updated instance
 
         public B language(String language) {
             headerSingle(.language);
             return (B)this;
         }

        
Set the language.

Parameters:
language the language of the response entity, if null any existing value for type will be removed
Returns:
the updated instance
 
         public B language(Locale language) {
             headerSingle(.language);
             return (B)this;
         }

        
Set the location.

Parameters:
location the location. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the base URI of the application (see UriInfo). If null any existing value for location will be removed.
Returns:
the updated instance.
 
         public B location(URI location) {
             headerSingle(.location);
             return (B)this;
         }

        
Set the content location.

Parameters:
location the content location. Relative or absolute URIs may be used for the value of content location. If null any existing value for content location will be removed.
Returns:
the updated instance
 
         public B contentLocation(URI location) {
             headerSingle(.location);
             return (B)this;
         }

        
Set the content encoding.

Parameters:
encoding the content encoding of the response entity, if null any existing value for type will be removed
Returns:
the updated instance
 
         public B encoding(String encoding) {
             headerSingle(.encoding);
             return (B)this;
         }

        
Set an entity tag.

Parameters:
tag the entity tag, if null any existing entity tag value will be removed.
Returns:
the updated instance
 
         public B tag(EntityTag tag) {
             headerSingle(.tag);
             return (B)this;
         }

        
Set a strong entity tag. This is a shortcut for tag(new EntityTag(value)).

Parameters:
tag the string content of a strong entity tag. The JAX-RS runtime will quote the supplied value when creating the header. If null any existing entity tag value will be removed.
Returns:
the updated instance
 
         public B tag(String tag) {
             return tag(tag == null ? null : new EntityTag(tag));
         }

        
Set the last modified date.

Parameters:
lastModified the last modified date, if null any existing last modified value will be removed.
Returns:
the updated instance
 
         public B lastModified(Date lastModified) {
             headerSingle(.lastModified);
             return (B)this;
         }

        
Set the cache control.

Parameters:
cacheControl the cache control directives, if null removes any existing cache control directives.
Returns:
the updated instance
 
         public B cacheControl(CacheControl cacheControl) {
             headerSingle(.cacheControl);
             return (B)this;
         }

        
Set the expires date.

Parameters:
expires the expiration date, if null removes any existing expires value.
Returns:
the updated instance
 
         public B expires(Date expires) {
             headerSingle(.expires);
             return (B)this;
         }

        
Add cookies.

Parameters:
cookies new cookies that will accompany the response. A null value will remove all cookies, including those added via the header(java.lang.String,java.lang.Object) method.
Returns:
the updated instance
 
         public B cookie(NewCookie... cookies) {
             if (cookies != null) {
                 for (NewCookie cookie : cookies)
                     header(.cookie);
             } else {
                 header(.null);
             }
             return (B)this;
         }

        
Add a header.

Parameters:
name the name of the header
value the value of the header, the header will be serialized using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the class of value or using its toString method if a header delegate is not available. If value is null then all current headers of the same name will be removed.
Returns:
the updated instance.
 
         public B header(String nameObject value) {
             return header(namevaluefalse);
         }

        
Add a header or replace an existing header.

Parameters:
name the name of the header
value the value of the header, the header will be serialized using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the class of value or using its toString method if a header delegate is not available. If value is null then all current headers of the same name will be removed.
Returns:
the updated instance.
 
         public B headerSingle(String nameObject value) {
             return header(namevaluetrue);
         }

        
Add a header.

Parameters:
name the name of the header
value the value of the header, the header will be serialized using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the class of value or using its toString method if a header delegate is not available. If value is null then all current headers of the same name will be removed.
single if true then replace the header if it exists, otherwise add the header.
Returns:
the updated instance.
        public B header(String nameObject valueboolean single) {
            if (value != null) {
                if (single) {
                    getMetadata().putSingle(namevalue);
                } else {
                    getMetadata().add(namevalue);
                }
            } else {
                getMetadata().remove(name);
            }
            return (B)this;
        }
    }
New to GrepCode? Check out our FAQ X