KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > message > MimeHeaders


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.message;
18
19 import javax.xml.soap.MimeHeader JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.ObjectInput JavaDoc;
22 import java.io.ObjectOutput JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 /**
26  * wraps javax.xml.soap.MimeHeaders and implements java.io.Serializable interface
27  */

28 public class MimeHeaders extends javax.xml.soap.MimeHeaders JavaDoc
29         implements java.io.Externalizable JavaDoc {
30     public MimeHeaders() {
31     }
32
33     public MimeHeaders(javax.xml.soap.MimeHeaders JavaDoc h) {
34         Iterator JavaDoc iterator = h.getAllHeaders();
35         while (iterator.hasNext()) {
36             MimeHeader JavaDoc hdr = (MimeHeader JavaDoc) iterator.next();
37             addHeader(hdr.getName(), hdr.getValue());
38         }
39     }
40
41     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
42         int size = in.readInt();
43         for (int i = 0; i < size; i++) {
44             Object JavaDoc key = in.readObject();
45             Object JavaDoc value = in.readObject();
46             addHeader((String JavaDoc)key, (String JavaDoc)value);
47         }
48     }
49
50     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
51         out.writeInt(getHeaderSize());
52         Iterator JavaDoc iterator = getAllHeaders();
53         while (iterator.hasNext()) {
54             MimeHeader JavaDoc hdr = (MimeHeader JavaDoc) iterator.next();
55             out.writeObject(hdr.getName());
56             out.writeObject(hdr.getValue());
57         }
58     }
59
60     private int getHeaderSize() {
61         int size = 0;
62         Iterator JavaDoc iterator = getAllHeaders();
63         while (iterator.hasNext()) {
64             iterator.next();
65             size++;
66         }
67         return size;
68     }
69 }
70
Popular Tags