View Javadoc
1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.http;
17  
18  import io.netty.util.internal.ObjectUtil;
19  
20  import java.util.Collections;
21  import java.util.Set;
22  import java.util.TreeSet;
23  
24  /**
25   * The default {@link Cookie} implementation.
26   *
27   * @deprecated Use {@link io.netty.handler.codec.http.cookie.DefaultCookie} instead.
28   */
29  @Deprecated
30  public class DefaultCookie extends io.netty.handler.codec.http.cookie.DefaultCookie implements Cookie {
31  
32      private String comment;
33      private String commentUrl;
34      private boolean discard;
35      private Set<Integer> ports = Collections.emptySet();
36      private Set<Integer> unmodifiablePorts = ports;
37      private int version;
38  
39      /**
40       * Creates a new cookie with the specified name and value.
41       */
42      public DefaultCookie(String name, String value) {
43          super(name, value);
44      }
45  
46      @Override
47      @Deprecated
48      public String getName() {
49          return name();
50      }
51  
52      @Override
53      @Deprecated
54      public String getValue() {
55          return value();
56      }
57  
58      @Override
59      @Deprecated
60      public String getDomain() {
61          return domain();
62      }
63  
64      @Override
65      @Deprecated
66      public String getPath() {
67          return path();
68      }
69  
70      @Override
71      @Deprecated
72      public String getComment() {
73          return comment();
74      }
75  
76      @Override
77      @Deprecated
78      public String comment() {
79          return comment;
80      }
81  
82      @Override
83      @Deprecated
84      public void setComment(String comment) {
85          this.comment = validateValue("comment", comment);
86      }
87  
88      @Override
89      @Deprecated
90      public String getCommentUrl() {
91          return commentUrl();
92      }
93  
94      @Override
95      @Deprecated
96      public String commentUrl() {
97          return commentUrl;
98      }
99  
100     @Override
101     @Deprecated
102     public void setCommentUrl(String commentUrl) {
103         this.commentUrl = validateValue("commentUrl", commentUrl);
104     }
105 
106     @Override
107     @Deprecated
108     public boolean isDiscard() {
109         return discard;
110     }
111 
112     @Override
113     @Deprecated
114     public void setDiscard(boolean discard) {
115         this.discard = discard;
116     }
117 
118     @Override
119     @Deprecated
120     public Set<Integer> getPorts() {
121         return ports();
122     }
123 
124     @Override
125     @Deprecated
126     public Set<Integer> ports() {
127         if (unmodifiablePorts == null) {
128             unmodifiablePorts = Collections.unmodifiableSet(ports);
129         }
130         return unmodifiablePorts;
131     }
132 
133     @Override
134     @Deprecated
135     public void setPorts(int... ports) {
136         ObjectUtil.checkNotNull(ports, "ports");
137 
138         int[] portsCopy = ports.clone();
139         if (portsCopy.length == 0) {
140             unmodifiablePorts = this.ports = Collections.emptySet();
141         } else {
142             Set<Integer> newPorts = new TreeSet<Integer>();
143             for (int p: portsCopy) {
144                 if (p <= 0 || p > 65535) {
145                     throw new IllegalArgumentException("port out of range: " + p);
146                 }
147                 newPorts.add(Integer.valueOf(p));
148             }
149             this.ports = newPorts;
150             unmodifiablePorts = null;
151         }
152     }
153 
154     @Override
155     @Deprecated
156     public void setPorts(Iterable<Integer> ports) {
157         Set<Integer> newPorts = new TreeSet<Integer>();
158         for (int p: ports) {
159             if (p <= 0 || p > 65535) {
160                 throw new IllegalArgumentException("port out of range: " + p);
161             }
162             newPorts.add(Integer.valueOf(p));
163         }
164         if (newPorts.isEmpty()) {
165             unmodifiablePorts = this.ports = Collections.emptySet();
166         } else {
167             this.ports = newPorts;
168             unmodifiablePorts = null;
169         }
170     }
171 
172     @Override
173     @Deprecated
174     public long getMaxAge() {
175         return maxAge();
176     }
177 
178     @Override
179     @Deprecated
180     public int getVersion() {
181         return version();
182     }
183 
184     @Override
185     @Deprecated
186     public int version() {
187         return version;
188     }
189 
190     @Override
191     @Deprecated
192     public void setVersion(int version) {
193         this.version = version;
194     }
195 }