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 (c) 2012 LinkedIn Corp.
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.
*/
/**
* $Id: $
*/
package com.linkedin.restli.client;
import com.linkedin.data.DataComplex;
import com.linkedin.data.schema.PathSpec;
import com.linkedin.data.template.DataTemplate;
import com.linkedin.internal.common.util.CollectionUtils;
import com.linkedin.restli.client.base.BuilderBase;
import com.linkedin.restli.common.ComplexResourceKey;
import com.linkedin.restli.common.CompoundKey;
import com.linkedin.restli.common.ResourceSpec;
import com.linkedin.restli.common.RestConstants;
import com.linkedin.util.ArgumentUtil;
import java.lang.reflect.Array;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/**
* @author Josh Walker
* @version $Revision: $
*/
public abstract class AbstractRequestBuilder> extends BuilderBase implements RequestBuilder
{
protected static final char HEADER_DELIMITER = ',';
protected final ResourceSpec _resourceSpec;
private Map _headers = new TreeMap(String.CASE_INSENSITIVE_ORDER);
private List _cookies = new ArrayList();
private final Map _queryParams = new HashMap();
private final Map> _queryParamClasses = new HashMap>();
private final Map _pathKeys = new HashMap();
private final CompoundKey _assocKey = new CompoundKey();
protected AbstractRequestBuilder(String baseUriTemplate, ResourceSpec resourceSpec, RestliRequestOptions requestOptions)
{
super(baseUriTemplate, requestOptions);
_resourceSpec = resourceSpec;
_requestOptions = requestOptions;
}
/**
* Create a header with the specified value if there is no existing name.
* Otherwise, append the specified value to the existing value, delimited by comma
*
* @param name name of the header
* @param value value of the header. If null, this method is no-op.
*/
public AbstractRequestBuilder addHeader(String name, String value)
{
if (value != null)
{
final String currValue = _headers.get(name);
final String newValue = currValue == null ? value : currValue + HEADER_DELIMITER + value;
_headers.put(name, newValue);
}
return this;
}
/**
* Create a header with the specified value if there is no existing name
* Otherwise, overwrite the existing header with the specified value to the existing value
*
* @param name name of the header
* @param value value of the header
*/
public AbstractRequestBuilder setHeader(String name, String value)
{
_headers.put(name, value);
return this;
}
/**
* Retrieves the value of the specified header
* @param name The name of the header to return
* @return The value of the specified header.
*/
protected String getHeader(String name)
{
return _headers.get(name);
}
/**
* Use the specified headers to replace the existing headers
* All old headers will be lost
*
* @param headers new headers
*/
public AbstractRequestBuilder setHeaders(Map headers)
{
_headers = new TreeMap(String.CASE_INSENSITIVE_ORDER);
_headers.putAll(headers);
return this;
}
/**
* Base class method for adding the cookies
* @return a new builder reference with new cookie added
* @param cookie
*/
public AbstractRequestBuilder addCookie(HttpCookie cookie)
{
if (cookie != null)
_cookies.add(cookie);
return this;
}
/**
* Base class method for setting the cookies
* @return a new builder reference with newly set cookie
* @param cookies
*/
public AbstractRequestBuilder setCookies(List cookies)
{
for (HttpCookie cookie : cookies)
{
addCookie(cookie);
}
return this;
}
/**
* Base class method for removing the cookies
* @return a new builder reference with empty cookie
*/
public AbstractRequestBuilder clearCookies()
{
_cookies = new ArrayList();
return this;
}
/**
* Retrieve the cookies in the request
* @return cookies
*/
protected List getCookies()
{
return _cookies;
}
public AbstractRequestBuilder setReqParam(String key, Object value)
{
ArgumentUtil.notNull(value, "value");
return setParam(key, value);
}
public AbstractRequestBuilder setReqParam(String key, Object value, Class> clazz)
{
ArgumentUtil.notNull(value, "value");
return setParam(key, value, clazz);
}
public AbstractRequestBuilder setParam(String key, Object value)
{
if (value == null)
{
return this;
}
return setParam(key, value, value.getClass());
}
public AbstractRequestBuilder setParam(String key, Object value, Class> clazz)
{
if (value == null)
{
return this;
}
_queryParams.put(key, value);
_queryParamClasses.put(key, clazz);
return this;
}
public AbstractRequestBuilder addReqParam(String key, Object value)
{
ArgumentUtil.notNull(value, "value");
return addParam(key, value);
}
public AbstractRequestBuilder addReqParam(String key, Object value, Class> clazz)
{
ArgumentUtil.notNull(value, "value");
return addParam(key, value, clazz);
}
public AbstractRequestBuilder addParam(String key, Object value)
{
if (value == null)
{
return this;
}
return addParam(key, value, value.getClass());
}
@SuppressWarnings("unchecked")
public AbstractRequestBuilder addParam(String key, Object value, Class> clazz)
{
if (value == null)
{
return this;
}
final Object existingData = _queryParams.get(key);
if (existingData == null)
{
final Collection