Beispiel #1
0
 targetRequire.async(blueprintModuleId).then(function(object) {
     try {
         Deserializer.create().initWithObjectAndRequire(object, targetRequire, blueprintModuleId).deserializeObject(function(blueprint) {
             if (blueprint) {
                 var binder = (blueprint._binder ? blueprint._binder : BinderModule.Binder.manager.defaultBinder); // We do not want to trigger the auto registration
                 var existingBlueprint = binder.blueprintForPrototype(blueprint.prototypeName, blueprint.moduleId);
                 if (existingBlueprint) {
                     deferredBlueprint.resolve(existingBlueprint);
                 } else {
                     binder.addBlueprint(blueprint);
                     blueprint.blueprintModuleId = blueprintModuleId;
                     if (blueprint._parentReference) {
                         // We need to grab the parent before we return or most operation will fail
                         blueprint._parentReference.promise(targetRequire).then(function(parentBlueprint) {
                                 blueprint._parent = parentBlueprint;
                                 deferredBlueprint.resolve(blueprint);
                             }
                         );
                     } else {
                         deferredBlueprint.resolve(blueprint);
                     }
                 }
             } else {
                 deferredBlueprint.reject(new Error("No Blueprint found " + blueprintModuleId));
             }
         }, targetRequire);
     } catch (exception) {
         deferredBlueprint.reject(new Error("Error deserializing Blueprint " + blueprintModuleId + " " + JSON.stringfy(exception)));
     }
 }, deferredBlueprint.reject);
Beispiel #2
0
 targetRequire.async(binderModuleId).then(function(object) {
     try {
         Deserializer.create().initWithObjectAndRequire(object, targetRequire, binderModuleId).deserializeObject(function(binder) {
             if (binder) {
                 binder.binderInstanceModuleId = binderModuleId;
                 Binder.manager.addBinder(this);
                 deferredBinder.resolve(binder);
             } else {
                 deferredBinder.reject(new Error("No Binder found " + binderModuleId));
             }
         }, targetRequire);
     } catch (exception) {
         deferredBinder.reject(new Error("Error deserializing Binder " + binderModuleId + " " + JSON.stringfy(exception)));
     }
 }, deferredBinder.reject);
