blob: bec84829860448826182416a4ee3f88c7fa2142b [file] [log] [blame]
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07001/*
2 * @author: ucla-cs
3 * This class represents ContentName
4 */
5
6
7var ContentName = function ContentName(_Components){
8
9
10 this.SCHEME = "ccnx:";
11
12 this.ORIGINAL_SCHEME = "ccn:";
13
14 this.SEPARATOR = "/";
15 this.ROOT = null;
16
17 if( typeof _Components == 'string') {
18 this.Components = _Components;
19
20
21 }
22 else if(typeof _Components === 'object' && _Components instanceof Array ){
23
24 this.Components = _Components;
25
26 }
27 else{
28
29 console.log("TODO: This should be an array");
30 this.Components==_Components;
31 }
32};
33
34
35
36
37ContentName.prototype.decode = function(/*XMLDecoder*/ decoder) {
38 decoder.readStartElement(this.getElementLabel());
39
40
41 this.Components = new Array(); //new ArrayList<byte []>();
42
43 while (decoder.peekStartElement(CCNProtocolDTags.Component)) {
44 this.add(decoder.readBinaryElement(CCNProtocolDTags.Component));
45 }
46
47 decoder.readEndElement();
48};
49
50ContentName.prototype.encode = function(/*XMLEncoder*/ encoder) {
51
52 //TODO Check if parameters are valid
53
54 encoder.writeStartElement(this.getElementLabel());
55 var count = this.Components.length;
56 for (var i=0; i < count; i++) {
57 encoder.writeElement(CCNProtocolDTags.Component, this.Components[i]);
58 }
59 encoder.writeEndElement();
60};
61
62ContentName.prototype.getElementLabel = function(){
63 return CCNProtocolDTags.Name;
64};
65
66ContentName.prototype.add = function(param){
67 return this.Components.push(param);
68};
69