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.
/*
* Copyright 2013 eXo Platform SAS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package juzu.request;
import juzu.PropertyType;
import juzu.Response;
import juzu.impl.bridge.spi.DispatchSPI;
import juzu.impl.common.ParameterHashMap;
import juzu.impl.common.ParameterMap;
import juzu.impl.request.Method;
import juzu.impl.request.Request;
import juzu.impl.bridge.spi.RequestBridge;
import java.util.Map;
/** @author Julien Viet */
public abstract class RequestContext {
/** . */
private static final Object[] EMPTY = new Object[0];
/** . */
protected final Method method;
/** . */
protected final Request request;
public RequestContext(Request request, Method method) {
this.request = request;
this.method = method;
}
public Method getMethod() {
return method;
}
public Map getParameters() {
return request.getParameters();
}
public HttpContext getHttpContext() {
return getBridge().getHttpContext();
}
public SecurityContext getSecurityContext() {
return getBridge().getSecurityContext();
}
public UserContext getUserContext() {
return getBridge().getUserContext();
}
public ApplicationContext getApplicationContext() {
return getBridge().getApplicationContext();
}
public T getProperty(PropertyType propertyType) {
return getBridge().getProperty(propertyType);
}
public abstract Phase getPhase();
protected abstract RequestBridge getBridge();
/**
* Create a dispatch object with unset parameters.
*
* @param method the method descriptor
* @return the corresponding dispatch object
*/
public Dispatch createDispatch(Method> method) {
DispatchSPI spi = getBridge().createDispatch(method.getPhase(), method.getHandle(), ParameterMap.EMPTY);
return request.createDispatch(method, spi);
}
public Phase.Action.Dispatch createActionDispatch(Method method) {
return (Phase.Action.Dispatch)createDispatch(method, EMPTY, ParameterMap.EMPTY);
}
public Phase.Action.Dispatch createActionDispatch(Method method, Object arg) {
return (Phase.Action.Dispatch)createDispatch(method, new Object[]{arg}, new ParameterHashMap());
}
public Phase.Action.Dispatch createActionDispatch(Method method, Object[] args) {
return (Phase.Action.Dispatch)createDispatch(method, args, new ParameterHashMap());
}
public Phase.View.Dispatch createViewDispatch(Method method) {
return (Phase.View.Dispatch)createDispatch(method, EMPTY, ParameterMap.EMPTY);
}
public Phase.View.Dispatch createViewDispatch(Method method, Object arg) {
return (Phase.View.Dispatch)createDispatch(method, new Object[]{arg}, new ParameterHashMap());
}
public Phase.View.Dispatch createViewDispatch(Method method, Object[] args) {
return (Phase.View.Dispatch)createDispatch(method, args, new ParameterHashMap());
}
public Phase.Resource.Dispatch createResourceDispatch(Method method) {
return (Phase.Resource.Dispatch)createDispatch(method, EMPTY, ParameterMap.EMPTY);
}
public Phase.Resource.Dispatch createResourceDispatch(Method method, Object arg) {
return (Phase.Resource.Dispatch)createDispatch(method, new Object[]{arg}, new ParameterHashMap());
}
public Phase.Resource.Dispatch createResourceDispatch(Method method, Object[] args) {
return (Phase.Resource.Dispatch)createDispatch(method, args, new ParameterHashMap());
}
public Response getResponse() {
return request.getResponse();
}
public void setResponse(Response response) {
request.setResponse(response);
}
private Dispatch createDispatch(Method> method, Object[] args, ParameterMap parameters) {
method.setArgs(args, parameters);
DispatchSPI spi = getBridge().createDispatch(method.getPhase(), method.getHandle(), parameters);
return request.createDispatch(method, spi);
}
}