-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjoose.mini.js
1 lines (1 loc) · 37.2 KB
/
joose.mini.js
1
var joosetop=this;Joose=function(){this.cc=null;this.currentModule=null;this.top=joosetop;this.globalObjects=[];this.anonymouseClassCounter=0};Joose.A={};Joose.A.each=function(C,B){for(var A=0;A<C.length;A++){B(C[A],A)}};Joose.A.exists=function(C,B){for(var A=0;A<C.length;A++){if(C[A]==B){return true}}return false};Joose.A.concat=function(A,B){A.push.apply(A,B);return A};Joose.A.grep=function(C,B){var A=[];Joose.A.each(C,function(D){if(B(D)){A.push(D)}});return A};Joose.A.remove=function(C,B){var A=[];Joose.A.each(C,function(D){if(D!==B){A.push(D)}});return A};Joose.S={};Joose.S.uppercaseFirst=function(A){var C=A.substr(0,1);var B=A.substr(1,A.length-1);C=C.toUpperCase();return C+B};Joose.S.isString=function(A){if(typeof A=="string"){return true}return false};Joose.O={};Joose.O.each=function(A,C){for(var B in A){C(A[B],B)}};Joose.O.eachSafe=function(A,C){for(var B in A){if(A.hasOwnProperty(B)){C(A[B],B)}}};Joose.O.extend=function(D,C){for(var B in C){var A=C[B];D[B]=A}};Joose.prototype={addToString:function(A,B){A.toString=B},isInstance:function(A){if(!A.meta){throw"isInstance only works with Joose objects and classes."}if(A.constructor===A.meta.c){return true}return false},init:function(){this.builder=new Joose.Builder();this.builder.globalize()},components:function(){return["Joose.Builder","Joose.Class","Joose.Method","Joose.ClassMethod","Joose.Attribute","Joose.Role","Joose.SimpleRequest","Joose.Gears","Joose.Storage","Joose.Storage.Unpacker","Joose.Decorator","Joose.Module","Joose.Prototype","Joose.TypeConstraint","Joose.TypeCoercion","Joose.Types"]},loadComponents:function(B){var A="";Joose.A.each(this.components(),function(D){var C=""+B+"/"+D.split(".").join("/")+".js";A+='<script type="text/javascript" src="'+C+'"><\/script>'});document.write(A)}};Joose.copyObject=function(B,C){var A="";Joose.O.each(B,function(E,D){A+=", "+D;C[D]=E});return C};Joose.emptyFunction=function(){};var joose=new Joose();Joose.bootstrap=function(){var B=new Joose.MetaClassBootstrap();B.builder=Joose.MetaClassBootstrap;Joose.MetaClass=B.createClass("Joose.MetaClass");Joose.MetaClass.meta.addNonJooseSuperClass("Joose.MetaClassBootstrap",B);Joose.MetaClass.meta.addMethod("initialize",function(){this._name="Joose.MetaClass"});var A=new Joose.MetaClass();A.builder=Joose.MetaClass;Joose.Class=A.createClass("Joose.Class");Joose.Class.meta.addSuperClass(Joose.MetaClass);Joose.MetaClass.meta.addMethod("initialize",function(){this._name="Joose.Class"})};Joose.bootstrap2=function(){Joose.Builder.Globals.joosify("Joose.Method",Joose.Method);Joose.Builder.Globals.joosify("Joose.Attribute",Joose.Attribute)};Joose.bootstrap3=function(){};Joose.MetaClassBootstrap=function(){this._name="Joose.MetaClassBootstrap";this.methodNames=[];this.attributeNames=["_name","isAbstract","isDetached","methodNames","attributeNames","methods","parentClasses","roles","c"];this.attributes={},this.methods={};this.classMethods={};this.parentClasses=[];this.roles=[];this.myRoles=[];this.isAbstract=false;this.isDetached=false};Joose.MetaClassBootstrap.prototype={toString:function(){if(this.meta){return"a "+this.meta.className()}return"NoMeta"},className:function(){return this._name},getName:function(){return this.className()},newMetaClass:function(){var B=this;var A=this.builder;var D=new A();D.builder=A;D._name=this._name;D.methodNames=[];D.attributeNames=[];D.methods={};D.classMethods={};D.parentClasses=[];D.roles=[];D.myRoles=[];D.attributes={};var C=this.meta;if(!C){C=this}D.meta=C;return D},createClass:function(B,A,D){var E=this.newMetaClass();var F;if(A){F=A}else{F=this.defaultClassFunctionBody();if(D){D.addElement(F)}}F.prototype.meta=E;F.meta=E;if(B==null){E._name="__anonymous__"}else{var C=B;if(D){C=D.getName()+"."+B}E._name=C}E.c=F;if(!D){joose.globalObjects.push(F)}E.addInitializer();E.addToString();E.addDetacher();return F},buildComplete:function(){},initializeFromProps:function(A){this._initializeFromProps(A)},_initializeFromProps:function(B){var C=this;if(B){Joose.O.eachSafe(B,function(H,G){var F=H;var E="handleProp"+G;if(C.meta.can(E)){C[E](F,B)}else{throw new Error("Called invalid builder "+G+" while creating class "+C.className())}});for(var A=0;A<this.roles.length;A++){var D=this.roles[A];D.meta.applyMethodModifiers(this.c)}C.buildComplete();C.validateClass()}},instantiate:function(){var A=function(){};A.prototype=this.c.prototype;A.prototype.constructor=this.c;var B=new A();this.c.apply(B,arguments);return B},defaultClassFunctionBody:function(){var A=function(){this.initialize.apply(this,arguments)};joose.addToString(A,function(){return this.meta.className()});return A},addToString:function(){this.addMethod("toString",function(){if(this.stringify){return this.stringify()}return"a "+this.meta.className()})},addInitializer:function(){if(!this.c.prototype.initialize){this.addMethod("initialize",this.initializer())}},initializer:function(){return function A(E){var G=this;if(this.meta.isAbstract){var D=this.meta.className();throw""+D+" is an abstract class and may not instantiated."}var C=this.meta.getAttributes();for(var F in C){if(C.hasOwnProperty(F)){var B=C[F];B.doInitialization(G,E)}}}},dieIfString:function(A){if(Joose.S.isString(A)){throw new TypeError("Parameter must not be a string.")}},addRole:function(A){this.dieIfString(A);var B=this.getClassObject();if(A.meta.apply(B)){this.roles.push(A);this.myRoles.push(A)}},getClassObject:function(){return this.c},classNameToClassObject:function(D){var F=joose.top;var E=D.split(".");var B=F;for(var C=0;C<E.length;C++){var A=E[C];B=B[A];if(!B){throw"Unable to find class "+D}}return B},addNonJooseSuperClass:function(C,B){var D=new Joose.MetaClassBootstrap();D.builder=Joose.MetaClassBootstrap;var A=D.createClass(C);Joose.O.each(B,function(F,E){if(typeof(F)=="function"){A.meta.addMethod(E,F)}else{A.meta.addAttribute(E,{init:F})}});this.addSuperClass(A)},addSuperClass:function(G){this.dieIfString(G);var I=this;var H=G.meta.getMethodNames();for(var E=0;E<H.length;E++){var B=H[E];var C=G.meta.getMethodObject(B);if(C){var A=C.copy();A.setIsFromSuperClass(true);I.addMethodObject(A)}C=G.meta.getClassMethodObject(B);if(C){var A=C.copy();A.setIsFromSuperClass(true);I.addMethodObject(A)}}Joose.O.eachSafe(G.meta.attributes,function(J,K){I.addAttribute(K,J.getProps())});var F=G.meta.roles;for(var E=0;E<F.length;E++){var D=F[E];I.roles.push(D)}this.parentClasses.unshift(G)},_fixMetaclassIncompatability:function(D){var A=D.meta;var C=A.meta.className();if(C=="Joose.Class"||C=="Joose.MetaClass"||C=="Joose.MetaClassBootstrap"){return}if(this.meta.meta.isa(A)){return}var E=A.meta.instantiate(this);for(var B in E){this[B]=E[B]}},isa:function(D){this.dieIfString(D);var A=D.meta.className();if(this.className()==A){return true}for(var B=0;B<this.parentClasses.length;B++){var C=this.parentClasses[B].meta;if(C.className()==A){return true}if(C.isa(D)){return true}}return false},wrapMethod:function(B,D,C,A){var E=this.getMethodObject(B);if(E){this.addMethodObject(E[D](C))}else{if(A){A()}else{throw new Error("Unable to apply "+D+" method modifier because method "+B+" does not exist")}}},dispatch:function(A){return this.getMethodObject(A).asFunction()},hasMethod:function(A){return this.methods[A]!=null||this.classMethods[A]!=null},addMethod:function(B,D,C){var A=new Joose.Method(B,D,C);this.addMethodObject(A)},addClassMethod:function(B,D,C){var A=new Joose.ClassMethod(B,D,C);this.addMethodObject(A)},addMethodObject:function(C){var A=C;var B=A.getName();if(!this.methods[B]&&!this.classMethods[B]){this.methodNames.push(B)}if(A.isClassMethod()){this.classMethods[B]=A}else{this.methods[B]=A}C.addToClass(this.c)},attributeMetaclass:function(){return Joose.Attribute},addAttribute:function(B,C){var D=this.attributeMetaclass();if(C&&C.metaclass){D=C.metaclass}var A=new D(B,C);A.apply(this.c)},getAttributes:function(){return this.attributes},getAttribute:function(A){return this.attributes[A]},setAttribute:function(A,B){return this.attributes[A]=B},getMethodObject:function(A){return this.methods[A]},getClassMethodObject:function(A){return this.classMethods[A]},getAttributeNames:function(){return this.attributeNames},getInstanceMethods:function(){var A=[];Joose.O.eachSafe(this.methods,function(B){A.push(B)});return A},getClassMethods:function(){var A=[];Joose.O.eachSafe(this.classMethods,function(B){A.push(B)});return A},getSuperClasses:function(){return this.parentClasses},getSuperClass:function(){return this.parentClasses[0]},getRoles:function(){return this.roles},getMethodNames:function(){return this.methodNames},makeAnonSubclass:function(){var A=this.createClass(this.className()+"__anon__"+joose.anonymouseClassCounter++);A.meta.addSuperClass(this.getClassObject());return A},addDetacher:function(){this.addMethod("detach",function A(){var C=this.meta;if(C.isDetached){return}var D=C.makeAnonSubclass();D.meta.isDetached=true;this.meta=D.meta;this.constructor=D;var B;if(!this.__proto__){B=this}else{B={};Joose.copyObject(this,B)}D.prototype=B;this.__proto__=D.prototype;return})},validateClass:function(){var C=this.getClassObject();var B=this;var A=true;Joose.A.each(this.roles,function(D){D.meta.isImplementedBy(C,A)})},can:function(A){var B=this.methods[A];if(!B){return false}return true},classCan:function(A){var B=this.classMethods[A];if(!B){return false}return true},does:function(B){for(var A=0;A<this.roles.length;A++){if(B===this.roles[A]){return true}}for(var A=0;A<this.roles.length;A++){if(this.roles[A].meta.does(B)){return true}}return false},implementsMyMethods:function(B){var A=true;Joose.A.each(this.getMethodNames(),function(D){var C=B.meta.can(D);if(!C){A=false}});return A},handleProprequires:function(A){var B=this;if(!this.meta.isa(Joose.Role)){throw ("Keyword 'requires' only available classes with a meta class of type Joose.Role")}if(A instanceof Array){Joose.A.each(A,function(C){B.addRequirement(C)})}else{B.addRequirement(A)}},handlePropisAbstract:function(A){this.isAbstract=A},handlePropisa:function(A){this.addSuperClass(A)},handlePropdoes:function(B){var A=this;if(B instanceof Array){Joose.A.each(B,function(C){A.addRole(C)})}else{A.addRole(B)}},handleProphas:function(D){var C=this;if(typeof D=="string"){var A=arguments[0];var B=arguments[1];C.addAttribute(A,B)}else{Joose.O.eachSafe(D,function(F,E){C.addAttribute(E,F)})}},handlePropmethod:function(A,C,B){this.addMethod(A,C,B)},handlePropmethods:function(B){var A=this;Joose.O.eachSafe(B,function(D,C){A.addMethod(C,D)})},handlePropclassMethods:function(B){var A=this;Joose.O.eachSafe(B,function(C,D){A.addMethodObject(new Joose.ClassMethod(D,C))})},handlePropworkers:function(B){var A=this;Joose.O.eachSafe(B,function(D,C){A.addWorker(C,D)})},handlePropbefore:function(B){var A=this;Joose.O.eachSafe(B,function(D,C){A.wrapMethod(C,"before",D)})},handlePropafter:function(B){var A=this;Joose.O.eachSafe(B,function(D,C){A.wrapMethod(C,"after",D)})},handleProparound:function(B){var A=this;Joose.O.eachSafe(B,function(D,C){A.wrapMethod(C,"around",D)})},handlePropoverride:function(B){var A=this;Joose.O.eachSafe(B,function(D,C){A.wrapMethod(C,"override",D)})},handlePropaugment:function(B){var A=this;Joose.O.eachSafe(B,function(D,C){A.wrapMethod(C,"augment",D,function(){A.addMethod(C,D)})})},handlePropdecorates:function(B){var A=this;Joose.O.eachSafe(B,function(D,C){A.decorate(D,C)})}};Joose.Attribute=function(A,B){this.initialize(A,B)};Joose.Attribute.prototype={_name:null,_props:null,getName:function(){return this._name},getProps:function(){return this._props},initialize:function(A,B){this._name=A;this.setProps(B)},setProps:function(A){if(A){this._props=A}else{this._props={}}},getIsa:function(){var A=this.getProps();if(A.isa){if(!A.isa.meta){return A.isa()}return A.isa}return},addSetter:function(G){var I=G.meta;var A=this.getName();var H=this.getProps();var F=this.getIsa();var C;if(F){if(!F.meta){throw new Error("Isa declarations in attribute declarations must be Joose classes, roles or type constraints")}var J=false;var D=false;if(Joose.Role&&F.meta.meta.isa(Joose.Role)){J=true}else{if(Joose.TypeConstraint&&F.meta.isa(Joose.TypeConstraint)){D=true}}C=function B(P,M){var N=P;try{if(H.nullable===true&&N==undefined){}else{if(D){var L=null;if(H.coerce){L=F.coerce(N)}if(L==null&&H.nullable!==true){F.validate(N)}else{N=L}}else{if(!N||!N.meta){throw new ReferenceError("The attribute "+A+" only accepts values that have a meta object.")}var K=J?N.meta.does(F):N.meta.isa(F);if(!K){throw new ReferenceError("The attribute "+A+" only accepts values that are objects of type "+F.meta.className()+".")}}}}catch(O){if(M){M.call(this,O,F)}else{throw O}}this[A]=N;return this}}else{C=function E(K){this[A]=K;return this}}I.addMethod(this.setterName(),C)},addGetter:function(E){var G=E.meta;var B=this.getName();var C=this.getProps();var D=function A(){return this[B]};var H=C.init;if(C.lazy){D=function F(){var I=this[B];if(typeof I=="function"&&I===H){this[B]=I.apply(this)}return this[B]}}G.addMethod(this.getterName(),D)},initializerName:function(){return this.toPublicName()},getterName:function(){if(this.__getterNameCache){return this.__getterNameCache}this.__getterNameCache="get"+Joose.S.uppercaseFirst(this.toPublicName());return this.__getterNameCache},setterName:function(){if(this.__setterNameCache){return this.__setterNameCache}this.__setterNameCache="set"+Joose.S.uppercaseFirst(this.toPublicName());return this.__setterNameCache},isPrivate:function(){return this.getName().charAt(0)=="_"},toPublicName:function(){if(this.__publicNameCache){return this.__publicNameCache}var A=this.getName();if(this.isPrivate()){this.__publicNameCache=A.substr(1);return this.__publicNameCache}this.__publicNameCache=A;return this.__publicNameCache},handleIs:function(D){var E=D.meta;var A=this.getName();var B=this.getProps();var C=B.is;if(C=="rw"||C=="ro"){this.addGetter(D)}if(C=="rw"){this.addSetter(D)}},handleInit:function(D){var C=this.getProps();var A=this.getName();D.prototype[A]=null;if(typeof C.init!="undefined"){var E=C.init;var B=typeof E;D.prototype[A]=E}},handleProps:function(A){this.handleIs(A);this.handleInit(A)},apply:function(B){var C=B.meta;var A=this.getName();this.handleProps(B);C.attributeNames.push(A);C.setAttribute(A,this);C.attributes[A]=this}};Joose.Method=function(A,C,B){this.initialize(A,C,B)};Joose.Method.prototype={_name:null,_body:null,_props:null,_isFromSuperClass:false,getName:function(){return this._name},getBody:function(){return this._body},getProps:function(){return this._props},isFromSuperClass:function(){return this._isFromSuperClass},setIsFromSuperClass:function(A){this._isFromSuperClass=A},copy:function(){return new Joose.Method(this.getName(),this.getBody(),this.getProps())},initialize:function(A,C,B){this._name=A;this._body=C;this._props=B;C.name=A;C.meta=this},isClassMethod:function(){return false},apply:function(A,B){return this._body.apply(A,B)},addToClass:function(A){A.prototype[this.getName()]=this.asFunction()},asFunction:function(){return this._body}};Joose.bootstrap();Joose.Builder=function(){this.globalize=function(){Joose.O.each(Joose.Builder.Globals,function(C,A){var B="Joose"+A;if(typeof joose.top[A]=="undefined"){joose.top[A]=C}joose.top[B]=C})}};Joose.Builder.Globals={Module:function(B,A){return Joose.Module.setup(B,A)},Role:function(A,B){if(!B.meta){B.meta=Joose.Role}return JooseClass(A,B)},Prototype:function(A,B){if(!B.meta){B.meta=Joose.Prototype}return JooseClass(A,B)},Class:function(A,G){var F=null;if(A){var E=A;if(joose.currentModule){E=joose.currentModule.getName()+"."+A}var H=joose.top;var C=E.split(".");for(var D=0;D<C.length;D++){H=H[C[D]]}F=H}if(F==null){var I;if(G&&G.meta){I=G.meta;delete G.meta}else{if(G&&G.isa&&G.isa!=Joose.Class){I=G.isa.meta.builder}else{I=Joose.Class}}var J=new I();J.builder=I;var F=J.createClass(A,null,joose.currentModule);F.meta.builder=I;var E=F.meta.className();if(A&&E){var H=joose.top;var B=new String(E);var C=B.split(".");for(var D=0;D<C.length-1;D++){if(H[C[D]]==null){H[C[D]]={}}H=H[C[D]]}H[C[C.length-1]]=F}}F.meta.initializeFromProps(G);return F},Type:function(B,D){var C=Joose.TypeConstraint.newFromTypeBuilder(B,D);var A=joose.currentModule;if(!A){JooseModule("TYPE");A=TYPE.meta}A.addElement(C);A.getContainer()[B]=C;return C},joosify:function(F,G){var H=G;var A=new Joose.Class();A.builder=Joose.Class;H.toString=function(){return this.meta.className()};H=A.createClass(F,H);var E=H.meta;for(var B in G.prototype){if(B=="meta"){continue}var D=G.prototype[B];if(typeof(D)=="function"){E.addMethod(B,D)}else{var C={};if(typeof(D)!="undefined"){C.init=D}E.addAttribute(B,C)}}return H},rw:"rw",ro:"ro"};joose.init();Joose.bootstrap2();(function(A){A("Joose.Method",{methods:{copy:function(){return this.meta.instantiate(this.getName(),this.getBody(),this.getProps())},_makeWrapped:function(B){return this.meta.instantiate(this.getName(),B)},around:function(B){var D=this.getBody();return this._makeWrapped(function C(){var F=this;var E=function(){return D.apply(F,arguments)};return B.apply(this,Joose.A.concat([E],arguments))})},before:function(C){var D=this.getBody();return this._makeWrapped(function B(){C.apply(this,arguments);return D.apply(this,arguments)})},after:function(C){var D=this.getBody();return this._makeWrapped(function B(){var E=D.apply(this,arguments);C.apply(this,arguments);return E})},override:function(C){var D=this.getBody();return this._makeWrapped(function B(){var G=this;var F=function(){return D.apply(G,arguments)};var H=this.SUPER;this.SUPER=F;var E=C.apply(this,arguments);this.SUPER=H;return E})},augment:function(C){var D=this.getBody();D.source=D.toString();return this._makeWrapped(function B(){var I=D;var G=this;var E=C;E.source=E.toString();if(!this.__INNER_STACK__){this.__INNER_STACK__=[]}this.__INNER_STACK__.push(E);var H=this.INNER;this.INNER=function(){return G.__INNER_STACK__.pop().apply(G,arguments)};var F=D.apply(this,arguments);this.INNER=H;return F})}}})})(JooseClass);(function(A){A("Joose.ClassMethod",{isa:Joose.Method,methods:{isClassMethod:function(){return true},addToClass:function(B){B[this.getName()]=this.asFunction()},copy:function(){return new Joose.ClassMethod(this.getName(),this.getBody(),this.getProps())}}})})(JooseClass);(function(A){A("Joose.Attribute",{after:{handleProps:function(B){this.handleHandles(B);this.handlePredicate(B)}},methods:{isPersistent:function(){var B=this.getProps();if(B.persistent==false){return false}return true},doInitialization:function(C,J){var B=this.initializerName();var H=this.getName();var G;var F=false;if(typeof J!="undefined"&&typeof J[B]!="undefined"){G=J[B];F=true}else{var E=this.getProps();var I=E.init;if(typeof I=="function"&&!E.lazy){G=I.call(C);F=true}else{if(E.required){throw"Required initialization parameter missing: "+B+"(While initializing "+C+")"}}}if(F){var D=this.setterName();if(C.meta.can(D)){C[D](G)}else{C[H]=G}}},handleHandles:function(F){var G=F.meta;var B=this.getName();var D=this.getProps();var C=D.handles;var H=D.isa;if(C){if(C=="*"){if(!H){throw"I need an isa property in order to handle a class"}var E=D.handleWith;G.decorate(H,B,E)}else{throw"Unsupported value for handles: "+C}}},handlePredicate:function(F){var G=F.meta;var D=this.getName();var E=this.getProps();var C=E.predicate;var B=this.getterName();if(C){G.addMethod(C,function(){var H=this[B]();return H?true:false})}}}})})(JooseClass);(function(A){A("Joose.Role",{isa:Joose.Class,has:["requiresMethodNames","methodModifiers","metaRoles"],methods:{wrapMethod:function(C,E,D,B){this.methodModifiers.push(arguments);var F=this.methodModifiers},requiresMethod:function(C){var B=false;Joose.A.each(this.requiresMethodNames,function(D){if(C==D){B=true}});return B},addInitializer:Joose.emptyFunction,defaultClassFunctionBody:function(){var B=function(){throw new Error("Roles may not be instantiated.")};joose.addToString(B,function(){return this.meta.className()});return B},addSuperClass:function(){throw new Error("Roles may not inherit from a super class.")},initialize:function(){this._name="Joose.Role";this.requiresMethodNames=[];this.methodModifiers=[]},addRequirement:function(B){this.requiresMethodNames.push(B)},unapply:function(C){if(!joose.isInstance(C)){throw new Error("You way only remove roles from instances.")}if(!C.meta.isDetached){throw new Error("You may only remove roles that were applied at runtime")}var D=this.getClassObject();var F=C.meta.myRoles;var J=false;var B=[];for(var E=0;E<F.length;E++){if(F[E]===D){J=true}else{B.push(F[E])}}if(!J){throw new Error("The role "+this.className()+" was not applied to the object at runtime")}var I=C.meta.getSuperClass();var H=I.meta.makeAnonSubclass();var G=new H();for(var E=0;E<B.length;E++){var D=B[E];H.meta.addRole(D)}H.prototype=G;C.meta=H.meta;C.constructor=H;C.__proto__=G},addMethodToClass:function(E,C){var B=E.getName();var D;if(E.isClassMethod()){D=C.meta.getClassMethodObject(B)}else{D=C.meta.getMethodObject(B)}if(!D||D.isFromSuperClass()){C.meta.addMethodObject(E)}},apply:function(D){if(D.meta.does(this.getClassObject())){return false}if(joose.isInstance(D)){D.detach();D.meta.addRole(this.getClassObject());this.applyMethodModifiers(D);var C=true;this.isImplementedBy(D,C)}else{var E=this;var F=this.getMethodNames();Joose.A.each(F,function G(I){var H=E.getMethodObject(I);if(H){E.addMethodToClass(H,D)}H=E.getClassMethodObject(I);if(H){E.addMethodToClass(H,D)}});if(this.metaRoles){Joose.A.each(this.metaRoles,function B(H){H.meta.apply(D.meta)})}}return true},applyMethodModifiers:function(B){Joose.A.each(this.methodModifiers,function C(D){B.meta.wrapMethod.apply(B.meta,D)})},hasRequiredMethods:function(E,C){var D=this;var B=true;Joose.A.each(this.requiresMethodNames,function(G){var F=E.meta.can(G);if(!F){if(C){throw ("Class "+E.meta.className()+" does not fully implement the role "+D.className()+". The method is "+G+" missing.")}B=false;return}});return B},isImplementedBy:function(D,C){var B=this.hasRequiredMethods(D,C);if(B){B=this.implementsMyMethods(D)}return B},handlePropmetaRoles:function(B){this.metaRoles=B}}});Joose.Role.anonymousClassCounter=0})(JooseClass);(function(A){A("Joose.SimpleRequest",{has:{_req:{}},methods:{initialize:function(){if(window.XMLHttpRequest){this._req=new XMLHttpRequest()}else{this._req=new ActiveXObject("Microsoft.XMLHTTP")}},getText:function(B){this._req.open("GET",B,false);try{this._req.send(null);if(this._req.status==200||this._req.status==0){return this._req.responseText}}catch(C){throw ("File not found: "+B);return null}throw ("File not found: "+B);return null}}})})(JooseClass);(function(A){A("Joose.Gears",{isa:Joose.Class,has:{wp:{},calls:{init:{}},callIndex:{init:0}},methods:{initialize:function(){JooseGearsInitializeGears();if(this.canGears()){this.wp=google.gears.factory.create("beta.workerpool");var B=this;this.wp.onmessage=function(D,C,E){B.handleGearsMessage(E)}}},handleGearsMessage:function(E){var D=E.body;var F=D.to;var C=D.ret;var B=this.calls[D.index];if(B.meta.can(F)){B[F].call(B,C)}},canGears:function(){return window.google&&window.google.gears&&window.google.gears.factory},addWorker:function(C,D,I){var E="on"+Joose.S.uppercaseFirst(C);var L=this.meta.getClassObject().ajaxRequest;if(!this.canGears()){var J=function(){var P=this;var O={sendReturn:function(Q,R){if(P.meta.can(R)){P[R].call(P,Q)}},clientHasGears:function(){return false},ajaxRequest:L};var N=D.apply(O,arguments);O.sendReturn(N,E)};this.addMethod(C,J,I);return}var G=this.can("jsonURL")?this.c.jsonURL():"json2.js";var M=new Joose.SimpleRequest().getText(G);var B="var timer = google.gears.factory.create('beta.timer');\nfunction aClass () {}; aClass.prototype."+C+" = "+D.toString()+"\n\naClass.prototype.clientHasGears = function () { return true }\naClass.prototype.ajaxRequest = "+L.toString()+"\n\nvar wp = google.gears.workerPool;\nwp.onmessage = function (a,b,message) {\nvar paras = message.body;\nvar o = new aClass();\no.sendReturn = function (ret, cbName) { wp.sendMessage({ ret: ret, to: cbName, index: paras.index }, message.sender) } \nvar ret = o."+C+".apply(o, paras.args); if(!ret) ret = null; \no.sendReturn(ret, paras.cbName);\n}\n\n";B+=M;var K=this.wp;var F=K.createWorker(B);var H=this;var J=function(){var N=[];for(var O=0;O<arguments.length;O++){N.push(arguments[O])}var P={args:N,cbName:E,index:H.callIndex};K.sendMessage(P,F);H.calls[H.callIndex]=this;H.callIndex++};this.addMethod(C,J,I)}},classMethods:{setupGearsCompat:function(){window.timer={setTimeout:function(B,C){return window.setTimeout(B,C)},setInterval:function(B,C){return window.setInterval(B,C)},clearTimeout:function(B){return window.clearTimeout(B)},clearInterval:function(B){return window.clearInterval(B)}}},clientHasGears:function(){return window.google&&window.google.gears&&window.google.gears.factory},ajaxRequest:function(B,C,F,K,H){var E;if(this.clientHasGears()){E=google.gears.factory.create("beta.httprequest")}else{E=window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()}var I="";if(F){for(var G in F){I+=encodeURIComponent(G)+"="+encodeURIComponent(F[G])+"&"}}var D=C;if(F&&B=="GET"){D+="?"+I}E.open(B,D,true);E.onreadystatechange=function J(){if(E.readyState==4){if(E.status>=200&&E.status<400){var L=E.responseText;K(L)}else{if(H){return H(E)}else{throw new Error("Error fetching url "+D+". Response code: "+E.status+" Response text: "+E.responseText)}}}};if(F&&B=="POST"){E.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");E.send(I)}else{I="";E.send(I)}}}})})(JooseClass);function JooseGearsInitializeGears(){if(window.google&&google.gears){return}var A=null;if(typeof GearsFactory!="undefined"){A=new GearsFactory()}else{try{A=new ActiveXObject("Gears.Factory");if(A.getBuildInfo().indexOf("ie_mobile")!=-1){A.privateSetGlobalObject(this)}}catch(B){if(navigator.mimeTypes["application/x-googlegears"]){A=document.createElement("object");A.style.display="none";A.width=0;A.height=0;A.type="application/x-googlegears";document.documentElement.appendChild(A)}}}if(!A){return}if(!window.google){google={}}if(!google.gears){google.gears={factory:A}}}(function(A,B){B("Joose.Storage",{methods:{toJSON:function(){return this.pack(Joose.Storage.TEMP_SEEN)},identity:function(){if(this.__ID__){return this.__ID__}else{return this.__ID__=Joose.Storage.OBJECT_COUNTER++}},pack:function(C){return this.meta.c.storageEngine().pack(this,C)}},classMethods:{storageEngine:function(){return Joose.Storage.Engine},unpack:function(C){return this.storageEngine().unpack(this,C)}}});B("Joose.Storage.jsonpickle",{does:Joose.Storage,classMethods:{storageEngine:function(){return Joose.Storage.Engine.jsonpickle}}});Joose.Storage.OBJECT_COUNTER=1;A("Joose.Storage.Engine",{classMethods:{pack:function(E,C){if(C){var I=E.identity();var G=C[I];if(G){return{__ID__:I}}}if(E.meta.can("prepareStorage")){E.prepareStorage()}if(C){C[E.identity()]=true}var H={__CLASS__:this.packedClassName(E),__ID__:E.identity()};var D=E.meta.getAttributes();Joose.O.eachSafe(D,function F(J,K){if(J.isPersistent()){H[K]=E[K]}});return H},unpack:function(E,D){var G=E.meta;var C=G.instantiate();var F=false;Joose.O.eachSafe(D,function H(K,I){if(I=="__CLASS__"){var J=Joose.Storage.Unpacker.packedClassNameToJSClassName(K);if(J!=C.meta.className()){throw new Error("Storage data is of wrong type "+J+". I am "+C.meta.className()+".")}F=true;return}C[I]=K});if(!F){throw new Error("Serialized data needs to include a __CLASS__ attribute.: "+D)}delete C.__ID__;if(C.meta.can("finishUnpack")){C.finishUnpack()}return C},packedClassName:function(D){if(D.meta.can("packedClassName")){return D.packedClassName()}var C=D.meta.className();var E=C.split(".");return E.join("::")}}});A("Joose.Storage.Engine.jsonpickle",{classMethods:{pack:function(E,C){if(C){var I=E.identity();var G=C[I];if(G){return{objectid__:I}}}if(E.meta.can("prepareStorage")){E.prepareStorage()}if(C){C[E.identity()]=true}var H={classname__:this.packedClassName(E),classmodule__:this.packedModuleName(E),objectid__:E.identity()};var D=E.meta.getAttributes();Joose.O.eachSafe(D,function F(J,K){if(J.isPersistent()){H[K]=E[K]}});return H},unpack:function(E,D){var G=E.meta;var C=G.instantiate();var F=false;Joose.O.eachSafe(D,function H(L,I){if(I=="classname__"){var K=L;var J=D.classmodule__;if(J){K=""+J+"."+L}if(K!=C.meta.className()){throw new Error("Storage data is of wrong type "+K+". I am "+C.meta.className()+".")}F=true;return}if(I=="classmodule__"){return}C[I]=L});if(!F){throw new Error("Serialized data needs to include a __CLASS__ attribute.: "+D)}if(C.meta.can("finishUnpack")){C.finishUnpack()}return C},packedClassName:function(D){var C=D.meta.className();var E=C.split(".");return E.pop()},packedModuleName:function(D){var C=D.meta.className();var E=C.split(".");E.pop();return E.join(".")}}});Joose.Storage.storageEngine=Joose.Storage.Engine;Joose.Storage.jsonpickle.storageEngine=Joose.Storage.Engine.jsonpickle})(JooseClass,JooseRole);(function(A){A("Joose.Storage.Unpacker",{classMethods:{unpack:function(D){var C=D.__CLASS__;if(!C){throw ("Serialized data needs to include a __CLASS__ attribute.")}var B=this.packedClassNameToJSClassName(C);var F=this.meta.classNameToClassObject(B);var E=F.unpack(D);var G;if(Joose.Storage.CACHE&&(G=D.__ID__)){Joose.Storage.CACHE[G]=E}return E},packedClassNameToJSClassName:function(B){var C=B.split("-");C=C[0].split("::");return C.join(".")},jsonParseFilter:function(B,C){if(C!=null&&typeof C=="object"){if(C.__CLASS__){return Joose.Storage.Unpacker.unpack(C)}if(C.__ID__){return Joose.Storage.CACHE[C.__ID__]}}return C},patchJSON:function(){var D=JSON.parse;var B=this.jsonParseFilter;JSON.parse=function(G,F){Joose.Storage.CACHE={};return D(G,function E(H,I){var J=I;if(F){J=F(H,I)}return B(H,J)})};var C=JSON.stringify;JSON.stringify=function(){Joose.Storage.TEMP_SEEN={};return C.apply(JSON,arguments)}}}});A("Joose.Storage.Unpacker.jsonpickle",{isa:Joose.Storage.Unpacker,classMethods:{unpack:function(D){var C=D.classname__;if(!C){throw ("Serialized data needs to include a classname__ attribute.")}var B=this.packedClassNameToJSClassName(C,D.classmodule__);var F=this.meta.classNameToClassObject(B);var E=F.unpack(D);var G;if(Joose.Storage.CACHE&&(G=D.objectid__)){Joose.Storage.CACHE[G]=E}return E},packedClassNameToJSClassName:function(D,C){var B="";if(C){B+=C+"."}B+=D;return B},jsonParseFilter:function(B,C){if(C!=null&&typeof C=="object"){if(C.classname__){return Joose.Storage.Unpacker.jsonpickle.unpack(C)}if(C.objectid__){return Joose.Storage.CACHE[C.objectid__]}}return C}}})})(JooseClass);(function(A){A("Joose.Decorator",{meta:Joose.Role,methods:{decorate:function(F,D,C){var E=this;var B=F.meta.getInstanceMethods();Joose.A.each(B,function(G){var H=G.getName();var J=D;if(!E.can(H)){var I=function(){var K=this[J];return K[H].apply(K,arguments)};if(C){I=C(H)}E.addMethod(H,I)}})}}});Joose.Decorator.meta.apply(Joose.Class)})(JooseClass);(function(A){A("Joose.Module",{has:{_name:{is:"rw"},_elements:{is:"rw"},_container:{is:"rw"}},classMethods:{setup:function(B,C){var J=this;var G=B.split(".");var F=joose.top;var I=[];var E;for(var H=0;H<G.length;H++){var D=G[H];if(D=="meta"){throw"Module names may not include a part called 'meta'."}var L=F[D];I.push(D);var B=I.join(".");if(typeof L=="undefined"){F[D]={};E=new Joose.Module(B);E.setContainer(F[D]);F[D].meta=E;Joose.Module._allModules.push(F[D])}else{E=L.meta;if(!(E&&E.meta&&(E.meta.isa(Joose.Module)))){throw"Trying to setup module "+B+" failed. There is already something else: "+E}}F=F[D]}var K=joose.currentModule;joose.currentModule=E;if(C){C(F)}joose.currentModule=K;return F},getAllModules:function(){return this._allModules}},methods:{alias:function(B){var C=this;if(arguments.length==0){return this}Joose.A.each(this.getElements(),function(D){var E=C.globalName(D.meta.className());if(B[E]===D){return}if(typeof B[E]!="undefined"){throw"There is already something else in the spot "+E}B[E]=D})},globalName:function(C){var B=this.getName();if(C.indexOf(B)!=0){throw"All things inside me should have a name that starts with "+B+". Name is "+C}var D=C.substr(B.length+1);if(D.indexOf(".")!=-1){throw"The things inside me should have no more dots in there name. Name is "+D}return D},removeGlobalSymbols:function(){Joose.A.each(this.getElements(),function(B){var C=this.globalName(B.getName());delete joose.top[C]})},initialize:function(B){this.setElements([]);this.setName(B)},isEmpty:function(){return this.getElements().length==0},addElement:function(B){if(!(B||B.meta)){throw"You may only add things that are Joose objects"}this._elements.push(B)},getNames:function(){var B=[];Joose.A.each(this.getElements(),function(C){B.push(C.meta.getName())});return B}}})})(JooseClass);__global__={};__global__.meta=new Joose.Module();__global__.meta.setName("__global__");__global__.meta.setContainer(__global__);Joose.Module._allModules=[__global__];JooseModule("__global__.nomodule",function(){});__global__.nomodule.meta._elements=joose.globalObjects;(function(A){A("Joose.Prototype",{isa:Joose.Class,override:{initializer:function(){var B=this.SUPER();return function(){B.apply(this,arguments);var C=this.meta;this.meta=new Joose.PrototypeLazyMetaObjectProxy();this.meta.metaObject=C;this.meta.object=this}}}});A("Joose.PrototypeLazyMetaObjectProxy",{has:{metaObject:{is:"rw",isa:Joose.Class,handles:"*",handleWith:function(B){return function(){var C=this.object;C.meta=this.metaObject;C.detach();C.meta[B].apply(C.meta,arguments)}}},object:{is:"rw"}}});Joose.bootstrap3()})(JooseClass);(function(A){A("Joose.TypeConstraint",{has:{_constraints:{is:"ro",init:function(){return[]}},_coercions:{is:"ro",init:function(){return[]}},_messages:{is:"ro",init:function(){return[]}},_callback:{is:"ro",init:function(){return function(B){throw new ReferenceError(B)}}},_name:{is:"ro"},_uses:{is:"ro"},props:{is:"rw"}},classMethods:{newFromTypeBuilder:function(C,F){var E=new Joose.TypeConstraint({name:C});if(F.uses&&typeof F.uses.meta!="undefined"&&F.uses.meta.isa(Joose.TypeConstraint)){E._uses=F.uses}if(F.where){E.addConstraint(F.where,F.message)}E.setProps(F);if(F.coerce){for(var D=0;D<F.coerce.length;D++){var B=F.coerce[D];E.addCoercion(new Joose.TypeCoercion({from:B.from,via:B.via}))}}return E}},methods:{stringify:function(){return this._name},makeSubType:function(B){var C=new Joose.TypeConstraint({name:B});Joose.A.each(this._constraints,function(D){C.addConstraint(D)});return C},addCoercion:function(B){this._coercions.push(B)},addConstraint:function(C,B){this._constraints.push(C);this._messages.push(B)},getConstraintList:function(){var B=this._constraints;if(this._uses){var C=this._uses.getConstraintList();return C.concat(B)}return B},getMessageList:function(){var C=this._messages;if(this._uses){var B=this._uses.getMessageList();return B.concat(C)}return C},validateBool:function(C){var B=this._validate(C);if(B==-1){return true}return false},validate:function(E){var B=this._validate(E);if(B==-1){return true}var D=this.getMessageList();var C=D[B]?D[B].call(this,E):"The passed value ["+E+"] is not a "+this;this._callback(C)},_validate:function(G){var D=this.getConstraintList();var E,C;for(E=0,C=D.length;E<C;E++){var F=D[E];var B=false;if(F instanceof RegExp){B=F.test(G)}else{B=F.call(this,G)}if(!B){return E}}return -1},coerce:function(G){if(this.validateBool(G)){return G}var F=this._coercions;for(var E=0,C=F.length;E<C;E++){var D=F[E];var B=D.coerce(G);if(B!==null){return B}}return null}}})})(JooseClass);(function(B,A){A("CoercionFrom",{where:function(C){if(C.meta&&C.meta.isa(Joose.TypeConstraint)){return true}return false}});B("Joose.TypeCoercion",{has:{_from:{isa:TYPE.CoercionFrom,is:"rw"},_via:{is:"rw"}},methods:{coerce:function(C){if(this._from.validateBool(C)){return this._via(C)}return null}}})})(JooseClass,JooseType);(function(A){A("Any",{where:function(B){return true}});A("Null",{uses:TYPE.Any,where:function(B){if(B===null){return true}return false}});A("NotNull",{uses:TYPE.Any,where:function(B){if(B===null){return false}return true}});A("Enum",{uses:TYPE.NotNull,message:function(B){return"The passed value ["+B+"] is not "+(this.getProps().strictMatch?"*strictly* ":"")+"one of ["+this.getProps().values.join(",")+"]"},where:function(D){var C=this;if(!C.getProps()||C.getProps().values===undefined||!(C.getProps().values instanceof Array)){throw"Enum Type needs Array of values in 'values' property of Type declaration"}var B=function(E){if(C.getProps().strictMatch===true){return(E===D)}return(E==D)};if(Joose.A.grep(C.getProps().values,B).length!=0){return true}return false}});A("Obj",{uses:TYPE.NotNull,where:function(B){if(B instanceof Object){return true}return false}});A("Str",{uses:TYPE.NotNull,where:function(B){if(typeof B=="string"||B instanceof String){return true}return false},coerce:[{from:TYPE.Any,via:function(B){if(B==null){return""}else{return""+B}}}]});A("Num",{uses:TYPE.NotNull,where:function(B){if(typeof B=="number"||B instanceof Number){return true}return false},coerce:[{from:TYPE.Str,via:function(B){if(B==null||B==""){return undefined}return parseFloat(B)}}]});A("Bool",{uses:TYPE.NotNull,where:function(C){if(C===true||C===false){return true}return false},coerce:[{from:TYPE.Any,via:function(B){if(B==null||B===""){return undefined}if(B==1||B=="1"||B=="true"){return true}if(B==0||B=="0"||B=="false"){return false}return null}}]});A("Int",{uses:TYPE.Num,where:function(C){var B=String(C);if(B.match(/^\d*\.\d$/)){return false}return true},coerce:[{from:TYPE.Str,via:function(B){if(B==null||B==""){return undefined}if(B.match(/^-{0,1}\d+$/)){return parseInt(B)}return}}]});A("Float",{uses:TYPE.Num,where:function(B){return true}});A("Func",{uses:TYPE.Obj,where:function(B){if(typeof B=="function"){return true}return false}});A("Array",{uses:TYPE.Obj,where:function(B){if(B instanceof Array){return true}return false}});A("Date",{uses:TYPE.Obj,where:function(B){if(B instanceof Date){return true}return false},coerce:[{from:TYPE.Str,via:function(C){var B;if(C==undefined||C==""){return undefined}else{if(B=C.match(/\s*(\d+)-(\d+)-(\d+)/)){return new Date(B[1],B[2]-1,[B[3]])}}return null}}]});A("Joose",{uses:TYPE.Obj,where:function(B){if(B.meta&&B.meta.meta.isa(Joose.Class)){return true}return false}})})(JooseType);