/* <copyright>
Copyright (c) 2012, Motorola Mobility LLC.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Motorola Mobility LLC nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</copyright> */
/**
@module montage/data/blueprint
@requires montage/core/core
@requires montage/data/store
@requires montage/data/object-id
@requires data/query
@requires core/exception
@requires data/object-property
@requires core/promise
@requires core/logger
*/
var Montage = require("montage").Montage;
var MappingFolder = require("data/mapping").MappingFolder;
var TemporaryObjectId = require("data/object-id").TemporaryObjectId;
var Query = require("data/query").Query;
var ObjectProperty = require("data/object-property").ObjectProperty;
var Promise = require("core/promise").Promise;
var Exception = require("core/exception").Exception;
var logger = require("core/logger").logger("blueprint");
/**
@private
*/
var _binderManager = null;
/**
@class module:montage/data/blueprint.BlueprintBinderManager
@classdesc A blueprint binder manager is a singleton that is responsible for loading and dispaching binders and blueprints.
@extends module:montage/core/core.Montage
*/
var BlueprintBinderManager = exports.BlueprintBinderManager = Montage.create(Montage, /** @lends module:montage/data/blueprint.BlueprintBinderManager# */ {
/**
Description TODO
@function
@returns itself
*/
init:{
serializable:false,
enumerable:false,
value:function () {
return this;
}
},
/**
Description TODO
@type {Property} Function
@default {Array} new Array(10)
*/
blueprintBinders:{
serializable:true,
writable:false,
distinct:true,
value:new Array(10)
},
/**
Add a new blueprint binder.
@function
@param {Property} binder TODO
*/
addBlueprintBinder:{
value:function (binder) {
if (binder !== null) {
var index = this.blueprintBinders.indexOf(binder);
if (index >= 0) {
this.blueprintBinders.splice(index, 1);
}
this.blueprintBinders.push(binder);
}
}
},
/**
Description TODO
@function
@param {Property} binder TODO
*/
removeBlueprintBinder:{
value:function (binder) {
if (binder !== null) {
var index = this.blueprintBinders.indexOf(binder);
if (index >= 0) {
this.blueprintBinders.splice(index, 1);
}
}
}
},
/**
Search through the binders for a blueprint that extends that prototype.
@function
@param {Property} prototypeName TODO
@param {Property} moduleId TODO
@returns The requested blueprint or null if this prototype is not managed.
*/
blueprintForPrototype: {
value: function(prototypeName, moduleId) {
var binder, blueprint, index;
for (index = 0; typeof (binder = this.blueprintBinders[index]) !== "undefined"; index++) {
blueprint = binder.blueprintForPrototype(prototypeName, moduleId);
if (blueprint !== null) {
return blueprint;
}
}
return null;
}
}
});
var BlueprintObject = exports.BlueprintObject = Montage.create(Montage, /** @lends module:montage/data/blueprint.BlueprintObject# */ {
/**
@private
*/
_name:{
serializable:true,
enumerable:false,
value:null
},
/**
Name of the object. The name is used to define the property on the object.
@function
@returns {String} this._name
*/
name:{
get:function () {
return this._name;
}
},
/**
@private
*/
_mappings:{
serializable:true,
enumerable:false,
distinct:true,
value: new Array(5)
},
/**
@private
*/
_mappingForName:{
value:{},
serializable:false,
distinct:true,
enumerable:false,
writable:false
},
deserializedFromSerialization:{
value:function () {
var aMapping, index;
for (index = 0; typeof (aMapping = this._mappings[index]) !== "undefined"; index++) {
this._mappingForName[aMapping.name] = aMapping;
}
}
},
/**
List of mappings attached to this object.
@function
@returns mappings
*/
mappings:{
get:function () {
return this._mappings;
}
},
/**
Add a mapping to the list of mappings.
@function
@param {mapping} mapping to add.
@returns mapping
*/
addMapping:{
value:function (mapping) {
if (mapping !== null) {
var index = this.mappings.indexOf(mapping);
if (index < 0) {
if (mapping.owner !== this) {
throw new Error(
"Mapping already owned: " + JSON.stringify(mapping));
}
this.mappings.push(mapping);
//
this._addMappingForName(mapping);
}
}
return mapping;
}
},
/**
Remove a mapping to the list of mappings.
@function
@param {mapping} mapping to remove.
@returns mapping
*/
removeMapping:{
value:function (mapping) {
if (mapping !== null) {
var index = this.mappings.indexOf(mapping);
if (index >= 0) {
this.mappings.splice(index, 1);
// Remove the cached entry
this._removeMappingForName(mapping);
}
}
return mapping;
}
},
/*
* @private
*/
_addMappingForName:{
value:function (mapping) {
this._mappingForName[mapping.name] = mapping;
return mapping;
}
},
/*
* @private
*/
_removeMappingForName:{
value:function (mapping) {
delete this._mappingForName[mapping.name];
return mapping;
}
},
/**
Retrieve a mapping from the list of mappings.<br/>
<b>Note:<b/> For Binder objects this function will return an array of mapping: One for each of the store used by the mapping name.
@function
@param {name} name of the mapping to retrieve.
@returns mapping
*/
mappingForName:{
value:function (name) {
return this._mappingForName[name];
}
}
});
/**
@class module:montage/data/blueprint.BlueprintBinder
@classdesc A blueprint binder is a collection of of blueprints for a specific access type. It also includes the connection information.
@extends module:montage/core/core.Montage
*/
var BlueprintBinder = exports.BlueprintBinder = Montage.create(BlueprintObject, /** @lends module:montage/data/blueprint.BlueprintBinder# */ {
/**
Returns the blueprint binder manager.
@type {Property}
@returns Blueprint Binder Manager
*/
manager:{
get:function () {
if (_binderManager === null) {
_binderManager = BlueprintBinderManager.create().init();
}
return _binderManager;
}
},
/**
Description TODO
@private
*/
_blueprintForPrototypeTable:{
value:{},
serializable:false,
distinct:true,
enumerable:false,
writable:false
},
/**
Description TODO
@type {Property}
@default {Table} {}
*/
restrictionsTable:{
value:{},
serializable:true,
distinct:true,
enumerable:false,
writable:false
},
/**
Description TODO
@function
@param {String} name TODO
@returns itself
*/
initWithName:{
value:function (name) {
this.name = (name !== null ? name : "default");
return this;
}
},
/**
Description TODO
|