Meki Cherkaoui | 97e7a59 | 2012-04-14 02:50:06 -0700 | [diff] [blame^] | 1 | |
| 2 | var ContentObject = function ContentObject(_Name,_SignedInfo,_Content,_Signature){ |
| 3 | |
| 4 | |
| 5 | if (typeof _Name === 'string'){ |
| 6 | var n = new Name(_Name); |
| 7 | } |
| 8 | else{ |
| 9 | //TODO Check the class of _Name |
| 10 | this.Name = _Name; |
| 11 | } |
| 12 | this.SignedInfo = _SignedInfo; |
| 13 | this.Content=_Content; |
| 14 | this.Signature = _Signature; |
| 15 | |
| 16 | }; |
| 17 | |
| 18 | |
| 19 | ContentObject.prototype.decode = function(/*XMLDecoder*/ decoder) { |
| 20 | |
| 21 | decoder.readStartElement(this.getElementLabel()); |
| 22 | |
| 23 | this.Signature = new Signature(); |
| 24 | this.Signature.decode(decoder); |
| 25 | |
| 26 | this.Name = new ContentName(); |
| 27 | this.Name.decode(decoder); |
| 28 | |
| 29 | this.SignedInfo = new SignedInfo(); |
| 30 | this.SignedInfo.decode(decoder); |
| 31 | |
| 32 | this.Content = decoder.readBinaryElement(CCNProtocolDTags.Content); |
| 33 | |
| 34 | decoder.readEndElement(); |
| 35 | |
| 36 | }; |
| 37 | |
| 38 | ContentObject.prototype.encode = function(/*XMLEncoder*/ encoder) { |
| 39 | |
| 40 | /*if((null == this.Name) && (null==this.SignedInfo) && (null ==this.Signature)){ |
| 41 | |
| 42 | throw "Illegal input inside encode of Content Object"; |
| 43 | }*/ |
| 44 | /* |
| 45 | * if (!validate()) { |
| 46 | throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing."); |
| 47 | }*/ |
| 48 | |
| 49 | encoder.writeStartElement(this.getElementLabel()); |
| 50 | |
| 51 | if(null!=this.Signature) this.Signature.encode(encoder); |
| 52 | if(null!=this.Name) this.Name.encode(encoder); |
| 53 | if(null!=this.SignedInfo) this.SignedInfo.encode(encoder); |
| 54 | |
| 55 | encoder.writeElement(CCNProtocolDTags.Content, this.Content); |
| 56 | |
| 57 | encoder.writeEndElement(); |
| 58 | |
| 59 | }; |
| 60 | |
| 61 | ContentObject.prototype.getElementLabel= function(){return CCNProtocolDTags.ContentObject;}; |