Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
/*
* 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 com.sun.jersey.core.header.OutBoundHeaders;
import com.sun.jersey.core.spi.factory.ResponseImpl;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.NewCookie;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.Response.StatusType;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.Variant;
/**
* 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 {@link Response} that preserves the
* type information of response entity thus it is not necessary to utilize
* {@link GenericEntity}. It provides equivalent functionality to
* {@link Response}.
*
* JResponse may be extended in combination with {@link AJResponseBuilder}
* specialization when building responses.
*
* Several methods have parameters of type URI, {@link UriBuilder} provides
* convenient methods to create such values as does
* {@link URI.create()}.
*
* @param The entity type
* @see JResponseBuilder
* @see Response
* @author [email protected]
*/
public class JResponse {
private final StatusType statusType;
private final E entity;
private final OutBoundHeaders headers;
/**
* Construct given a status type, entity and metadata.
*
* @param statusType the status type
* @param headers the metadata, it is the callers responsibility to copy
* the metadata if necessary.
* @param entity the entity
*/
public JResponse(StatusType statusType, OutBoundHeaders headers, E entity) {
this.statusType = statusType;
this.entity = entity;
this.headers = headers;
}
/**
* Construct given a status, entity and metadata.
*
* @param status the status
* @param headers the metadata, it is the callers responsibility to copy
* the metadata if necessary.
* @param entity the entity
*/
public JResponse(int status, OutBoundHeaders headers, E entity) {
this(ResponseImpl.toStatusType(status), headers, entity);
}
/**
* Construct a shallow copy. The metadata map will be copied but not the
* key/value references.
*
* @param that the JResponse to copy from.
*/
public JResponse(JResponse that) {
this(that.statusType,
that.headers != null ? new OutBoundHeaders(that.headers) : null,
that.entity);
}
/**
* Construct from a {@link AJResponseBuilder}.
*
* @param b the builder.
*/
protected JResponse(AJResponseBuilder b) {
this.statusType = b.getStatusType();
this.entity = b.getEntity();
this.headers = b.getMetadata();
}
/**
* Convert to a {@link Response} compatible instance.
*
* @return the {@link Response} compatible instance.
*/
public JResponseAsResponse toResponse() {
return new JResponseAsResponse(this);
}
/**
* Convert to a {@link Response} compatible instance.
*
* @param type the entity type
* @return the {@link Response} compatible instance.
*/
public JResponseAsResponse toResponse(Type type) {
return new JResponseAsResponse(this, type);
}
/**
* Get the status type associated with the response.
*
* @return the response status type.
*/
public StatusType getStatusType() {
return statusType;
}
/**
* Get the status code associated with the response.
*
* @return the response status code.
*/
public int getStatus() {
return statusType.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 {@link javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate}
* if one is available via
* {@link javax.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)}
* for the class of the value or using the values {@code toString} method if a
* header delegate is not available.
*
* @return response metadata as a map
*/
public OutBoundHeaders getMetadata() {
return headers;
}
/**
* Get the response entity. The response will be serialized using a
* MessageBodyWriter for the class and type the entity E.
*
* @return the response entity.
* @see javax.ws.rs.ext.MessageBodyWriter
*/
public E getEntity() {
return entity;
}
/**
* Get the type of the entity.
*
* @return 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 = (ParameterizedType) superclass;
return parameterized.getActualTypeArguments()[0];
}
/**
* Create a new {@link JResponseBuilder} by performing a shallow copy of an
* existing {@link 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.
*
* @param The entity type
* @param response a Response from which the status code, entity and metadata
* will be copied
* @return a new JResponseBuilder
*/
public static JResponseBuilder fromResponse(Response response) {
JResponseBuilder b = status(response.getStatus());
b.entity(response.getEntity());
for (String headerName: response.getMetadata().keySet()) {
List