blob: 54d70f9f49eb6aefecd7b9f87363b8a29385f591 [file] [log] [blame]
Meki Cherkaouib0365a72012-02-18 00:59:57 -08001
2var CCNProtocolDTags = require('./CCNProtocolDTags').CCNProtocolDTags;
3
4var ContentName = function ContentName(_Components){
5
6
7 this.SCHEME = "ccnx:";
8
9 this.ORIGINAL_SCHEME = "ccn:";
10
11 this.SEPARATOR = "/";
12 this.ROOT = null;
13
14 this.Components = _Components;
15};
16
17exports.ContentName = ContentName;
18
19ContentName.prototype.decode = function(/*XMLDecoder*/ decoder) {
20 decoder.readStartElement(this.getElementLabel());
21
22 this.Components = new Array(); //new ArrayList<byte []>();
23
24 while (decoder.peekStartElement(CCNProtocolDTags.Component)) {
25 this.Components.add(decoder.readBinaryElement(CCNProtocolDTags.Component));
26 }
27
28 decoder.readEndElement();
29};
30
31ContentName.prototype.encode = function(/*XMLEncoder*/ encoder) {
32 //if (!validate()) {
33 //throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
34 //}
35
36 encoder.writeStartElement(this.getElementLabel());
37 var count = this.Components.length;
38 for (var i=0; i < count; ++i) {
39 encoder.writeElement(CCNProtocolDTags.Component, this.Components.get(i));
40 }
41 encoder.writeEndElement();
42};
43
44ContentName.prototype.getElementLabel = function(){
45 return CCNProtocolDTags.Name;
46};