Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * @author: ucla-cs |
| 3 | * This class represents ContentName |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | var 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 | |
| 37 | ContentName.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 | |
| 50 | ContentName.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 | |
| 62 | ContentName.prototype.getElementLabel = function(){ |
| 63 | return CCNProtocolDTags.Name; |
| 64 | }; |
| 65 | |
| 66 | ContentName.prototype.add = function(param){ |
| 67 | return this.Components.push(param); |
| 68 | }; |
| 69 | |