Meki Cherkaoui | b0365a7 | 2012-02-18 00:59:57 -0800 | [diff] [blame^] | 1 | |
| 2 | var CCNProtocolDTags = require('./CCNProtocolDTags').CCNProtocolDTags; |
| 3 | |
| 4 | var 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 | |
| 17 | exports.ContentName = ContentName; |
| 18 | |
| 19 | ContentName.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 | |
| 31 | ContentName.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 | |
| 44 | ContentName.prototype.getElementLabel = function(){ |
| 45 | return CCNProtocolDTags.Name; |
| 46 | }; |