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    *   http://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 java.util.Collections;
19  import java.util.Set;
20  import java.util.TreeSet;
21  
22  /**
23   * The default {@link Cookie} implementation.
24   *
25   * @deprecated Use {@link io.netty.handler.codec.http.cookie.DefaultCookie} instead.
26   */
27  @Deprecated
28  public class DefaultCookie extends io.netty.handler.codec.http.cookie.DefaultCookie implements Cookie {
29  
30      private String comment;
31      private String commentUrl;
32      private boolean discard;
33      private Set<Integer> ports = Collections.emptySet();
34      private Set<Integer> unmodifiablePorts = ports;
35      private int version;
36  
37      /**
38       * Creates a new cookie with the specified name and value.
39       */
40      public DefaultCookie(String name, String value) {
41          super(name, value);
42      }
43  
44      @Override
45      @Deprecated
46      public String getName() {
47          return name();
48      }
49  
50      @Override
51      @Deprecated
52      public String getValue() {
53          return value();
54      }
55  
56      @Override
57      @Deprecated
58      public String getDomain() {
59          return domain();
60      }
61  
62      @Override
63      @Deprecated
64      public String getPath() {
65          return path();
66      }
67  
68      @Override
69      @Deprecated
70      public String getComment() {
71          return comment();
72      }
73  
74      @Override
75      @Deprecated
76      public String comment() {
77          return comment;
78      }
79  
80      @Override
81      @Deprecated
82      public void setComment(String comment) {
83          this.comment = validateValue("comment", comment);
84      }
85  
86      @Override
87      @Deprecated
88      public String getCommentUrl() {
89          return commentUrl();
90      }
91  
92      @Override
93      @Deprecated
94      public String commentUrl() {
95          return commentUrl;
96      }
97  
98      @Override
99      @Deprecated
100     public void setCommentUrl(String commentUrl) {
101         this.commentUrl = validateValue("commentUrl", commentUrl);
102     }
103 
104     @Override
105     @Deprecated
106     public boolean isDiscard() {
107         return discard;
108     }
109 
110     @Override
111     @Deprecated
112     public void setDiscard(boolean discard) {
113         this.discard = discard;
114     }
115 
116     @Override
117     @Deprecated
118     public Set<Integer> getPorts() {
119         return ports();
120     }
121 
122     @Override
123     @Deprecated
124     public Set<Integer> ports() {
125         if (unmodifiablePorts == null) {
126             unmodifiablePorts = Collections.unmodifiableSet(ports);
127         }
128         return unmodifiablePorts;
129     }
130 
131     @Override
132     @Deprecated
133     public void setPorts(int... ports) {
134         if (ports == null) {
135             throw new NullPointerException("ports");
136         }
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 }