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