class CookieHeaderProvider implements RuntimeDelegate.HeaderDelegate<Cookie> {

    @Override
    public Cookie fromString(String cookieValue) {
        if (cookieValue == null) {
            throw new IllegalArgumentException("Cookie value can not be null");
        }

        int version = NewCookie.DEFAULT_VERSION;
        int maxAge = NewCookie.DEFAULT_MAX_AGE;
        String name = null;
        String value = null;
        String path = null;
        String domain = null;
        String comment = null;
        Date expiry = null;
        boolean secure = false;
        boolean httpOnly = false;

        String[] parts = cookieValue.split(";");
        for (String part : parts) {
            String token = part.trim();
            if (token.startsWith(VERSION)) {
                version = Integer.parseInt(token.substring(VERSION.length() + 1));
            } else if (token.startsWith(PATH)) {
                path = token.substring(PATH.length() + 1);
            } else if (token.startsWith(DOMAIN)) {
                domain = token.substring(DOMAIN.length() + 1);
            } else if (token.startsWith(SECURE)) {
                secure = Boolean.TRUE;
            } else if (token.startsWith(HTTP_ONLY)) {
                httpOnly = Boolean.TRUE;
            } else if (token.startsWith(COMMENT)) {
                comment = token.substring(COMMENT.length() + 1);
            } else if (token.startsWith(MAX_AGE)) {
                maxAge = Integer.parseInt(token.substring(MAX_AGE.length() + 1));
            } else if (token.startsWith(EXPIRES)) {
                try {
                    //All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT)
                    dateFormat.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
                    expiry = dateFormat.parse(token.substring(EXPIRES.length() + 1));
                } catch (ParseException e) {
                    log.error("Error while parsing the Date value. Hence return null", e);
                }
            } else {
                int i = token.indexOf('=');
                if (i != -1) {
                    name = token.substring(0, i);
                    value = i == token.length()  + 1 ? "" : token.substring(i + 1);
                }
            }
        }

        if (name == null) {
            throw new IllegalArgumentException("Cookie is malformed : " + cookieValue);
        }

        return new NewCookie(name, value, path, domain, version, comment, maxAge, expiry, secure, httpOnly);
    }

}