var Montage=require("montage").Montage,Enum=require("core/enum").Enum,Promise=require("core/promise").Promise,Selector=require("core/selector").Selector,Semantics=require("core/selector/semantics").Semantics,Serializer=require("core/serializer").Serializer,Deserializer=require("core/deserializer").Deserializer,logger=require("core/logger").logger("component-description"),ComponentDescription=exports.ComponentDescription=Montage.create(Montage,{_component:{serializable:!1,enumerable:!1,value:null},component:{get:function(){return this._component}},initWithComponent:{value:function(e){return this._component=e,this._component.description=this,this}},getComponentDescriptionFromComponentModule:{value:function(e){var t=Montage.getInfoForObject(e),n=t.moduleId,r=n.lastIndexOf("/"),i=n+"/"+n.slice(r===-1?0:r+1,-5)+"-description.json",s=Promise.defer();return t.require.async(i).then(function(n){Deserializer.create().initWithObjectAndRequire(n,t.require,i).deserializeObject(function(t){t?(t._component=e,s.resolve(t)):s.reject("No Component Description found "+i)},require)},s.reject),s.promise}},identifier:{get:function(){return[this.component.identifier,"description"].join("_")}},_componentPropertyDescriptions:{serializable:!0,enumerable:!1,distinct:!0,value:{}},componentPropertyDescriptions:{get:function(){var e=[],t;for(t in this._componentPropertyDescriptions)e.push(this._componentPropertyDescriptions[t]);return e}},componentPropertyDescriptionForName:{value:function(e){return this._componentPropertyDescriptions[e]}},addComponentPropertyDescription:{value:function(e){var t=this._componentPropertyDescriptions[e];return t==null&&(t=ComponentPropertyDescription.create().initWithPropertyAndComponentDescription(e,this),this._componentPropertyDescriptions[e]=t),t}},removeComponentPropertyDescription:{value:function(e){var t=this._componentPropertyDescriptions[e];return t!=null&&delete this._componentPropertyDescriptions[e],t}},_componentPropertyDescriptionGroups:{serializable:!0,enumerable:!1,distinct:!0,value:{}},componentPropertyDescriptionGroups:{get:function(){var e=[];for(var t in this._componentPropertyDescriptionGroups)e.push(t);return e}},componentPropertyDescriptionGroupForName:{value:function(e){var t=this._componentPropertyDescriptionGroups[e];return t!=null?t:[]}},addComponentPropertyDescriptionGroup:{value:function(e){var t=this._componentPropertyDescriptionGroups[e];return t==null&&(t=[],this._componentPropertyDescriptionGroups[e]=t),t}},removeComponentPropertyDescriptionGroup:{value:function(e){var t=this._componentPropertyDescriptionGroups[e];return t!=null&&delete this._componentPropertyDescriptionGroups[e],t}},addComponentPropertyDescriptionToGroup:{value:function(e,t){var n=this._componentPropertyDescriptionGroups[t];n==null&&(n=this.addComponentPropertyDescriptionGroup(t));var r=this._componentPropertyDescriptions[e];r==null&&(r=this.addComponentPropertyDescription(e));var i=n.indexOf(r);return i<0&&n.push(r),n}},removeComponentPropertyDescriptionFromGroup:{value:function(e,t){var n=this._componentPropertyDescriptionGroups[t],r=this._componentPropertyDescriptions[e];if(n!=null&&r!=null){var i=n.indexOf(r);i>=0&&n.splice(i,1)}return n!=null?n:[]}},_componentPropertyValidationRules:{serializable:!0,enumerable:!1,distinct:!0,value:{}},componentPropertyValidationRules:{get:function(){var e=[];for(var t in this._componentPropertyValidationRules)e.push(this._componentPropertyValidationRules[t]);return e}},componentPropertyValidationRuleForName:{value:function(e){return this._componentPropertyValidationRules[e]}},addComponentPropertyValidationRule:{value:function(e){var t=this._componentPropertyValidationRules[e];return t==null&&(t=ComponentPropertyValidationRule.create().initWithNameAndComponentDescription(e,this),this._componentPropertyValidationRules[e]=t),t}},removeComponentPropertyValidationRule:{value:function(e){var t=this._componentPropertyValidationRules[e];return t!=null&&delete this._componentPropertyValidationRules[e],t}},evaluateRules:{value:function(){var e=[];for(var t in this._componentPropertyValidationRules){var n=this._componentPropertyValidationRules[t];n.evaluateRule()&&e.push(n.messageKey)}return e}}}),ValueType=Enum.create().initWithMembers("string","number","boolean","date","enum","set","list","map","url","object"),ComponentPropertyDescription=exports.ComponentPropertyDescription=Montage.create(Montage,{_componentDescription:{serializable:!0,enumerable:!1,value:null},componentDescription:{get:function(){return this._componentDescription}},_name:{serializable:!0,enumerable:!1,value:""},name:{get:function(){return this._name}},initWithPropertyAndComponentDescription:{value:function(e,t){return this._name=e,this._componentDescription=t,this}},identifier:{get:function(){return[this.componentDescription.identifier,this.name].join("_")}},writable:{get:function(){return Montage.getPropertyProperty(this.componentDescription.component,this.name,"writable")}},serializable:{get:function(){return Montage.getPropertyProperty(this.componentDescription.component,this.name,"serializable")}},distinct:{get:function(){return Montage.getPropertyProperty(this.componentDescription.component,this.name,"distinct")}},_valueType:{serializable:!0,enumerable:!1,value:null},valueType:{serializable:!1,get:function(){return this._valueType===""?"string":this._valueType},set:function(e){this._valueType=e}},_enumValues:{serializable:!0,enumerable:!1,value:null},enumValues:{serializable:!1,get:function(){return this._enumValues?this._enumValues_enumValues:[]},set:function(e){Array.isArray(e)&&(this._enumValues=e)}},helpString:{serializable:!0,value:""}}),ComponentPropertyValidationRule=exports.ComponentPropertyValidationRule=Montage.create(Montage,{_componentDescription:{serializable:!0,enumerable:!1,value:null},componentDescription:{get:function(){return this._componentDescription}},identifier:{get:function(){return[this.componentDescription.identifier,"rule",this.name].join("_")}},_name:{serializable:!0,enumerable:!1,value:""},name:{get:function(){return this._name}},initWithNameAndComponentDescription:{value:function(e,t){return this._name=e,this._componentDescription=t,this}},_validationSelector:{enumerable:!1,value:null},validationSelector:{serializable:!1,get:function(){return this._validationSelector||(this._validationSelector=Selector.false),this._validationSelector},set:function(e){this._validationSelector=e}},_messageKey:{serializable:!0,enumerable:!1,value:""},messageKey:{serializable:!1,get:function(){return!this._messageKey||this._messageKey.length==0?ths._name:this._messageKey},set:function(e){this._messageKey=e}},_propertyValidationEvaluator:{serializable:!1,enumerable:!1,value:null},evaluateRule:{value:function(){if(_propertyValidationEvaluator===null){var e=PropertyValidationSemantics.create().initWithComponentDescription(this.componentDescription);_propertyValidationEvaluator=e.compile(this.selector.syntax)}return _propertyValidationEvaluator(this.componentDescription.component)}}}),PropertyValidationSemantics=exports.PropertyValidationSemantics=Semantics.create(Semantics,{_componentDescription:{serializable:!0,enumerable:!1,value:null},componentDescription:{get:function(){return this._componentDescription}},initWithComponentDescription:{value:function(e){return this._componentDescription=e,this}},compile:{value:function(e,t){Semantics.compile.call(self,e,t)}},operators:{value:{isBound:function(e){return!e}}},evaluators:{value:{isBound:function(e,t){var n=this;return function(r,i){var r=n.count(e(r,i));return t(r,i)}}}}});for(var name in Semantics.operators)PropertyValidationSemantics.operators[name]=Semantics.operators[name];for(var name in Semantics.evaluators)PropertyValidationSemantics.evaluators[name]=Semantics.evaluators[name]
Beispiel #4
0
 _createDeserializer: {value: function(serialization) {
     var rootUrl = this._rootUrl ? this._rootUrl.input : window.location.href;
     return this._deserializer = Deserializer.create().initWithStringAndRequire(this._ownerSerialization = serialization, this._require, rootUrl);
 }},
