public Map getCookies()

in web/src/main/java/org/apache/commons/chain2/web/faces/FacesWebContext.java [178:206]


    public Map<String, Cookie> getCookies() {
        @SuppressWarnings("unchecked") // Assume faces is following contract
        Map<String, Object> facesCookieMap = context.getExternalContext().getRequestCookieMap();

        /* This ugly hack was done because the faces API implements
         * the cookie collection using <String, Object> instead of <String, Cookie>.
         * So we painstakingly check for type safety and cast it as a Map<String, Cookie>.
         */
        Iterator<Object> itr = facesCookieMap.values().iterator();

        if (itr.hasNext()) {
            Object cookieObj = itr.next();

            if (cookieObj instanceof Cookie) {
                // See comment above about type safety check
                @SuppressWarnings({ "unchecked", "rawtypes" })
                Map<String, Cookie> cookieMap = Collections.checkedMap(
                        (Map) facesCookieMap, String.class, Cookie.class);

                return cookieMap;
            } else {
                String msg = "Could not cast cookie Map into <String, Cookie>. " +
                        "Actual Cookie type is: " + cookieObj.getClass().toString();
                throw new ClassCastException(msg);
            }
        } else {
            return Collections.emptyMap();
        }
    }