001/*
002 * ====================================================================
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 * ====================================================================
020 *
021 * This software consists of voluntary contributions made by many
022 * individuals on behalf of the Apache Software Foundation.  For more
023 * information on the Apache Software Foundation, please see
024 * <http://www.apache.org/>.
025 *
026 */
027
028package org.apache.http.impl.cookie;
029
030import java.util.Date;
031
032import org.apache.http.cookie.SetCookie2;
033
034/**
035 * Default implementation of {@link SetCookie2}.
036 *
037 * @since 4.0
038 */
039public class BasicClientCookie2 extends BasicClientCookie implements SetCookie2 {
040
041    private static final long serialVersionUID = -7744598295706617057L;
042
043    private String commentURL;
044    private int[] ports;
045    private boolean discard;
046
047    /**
048     * Default Constructor taking a name and a value. The value may be null.
049     *
050     * @param name The name.
051     * @param value The value.
052     */
053    public BasicClientCookie2(final String name, final String value) {
054        super(name, value);
055    }
056
057    @Override
058    public int[] getPorts() {
059        return this.ports;
060    }
061
062    @Override
063    public void setPorts(final int[] ports) {
064        this.ports = ports;
065    }
066
067    @Override
068    public String getCommentURL() {
069        return this.commentURL;
070    }
071
072    @Override
073    public void setCommentURL(final String commentURL) {
074        this.commentURL = commentURL;
075    }
076
077    @Override
078    public void setDiscard(final boolean discard) {
079        this.discard = discard;
080    }
081
082    @Override
083    public boolean isPersistent() {
084        return !this.discard && super.isPersistent();
085    }
086
087    @Override
088    public boolean isExpired(final Date date) {
089        return this.discard || super.isExpired(date);
090    }
091
092    @Override
093    public Object clone() throws CloneNotSupportedException {
094        final BasicClientCookie2 clone = (BasicClientCookie2) super.clone();
095        if (this.ports != null) {
096            clone.ports = this.ports.clone();
097        }
098        return clone;
099    }
100
101}
102