Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * @author: ucla-cs |
| 3 | * This class represents ContentObject Objects |
| 4 | */ |
| 5 | var ContentObject = function ContentObject(_Name,_SignedInfo,_Content,_Signature){ |
| 6 | |
| 7 | |
| 8 | if (typeof _Name === 'string'){ |
| 9 | var n = new Name(_Name); |
| 10 | } |
| 11 | else{ |
| 12 | //TODO Check the class of _Name |
| 13 | this.Name = _Name; |
| 14 | } |
| 15 | this.SignedInfo = _SignedInfo; |
| 16 | this.Content=_Content; |
| 17 | this.Signature = _Signature; |
| 18 | |
| 19 | }; |
| 20 | |
| 21 | |
| 22 | ContentObject.prototype.decode = function(/*XMLDecoder*/ decoder) { |
| 23 | |
| 24 | decoder.readStartElement(this.getElementLabel()); |
| 25 | |
| 26 | this.Signature = new Signature(); |
| 27 | this.Signature.decode(decoder); |
| 28 | |
| 29 | this.Name = new ContentName(); |
| 30 | this.Name.decode(decoder); |
| 31 | |
| 32 | this.SignedInfo = new SignedInfo(); |
| 33 | this.SignedInfo.decode(decoder); |
| 34 | |
| 35 | this.Content = decoder.readBinaryElement(CCNProtocolDTags.Content); |
| 36 | |
| 37 | decoder.readEndElement(); |
| 38 | |
| 39 | }; |
| 40 | |
| 41 | ContentObject.prototype.encode = function(/*XMLEncoder*/ encoder) { |
| 42 | |
| 43 | //TODO verify Name, SignedInfo and Signature is present |
| 44 | |
| 45 | |
| 46 | encoder.writeStartElement(this.getElementLabel()); |
| 47 | |
| 48 | if(null!=this.Signature) this.Signature.encode(encoder); |
| 49 | if(null!=this.Name) this.Name.encode(encoder); |
| 50 | if(null!=this.SignedInfo) this.SignedInfo.encode(encoder); |
| 51 | |
| 52 | encoder.writeElement(CCNProtocolDTags.Content, this.Content); |
| 53 | |
| 54 | encoder.writeEndElement(); |
| 55 | |
| 56 | }; |
| 57 | |
| 58 | ContentObject.prototype.getElementLabel= function(){return CCNProtocolDTags.ContentObject;}; |