return new tizen.NDEFMessage();
}
- return new tizen.NDEFMessage(result.records);
+ return new tizen.NDEFMessage(toRecordsArray(result.records));
};
NFCAdapter.prototype.setExclusiveModeForTransaction = function() {
native_.call('NFCAdapter_getAIDsForCategory', data, callback);
};
+function InternalRecordData(tnf, type, payload, id) {
+ this.tnf = tnf;
+ this.type = type;
+ this.payload = payload;
+ this.id = id;
+};
+
+var toRecordsArray = function(array) {
+ var result = [];
+ if (type_.isNullOrUndefined(array) || !type_.isArray(array)) {
+ return result;
+ }
+
+ for (var i = 0; i < array.length; i++) {
+ var data = new InternalRecordData(array[i].tnf, array[i].type, array[i].payload, array[i].id);
+
+ if (array[i].recordType == 'Record') {
+ result.push(new tizen.NDEFRecord(data.tnf_, data.type_, data.payload_, data.id_));
+ continue;
+ }
+
+ if (array[i].recordType == 'RecordText') {
+ result.push(new tizen.NDEFRecordText(array[i].text, array[i].languageCode,
+ array[i].encoding, data));
+ continue;
+ }
+
+ if (array[i].recordType == 'RecordURI') {
+ result.push(new tizen.NDEFRecordURI(array[i].uri, data));
+ continue;
+ }
+
+ if (array[i].recordType == 'RecordMedia') {
+ result.push(new tizen.NDEFRecordMedia(array[i].mimeType, array[i].data, data));
+ continue;
+ }
+ }
+
+ return result;
+};
+
//////////////////NFCTag /////////////////
function NFCTag(tagid) {
args.errorCallback(native_.getErrorObject(result));
}
} else {
- var message = new tizen.NDEFMessage(result.records);
+ var message = new tizen.NDEFMessage(toRecordsArray(result.records));
args.readCallback(message);
}
});
};
//////////////////NDEFRecordText /////////////////
-tizen.NDEFRecordText = function(text, languageCode, encoding) {
+tizen.NDEFRecordText = function(text, languageCode, encoding, internal_) {
var text_ = undefined;
var languageCode_ = undefined;
var encoding_ = NDEFRecordTextEncoding[encoding] ?
text_ = converter_.toString(text);
languageCode_ = converter_.toString(languageCode);
- var result = native_.callSync(
- 'NDEFRecordText_constructor', {
- 'text': text_,
- 'languageCode' : languageCode_,
- 'encoding' : encoding_
- }
- );
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
+ if (!type_.isNullOrUndefined(internal_) && (internal_ instanceof InternalRecordData)) {
+ tizen.NDEFRecord.call(this, internal_.tnf_, internal_.type_, internal_.payload_, internal_.id_);
+ } else {
+ var result = native_.callSync(
+ 'NDEFRecordText_constructor', {
+ 'text': text_,
+ 'languageCode' : languageCode_,
+ 'encoding' : encoding_
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ tizen.NDEFRecord.call(this, result.result.tnf, result.result.type,
+ result.result.payload, result.result.id);
}
- tizen.NDEFRecord.call(this, result.result.tnf, result.result.type,
- result.result.payload, result.result.id);
} else {
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
tizen.NDEFRecordText.prototype.constructor = tizen.NDEFRecordText;
//////////////////NDEFRecordURI /////////////////
-tizen.NDEFRecordURI = function(uri) {
+tizen.NDEFRecordURI = function(uri, internal_) {
var uri_ = undefined;
try {
if (arguments.length >= 1) {
uri_ = converter_.toString(uri);
- var result = native_.callSync(
- 'NDEFRecordURI_constructor', {
- 'uri': uri_
- }
- );
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
+ if (!type_.isNullOrUndefined(internal_) && (internal_ instanceof InternalRecordData)) {
+ tizen.NDEFRecord.call(this, internal_.tnf_, internal_.type_, internal_.payload_, internal_.id_);
+ } else {
+ var result = native_.callSync(
+ 'NDEFRecordURI_constructor', {
+ 'uri': uri_
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ tizen.NDEFRecord.call(this, result.result.tnf, result.result.type,
+ result.result.payload, result.result.id);
}
- tizen.NDEFRecord.call(this, result.result.tnf, result.result.type,
- result.result.payload, result.result.id);
} else {
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
tizen.NDEFRecordURI.prototype.constructor = tizen.NDEFRecordURI;
//////////////////NDEFRecordMedia /////////////////
-tizen.NDEFRecordMedia = function(mimeType, data) {
+tizen.NDEFRecordMedia = function(mimeType, data, internal_) {
var mimeType_ = undefined;
var data_ = undefined;
try {
mimeType_ = converter_.toString(mimeType);
data_ = toByteArray(data, Math.pow(2, 32) - 1);
- var result = native_.callSync(
- 'NDEFRecordMedia_constructor', {
- 'mimeType': mimeType_,
- 'data': data_,
- 'dataSize': data_.length
- }
- );
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
+ if (!type_.isNullOrUndefined(internal_) && (internal_ instanceof InternalRecordData)) {
+ tizen.NDEFRecord.call(this, internal_.tnf_, internal_.type_, internal_.payload_, internal_.id_);
+ } else {
+ var result = native_.callSync(
+ 'NDEFRecordMedia_constructor', {
+ 'mimeType': mimeType_,
+ 'data': data_,
+ 'dataSize': data_.length
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ tizen.NDEFRecord.call(this, result.result.tnf, result.result.type,
+ result.result.payload, result.result.id);
}
- tizen.NDEFRecord.call(this, result.result.tnf, result.result.type,
- result.result.payload, result.result.id);
} else {
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}