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.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2013-2014 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 org.glassfish.jersey.server.mvc.internal;
import java.security.AccessController;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.Produces;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.inject.Inject;
import javax.inject.Provider;
import org.glassfish.jersey.internal.Errors;
import org.glassfish.jersey.internal.util.Producer;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.message.internal.MediaTypes;
import org.glassfish.jersey.process.Inflector;
import org.glassfish.jersey.server.ExtendedUriInfo;
import org.glassfish.jersey.server.internal.inject.ConfiguredValidator;
import org.glassfish.jersey.server.model.Invocable;
import org.glassfish.jersey.server.model.ModelProcessor;
import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.server.model.ResourceMethod;
import org.glassfish.jersey.server.model.ResourceModel;
import org.glassfish.jersey.server.model.RuntimeResource;
import org.glassfish.jersey.server.model.internal.ModelHelper;
import org.glassfish.jersey.server.model.internal.ModelProcessorUtil;
import org.glassfish.jersey.server.mvc.Template;
import org.glassfish.jersey.server.mvc.Viewable;
import jersey.repackaged.com.google.common.collect.Lists;
/**
* {@link ModelProcessor Model processor} enhancing (sub-)resources with {@value HttpMethod#GET} methods responsible of producing
* implicit {@link org.glassfish.jersey.server.mvc.Viewable viewables}.
*
* Note: Resource classes has to be annotated with {@link Template} annotation in order to be enhanced by this model processor.
*
* @author Michal Gajdos (michal.gajdos at oracle.com)
* @see Template
*/
class TemplateModelProcessor implements ModelProcessor {
/**
* Path parameter representing implicit template name.
*/
private static final String IMPLICIT_VIEW_PATH_PARAMETER = "implicit-view-path-parameter";
private static final String IMPLICIT_VIEW_PATH_PARAMETER_TEMPLATE = "{" + IMPLICIT_VIEW_PATH_PARAMETER + "}";
private final ResourceContext resourceContext;
private final Provider extendedUriInfoProvider;
private final Provider validatorProvider;
/**
* Inflector producing response with {@link org.glassfish.jersey.server.mvc.spi.ResolvedViewable resolved viewable} where
* model is the resource class annotated with {@link Template} or 404 as its status code.
*/
private class TemplateInflectorImpl implements TemplateInflector, Inflector {
private final String templateName;
private final Class> resourceClass;
private final Object resourceInstance;
private Class> modelClass;
/**
* Create enhancing template {@link Inflector inflector} method.
*
* @param templateName template name for the produced {@link org.glassfish.jersey.server.mvc.Viewable viewable}.
* @param resourceClass model class for the produced {@link org.glassfish.jersey.server.mvc.Viewable viewable}.
* Should not be {@code null}.
* @param resourceInstance model for the produced {@link org.glassfish.jersey.server.mvc.Viewable viewable}. May be
* {@code null}.
*/
private TemplateInflectorImpl(final String templateName, final Class> resourceClass,
final Object resourceInstance) {
this.templateName = templateName;
this.resourceClass = resourceClass;
this.resourceInstance = resourceInstance;
}
@Override
public Response apply(ContainerRequestContext requestContext) {
final List templateNames = getTemplateNames(requestContext);
final Object model = getModel(extendedUriInfoProvider.get());
// Validate resource class.
final ConfiguredValidator validator = validatorProvider.get();
if (validator != null) {
validator.validateResourceAndInputParams(model, null, null);
}
return Response.ok().entity(new ImplicitViewable(templateNames, model, resourceClass)).build();
}
@Override
public Class> getModelClass() {
return modelClass;
}
private Object setModelClass(final Object model) {
if (modelClass == null) {
modelClass = model.getClass();
}
return model;
}
/**
* Obtains a model object for a viewable.
*
* @param extendedUriInfo uri info to obtain last matched resource from.
* @return a model object.
*/
private Object getModel(final ExtendedUriInfo extendedUriInfo) {
final List