KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > exchange > simple > PacketImpl


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.exchange.simple;
14
15 import info.magnolia.exchange.Packet;
16 import info.magnolia.exchange.PacketBody;
17 import info.magnolia.exchange.PacketHeader;
18 import info.magnolia.exchange.PacketType;
19
20 import java.util.Iterator JavaDoc;
21
22 import org.apache.log4j.Logger;
23 import org.doomdark.uuid.UUIDGenerator;
24
25
26 /**
27  * Date: May 4, 2004 Time: 5:09:41 PM
28  * @author Sameer Charles
29  */

30 public class PacketImpl implements Packet {
31
32     private static Logger log = Logger.getLogger(PacketImpl.class);
33
34     private String JavaDoc id;
35
36     private PacketHeader header;
37
38     private PacketBody body;
39
40     public PacketImpl() {
41         this.header = new PacketHeaderImpl();
42         this.body = new PacketBodyImpl();
43     }
44
45     public String JavaDoc getID() {
46         return this.id;
47     }
48
49     public void assignID() {
50         this.id = UUIDGenerator.getInstance().generateTimeBasedUUID().toString();
51         this.getHeaders().addHeader("id", id); //$NON-NLS-1$
52
}
53
54     public void assignID(String JavaDoc id) {
55         this.id = id;
56         this.getHeaders().addHeader("ID", id); //$NON-NLS-1$
57
}
58
59     public void setChannelID(String JavaDoc id) {
60         log.debug("Method not implemented (setChannelID)"); //$NON-NLS-1$
61
}
62
63     public String JavaDoc getChannelID() {
64         log.debug("Method not implemented (getChannelID)"); //$NON-NLS-1$
65
return null;
66     }
67
68     public PacketHeader getHeaders() {
69         return this.header;
70     }
71
72     public void setHeaders(PacketHeader header) {
73         /**
74          * Add key by key to make sure we dont loose any existing keys assigned to this header object.
75          */

76         Iterator JavaDoc keys = header.getKeys().iterator();
77         while (keys.hasNext()) {
78             String JavaDoc key = (String JavaDoc) keys.next();
79             this.header.addHeader(key, header.getValueByName(key));
80         }
81     }
82
83     public void setBody(PacketBody body) {
84         this.body = body;
85         this.getHeaders().addHeader("Type", PacketType.getNameByType(this.body.getType())); //$NON-NLS-1$
86
}
87
88     public PacketBody getBody() {
89         return this.body;
90     }
91 }
92
Popular Tags