Source: synchronization/endpoint/mobile-resource.js

/**
 * Copyright© 2016, Oracle and/or its affiliates. All rights reserved.
 */

/**
 * Base class for MobileObject, MobileCollection and MobileFile.
 * @abstract
 * @constructor
 * @global
 */
function MobileResource(endpoint, uri) {

  if (this.constructor === MobileResource) {
    throw new Error("Can't instantiate abstract class!");
  }

  var _uri = uri;
  var _endpoint = endpoint;

  this._getEndpoint = function(){
    return _endpoint;
  };

  this._getMcsId = function(){
    return _uri ? _uri.substring(_uri.lastIndexOf('/') + 1, _uri.length) : null;
  };

  this._getMcsURI = function(){
    return _uri;
  };


  // TODO: next version release
  // /**
  //  * The time that this resource was last synchronized, null if it was never synchronized ex if it was just created locally.
  //  * @type {Date}
  //  * @readonly
  //  */
  // this.lastSyncTime = null;
  // Object.defineProperty(this, "lastSyncTime", {
  //   get: function() {
  //     return this._syncResource == null ? null : new Date(this._syncResource.lastSyncTime);
  //   }
  // });

  // TODO: next version release
  // /**
  //  * Returns true if the resource has pending offline updates, false otherwise.
  //  * @type {Boolean}
  //  * @readonly
  //  */
  // Object.defineProperty(this, "hasOfflineUpdates", {
  //   get: function() {
  //     return this._syncResource != null && this._syncResource.offlineState != mcs._OfflineState.noOfflineUpdates;
  //   }
  // });

  // TODO: next version release
  // /**
  //  * Returns true if this resource is pinned, false otherwise.
  //  * @type {Boolean}
  //  * @readonly
  //  */
  // this.isPinned = null;
  // Object.defineProperty(this, "isPinned", {
  //   get: function() {
  //     return this._syncResource == null ? false : this._syncResource.pinState != mcs._PinState.unpinned;
  //   }
  // });

  // TODO: next version release
  // /**
  //  * Callback invoked after successfully pinning or unpinning.
  //  * @callback MobileResource~successCallback
  //  * @param mobileObject {MobileObject} The saved MobileObject instance which the server may have updated.
  //  */
  //
  // /**
  //  * Callback invoked on error.
  //  * @callback MobileResource~errorCallback
  //  * @param statusCode {Number} Any HTTP status code returned from the server, if available.
  //  * @param headers {Array} The HTTP headers returned from the server, if available.
  //  * @param message {String} The HTTP payload from the server, if available, or an error message.
  //  */
  //
  // /**
  //  * Pins this resource so that it will be available for offline access. Pinned resources are available for offline
  //  * access and can be synchronized in a batch by calling [SynchronizePinnedResources]{@link Synchronizer#SynchronizePinnedResources}.
  //  * @param successCallback {MobileResource~successCallback} Callback invoked on success.
  //  * @param errorCallback {MobileResource~errorCallback} Callback invoked on error.
  //  */
  // this.pin = function(successCallback, errorCallback) {
  //   if(this._syncResource != null) {
  //     this._getEndpoint().synchronization._pin(this._syncResource, successCallback, errorCallback);
  //   }
  // };

  // TODO: next version release
  // /**
  //  * Unpins this resource.
  //  * @param successCallback {MobileResource~successCallback} Callback invoked on success.
  //  * @param errorCallback {MobileResource~errorCallback} Callback invoked on error.
  //  */
  // this.unpin = function(successCallback, errorCallback) {
  //   if(this._syncResource != null) {
  //     this._getEndpoint().synchronization._unpin(this._syncResource, successCallback, errorCallback);
  //   }
  // };

  // TODO: next version release
  // /**
  //  * Discards any udpates made to this resource and reloads the data.
  //  * @param discardOfflineUpdates {Boolean} If true will delete all offline updates from the cache.
  //  * @param reloadFromService {Boolean} If true will reload from the service if online or from the cache if offline.
  //  * @param successCallback {MobileResource~successCallback} Callback invoked on success.
  //  * @param errorCallback {MobileResource~errorCallback} Callback invoked on error.
  //  */
  // this.reload = function(discardOfflineUpdates, reloadFromService, successCallback, errorCallback) {
  //   this._getEndpoint()._reload(this._type == mcs._SyncResourceType.file, this, discardOfflineUpdates, reloadFromService, successCallback, errorCallback);
  // };
}