Example usage for javax.servlet.http Cookie value

List of usage examples for javax.servlet.http Cookie value

Introduction

In this page you can find the example usage for javax.servlet.http Cookie value.

Prototype

String value

To view the source code for javax.servlet.http Cookie value.

Click Source Link

Usage

From source file:org.eiichiro.bootleg.AbstractRequest.java

/**
 * Constructs Web endpoint parameter from the specified source list or type.
 * This method is invoked for every Web endpoint method parameter by 
 * {@link Receive}. This method processes according to the following steps: 
 * <ol>// w w  w . j  a v a  2  s  .c o  m
 * <li>If the specified type is an array type, returns <code>null</code>. An 
 * array type is not supported in this class.</li>
 * <li>If the specified type is built-in type (See {@link Types#isBuiltinType(Type)}), 
 * returns the built-in instance.</li>
 * <li>Constructs the value as the specified type from the specified sources 
 * and names. If the Web endpoint parameter is declared without any source 
 * annotation except built-in type, this method always returns <code>null</code>.
 * </li>
 * <li>If the construction result is not <code>null</code>, returns the 
 * result to the client.</li>
 * <li>If the result is <code>null</code> of primitive type, returns the 
 * default value of each primitive type to the client.</li>
 * <li>If the result is <code>null</code> of supported collection type (See 
 * {@link Types#isSupportedCollection(Type)}), returns the empty collection 
 * of the specified type to the client.</li>
 * <li>Otherwise, returns <code>null</code>.</li>
 * </ol>
 * 
 * @param type The type of Web endpoint parameter.
 * @param sources The source list from which Web endpoint parameter is 
 * constructed.
 * @return Web endpoint method parameter.
 */
public Object get(Type type, List<Annotation> sources) {
    if (Types.isArray(type)) {
        logger.warn("Array type is not supported in [" + getClass() + "]");
        return null;
    } else if (Types.isBuiltinType(type)) {
        return builtin(type);
    }

    for (Annotation source : sources) {
        Object parameter = null;

        if (source instanceof Query) {
            Query query = (Query) source;
            parameter = query(type, query.value());
        } else if (source instanceof Body) {
            Body body = (Body) source;
            parameter = body(type, body.value());
        } else if (source instanceof Header) {
            Header header = (Header) source;
            parameter = header(type, header.value());
        } else if (source instanceof org.eiichiro.bootleg.annotation.Cookie) {
            org.eiichiro.bootleg.annotation.Cookie cookie = (org.eiichiro.bootleg.annotation.Cookie) source;
            parameter = cookie(type, cookie.value());
        } else if (source instanceof Session) {
            Session session = (Session) source;
            parameter = session(type, session.value());
        } else if (source instanceof Application) {
            Application application = (Application) source;
            parameter = application(type, application.value());
        } else if (source instanceof Path) {
            Path path = (Path) source;
            parameter = path(type, path.value());
        } else {
            logger.warn("Unknown source [" + source + "]");
        }

        if (parameter != null) {
            return parameter;
        }
    }

    if (Types.isPrimitive(type)) {
        logger.debug("Cannot construct [" + type + "] primitive; Returns the default value");
        return primitive(type);
    } else if (Types.isCollection(type)) {
        if (Types.isSupportedCollection(type)) {
            logger.debug("Cannot construct [" + type + "] collection; Returns the empty colleciton");
            return Types.getEmptyCollection(type);
        } else {
            logger.warn("Collection type " + type + " is not supported in [" + getClass() + "]");
            return null;
        }
    }

    StringBuilder builder = new StringBuilder();

    for (Annotation source : sources) {
        builder.append(source + " ");
    }

    logger.debug("Cannot construct Web endpoint method parameter [" + builder + type + "]");
    return null;
}