Beispiel #5
0
 get: function() {
     return this._deserializer || (this._deserializer = Deserializer.create().initWithString(this._rootObjectSerialization));
 }
Beispiel #6
0
Deserializer.defineDeserializationUnit("bindings", function(object, bindings, deserializer) {
    for (var sourcePath in bindings) {
        var binding = bindings[sourcePath],
            dotIndex;

        if (!("boundObject" in binding)) {
            var targetPath = binding["<-"] || binding["<->"] || binding["<<->"];

            if ("<<->" in binding) {
                console.warn("WARNING: <<-> in bindings is deprectated, use <-> only, please update now.")
            }

            if (targetPath) {
                if (targetPath[0] !== "@") {
                    logger.error("Invalid binding syntax '" + targetPath + "', should be in the form of '@label.path'.");
                    throw "Invalid binding syntax '" + targetPath + "'";
                }
            } else {
                logger.error("Invalid binding syntax '" + JSON.stringify(binding) + "'.");
                throw "Invalid binding syntax '" + JSON.stringify(binding) + "'";
            }

            dotIndex = targetPath.indexOf(".");
            binding.boundObject = deserializer.getObjectByLabel(targetPath.slice(1, dotIndex));
            binding.boundObjectPropertyPath = targetPath.slice(dotIndex+1);
            if ("<-" in binding) {
                binding.oneway = true;
            }
        }
        Object.defineBinding(object, sourcePath, binding);
    }
});
"use strict";var Montage=require("montage").Montage,Promise=require("core/promise").Promise,Deserializer=require("core/deserializer").Deserializer,ObjectProperty=require("core/meta/object-property").ObjectProperty,Enum=require("core/enum").Enum,BinderModule=require("core/meta/binder"),BlueprintReference=require("core/meta/blueprint-reference").BlueprintReference,PropertyBlueprint=require("core/meta/property-blueprint").PropertyBlueprint,AssociationBlueprint=require("core/meta/association-blueprint").AssociationBlueprint,DerivedPropertyBlueprint=require("core/meta/derived-property-blueprint").DerivedPropertyBlueprint,PropertyValidationRule=require("core/meta/validation-rule").PropertyValidationRule,logger=require("core/logger").logger("blueprint"),Defaults={name:"default",moduleId:"",prototypeName:"",customPrototype:!1},Blueprint=exports.Blueprint=Montage.create(Montage,{FileExtension:{value:"-blueprint.json"},initWithName:{value:function(e){return this.initWithNameAndModuleId(e,null)}},initWithNameAndModuleId:{value:function(e,t){return this._name=e!==null?e:"default",this.prototypeName=this.name,this.moduleId=t,this.customPrototype=!1,this}},serializeSelf:{value:function(e){e.setProperty("name",this.name),this._binder&&!this.binder.isDefault&&e.setProperty("binder",this._binder,"reference"),e.setProperty("blueprintModuleId",this.blueprintInstanceModuleId),this._parentReference&&e.setProperty("parent",this._parentReference),this._setPropertyWithDefaults(e,"moduleId",this.moduleId),this.prototypeName===this.name&&this._setPropertyWithDefaults(e,"prototypeName",this.prototypeName),this._setPropertyWithDefaults(e,"customPrototype",this.customPrototype),this._propertyBlueprints.length>0&&e.setProperty("propertyBlueprints",this._propertyBlueprints),Object.getOwnPropertyNames(this._propertyBlueprintGroups).length>0&&e.setProperty("propertyBlueprintGroups",this._propertyBlueprintGroups),this._propertyValidationRules.length>0&&e.setProperty("propertyValidationRules",this._propertyValidationRules)}},deserializeSelf:{value:function(e){this._name=e.getProperty("name");var t=e.getProperty("binder");t&&(this._binder=t),this.blueprintInstanceModuleId=e.getProperty("blueprintModuleId"),this._parentReference=e.getProperty("parent"),this.moduleId=this._getPropertyWithDefaults(e,"moduleId"),this.prototypeName=this._getPropertyWithDefaults(e,"prototypeName"),this.prototypeName===""&&(this.prototypeName=this.name),this.customPrototype=this._getPropertyWithDefaults(e,"customPrototype");var n;n=e.getProperty("propertyBlueprints"),n&&(this._propertyBlueprints=n),n=e.getProperty("propertyBlueprintGroups"),n&&(this._propertyBlueprintGroups=n),n=e.getProperty("propertyValidationRules"),n&&(this._propertyValidationRules=n)}},_setPropertyWithDefaults:{value:function(e,t,n){n!=Defaults[t]&&e.setProperty(t,n)}},_getPropertyWithDefaults:{value:function(e,t){var n=e.getProperty(t);return n?n:Defaults[t]}},_name:{value:null},name:{get:function(){return this._name}},create:{value:function(e,t){if(typeof e=="undefined"||Blueprint.isPrototypeOf(e)){var n=Object.getPrototypeOf(Blueprint).create;return n.call(this,typeof e=="undefined"?this:e,t)}var r=Montage.create(e,t);return this.ObjectProperty.applyWithBlueprint(r,this),this.customPrototype=!0,r}},newInstance:{value:function(){var e=this.newInstancePrototype();return e?e.create():null}},newInstancePrototype:{value:function(){var e=this;if(this.customPrototype){var t=Promise.defer();return require.async(this.moduleId,function(e){t.resolve(e)}),t.promise.then(function(t){var n=t[e.prototypeName];return n?n:null})}if(typeof exports[e.prototypeName]=="undefined"){var n=this.parent?this.parent.newInstancePrototype():Montage,r=Montage.create(n,{init:{value:function(){return this}}});this.ObjectProperty.applyWithBlueprint(r,this),exports[e.prototypeName]=r}var i=exports[e.prototypeName];return i?i:null}},ObjectProperty:{serializable:!1,enumerable:!0,get:function(){return this.binder?this.binder.ObjectProperty:BinderModule.Binder.manager.defaultBlueprintObjectProperty}},blueprintInstanceModuleId:{serializable:!1,value:null},getBlueprintWithModuleId:{value:function(e,t){var n=Promise.defer(),r=t;return r||(r=this.require),r.async(e).then(function(t){try{Deserializer.create().initWithObjectAndRequire(t,r,e).deserializeObject(function(t){if(t){var i=t._binder?t._binder:BinderModule.Binder.manager.defaultBinder,s=i.blueprintForPrototype(t.prototypeName,t.moduleId);s?n.resolve(s):(i.addBlueprint(t),t.blueprintInstanceModuleId=e,t._parentReference?t._parentReference.promise(r).then(function(e){t._parent=e,n.resolve(t)}):n.resolve(t))}else n.reject(new Error("No Blueprint found "+e))},r)}catch(i){n.reject(new Error("Error deserializing Blueprint "+e+" "+JSON.stringfy(i)))}},n.reject),n.promise}},createDefaultBlueprintForObject:{value:function(e){if(e){var t=Montage.getInfoForObject(e).isInstance?Object.getPrototypeOf(e):e,n=Montage.getInfoForObject(t),r=Blueprint.create().initWithNameAndModuleId(n.objectName,n.moduleId);for(var i in t)if(i.charAt(0)!=="_"&&t.hasOwnProperty(i)){var s=t[i],o;Array.isArray(s)?o=r.addToManyPropertyBlueprintNamed(i):o=r.addToOnePropertyBlueprintNamed(i),r.addPropertyBlueprintToGroupNamed(o,n.objectName)}var u=Object.getPrototypeOf(t);return"blueprint"in u&&u.blueprint.then(function(e){r.parent=e}),r}return UnknownBlueprint}},identifier:{get:function(){return["blueprint",this.name.toLowerCase()].join("_")}},_binder:{value:null},binder:{serializable:!1,get:function(){return this._binder||(this._binder=BinderModule.Binder.manager.defaultBinder,this._binder.addBlueprint(this)),this._binder},set:function(e){this._binder=e}},_parentReference:{value:null},_parent:{value:null},parent:{serializable:!1,get:function(){return this._parent},set:function(e){e?(this._parentReference=BlueprintReference.create().initWithValue(e),this._parent=e):(this._parentReference=null,this._parent=null)}},moduleId:{value:""},prototypeName:{value:null},customPrototype:{value:!1},_propertyBlueprints:{value:[],distinct:!0},propertyBlueprints:{get:function(){var e=[];return e=e.concat(this._propertyBlueprints),this.parent&&(e=e.concat(this.parent.propertyBlueprints)),e}},_propertyBlueprintsTable:{value:{},distinct:!0,writable:!1},addPropertyBlueprint:{value:function(e){if(e!==null&&e.name!==null){var t=this._propertyBlueprints.indexOf(e);t<0&&(e.owner!==null&&e.owner!==this&&e.owner.removePropertyBlueprint(e),this._propertyBlueprints.push(e),this._propertyBlueprintsTable[e.name]=e,e._owner=this)}return e}},removePropertyBlueprint:{value:function(e){if(e!==null&&e.name!==null){var t=this._propertyBlueprints.indexOf(e);t>=0&&(this._propertyBlueprints.splice(t,1),delete this._propertyBlueprintsTable[e.name],e._owner=null)}return e}},newPropertyBlueprint:{value:function(e,t){return PropertyBlueprint.create().initWithNameBlueprintAndCardinality(e,this,t)}},newAssociationBlueprint:{value:function(e,t){return AssociationBlueprint.create().initWithNameBlueprintAndCardinality(e,this,t)}},newDerivedPropertyBlueprint:{value:function(e,t){return DerivedPropertyBlueprint.create().initWithNameBlueprintAndCardinality(e,this,t)}},addToOnePropertyBlueprintNamed:{value:function(e){return this.addPropertyBlueprint(this.newPropertyBlueprint(e,1))}},addToManyPropertyBlueprintNamed:{value:function(e){return this.addPropertyBlueprint(this.newPropertyBlueprint(e,Infinity))}},addToOneAssociationBlueprintNamed:{value:function(e,t){var n=this.addPropertyBlueprint(this.newAssociationBlueprint(e,1));return t&&(n.targetBlueprint=t.owner,t.targetBlueprint=this),n}},addToManyAssociationBlueprintNamed:{value:function(e,t){var n=this.addPropertyBlueprint(this.newAssociationBlueprint(e,Infinity));return t&&(n.targetBlueprint=t.owner,t.targetBlueprint=this),n}},propertyBlueprintForName:{value:function(e){var t=this._propertyBlueprintsTable[e];if(typeof t=="undefined"){t=UnknownPropertyBlueprint;var n,r;for(r=0;typeof (n=this._propertyBlueprints[r])!="undefined";r++)if(n.name===e){t=n;break}this._propertyBlueprintsTable[e]=t}return t===UnknownPropertyBlueprint&&(t=null),!t&&this.parent&&(t=this.parent.propertyBlueprintForName(e)),t}},_propertyBlueprintGroups:{distinct:!0,value:{}},propertyBlueprintGroups:{get:function(){var e=[];for(var t in this._propertyBlueprintGroups)e.push(t);return this.parent&&(e=e.concat(this.parent.propertyBlueprintGroups)),e}},propertyBlueprintGroupForName:{value:function(e){var t=this._propertyBlueprintGroups[e];return!t&&this.parent&&(t=this.parent.propertyBlueprintGroupForName(e)),t!=null?t:[]}},addPropertyBlueprintGroupNamed:{value:function(e){var t=this._propertyBlueprintGroups[e];return t==null&&(t=[],this._propertyBlueprintGroups[e]=t),t}},removePropertyBlueprintGroupNamed:{value:function(e){var t=this._propertyBlueprintGroups[e];return t!=null&&delete this._propertyBlueprintGroups[e],t}},addPropertyBlueprintToGroupNamed:{value:function(e,t){var n=this._propertyBlueprintGroups[t];n==null&&(n=this.addPropertyBlueprintGroupNamed(t));var r=n.indexOf(e);return r<0&&n.push(e),n}},removePropertyBlueprintFromGroupNamed:{value:function(e,t){var n=this._propertyBlueprintGroups[t];if(n!=null&&e!=null){var r=n.indexOf(e);r>=0&&n.splice(r,1)}return n!=null?n:[]}},_propertyValidationRules:{value:{}},propertyValidationRules:{get:function(){var e=[];for(var t in this._propertyValidationRules)e.push(this._propertyValidationRules[t]);return this.parent&&(e=e.concat(this.parent.propertyValidationRules)),e}},propertyValidationRuleForName:{value:function(e){var t=his._propertyValidationRules[e];return!t&&this.parent&&(t=this.parent.propertyValidationRuleForName(e)),t}},addPropertyValidationRule:{value:function(e){var t=this._propertyValidationRules[e];return t==null&&(t=PropertyValidationRule.create().initWithNameAndBlueprint(e,this),this._propertyValidationRules[e]=t),t}},removePropertyValidationRule:{value:function(e){var t=this._propertyValidationRules[e];return t!=null&&delete this._propertyValidationRules[e],t}},evaluateRules:{value:function(e){var t=[];for(var n in this._propertyValidationRules){var r=this._propertyValidationRules[n];r.evaluateRule(e)&&t.push(r.messageKey)}return t}},blueprintModuleId:require("montage")._blueprintModuleIdDescriptor,blueprint:require("montage")._blueprintDescriptor}),UnknownBlueprint=Object.freeze(Blueprint.create().initWithName("Unknown")),UnknownPropertyBlueprint=Object.freeze(PropertyBlueprint.create().initWithNameBlueprintAndCardinality("Unknown",null,1))