01: /*
02: HttpdBase4J: An embeddable Java web server framework that supports HTTP, HTTPS,
03: templated content and serving content from inside a jar or archive.
04: Copyright (C) 2007 Donald Munro
05:
06: This library is free software; you can redistribute it and/or
07: modify it under the terms of the GNU Lesser General Public
08: License as published by the Free Software Foundation; either
09: version 2.1 of the License, or (at your option) any later version.
10:
11: This library is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public
17: License along with this library; if not,see http://www.gnu.org/licenses/lgpl.txt
18: */
19:
20: package net.homeip.donaldm.httpdbase4j;
21:
22: import com.sun.net.httpserver.Headers;
23: import java.util.Iterator;
24: import java.util.List;
25: import java.util.Map;
26: import java.util.Set;
27:
28: /**
29: * Wrapper for com.sun.net.httpserver.Headers that implements the Clonable
30: * interface and a copy constructor
31: * @author Donald Munro
32: */
33: public class CloneableHeaders extends Headers implements Cloneable
34: //----------------------------------------------------------------
35: {
36: /**
37: * Create a new CloneableHeaders instance
38: */
39: public CloneableHeaders() {
40: super ();
41: }
42:
43: /**
44: * Copy a new CloneableHeaders instance
45: * @param h Headers instance to copy
46: */
47: public CloneableHeaders(Headers h) {
48: super ();
49: if (h != null) {
50: Set<Map.Entry<String, List<String>>> entries = h.entrySet();
51: _copyTo(entries, this );
52: }
53: }
54:
55: /**
56: * @inheritDoc
57: */
58: protected Object clone() throws CloneNotSupportedException
59: //--------------------------------------------------------
60: {
61: Headers klone = (Headers) super .clone();
62: Set<Map.Entry<String, List<String>>> entries = entrySet();
63: return _copyTo(entries, klone);
64: }
65:
66: private Headers _copyTo(
67: Set<Map.Entry<String, List<String>>> entries, Headers klone)
68: //-------------------------------------------------------------------
69: {
70: klone.clear();
71: for (Iterator<Map.Entry<String, List<String>>> i = entries
72: .iterator(); i.hasNext();) {
73: Map.Entry<String, List<String>> e = i.next();
74: String k = e.getKey();
75: List<String> l = e.getValue();
76: for (Iterator<String> j = l.iterator(); j.hasNext();)
77: klone.add(k, j.next());
78: }
79: return klone;
80: }
81:
82: }
|