Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "ClazzJS", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"ignore": [ | ||
@@ -11,4 +11,4 @@ "node_modules", | ||
"dependencies": { | ||
"MetaJS": "~0.2.0" | ||
"MetaJS": "~0.3.0" | ||
} | ||
} |
1296
dist/ClazzJS.js
@@ -1,68 +0,208 @@ | ||
;(function(global, Meta, undefined) { | ||
;(function(global, meta, undefined) { | ||
var Clazz = function(name /* [dependencies] || ( [parent], [metaTypes], meta) */) { | ||
var parent, metaTypes, meta; | ||
var Clazz = function(manager, factory, namespace) { | ||
var last = arguments[arguments.length-1]; | ||
var clazz = function(name, parent, process, meta) { | ||
if (typeof last !== 'function' && Object.prototype.toString.call(last) !== '[object Object]') { | ||
return Manager.get(name, /* actually dependencies */parent || []) | ||
var last = arguments[arguments.length-1]; | ||
// Getting of existed clazz | ||
if (typeof last !== 'function' && Object.prototype.toString.call(last) !== '[object Object]') { | ||
return clazz.get(name, /* actually dependencies */ parent); | ||
} | ||
clazz.set(name, parent, process, meta); | ||
} | ||
meta = last; | ||
parent = arguments[1]; | ||
metaTypes = arguments[2]; | ||
for (var property in Clazz.prototype) { | ||
clazz[property] = Clazz.prototype[property]; | ||
} | ||
if (Object.prototype.toString.call(parent) === '[objectArray]') { | ||
metaTypes = parent; | ||
parent = null; | ||
clazz.getManager = function() { | ||
return manager; | ||
} | ||
if (metaTypes === meta) { | ||
metaTypes = null; | ||
clazz.getFactory = function() { | ||
return factory; | ||
} | ||
if (parent === meta) { | ||
parent = null; | ||
clazz.getNamespace = function() { | ||
return namespace; | ||
} | ||
Manager.setMeta(name, { | ||
parent: parent, | ||
metaTypes: metaTypes, | ||
meta: meta | ||
}); | ||
return clazz; | ||
} | ||
var NameSpace = function(namespace) { | ||
if (NameSpace.current() === namespace) { | ||
return; | ||
Clazz.prototype = { | ||
get: function(name, dependencies) { | ||
name = this.resolveName(name); | ||
if (!name) { | ||
throw new Error('Clazz with name "' + name + '" does not exits!'); | ||
} | ||
dependencies = dependencies || []; | ||
var manager = this.getManager(); | ||
var factory = this.getFactory(); | ||
if (!manager.hasClazz(name, dependencies)) { | ||
var meta = manager.getMeta(name); | ||
manager.setClazz(factory.create({ | ||
name: name, | ||
dependencies: dependencies, | ||
process: meta.process, | ||
parent: this.adjustParent(meta.parent), | ||
meta: meta.meta | ||
})); | ||
} | ||
return manager.getClazz(name, dependencies) | ||
}, | ||
has: function(name) { | ||
return !!this.resolveName(name); | ||
}, | ||
set: function(name, parent, process, meta) { | ||
var namespace = this.getNamespace(); | ||
var manager = this.getManager(); | ||
// Creation of new clazz | ||
if (typeof name === 'object') { | ||
parent = name.parent; | ||
process = name.process; | ||
meta = name.meta; | ||
name = name.name; | ||
} | ||
else { | ||
if (typeof meta === 'undefined') { | ||
meta = process; | ||
process = null; | ||
} | ||
if (typeof meta === 'undefined') { | ||
meta = parent; | ||
parent = null; | ||
} | ||
if (Object.prototype.toString.call(parent) === '[object Array]') { | ||
process = parent; | ||
parent = null; | ||
} | ||
} | ||
name = namespace.apply(name); | ||
manager.setMeta(name, { | ||
parent: parent , | ||
process: process, | ||
meta: meta | ||
}); | ||
return this; | ||
}, | ||
resolveName: function(name) { | ||
var paths, aname, i, ii; | ||
var manager = this.getManager(); | ||
var namespace = this.getNamespace(); | ||
paths = namespace.getPaths(); | ||
for (i = 0, ii = paths.length; i < ii; ++i) { | ||
aname = namespace.apply(name, paths[i]); | ||
if (manager.hasMeta(aname)) { | ||
return aname; | ||
} | ||
} | ||
return false; | ||
}, | ||
adjustParent: function(parent) { | ||
if (typeof parent === 'string') { | ||
parent = [parent]; | ||
} | ||
if (Object.prototype.toString.call(parent) === '[object Array]') { | ||
parent = this.get(parent[0], parent[1] || []) | ||
} | ||
return parent; | ||
} | ||
NameSpace._stack.push(namespace); | ||
} | ||
var Namespace = function(manager, factory, baseNamespace, space, global, Class) { | ||
Class = Class || Clazz; | ||
NameSpace.GLOBAL = 'GLOBAL'; | ||
NameSpace.DELIMITERS = ['\\', '/', '_', '-', '.'] | ||
var namespace = function(space, callback) { | ||
var newNamespace = new Namespace(manager, factory, namespace, space, global); | ||
var newClazz = new Class(manager, factory, namespace); | ||
NameSpace._stack = []; | ||
if (callback) { | ||
callback(newNamespace, newClazz); | ||
} | ||
NameSpace.end = function() { | ||
this._stack.pop(); | ||
} | ||
return newClazz; | ||
} | ||
NameSpace.current = function() { | ||
return this._stack[this._stack.length - 1] || this.GLOBAL; | ||
namespace.getManager = function() { | ||
return manager; | ||
} | ||
namespace.getFactory = function() { | ||
return factory; | ||
} | ||
namespace.getBaseNamespace = function() { | ||
return baseNamespace; | ||
} | ||
namespace.getGlobal = function() { | ||
return global; | ||
} | ||
namespace.getPath = function() { | ||
return Namespace.adjust((baseNamespace ? baseNamespace.getPath() : Namespace.GLOBAL)+Namespace.getDelimiter()+space); | ||
} | ||
namespace.getPaths = function() { | ||
var paths = this.getPath(); | ||
if (-1 === paths.indexOf(Namespace.GLOBAL)) { | ||
paths.push(Namespace.GLOBAL); | ||
} | ||
return [this.getPath()] | ||
} | ||
namespace.apply = function(space, path) { | ||
return Namespace.adjust((path || this.getPath())+Namespace.getDelimiter()+space); | ||
} | ||
return namespace; | ||
} | ||
NameSpace.whereLookFor = function() { | ||
var current = this.current(), lookfor = [current]; | ||
Namespace.GLOBAL = 'GLOBAL'; | ||
Namespace.DEFAULT_DELIMITER = '.'; | ||
Namespace.DELIMITERS = ['\\', '/', '_', '-', '.'] | ||
if (current !== this.GLOBAL) { | ||
lookfor.push(this.GLOBAL); | ||
Namespace._delimiter = null; | ||
Namespace.setDelimiter = function(delimiter) { | ||
if (!(delimiter in this.DELIMITERS)) { | ||
throw new Error('Unsupported delimiter'); | ||
} | ||
} | ||
return lookfor; | ||
Namespace.getDelimiter = function() { | ||
return this._delimiter || this.DEFAULT_DELIMITER | ||
} | ||
NameSpace.getDelimitersRegexp = function() { | ||
return new RegExp('[\\' + this.DELIMITERS.join('\\') + ']'); | ||
Namespace.adjust = function(space) { | ||
var regexp = '[\\' + this.DELIMITERS.join('\\') + ']'; | ||
return space | ||
.replace(new RegExp(regexp + '+', 'g'), this.getDelimiter()) | ||
.replace(new RegExp('^' + regexp + '|' + regexp + '$'), '') | ||
} | ||
var Base = function() { | ||
this.uid = ++Base.uid; | ||
if (typeof this.init === 'function') { | ||
@@ -79,2 +219,3 @@ var response = this.init.apply(this, Array.prototype.slice.call(arguments)); | ||
Base.DEPENDENCIES = []; | ||
Base.uid = 0; | ||
@@ -93,39 +234,34 @@ Base.parent = null; | ||
} | ||
var Factory = { | ||
var Factory = function(BaseClazz, meta) { | ||
this._clazzUID = 0; | ||
this.BaseClazz = BaseClazz; | ||
this.meta = meta; | ||
} | ||
META_TYPE: 'ClazzJS.Clazz', | ||
Factory.prototype = { | ||
DEFAULT_PROCESSORS: { | ||
clazz: ['Clazz.Clazz'], | ||
proto: ['Clazz.Proto'] | ||
}, | ||
CLASS_NAME: 'Clazz{uid}', | ||
_clazzUID: 0, | ||
create: function(params) { | ||
var clazz, i, ii; | ||
var name = params.name || this.generateName(); | ||
var parent = params.parent; | ||
var metaTypes = params.metaTypes || [this.META_TYPE]; | ||
var processors = params.process || this.DEFAULT_PROCESSORS; | ||
var meta = params.meta; | ||
var dependencies = params.dependencies || []; | ||
if (typeof parent === 'string') { | ||
parent = [parent]; | ||
} | ||
if (Object.prototype.toString.call(parent) === '[object Array]') { | ||
parent = Manager.get(parent[0], parent[1] || []) | ||
} | ||
var clazz = this.createClazz(name, parent); | ||
clazz = this.createClazz(name, parent); | ||
clazz.DEPENDENCIES = dependencies; | ||
if (typeof meta === 'function') { | ||
meta = meta.apply(clazz, dependencies); | ||
} | ||
if (meta) { | ||
if (typeof meta === 'function') { | ||
meta = meta.apply(clazz, dependencies); | ||
} | ||
for (i = 0, ii = metaTypes.length; i < ii; ++i) { | ||
if (typeof metaTypes[i] === 'string') { | ||
metaTypes[i] = Meta.Manager.getType(metaTypes[i]); | ||
} | ||
metaTypes[i].process(clazz, meta); | ||
} | ||
this.applyMeta(clazz, meta, processors); | ||
} | ||
@@ -138,3 +274,3 @@ | ||
if (!parent) { | ||
parent = Base; | ||
parent = this.BaseClazz; | ||
} | ||
@@ -171,2 +307,23 @@ | ||
applyMeta: function(clazz, meta, processors) { | ||
var types = { clazz: clazz, proto: clazz.prototype }, typeProcessors, processor, i, ii; | ||
for (var type in types) { | ||
if (type in processors) { | ||
typeProcessors = processors[type] | ||
if (Object.prototype.toString.call(typeProcessors) !== '[object Array]') { | ||
typeProcessors = [typeProcessors]; | ||
} | ||
for (i = 0, ii = typeProcessors.length; i < ii; ++i) { | ||
processor = typeProcessors[i]; | ||
if (typeof processor === 'string') { | ||
processor = this.meta.processor(processor); | ||
} | ||
processor.process(types[type], meta); | ||
} | ||
} | ||
} | ||
}, | ||
generateName: function() { | ||
@@ -176,26 +333,12 @@ return this.CLASS_NAME.replace('{uid}', ++this._clazzUID); | ||
} | ||
var Manager = { | ||
var Manager = function() { | ||
this._clazz = {}; | ||
this._meta = {}; | ||
} | ||
_clazz: {}, | ||
_meta: {}, | ||
Manager.prototype = { | ||
adjustName: function(name, namespace) { | ||
if (typeof namespace === 'undefined') { | ||
namespace = NameSpace.current(); | ||
} | ||
return (namespace+'.'+name).replace(NameSpace.getDelimitersRegexp(), '.'); | ||
}, | ||
setMeta: function(name, meta) { | ||
this._meta[name] = meta; | ||
if (meta.metaTypes) { | ||
for (var i = 0, ii = meta.metaTypes.length; i < ii; ++i) { | ||
if (typeof meta.metaTypes[i] === 'string') { | ||
meta.metaTypes[i] = Meta.Manager.getType(meta.metaTypes[i]); | ||
} | ||
} | ||
} | ||
this._meta[this.adjustName(name)] = meta; | ||
return this; | ||
@@ -205,34 +348,16 @@ }, | ||
hasMeta: function(name) { | ||
var i, ii, namespaces = NameSpace.whereLookFor(); | ||
for (i = 0, ii = namespaces.length; i < ii; ++i) { | ||
if (this.adjustName(name, namespaces[i]) in this._meta) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return name in this._meta; | ||
}, | ||
getMeta: function(name) { | ||
var i, ii, aname, namespaces = NameSpace.whereLookFor(); | ||
for (i = 0, ii = namespaces.length; i < ii; ++i) { | ||
aname = this.adjustName(name, namespaces[i]); | ||
if (aname in this._meta) { | ||
return this._meta[aname]; | ||
} | ||
if (!this.hasMeta(name)) { | ||
throw new Error('Meta does not exists for "' + name + '"!'); | ||
} | ||
throw new Error('Meta does not exists for "' + name + '"!'); | ||
return this._meta[name]; | ||
}, | ||
getClazz: function(name, dependencies) { | ||
var i, ii, j, jj, clazz, aname, namespaces = NameSpace.whereLookFor(), isFound; | ||
var i, ii, j, jj, clazz, isFound; | ||
for (i = 0, ii = namespaces.length; i < ii; ++i) { | ||
aname = this.adjustName(name, namespaces[i]); | ||
if (aname in this._clazz) { | ||
clazz = this._clazz[aname]; | ||
break; | ||
} | ||
} | ||
clazz = this._clazz[name]; | ||
@@ -262,11 +387,5 @@ if (Object.prototype.toString.apply(clazz) === '[object Array]') { | ||
hasClazz: function(name, dependencies) { | ||
var i, ii, j, jj, clazz, aname, namespaces = NameSpace.whereLookFor(), isFound; | ||
var i, ii, j, jj, clazz, isFound; | ||
for (i = 0, ii = namespaces.length; i < ii; ++i) { | ||
aname = this.adjustName(name, namespaces[i]); | ||
if (aname in this._clazz) { | ||
clazz = this._clazz[aname]; | ||
break; | ||
} | ||
} | ||
clazz = this._clazz[name]; | ||
@@ -303,28 +422,24 @@ if (Object.prototype.toString.apply(clazz) === '[object Array]') { | ||
} | ||
var aname = this.adjustName(name); | ||
if (!(aname in this._clazz)) { | ||
this._clazz[aname] = []; | ||
if (!(name in this._clazz)) { | ||
this._clazz[name] = []; | ||
} | ||
this._clazz[aname].push(clazz); | ||
this._clazz[name].push(clazz); | ||
return this; | ||
}, | ||
get: function(name , dependencies) { | ||
if (!this.hasClazz(name, dependencies)) { | ||
var meta = this.getMeta(name); | ||
meta.name = name; | ||
meta.dependencies = dependencies; | ||
this.setClazz(Factory.create(meta)); | ||
} | ||
return this.getClazz(name, dependencies); | ||
}, | ||
has: function(name) { | ||
return this.hasClazz(name) || this.hasMeta(name); | ||
} | ||
} | ||
var ConstantsInitProcessor = function(object, constants) { | ||
meta.processor('Clazz.Clazz', 'Meta.Options', { | ||
options: { | ||
constants: 'Clazz.Constants', | ||
clazz_properties: 'Clazz.Properties', | ||
clazz_methods: 'Clazz.Methods' | ||
} | ||
}) | ||
meta.processor('Clazz.Constants', 'Meta.Chain', { | ||
processors: { | ||
init: 'Clazz.Constants.Init', | ||
interface: 'Clazz.Constants.Interface' | ||
} | ||
}) | ||
meta.processor('Clazz.Constants.Init', function(object, constants) { | ||
object['__constants'] = {}; | ||
@@ -335,51 +450,53 @@ | ||
} | ||
} | ||
var ConstantsInterfaceProcessor = new Meta.Processors.Interface({ | ||
}) | ||
meta.processor('Clazz.Constants.Interface', 'Meta.Interface', { | ||
const: function(name) { | ||
return this.__getConstant(name); | ||
}, | ||
interface: { | ||
__getConstant: function(name, constants) { | ||
var self = this; | ||
const: function(name) { | ||
return this.__getConstant(name); | ||
}, | ||
if (typeof constants === 'undefined') { | ||
constants = self.__getConstants(); | ||
} | ||
__getConstant: function(name, constants) { | ||
var self = this; | ||
if (typeof name !== 'undefined') { | ||
if (!(name in constants)) { | ||
throw new Error('Constant "' + name + '" does not defined!'); | ||
if (typeof constants === 'undefined') { | ||
constants = self.__getConstants(); | ||
} | ||
constants = constants[name]; | ||
if (Object.prototype.toString.apply(constants) === '[object Object]') { | ||
return function(name) { | ||
return self.__getConstant(name, constants) | ||
if (typeof name !== 'undefined') { | ||
if (!(name in constants)) { | ||
throw new Error('Constant "' + name + '" does not defined!'); | ||
} | ||
constants = constants[name]; | ||
if (Object.prototype.toString.apply(constants) === '[object Object]') { | ||
return function(name) { | ||
return self.__getConstant(name, constants) | ||
} | ||
} | ||
} | ||
} | ||
return constants; | ||
}, | ||
return constants; | ||
}, | ||
__getConstants: function() { | ||
var constants = {}, parent = this; | ||
__getConstants: function() { | ||
var constants = {}, parent = this; | ||
while (parent) { | ||
if (parent.hasOwnProperty('__constants')) { | ||
for (var constant in parent['__constants']) { | ||
if (!(constant in constants)) { | ||
constants[constant] = parent['__constants'][constant]; | ||
while (parent) { | ||
if (parent.hasOwnProperty('__constants')) { | ||
for (var constant in parent['__constants']) { | ||
if (!(constant in constants)) { | ||
constants[constant] = parent['__constants'][constant]; | ||
} | ||
} | ||
} | ||
parent = parent.parent; | ||
} | ||
parent = parent.parent; | ||
return constants; | ||
} | ||
return constants; | ||
} | ||
}) | ||
meta.processor('Clazz.Methods', function(object, methods) { | ||
}); | ||
var MethodsProcessor = function(object, methods) { | ||
// Copy parent clazz methods | ||
@@ -402,5 +519,18 @@ if (typeof object === 'function' && object.parent) { | ||
} | ||
} | ||
var PropertiesDefaultsProcessor = { | ||
}) | ||
meta.processor('Clazz.Properties', 'Meta.Chain', { | ||
processors: { | ||
init: 'Clazz.Properties.Init', | ||
interface: 'Clazz.Properties.Interface', | ||
meta: 'Clazz.Properties.Meta', | ||
defaults: 'Clazz.Properties.Defaults' | ||
} | ||
}); | ||
meta.processor('Clazz.Properties.Defaults', { | ||
DEFAULT: { | ||
hash: {}, | ||
array: [] | ||
}, | ||
process: function(object) { | ||
@@ -419,535 +549,505 @@ | ||
} | ||
object['_' + property] = this.copy(defaultValue); | ||
object['_' + property] = this.__copy(defaultValue); | ||
} | ||
}, | ||
copy: function(object) { | ||
var copy, toString = Object.prototype.toString.apply(object); | ||
if (typeof object !== 'object') { | ||
copy = object; | ||
} | ||
else if ('[object Date]' === toString) { | ||
copy = new Date(object.getTime()) | ||
} | ||
else if ('[object Array]' === toString) { | ||
copy = []; | ||
for (var i = 0, ii = object.length; i < ii; ++i) { | ||
copy[i] = this.copy(object[i]); | ||
} | ||
} | ||
else if ('[object RegExp]' === toString) { | ||
copy = new RegExp(object.source); | ||
} | ||
else { | ||
copy = {} | ||
for (var property in object) { | ||
copy[property] = this.copy(object[property]); | ||
} | ||
} | ||
return copy; | ||
}, | ||
DEFAULT: { | ||
hash: {}, | ||
array: [] | ||
} | ||
} | ||
var PropertiesInitProcessor = function(object, properties) { | ||
}) | ||
meta.processor('Clazz.Properties.Init', function(object, properties) { | ||
for (var property in properties) { | ||
object['_' + property] = undefined; | ||
} | ||
}) | ||
meta.processor('Clazz.Properties.Interface', 'Meta.Interface', { | ||
} | ||
var PropertiesInterfaceProcessor = new Meta.Processors.Interface({ | ||
interface: { | ||
__setters: {}, | ||
__getters: {}, | ||
__setters: {}, | ||
__getters: {}, | ||
__properties: {}, | ||
__properties: {}, | ||
init: function(data) { | ||
this.__setData(data); | ||
}, | ||
init: function(data) { | ||
this.__setData(data); | ||
}, | ||
__setProperties: function(properties) { | ||
for (var property in properties) { | ||
this.__setProperty(property, properties[property]); | ||
} | ||
return this; | ||
}, | ||
__setProperties: function(properties) { | ||
for (var property in properties) { | ||
this.__setProperty(property, properties[property]); | ||
} | ||
return this; | ||
}, | ||
__getProperties: function() { | ||
return this.__properties; | ||
}, | ||
__getProperties: function() { | ||
return this.__properties; | ||
}, | ||
__setProperty: function(property, key, value) { | ||
property = this.__adjustPropertyName(property); | ||
__setProperty: function(property, key, value) { | ||
property = this.__adjustPropertyName(property); | ||
if (typeof this.__properties[property] === 'undefined') { | ||
this.__properties[property] = {}; | ||
} | ||
if ({}.constructor === key.constructor) { | ||
for (var prop in key) { | ||
this.__properties[property][prop] = key[prop]; | ||
if (typeof this.__properties[property] === 'undefined') { | ||
this.__properties[property] = {}; | ||
} | ||
} | ||
else { | ||
this.__properties[property][key] = value; | ||
} | ||
if ({}.constructor === key.constructor) { | ||
for (var prop in key) { | ||
this.__properties[property][prop] = key[prop]; | ||
} | ||
} | ||
else { | ||
this.__properties[property][key] = value; | ||
} | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
__getProperty: function(property, key) { | ||
return typeof key === 'undefined' | ||
? this.__properties[property] | ||
: this.__properties[property] && this.__properties[property][key]; | ||
}, | ||
__getProperty: function(property, key) { | ||
return typeof key === 'undefined' | ||
? this.__properties[property] | ||
: this.__properties[property] && this.__properties[property][key]; | ||
}, | ||
__hasProperty: function(property) { | ||
property = this.__adjustPropertyName(property); | ||
__hasProperty: function(property) { | ||
property = this.__adjustPropertyName(property); | ||
return ('_' + property) in this && typeof this['_' + property] !== 'function'; | ||
}, | ||
return property in this.__properties; | ||
}, | ||
__adjustPropertyName: function(name) { | ||
return name.replace(/(?:_)\w/, function (match) { return match[1].toUpperCase(); }); | ||
}, | ||
__adjustPropertyName: function(name) { | ||
return name.replace(/(?:_)\w/, function (match) { return match[1].toUpperCase(); }); | ||
}, | ||
__setData: function(data) { | ||
for (var property in data) { | ||
if (!this.__hasProperty(property)) { | ||
continue; | ||
__setData: function(data) { | ||
for (var property in data) { | ||
if (!this.__hasProperty(property)) { | ||
continue; | ||
} | ||
this.__setPropertyValue(property, data[property]); | ||
} | ||
this.__setPropertyValue(property, data[property]); | ||
} | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
__getPropertyValue: function(property /*, fields... */) { | ||
var getters, i, ii, name, value; | ||
__getPropertyValue: function(property /*, fields... */) { | ||
var getters, i, ii, name, value; | ||
property = this.__adjustPropertyName(property); | ||
property = this.__adjustPropertyName(property); | ||
if (!this.__hasProperty(property)) { | ||
throw new Error('Can\'t get! Property "' + property + '" does not exists!'); | ||
} | ||
if (!this.__hasProperty(property)) { | ||
throw new Error('Can\'t get! Property "' + property + '" does not exists!'); | ||
} | ||
value = this['_' + property]; | ||
value = this['_' + property]; | ||
getters = this.__getGetters(property); | ||
getters = this.__getGetters(property); | ||
for (name in getters) { | ||
value = getters[name].call(this, value); | ||
} | ||
for (name in getters) { | ||
value = getters[name].call(this, value); | ||
} | ||
var fields = Object.prototype.toString.call(arguments[1]) === '[object Array]' | ||
? arguments[1] | ||
: Array.prototype.slice.call(arguments, 1); | ||
var fields = Object.prototype.toString.call(arguments[1]) === '[object Array]' | ||
? arguments[1] | ||
: Array.prototype.slice.call(arguments, 1); | ||
for (i = 0, ii = fields.length; i < ii; ++i) { | ||
value = value[fields[i]]; | ||
} | ||
for (i = 0, ii = fields.length; i < ii; ++i) { | ||
value = value[fields[i]]; | ||
} | ||
return value; | ||
}, | ||
return value; | ||
}, | ||
__setPropertyValue: function(property /* fields... , value */) { | ||
var setters, i, ii, name, fields, value, setValue = arguments[arguments.length - 1]; | ||
__setPropertyValue: function(property /* fields... , value */) { | ||
var setters, i, ii, name, fields, value, setValue = arguments[arguments.length - 1]; | ||
property = this.__adjustPropertyName(property); | ||
property = this.__adjustPropertyName(property); | ||
if (!this.__hasProperty(property)) { | ||
throw new Error('Can\'t set! Property "' + property + '" does not exists!'); | ||
} | ||
if (!this.__hasProperty(property)) { | ||
throw new Error('Can\'t set! Property "' + property + '" does not exists!'); | ||
} | ||
fields = Object.prototype.toString.call(arguments[1]) === '[object Array]' | ||
? arguments[1] | ||
: Array.prototype.slice.call(arguments, 1, -1); | ||
fields = Object.prototype.toString.call(arguments[1]) === '[object Array]' | ||
? arguments[1] | ||
: Array.prototype.slice.call(arguments, 1, -1); | ||
if (fields && fields.length) { | ||
value = this['_' + property]; | ||
for (i = 0, ii = fields.length - 1; i < ii; ++i) { | ||
if (!(fields[i] in value)) { | ||
value[fields[i]] = {}; | ||
if (fields && fields.length) { | ||
value = this['_' + property]; | ||
for (i = 0, ii = fields.length - 1; i < ii; ++i) { | ||
if (!(fields[i] in value)) { | ||
value[fields[i]] = {}; | ||
} | ||
value = value[fields[i]]; | ||
} | ||
value = value[fields[i]]; | ||
value[fields[i]] = setValue; | ||
} | ||
value[fields[i]] = setValue; | ||
} | ||
else { | ||
value = setValue; | ||
} | ||
else { | ||
value = setValue; | ||
} | ||
setters = this.__getSetters(property); | ||
setters = this.__getSetters(property); | ||
for (name in setters) { | ||
value = setters[name].call(this, value); | ||
} | ||
for (name in setters) { | ||
value = setters[name].call(this, value); | ||
} | ||
this['_' + property] = value; | ||
this['_' + property] = value; | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
__isPropertyValue: function(property /* fields... , value */) { | ||
var fields = Object.prototype.toString.apply(arguments[1]) === '[object Array]' | ||
__isPropertyValue: function(property /* fields... , value */) { | ||
var fields = Object.prototype.toString.apply(arguments[1]) === '[object Array]' | ||
? arguments[1] | ||
: Array.prototype.slice.call(arguments, 1); | ||
var value = this.__getPropertyValue(property, fields); | ||
var compare = arguments[arguments.length - 1]; | ||
var value = this.__getPropertyValue(property, fields); | ||
var compare = arguments[arguments.length - 1]; | ||
return typeof value !== 'undefined' ? value == compare : !!value; | ||
}, | ||
return typeof value !== 'undefined' ? value == compare : !!value; | ||
}, | ||
__hasPropertyValue: function(property /*, fields... */) { | ||
var fields = Object.prototype.toString.apply(arguments[1]) === '[object Array]' | ||
? arguments[1] | ||
: Array.prototype.slice.call(arguments, 1); | ||
__hasPropertyValue: function(property /*, fields... */) { | ||
var fields = Object.prototype.toString.apply(arguments[1]) === '[object Array]' | ||
? arguments[1] | ||
: Array.prototype.slice.call(arguments, 1); | ||
var value = this.__getPropertyValue(property, fields); | ||
var value = this.__getPropertyValue(property, fields); | ||
if (Object.prototype.toString.apply(value) === '[object Object]') { | ||
for (var p in value) { | ||
return true; | ||
if (Object.prototype.toString.apply(value) === '[object Object]') { | ||
for (var p in value) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
return false; | ||
} | ||
return !((typeof this[value] === 'undefined') | ||
|| (value === null) | ||
|| (typeof value === 'string' && value === '') | ||
|| (Object.prototype.toString.apply(value) === '[object Array]' && value.length === 0)); | ||
}, | ||
return !((typeof this[value] === 'undefined') | ||
|| (value === null) | ||
|| (typeof value === 'string' && value === '') | ||
|| (Object.prototype.toString.apply(value) === '[object Array]' && value.length === 0)); | ||
}, | ||
__addSetter: function(property, weight, callback) { | ||
if (typeof callback === 'undefined') { | ||
callback = weight; | ||
weight = 0; | ||
} | ||
if (typeof callback !== 'function') { | ||
throw new Error('Set callback must be a function!'); | ||
} | ||
if (!(property in this.__setters)) { | ||
this.__setters[property] = []; | ||
} | ||
this.__setters[property].push([weight, callback]); | ||
__addSetter: function(property, weight, callback) { | ||
if (typeof callback === 'undefined') { | ||
callback = weight; | ||
weight = 0; | ||
} | ||
if (typeof callback !== 'function') { | ||
throw new Error('Set callback must be a function!'); | ||
} | ||
if (!(property in this.__setters)) { | ||
this.__setters[property] = []; | ||
} | ||
this.__setters[property].push([weight, callback]); | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
__getSetters: function(property) { | ||
var i, ii, setters, prop, allSetters = {}, parent = this.clazz.prototype; | ||
__getSetters: function(property) { | ||
var i, ii, setters, prop, allSetters = {}, parent = this.clazz.prototype; | ||
while (parent) { | ||
if (parent.hasOwnProperty('__setters')) { | ||
for (prop in parent.__setters) { | ||
if (!(prop in allSetters)) { | ||
allSetters[prop] = parent.__setters[prop]; | ||
while (parent) { | ||
if (parent.hasOwnProperty('__setters')) { | ||
for (prop in parent.__setters) { | ||
if (!(prop in allSetters)) { | ||
allSetters[prop] = parent.__setters[prop]; | ||
} | ||
} | ||
} | ||
parent = parent.parent; | ||
} | ||
parent = parent.parent; | ||
} | ||
if (typeof property !== 'undefined') { | ||
setters = []; | ||
if (property in allSetters && allSetters[property].length) { | ||
if (typeof property !== 'undefined') { | ||
setters = []; | ||
if (property in allSetters && allSetters[property].length) { | ||
allSetters[property].sort(function(s1, s2) { | ||
return s2[0] - s1[0]; | ||
}); | ||
allSetters[property].sort(function(s1, s2) { | ||
return s2[0] - s1[0]; | ||
}); | ||
for (i = 0, ii = allSetters[property].length; i < ii; ++i) { | ||
setters.push(allSetters[property][i][1]); | ||
for (i = 0, ii = allSetters[property].length; i < ii; ++i) { | ||
setters.push(allSetters[property][i][1]); | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
setters = allSetters; | ||
} | ||
else { | ||
setters = allSetters; | ||
} | ||
return setters; | ||
}, | ||
return setters; | ||
}, | ||
__addGetter: function(property, weight, callback) { | ||
if (typeof callback === 'undefined') { | ||
callback = weight; | ||
weight = 0; | ||
} | ||
if (typeof callback !== 'function') { | ||
throw new Error('Get callback must be a function!'); | ||
} | ||
if (!(property in this.__getters)) { | ||
this.__getters[property] = []; | ||
} | ||
this.__getters[property].push([weight, callback]); | ||
__addGetter: function(property, weight, callback) { | ||
if (typeof callback === 'undefined') { | ||
callback = weight; | ||
weight = 0; | ||
} | ||
if (typeof callback !== 'function') { | ||
throw new Error('Get callback must be a function!'); | ||
} | ||
if (!(property in this.__getters)) { | ||
this.__getters[property] = []; | ||
} | ||
this.__getters[property].push([weight, callback]); | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
__getGetters: function(property) { | ||
var i, ii, prop, getters, allGetters = {}, parent = this.clazz.prototype; | ||
__getGetters: function(property) { | ||
var i, ii, prop, getters, allGetters = {}, parent = this.clazz.prototype; | ||
while (parent) { | ||
if (parent.hasOwnProperty('__getters')) { | ||
for (prop in parent.__getters) { | ||
if (!(prop in allGetters)) { | ||
allGetters[prop] = parent.__getters[prop]; | ||
while (parent) { | ||
if (parent.hasOwnProperty('__getters')) { | ||
for (prop in parent.__getters) { | ||
if (!(prop in allGetters)) { | ||
allGetters[prop] = parent.__getters[prop]; | ||
} | ||
} | ||
} | ||
parent = parent.parent; | ||
} | ||
parent = parent.parent; | ||
} | ||
if (typeof property !== 'undefined') { | ||
getters = []; | ||
if (property in allGetters && allGetters[property].length) { | ||
if (typeof property !== 'undefined') { | ||
getters = []; | ||
if (property in allGetters && allGetters[property].length) { | ||
allGetters[property].sort(function(s1, s2) { | ||
return s2[0] - s1[0]; | ||
}); | ||
allGetters[property].sort(function(s1, s2) { | ||
return s2[0] - s1[0]; | ||
}); | ||
for (i = 0, ii = allGetters[property].length; i < ii; ++i) { | ||
getters.push(allGetters[property][i][1]); | ||
for (i = 0, ii = allGetters[property].length; i < ii; ++i) { | ||
getters.push(allGetters[property][i][1]); | ||
} | ||
} | ||
} | ||
else { | ||
getters = allGetters; | ||
} | ||
return getters; | ||
} | ||
else { | ||
getters = allGetters; | ||
} | ||
return getters; | ||
} | ||
}) | ||
var PropertiesMetaProcessor = { | ||
meta.processor('Clazz.Properties.Meta', function(object, properties) { | ||
for (var property in properties) { | ||
process: function(object, properties) { | ||
for (var property in properties) { | ||
this.MetaHandler.process(object, properties[property], property) | ||
var pmeta = properties[property]; | ||
if (Object.prototype.toString.call(pmeta) === '[object Array]') { | ||
properties[property] = pmeta = 3 === pmeta.length ? { type: [pmeta[0], pmeta[2]], default: pmeta[1] }: { type: pmeta } | ||
} | ||
}, | ||
else if (typeof pmeta !== 'object' || pmeta === null) { | ||
properties[property] = pmeta = { default: pmeta } | ||
} | ||
MetaHandler: new Meta.Handler({ | ||
options: { | ||
type: { | ||
process: function(object, type, option, property) { | ||
var self = this, params = {}; | ||
if (Object.prototype.toString.apply(type) === '[object Array]') { | ||
params = type[1]; | ||
type = type[0]; | ||
} | ||
if (!(type in this.TYPES)) { | ||
throw new Error('Unsupported property type "' + type + '"!'); | ||
} | ||
if (!('methods' in pmeta)) { | ||
pmeta.methods = ['get', 'set', 'has', 'is'] | ||
} | ||
object.__setProperty(property, 'type', type); | ||
meta.processor('Clazz.Property').process(object, pmeta, property); | ||
} | ||
}) | ||
meta.processor('Clazz.Property', 'Meta.Options', { | ||
options: { | ||
type: 'Clazz.Property.Type', | ||
default: 'Clazz.Property.Default', | ||
methods: 'Clazz.Property.Methods', | ||
converters: 'Clazz.Property.Converters', | ||
constraints: 'Clazz.Property.Constraints' | ||
} | ||
}) | ||
meta.processor('Clazz.Property.Constraints', function(object, constraints, property) { | ||
object.__addSetter(property, function(value) { | ||
return self.checkValue(value, type, params); | ||
}); | ||
}, | ||
object.__addSetter(property, function(value) { | ||
for (var name in constraints) { | ||
if (!constraints[name].call(this, value)) { | ||
throw new Error('Constraint "' + name + '" was failed!'); | ||
} | ||
} | ||
return value; | ||
}) | ||
}) | ||
meta.processor('Clazz.Property.Converters', function(object, converters, property) { | ||
checkValue: function(value, type, params) { | ||
return this.TYPES[type].call(this, value, params); | ||
}, | ||
object.__addSetter(property, 1000, function(value) { | ||
for (var name in converters) { | ||
value = converters[name].call(this, value); | ||
} | ||
return value; | ||
}) | ||
}) | ||
meta.processor('Clazz.Property.Default', function(object, defaultValue, property) { | ||
if (typeof defaultValue === 'function') { | ||
defaultValue = defaultValue(); | ||
} | ||
TYPES: { | ||
boolean: function(value) { | ||
return Boolean(value); | ||
}, | ||
number: function(value, params) { | ||
value = Number(value); | ||
if ('min' in params && value < params['min']) { | ||
throw new Error('Value "' + value + '" must not be less then "' + params['min'] + '"!'); | ||
} | ||
if ('max' in params && value > params['max']) { | ||
throw new Error('Value "' + value + '" must not be greater then "' + params['max'] + '"!'); | ||
} | ||
return value; | ||
}, | ||
string: function(value, params) { | ||
value = String(value); | ||
if ('pattern' in params && !params['pattern'].test(value)) { | ||
throw new Error('Value "' + value + '" does not match pattern "' + params['pattern'] + '"!'); | ||
} | ||
return value; | ||
}, | ||
datetime: function(value) { | ||
if (!(value instanceof Date)) { | ||
value = new Date(Date.parse(value)); | ||
} | ||
return value; | ||
}, | ||
array: function(value, params) { | ||
return typeof value === 'string' ? value.split(params['delimiter'] || ',') : [].concat(value); | ||
}, | ||
hash: function(value, params) { | ||
if ({}.constructor !== value.constructor) { | ||
throw new Error('Incorrect value: not hash type!'); | ||
} | ||
if ('keys' in params) { | ||
for (var prop in value) { | ||
if (!(prop in params.keys)) { | ||
throw new Error('Unsupported hash key "' + prop + '"!'); | ||
} | ||
} | ||
} | ||
if ('element' in params) { | ||
this.checkValue.apply(this, [].concat(params.element)); | ||
} | ||
return value; | ||
} | ||
} | ||
}, | ||
object.__setProperty(property, 'default', defaultValue); | ||
}) | ||
meta.processor('Clazz.Property.Methods', { | ||
default: { | ||
process: function(object, defaultValue, option, property) { | ||
var type; | ||
process: function(object, methods, property) { | ||
if (Object.prototype.toString.apply(methods) !== '[object Array]') { | ||
methods = [methods]; | ||
} | ||
if (typeof defaultValue === 'function') { | ||
defaultValue = defaultValue(); | ||
} | ||
for (var i = 0, ii = methods.length; i < ii; ++i) { | ||
this.addMethod(methods[i], object, property); | ||
} | ||
}, | ||
addMethod: function(name, object, property) { | ||
var method = this.createMethod(name, property); | ||
object[method.name] = method.body; | ||
}, | ||
object.__setProperty(property, 'default', defaultValue); | ||
} | ||
}, | ||
createMethod: function(name, property) { | ||
if (!(name in this.METHODS)) { | ||
throw new Error('Unsupported method "' + name + '"!'); | ||
} | ||
var method = this.METHODS[name](property); | ||
methods: { | ||
if (typeof method === 'function') { | ||
method = { | ||
name: name + property[0].toUpperCase() + property.slice(1), | ||
body: method | ||
} | ||
} | ||
return method; | ||
}, | ||
process: function(object, methods, option, property) { | ||
if (Object.prototype.toString.apply(methods) !== '[object Array]') { | ||
methods = [methods]; | ||
} | ||
for (var i = 0, ii = methods.length; i < ii; ++i) { | ||
this.addMethod(methods[i], object, property); | ||
} | ||
}, | ||
addMethod: function(name, object, property) { | ||
var method = this.createMethod(name, property); | ||
object[method.name] = method.body; | ||
}, | ||
createMethod: function(name, property) { | ||
if (!(name in this.METHODS)) { | ||
throw new Error('Unsupported method "' + name + '"!'); | ||
} | ||
var method = this.METHODS[name](property); | ||
if (typeof method === 'function') { | ||
method = { | ||
name: name + property[0].toUpperCase() + property.slice(1), | ||
body: method | ||
} | ||
} | ||
return method; | ||
}, | ||
METHODS: { | ||
get: function(property) { | ||
return function() { | ||
return this.__getPropertyValue.apply(this, [property].concat(Array.prototype.slice.call(arguments))); | ||
} | ||
}, | ||
set: function(property) { | ||
return function(value) { | ||
return this.__setPropertyValue.apply(this, [property].concat(Array.prototype.slice.call(arguments))); | ||
} | ||
}, | ||
is: function(property) { | ||
return { | ||
name: (0 !== property.indexOf('is') ? 'is' : '') + property[0].toUpperCase() + property.slice(1), | ||
body: function() { | ||
return this.__isPropertyValue.apply(this, [property].concat(Array.prototype.slice.call(arguments))); | ||
} | ||
} | ||
}, | ||
has: function(property) { | ||
return function() { | ||
return this.__hasPropertyValue.apply(this, [property].concat(Array.prototype.slice.call(arguments))); | ||
} | ||
} | ||
METHODS: { | ||
get: function(property) { | ||
return function() { | ||
return this.__getPropertyValue.apply(this, [property].concat(Array.prototype.slice.call(arguments))); | ||
} | ||
}, | ||
set: function(property) { | ||
return function(value) { | ||
return this.__setPropertyValue.apply(this, [property].concat(Array.prototype.slice.call(arguments))); | ||
} | ||
}, | ||
is: function(property) { | ||
return { | ||
name: (0 !== property.indexOf('is') ? 'is' : '') + property[0].toUpperCase() + property.slice(1), | ||
body: function() { | ||
return this.__isPropertyValue.apply(this, [property].concat(Array.prototype.slice.call(arguments))); | ||
} | ||
}, | ||
converters: function(object, converters, option, property) { | ||
object.__addSetter(property, 1000, function(value) { | ||
for (var name in converters) { | ||
value = converters[name].call(this, value); | ||
} | ||
return value; | ||
}) | ||
}, | ||
constraints: function(object, constraints, option, property) { | ||
object.__addSetter(property, function(value) { | ||
for (var name in constraints) { | ||
if (!constraints[name].call(this, value)) { | ||
throw new Error('Constraint "' + name + '" was failed!'); | ||
} | ||
} | ||
return value; | ||
}) | ||
} | ||
}, | ||
has: function(property) { | ||
return function() { | ||
return this.__hasPropertyValue.apply(this, [property].concat(Array.prototype.slice.call(arguments))); | ||
} | ||
} | ||
}) | ||
} | ||
Meta.Processors.sets({ | ||
} | ||
}) | ||
meta.processor('Clazz.Property.Type', { | ||
clazz_constants_init: ConstantsInitProcessor, | ||
clazz_constants_interface: ConstantsInterfaceProcessor, | ||
process: function(object, type, property) { | ||
var self = this, params = {}; | ||
clazz_constants: [ | ||
'clazz_constants_init', | ||
'clazz_constants_interface' | ||
], | ||
if (Object.prototype.toString.apply(type) === '[object Array]') { | ||
params = type[1] || []; | ||
type = type[0]; | ||
} | ||
if (!(type in this.TYPES)) { | ||
throw new Error('Unsupported property type "' + type + '"!'); | ||
} | ||
clazz_properties_init: PropertiesInitProcessor, | ||
clazz_properties_interface: PropertiesInterfaceProcessor, | ||
clazz_properties_meta: PropertiesMetaProcessor, | ||
clazz_properties_defaults: PropertiesDefaultsProcessor, | ||
object.__setProperty(property, 'type', type); | ||
clazz_properties: [ | ||
'clazz_properties_init', | ||
'clazz_properties_interface', | ||
'clazz_properties_meta', | ||
'clazz_properties_defaults' | ||
], | ||
object.__addSetter(property, function(value) { | ||
return self.checkValue(value, type, params, property); | ||
}); | ||
}, | ||
clazz_methods: MethodsProcessor | ||
}); | ||
checkValue: function(value, type, params, property) { | ||
return this.TYPES[type].call(this, value, params, property); | ||
}, | ||
Meta.Manager.setType(Factory.META_TYPE, { | ||
clazz: { | ||
options: { | ||
constants: 'clazz_constants', | ||
clazz_properties: 'clazz_properties', | ||
clazz_methods: 'clazz_methods' | ||
} | ||
}, | ||
object: { | ||
objectHandler: function(object) { | ||
return object.prototype; | ||
TYPES: { | ||
boolean: function(value) { | ||
return Boolean(value); | ||
}, | ||
options: { | ||
properties: 'clazz_properties', | ||
methods: 'clazz_methods' | ||
number: function(value, params) { | ||
value = Number(value); | ||
if ('min' in params && value < params['min']) { | ||
throw new Error('Value "' + value + '" must not be less then "' + params['min'] + '"!'); | ||
} | ||
if ('max' in params && value > params['max']) { | ||
throw new Error('Value "' + value + '" must not be greater then "' + params['max'] + '"!'); | ||
} | ||
return value; | ||
}, | ||
string: function(value, params) { | ||
value = String(value); | ||
if ('pattern' in params && !params.pattern.test(value)) { | ||
throw new Error('Value "' + value + '" does not match pattern "' + params.pattern + '"!'); | ||
} | ||
if ('variants' in params && -1 === params.variants.indexOf(value)) { | ||
throw new Error('Value "' + value + '" must be one of "' + params.variants.join(', ') + '"!'); | ||
} | ||
return value; | ||
}, | ||
datetime: function(value) { | ||
if (!(value instanceof Date)) { | ||
value = new Date(Date.parse(value)); | ||
} | ||
return value; | ||
}, | ||
object: function(value, params, property) { | ||
if (typeof value !== 'object' || Object.prototype.toString.call(value) === '[object Array]') { | ||
throw new Error('Incorrect value: not object type for property "' + property + '"!'); | ||
} | ||
if ('instanceof' in params) { | ||
var clazz = params.instanceof; | ||
if (Object.prototype.toString.call(clazz) === '[object Array]') { | ||
clazz = Clazz(clazz[0], clazz[1] || []); | ||
} | ||
if (!(value instanceof clazz)) { | ||
throw new Error('Value does not instance of clazz "' + clazz.NAME + '"!'); | ||
} | ||
} | ||
return value | ||
}, | ||
array: function(value, params) { | ||
return typeof value === 'string' ? value.split(params['delimiter'] || ',') : [].concat(value); | ||
}, | ||
hash: function(value, params, property) { | ||
if ({}.constructor !== value.constructor) { | ||
throw new Error('Incorrect value: not hash type for property "' + property +'"!'); | ||
} | ||
if ('keys' in params) { | ||
for (var prop in value) { | ||
if (!(prop in params.keys)) { | ||
throw new Error('Unsupported hash key "' + prop + '"!'); | ||
} | ||
} | ||
} | ||
if ('element' in params) { | ||
this.checkValue.apply(this, [].concat(params.element)); | ||
} | ||
return value; | ||
}, | ||
clazz: function(value, params, property) { | ||
if (typeof value !== 'function' || !('NAME' in value) || !('parent' in value)) { | ||
throw new Error('Incorrect value: not clazz type for property "' + property +'"!'); | ||
} | ||
return value; | ||
} | ||
} | ||
}); | ||
}) | ||
meta.processor('Clazz.Proto', 'Meta.Options', { | ||
options: { | ||
properties: 'Clazz.Properties', | ||
methods: 'Clazz.Methods' | ||
} | ||
}) | ||
;(function(global, meta) { | ||
Clazz.Base = Base; | ||
Clazz.Factory = Factory; | ||
Clazz.Manager = Manager; | ||
var factory = new Factory(Base, meta); | ||
var manager = new Manager(); | ||
var namespace = new Namespace(manager, factory, null, '', global, Clazz); | ||
var clazz = namespace(); | ||
global.NameSpace = NameSpace; | ||
global.Clazz = Clazz; | ||
global.namespace = namespace; | ||
global.clazz = clazz; | ||
})(this, Meta); | ||
})(global, meta); | ||
})(this, meta); |
@@ -1,2 +0,2 @@ | ||
!function(a,b,c){var d=function(a){var b,c,d,e=arguments[arguments.length-1];return"function"!=typeof e&&"[object Object]"!==Object.prototype.toString.call(e)?h.get(a,b||[]):(d=e,b=arguments[1],c=arguments[2],"[objectArray]"===Object.prototype.toString.call(b)&&(c=b,b=null),c===d&&(c=null),b===d&&(b=null),h.setMeta(a,{parent:b,metaTypes:c,meta:d}),void 0)},e=function(a){e.current()!==a&&e._stack.push(a)};e.GLOBAL="GLOBAL",e.DELIMITERS=["\\","/","_","-","."],e._stack=[],e.end=function(){this._stack.pop()},e.current=function(){return this._stack[this._stack.length-1]||this.GLOBAL},e.whereLookFor=function(){var a=this.current(),b=[a];return a!==this.GLOBAL&&b.push(this.GLOBAL),b},e.getDelimitersRegexp=function(){return new RegExp("[\\"+this.DELIMITERS.join("\\")+"]")};var f=function(){if("function"==typeof this.init){var a=this.init.apply(this,Array.prototype.slice.call(arguments));if("undefined"!=typeof a)return a}};f.NAME="__BASE_CLAZZ__",f.DEPENDENCIES=[],f.parent=null,f.create=function(){var a=arguments;return new this(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10])},f.prototype={parent:null,clazz:f};var g={META_TYPE:"ClazzJS.Clazz",CLASS_NAME:"Clazz{uid}",_clazzUID:0,create:function(a){var c,d,e,f=a.name||this.generateName(),g=a.parent,i=a.metaTypes||[this.META_TYPE],j=a.meta,k=a.dependencies||[];if("string"==typeof g&&(g=[g]),"[object Array]"===Object.prototype.toString.call(g)&&(g=h.get(g[0],g[1]||[])),c=this.createClazz(f,g),c.DEPENDENCIES=k,j)for("function"==typeof j&&(j=j.apply(c,k)),d=0,e=i.length;e>d;++d)"string"==typeof i[d]&&(i[d]=b.Manager.getType(i[d])),i[d].process(c,j);return c},createClazz:function(a,b){b||(b=f);var d=function(){var a=b.apply(this,Array.prototype.slice.call(arguments));return"undefined"!=typeof a?a:void 0};for(var e in b)"function"==typeof b[e]?d[e]=b[e]:"_"===e[0]&&(d[e]=c);return d.NAME=a||this.generateName(),d.parent=b,d.prototype=Object.create(b.prototype),d.prototype.clazz=d,d.prototype.parent=b.prototype,d},generateName:function(){return this.CLASS_NAME.replace("{uid}",++this._clazzUID)}},h={_clazz:{},_meta:{},adjustName:function(a,b){return"undefined"==typeof b&&(b=e.current()),(b+"."+a).replace(e.getDelimitersRegexp(),".")},setMeta:function(a,c){if(c.metaTypes)for(var d=0,e=c.metaTypes.length;e>d;++d)"string"==typeof c.metaTypes[d]&&(c.metaTypes[d]=b.Manager.getType(c.metaTypes[d]));return this._meta[this.adjustName(a)]=c,this},hasMeta:function(a){var b,c,d=e.whereLookFor();for(b=0,c=d.length;c>b;++b)if(this.adjustName(a,d[b])in this._meta)return!0;return!1},getMeta:function(a){var b,c,d,f=e.whereLookFor();for(b=0,c=f.length;c>b;++b)if(d=this.adjustName(a,f[b]),d in this._meta)return this._meta[d];throw new Error('Meta does not exists for "'+a+'"!')},getClazz:function(a,b){var c,d,f,g,h,i,j=e.whereLookFor(),k;for(c=0,d=j.length;d>c;++c)if(i=this.adjustName(a,j[c]),i in this._clazz){h=this._clazz[i];break}if("[object Array]"===Object.prototype.toString.apply(h))for(b||(b=[]),c=0,d=h.length;d>c;++c){for(k=!0,f=0,g=h[c].DEPENDENCIES.length;g>f;++f)if(h[c].DEPENDENCIES[f]!==b[f]){k=!1;break}if(k)return h[c]}throw new Error('Clazz "'+a+'" does not exists!')},hasClazz:function(a,b){var c,d,f,g,h,i,j=e.whereLookFor(),k;for(c=0,d=j.length;d>c;++c)if(i=this.adjustName(a,j[c]),i in this._clazz){h=this._clazz[i];break}if("[object Array]"===Object.prototype.toString.apply(h)){if(!b)return!0;for(c=0,d=h.length;d>c;++c){for(k=!0,f=0,g=h[c].DEPENDENCIES.length;g>f;++f)if(h[c].DEPENDENCIES[f]!==b[f]){k=!1;break}if(k)return!0}}return!1},setClazz:function(a,b){if("function"==typeof a&&(b=a,a=b.NAME),"function"!=typeof b)throw new Error("Clazz must be a function!");var c=this.adjustName(a);return c in this._clazz||(this._clazz[c]=[]),this._clazz[c].push(b),this},get:function(a,b){if(!this.hasClazz(a,b)){var c=this.getMeta(a);c.name=a,c.dependencies=b,this.setClazz(g.create(c))}return this.getClazz(a,b)},has:function(a){return this.hasClazz(a)||this.hasMeta(a)}},i=function(a,b){a.__constants={};for(var c in b)a.__constants[c]=b[c]},j=new b.Processors.Interface({"const":function(a){return this.__getConstant(a)},__getConstant:function(a,b){var c=this;if("undefined"==typeof b&&(b=c.__getConstants()),"undefined"!=typeof a){if(!(a in b))throw new Error('Constant "'+a+'" does not defined!');if(b=b[a],"[object Object]"===Object.prototype.toString.apply(b))return function(a){return c.__getConstant(a,b)}}return b},__getConstants:function(){for(var a={},b=this;b;){if(b.hasOwnProperty("__constants"))for(var c in b.__constants)c in a||(a[c]=b.__constants[c]);b=b.parent}return a}}),k=function(a,b){if("function"==typeof a&&a.parent)for(var c in a.parent)"function"==typeof a.parent[c]&&(a[c]=a.parent[c]);for(var c in b){if("function"!=typeof b[c])throw new Error('Method "'+c+'" must be a function!');a[c]=b[c]}},l={process:function(a){var b,c,d,e=a.__properties;for(d in e)c=e[d]["default"],"undefined"==typeof c&&(b=e[d].type,"undefined"!=typeof b&&b in this.DEFAULT&&(c=this.DEFAULT[b])),a["_"+d]=this.copy(c)},copy:function(a){var b,c=Object.prototype.toString.apply(a);if("object"!=typeof a)b=a;else if("[object Date]"===c)b=new Date(a.getTime());else if("[object Array]"===c){b=[];for(var d=0,e=a.length;e>d;++d)b[d]=this.copy(a[d])}else if("[object RegExp]"===c)b=new RegExp(a.source);else{b={};for(var f in a)b[f]=this.copy(a[f])}return b},DEFAULT:{hash:{},array:[]}},m=function(a,b){for(var d in b)a["_"+d]=c},n=new b.Processors.Interface({__setters:{},__getters:{},__properties:{},init:function(a){this.__setData(a)},__setProperties:function(a){for(var b in a)this.__setProperty(b,a[b]);return this},__getProperties:function(){return this.__properties},__setProperty:function(a,b,c){if(a=this.__adjustPropertyName(a),"undefined"==typeof this.__properties[a]&&(this.__properties[a]={}),{}.constructor===b.constructor)for(var d in b)this.__properties[a][d]=b[d];else this.__properties[a][b]=c;return this},__getProperty:function(a,b){return"undefined"==typeof b?this.__properties[a]:this.__properties[a]&&this.__properties[a][b]},__hasProperty:function(a){return a=this.__adjustPropertyName(a),"_"+a in this&&"function"!=typeof this["_"+a]},__adjustPropertyName:function(a){return a.replace(/(?:_)\w/,function(a){return a[1].toUpperCase()})},__setData:function(a){for(var b in a)this.__hasProperty(b)&&this.__setPropertyValue(b,a[b]);return this},__getPropertyValue:function(a){var b,c,d,e,f;if(a=this.__adjustPropertyName(a),!this.__hasProperty(a))throw new Error("Can't get! Property \""+a+'" does not exists!');f=this["_"+a],b=this.__getGetters(a);for(e in b)f=b[e].call(this,f);var g="[object Array]"===Object.prototype.toString.call(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);for(c=0,d=g.length;d>c;++c)f=f[g[c]];return f},__setPropertyValue:function(a){var b,c,d,e,f,g,h=arguments[arguments.length-1];if(a=this.__adjustPropertyName(a),!this.__hasProperty(a))throw new Error("Can't set! Property \""+a+'" does not exists!');if(f="[object Array]"===Object.prototype.toString.call(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1,-1),f&&f.length){for(g=this["_"+a],c=0,d=f.length-1;d>c;++c)f[c]in g||(g[f[c]]={}),g=g[f[c]];g[f[c]]=h}else g=h;b=this.__getSetters(a);for(e in b)g=b[e].call(this,g);return this["_"+a]=g,this},__isPropertyValue:function(a){var b="[object Array]"===Object.prototype.toString.apply(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1),c=this.__getPropertyValue(a,b),d=arguments[arguments.length-1];return"undefined"!=typeof c?c==d:!!c},__hasPropertyValue:function(a){var b="[object Array]"===Object.prototype.toString.apply(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1),c=this.__getPropertyValue(a,b);if("[object Object]"===Object.prototype.toString.apply(c)){for(var d in c)return!0;return!1}return!("undefined"==typeof this[c]||null===c||"string"==typeof c&&""===c||"[object Array]"===Object.prototype.toString.apply(c)&&0===c.length)},__addSetter:function(a,b,c){if("undefined"==typeof c&&(c=b,b=0),"function"!=typeof c)throw new Error("Set callback must be a function!");return a in this.__setters||(this.__setters[a]=[]),this.__setters[a].push([b,c]),this},__getSetters:function(a){for(var b,c,d,e,f={},g=this.clazz.prototype;g;){if(g.hasOwnProperty("__setters"))for(e in g.__setters)e in f||(f[e]=g.__setters[e]);g=g.parent}if("undefined"!=typeof a){if(d=[],a in f&&f[a].length)for(f[a].sort(function(a,b){return b[0]-a[0]}),b=0,c=f[a].length;c>b;++b)d.push(f[a][b][1])}else d=f;return d},__addGetter:function(a,b,c){if("undefined"==typeof c&&(c=b,b=0),"function"!=typeof c)throw new Error("Get callback must be a function!");return a in this.__getters||(this.__getters[a]=[]),this.__getters[a].push([b,c]),this},__getGetters:function(a){for(var b,c,d,e,f={},g=this.clazz.prototype;g;){if(g.hasOwnProperty("__getters"))for(d in g.__getters)d in f||(f[d]=g.__getters[d]);g=g.parent}if("undefined"!=typeof a){if(e=[],a in f&&f[a].length)for(f[a].sort(function(a,b){return b[0]-a[0]}),b=0,c=f[a].length;c>b;++b)e.push(f[a][b][1])}else e=f;return e}}),o={process:function(a,b){for(var c in b)this.MetaHandler.process(a,b[c],c)},MetaHandler:new b.Handler({options:{type:{process:function(a,b,c,d){var e=this,f={};if("[object Array]"===Object.prototype.toString.apply(b)&&(f=b[1],b=b[0]),!(b in this.TYPES))throw new Error('Unsupported property type "'+b+'"!');a.__setProperty(d,"type",b),a.__addSetter(d,function(a){return e.checkValue(a,b,f)})},checkValue:function(a,b,c){return this.TYPES[b].call(this,a,c)},TYPES:{"boolean":function(a){return Boolean(a)},number:function(a,b){if(a=Number(a),"min"in b&&a<b.min)throw new Error('Value "'+a+'" must not be less then "'+b.min+'"!');if("max"in b&&a>b.max)throw new Error('Value "'+a+'" must not be greater then "'+b.max+'"!');return a},string:function(a,b){if(a=String(a),"pattern"in b&&!b.pattern.test(a))throw new Error('Value "'+a+'" does not match pattern "'+b.pattern+'"!');return a},datetime:function(a){return a instanceof Date||(a=new Date(Date.parse(a))),a},array:function(a,b){return"string"==typeof a?a.split(b.delimiter||","):[].concat(a)},hash:function(a,b){if({}.constructor!==a.constructor)throw new Error("Incorrect value: not hash type!");if("keys"in b)for(var c in a)if(!(c in b.keys))throw new Error('Unsupported hash key "'+c+'"!');return"element"in b&&this.checkValue.apply(this,[].concat(b.element)),a}}},"default":{process:function(a,b,c,d){var e;"function"==typeof b&&(b=b()),a.__setProperty(d,"default",b)}},methods:{process:function(a,b,c,d){"[object Array]"!==Object.prototype.toString.apply(b)&&(b=[b]);for(var e=0,f=b.length;f>e;++e)this.addMethod(b[e],a,d)},addMethod:function(a,b,c){var d=this.createMethod(a,c);b[d.name]=d.body},createMethod:function(a,b){if(!(a in this.METHODS))throw new Error('Unsupported method "'+a+'"!');var c=this.METHODS[a](b);return"function"==typeof c&&(c={name:a+b[0].toUpperCase()+b.slice(1),body:c}),c},METHODS:{get:function(a){return function(){return this.__getPropertyValue.apply(this,[a].concat(Array.prototype.slice.call(arguments)))}},set:function(a){return function(b){return this.__setPropertyValue.apply(this,[a].concat(Array.prototype.slice.call(arguments)))}},is:function(a){return{name:(0!==a.indexOf("is")?"is":"")+a[0].toUpperCase()+a.slice(1),body:function(){return this.__isPropertyValue.apply(this,[a].concat(Array.prototype.slice.call(arguments)))}}},has:function(a){return function(){return this.__hasPropertyValue.apply(this,[a].concat(Array.prototype.slice.call(arguments)))}}}},converters:function(a,b,c,d){a.__addSetter(d,1e3,function(a){for(var c in b)a=b[c].call(this,a);return a})},constraints:function(a,b,c,d){a.__addSetter(d,function(a){for(var c in b)if(!b[c].call(this,a))throw new Error('Constraint "'+c+'" was failed!');return a})}}})};b.Processors.sets({clazz_constants_init:i,clazz_constants_interface:j,clazz_constants:["clazz_constants_init","clazz_constants_interface"],clazz_properties_init:m,clazz_properties_interface:n,clazz_properties_meta:o,clazz_properties_defaults:l,clazz_properties:["clazz_properties_init","clazz_properties_interface","clazz_properties_meta","clazz_properties_defaults"],clazz_methods:k}),b.Manager.setType(g.META_TYPE,{clazz:{options:{constants:"clazz_constants",clazz_properties:"clazz_properties",clazz_methods:"clazz_methods"}},object:{objectHandler:function(a){return a.prototype},options:{properties:"clazz_properties",methods:"clazz_methods"}}}),d.Base=f,d.Factory=g,d.Manager=h,a.NameSpace=e,a.Clazz=d}(this,Meta); | ||
!function(a,b,c){var d=function(a,b,c){var e=function(a,b,c,d){var f=arguments[arguments.length-1];return"function"!=typeof f&&"[object Object]"!==Object.prototype.toString.call(f)?e.get(a,b):(e.set(a,b,c,d),void 0)};for(var f in d.prototype)e[f]=d.prototype[f];return e.getManager=function(){return a},e.getFactory=function(){return b},e.getNamespace=function(){return c},e};d.prototype={get:function(a,b){if(a=this.resolveName(a),!a)throw new Error('Clazz with name "'+a+'" does not exits!');b=b||[];var c=this.getManager(),d=this.getFactory();if(!c.hasClazz(a,b)){var e=c.getMeta(a);c.setClazz(d.create({name:a,dependencies:b,process:e.process,parent:this.adjustParent(e.parent),meta:e.meta}))}return c.getClazz(a,b)},has:function(a){return!!this.resolveName(a)},set:function(a,b,c,d){var e=this.getNamespace(),f=this.getManager();return"object"==typeof a?(b=a.parent,c=a.process,d=a.meta,a=a.name):("undefined"==typeof d&&(d=c,c=null),"undefined"==typeof d&&(d=b,b=null),"[object Array]"===Object.prototype.toString.call(b)&&(c=b,b=null)),a=e.apply(a),f.setMeta(a,{parent:b,process:c,meta:d}),this},resolveName:function(a){var b,c,d,e,f=this.getManager(),g=this.getNamespace();for(b=g.getPaths(),d=0,e=b.length;e>d;++d)if(c=g.apply(a,b[d]),f.hasMeta(c))return c;return!1},adjustParent:function(a){return"string"==typeof a&&(a=[a]),"[object Array]"===Object.prototype.toString.call(a)&&(a=this.get(a[0],a[1]||[])),a}};var e=function(a,b,c,f,g,h){h=h||d;var i=function(c,d){var f=new e(a,b,i,c,g),j=new h(a,b,i);return d&&d(f,j),j};return i.getManager=function(){return a},i.getFactory=function(){return b},i.getBaseNamespace=function(){return c},i.getGlobal=function(){return g},i.getPath=function(){return e.adjust((c?c.getPath():e.GLOBAL)+e.getDelimiter()+f)},i.getPaths=function(){var a=this.getPath();return-1===a.indexOf(e.GLOBAL)&&a.push(e.GLOBAL),[this.getPath()]},i.apply=function(a,b){return e.adjust((b||this.getPath())+e.getDelimiter()+a)},i};e.GLOBAL="GLOBAL",e.DEFAULT_DELIMITER=".",e.DELIMITERS=["\\","/","_","-","."],e._delimiter=null,e.setDelimiter=function(a){if(!(a in this.DELIMITERS))throw new Error("Unsupported delimiter")},e.getDelimiter=function(){return this._delimiter||this.DEFAULT_DELIMITER},e.adjust=function(a){var b="[\\"+this.DELIMITERS.join("\\")+"]";return a.replace(new RegExp(b+"+","g"),this.getDelimiter()).replace(new RegExp("^"+b+"|"+b+"$"),"")};var f=function(){if(this.uid=++f.uid,"function"==typeof this.init){var a=this.init.apply(this,Array.prototype.slice.call(arguments));if("undefined"!=typeof a)return a}};f.NAME="__BASE_CLAZZ__",f.DEPENDENCIES=[],f.uid=0,f.parent=null,f.create=function(){var a=arguments;return new this(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10])},f.prototype={parent:null,clazz:f};var g=function(a,b){this._clazzUID=0,this.BaseClazz=a,this.meta=b};g.prototype={DEFAULT_PROCESSORS:{clazz:["Clazz.Clazz"],proto:["Clazz.Proto"]},CLASS_NAME:"Clazz{uid}",create:function(a){var b=a.name||this.generateName(),c=a.parent,d=a.process||this.DEFAULT_PROCESSORS,e=a.meta,f=a.dependencies||[],g=this.createClazz(b,c);return g.DEPENDENCIES=f,"function"==typeof e&&(e=e.apply(g,f)),e&&this.applyMeta(g,e,d),g},createClazz:function(a,b){b||(b=this.BaseClazz);var d=function(){var a=b.apply(this,Array.prototype.slice.call(arguments));return"undefined"!=typeof a?a:void 0};for(var e in b)"function"==typeof b[e]?d[e]=b[e]:"_"===e[0]&&(d[e]=c);return d.NAME=a||this.generateName(),d.parent=b,d.prototype=Object.create(b.prototype),d.prototype.clazz=d,d.prototype.parent=b.prototype,d},applyMeta:function(a,b,c){var d={clazz:a,proto:a.prototype},e,f,g,h;for(var i in d)if(i in c)for(e=c[i],"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),g=0,h=e.length;h>g;++g)f=e[g],"string"==typeof f&&(f=this.meta.processor(f)),f.process(d[i],b)},generateName:function(){return this.CLASS_NAME.replace("{uid}",++this._clazzUID)}};var h=function(){this._clazz={},this._meta={}};h.prototype={setMeta:function(a,b){return this._meta[a]=b,this},hasMeta:function(a){return a in this._meta},getMeta:function(a){if(!this.hasMeta(a))throw new Error('Meta does not exists for "'+a+'"!');return this._meta[a]},getClazz:function(a,b){var c,d,e,f,g,h;if(g=this._clazz[a],"[object Array]"===Object.prototype.toString.apply(g))for(b||(b=[]),c=0,d=g.length;d>c;++c){for(h=!0,e=0,f=g[c].DEPENDENCIES.length;f>e;++e)if(g[c].DEPENDENCIES[e]!==b[e]){h=!1;break}if(h)return g[c]}throw new Error('Clazz "'+a+'" does not exists!')},hasClazz:function(a,b){var c,d,e,f,g,h;if(g=this._clazz[a],"[object Array]"===Object.prototype.toString.apply(g)){if(!b)return!0;for(c=0,d=g.length;d>c;++c){for(h=!0,e=0,f=g[c].DEPENDENCIES.length;f>e;++e)if(g[c].DEPENDENCIES[e]!==b[e]){h=!1;break}if(h)return!0}}return!1},setClazz:function(a,b){if("function"==typeof a&&(b=a,a=b.NAME),"function"!=typeof b)throw new Error("Clazz must be a function!");return a in this._clazz||(this._clazz[a]=[]),this._clazz[a].push(b),this}},b.processor("Clazz.Clazz","Meta.Options",{options:{constants:"Clazz.Constants",clazz_properties:"Clazz.Properties",clazz_methods:"Clazz.Methods"}}),b.processor("Clazz.Constants","Meta.Chain",{processors:{init:"Clazz.Constants.Init","interface":"Clazz.Constants.Interface"}}),b.processor("Clazz.Constants.Init",function(a,b){a.__constants={};for(var c in b)a.__constants[c]=b[c]}),b.processor("Clazz.Constants.Interface","Meta.Interface",{"interface":{"const":function(a){return this.__getConstant(a)},__getConstant:function(a,b){var c=this;if("undefined"==typeof b&&(b=c.__getConstants()),"undefined"!=typeof a){if(!(a in b))throw new Error('Constant "'+a+'" does not defined!');if(b=b[a],"[object Object]"===Object.prototype.toString.apply(b))return function(a){return c.__getConstant(a,b)}}return b},__getConstants:function(){for(var a={},b=this;b;){if(b.hasOwnProperty("__constants"))for(var c in b.__constants)c in a||(a[c]=b.__constants[c]);b=b.parent}return a}}}),b.processor("Clazz.Methods",function(a,b){if("function"==typeof a&&a.parent)for(var c in a.parent)"function"==typeof a.parent[c]&&(a[c]=a.parent[c]);for(var c in b){if("function"!=typeof b[c])throw new Error('Method "'+c+'" must be a function!');a[c]=b[c]}}),b.processor("Clazz.Properties","Meta.Chain",{processors:{init:"Clazz.Properties.Init","interface":"Clazz.Properties.Interface",meta:"Clazz.Properties.Meta",defaults:"Clazz.Properties.Defaults"}}),b.processor("Clazz.Properties.Defaults",{DEFAULT:{hash:{},array:[]},process:function(a){var b,c,d,e=a.__properties;for(d in e)c=e[d]["default"],"undefined"==typeof c&&(b=e[d].type,"undefined"!=typeof b&&b in this.DEFAULT&&(c=this.DEFAULT[b])),a["_"+d]=this.__copy(c)}}),b.processor("Clazz.Properties.Init",function(a,b){for(var d in b)a["_"+d]=c}),b.processor("Clazz.Properties.Interface","Meta.Interface",{"interface":{__setters:{},__getters:{},__properties:{},init:function(a){this.__setData(a)},__setProperties:function(a){for(var b in a)this.__setProperty(b,a[b]);return this},__getProperties:function(){return this.__properties},__setProperty:function(a,b,c){if(a=this.__adjustPropertyName(a),"undefined"==typeof this.__properties[a]&&(this.__properties[a]={}),{}.constructor===b.constructor)for(var d in b)this.__properties[a][d]=b[d];else this.__properties[a][b]=c;return this},__getProperty:function(a,b){return"undefined"==typeof b?this.__properties[a]:this.__properties[a]&&this.__properties[a][b]},__hasProperty:function(a){return a=this.__adjustPropertyName(a),a in this.__properties},__adjustPropertyName:function(a){return a.replace(/(?:_)\w/,function(a){return a[1].toUpperCase()})},__setData:function(a){for(var b in a)this.__hasProperty(b)&&this.__setPropertyValue(b,a[b]);return this},__getPropertyValue:function(a){var b,c,d,e,f;if(a=this.__adjustPropertyName(a),!this.__hasProperty(a))throw new Error("Can't get! Property \""+a+'" does not exists!');f=this["_"+a],b=this.__getGetters(a);for(e in b)f=b[e].call(this,f);var g="[object Array]"===Object.prototype.toString.call(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);for(c=0,d=g.length;d>c;++c)f=f[g[c]];return f},__setPropertyValue:function(a){var b,c,d,e,f,g,h=arguments[arguments.length-1];if(a=this.__adjustPropertyName(a),!this.__hasProperty(a))throw new Error("Can't set! Property \""+a+'" does not exists!');if(f="[object Array]"===Object.prototype.toString.call(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1,-1),f&&f.length){for(g=this["_"+a],c=0,d=f.length-1;d>c;++c)f[c]in g||(g[f[c]]={}),g=g[f[c]];g[f[c]]=h}else g=h;b=this.__getSetters(a);for(e in b)g=b[e].call(this,g);return this["_"+a]=g,this},__isPropertyValue:function(a){var b="[object Array]"===Object.prototype.toString.apply(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1),c=this.__getPropertyValue(a,b),d=arguments[arguments.length-1];return"undefined"!=typeof c?c==d:!!c},__hasPropertyValue:function(a){var b="[object Array]"===Object.prototype.toString.apply(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1),c=this.__getPropertyValue(a,b);if("[object Object]"===Object.prototype.toString.apply(c)){for(var d in c)return!0;return!1}return!("undefined"==typeof this[c]||null===c||"string"==typeof c&&""===c||"[object Array]"===Object.prototype.toString.apply(c)&&0===c.length)},__addSetter:function(a,b,c){if("undefined"==typeof c&&(c=b,b=0),"function"!=typeof c)throw new Error("Set callback must be a function!");return a in this.__setters||(this.__setters[a]=[]),this.__setters[a].push([b,c]),this},__getSetters:function(a){for(var b,c,d,e,f={},g=this.clazz.prototype;g;){if(g.hasOwnProperty("__setters"))for(e in g.__setters)e in f||(f[e]=g.__setters[e]);g=g.parent}if("undefined"!=typeof a){if(d=[],a in f&&f[a].length)for(f[a].sort(function(a,b){return b[0]-a[0]}),b=0,c=f[a].length;c>b;++b)d.push(f[a][b][1])}else d=f;return d},__addGetter:function(a,b,c){if("undefined"==typeof c&&(c=b,b=0),"function"!=typeof c)throw new Error("Get callback must be a function!");return a in this.__getters||(this.__getters[a]=[]),this.__getters[a].push([b,c]),this},__getGetters:function(a){for(var b,c,d,e,f={},g=this.clazz.prototype;g;){if(g.hasOwnProperty("__getters"))for(d in g.__getters)d in f||(f[d]=g.__getters[d]);g=g.parent}if("undefined"!=typeof a){if(e=[],a in f&&f[a].length)for(f[a].sort(function(a,b){return b[0]-a[0]}),b=0,c=f[a].length;c>b;++b)e.push(f[a][b][1])}else e=f;return e}}}),b.processor("Clazz.Properties.Meta",function(a,c){for(var d in c){var e=c[d];"[object Array]"===Object.prototype.toString.call(e)?c[d]=e=3===e.length?{type:[e[0],e[2]],"default":e[1]}:{type:e}:("object"!=typeof e||null===e)&&(c[d]=e={"default":e}),"methods"in e||(e.methods=["get","set","has","is"]),b.processor("Clazz.Property").process(a,e,d)}}),b.processor("Clazz.Property","Meta.Options",{options:{type:"Clazz.Property.Type","default":"Clazz.Property.Default",methods:"Clazz.Property.Methods",converters:"Clazz.Property.Converters",constraints:"Clazz.Property.Constraints"}}),b.processor("Clazz.Property.Constraints",function(a,b,c){a.__addSetter(c,function(a){for(var c in b)if(!b[c].call(this,a))throw new Error('Constraint "'+c+'" was failed!');return a})}),b.processor("Clazz.Property.Converters",function(a,b,c){a.__addSetter(c,1e3,function(a){for(var c in b)a=b[c].call(this,a);return a})}),b.processor("Clazz.Property.Default",function(a,b,c){"function"==typeof b&&(b=b()),a.__setProperty(c,"default",b)}),b.processor("Clazz.Property.Methods",{process:function(a,b,c){"[object Array]"!==Object.prototype.toString.apply(b)&&(b=[b]);for(var d=0,e=b.length;e>d;++d)this.addMethod(b[d],a,c)},addMethod:function(a,b,c){var d=this.createMethod(a,c);b[d.name]=d.body},createMethod:function(a,b){if(!(a in this.METHODS))throw new Error('Unsupported method "'+a+'"!');var c=this.METHODS[a](b);return"function"==typeof c&&(c={name:a+b[0].toUpperCase()+b.slice(1),body:c}),c},METHODS:{get:function(a){return function(){return this.__getPropertyValue.apply(this,[a].concat(Array.prototype.slice.call(arguments)))}},set:function(a){return function(b){return this.__setPropertyValue.apply(this,[a].concat(Array.prototype.slice.call(arguments)))}},is:function(a){return{name:(0!==a.indexOf("is")?"is":"")+a[0].toUpperCase()+a.slice(1),body:function(){return this.__isPropertyValue.apply(this,[a].concat(Array.prototype.slice.call(arguments)))}}},has:function(a){return function(){return this.__hasPropertyValue.apply(this,[a].concat(Array.prototype.slice.call(arguments)))}}}}),b.processor("Clazz.Property.Type",{process:function(a,b,c){var d=this,e={};if("[object Array]"===Object.prototype.toString.apply(b)&&(e=b[1]||[],b=b[0]),!(b in this.TYPES))throw new Error('Unsupported property type "'+b+'"!');a.__setProperty(c,"type",b),a.__addSetter(c,function(a){return d.checkValue(a,b,e,c)})},checkValue:function(a,b,c,d){return this.TYPES[b].call(this,a,c,d)},TYPES:{"boolean":function(a){return Boolean(a)},number:function(a,b){if(a=Number(a),"min"in b&&a<b.min)throw new Error('Value "'+a+'" must not be less then "'+b.min+'"!');if("max"in b&&a>b.max)throw new Error('Value "'+a+'" must not be greater then "'+b.max+'"!');return a},string:function(a,b){if(a=String(a),"pattern"in b&&!b.pattern.test(a))throw new Error('Value "'+a+'" does not match pattern "'+b.pattern+'"!');if("variants"in b&&-1===b.variants.indexOf(a))throw new Error('Value "'+a+'" must be one of "'+b.variants.join(", ")+'"!');return a},datetime:function(a){return a instanceof Date||(a=new Date(Date.parse(a))),a},object:function(a,b,c){if("object"!=typeof a||"[object Array]"===Object.prototype.toString.call(a))throw new Error('Incorrect value: not object type for property "'+c+'"!');if("instanceof"in b){var e=b.instanceof;if("[object Array]"===Object.prototype.toString.call(e)&&(e=d(e[0],e[1]||[])),!(a instanceof e))throw new Error('Value does not instance of clazz "'+e.NAME+'"!')}return a},array:function(a,b){return"string"==typeof a?a.split(b.delimiter||","):[].concat(a)},hash:function(a,b,c){if({}.constructor!==a.constructor)throw new Error('Incorrect value: not hash type for property "'+c+'"!');if("keys"in b)for(var d in a)if(!(d in b.keys))throw new Error('Unsupported hash key "'+d+'"!');return"element"in b&&this.checkValue.apply(this,[].concat(b.element)),a},clazz:function(a,b,c){if(!("function"==typeof a&&"NAME"in a&&"parent"in a))throw new Error('Incorrect value: not clazz type for property "'+c+'"!');return a}}}),b.processor("Clazz.Proto","Meta.Options",{options:{properties:"Clazz.Properties",methods:"Clazz.Methods"}}),function(a,b){var c=new g(f,b),i=new h,j=new e(i,c,null,"",a,d),k=j();a.namespace=j,a.clazz=k}(a,b)}(this,meta); | ||
//# sourceMappingURL=dist/ClazzJS.min.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
"src/Clazz.js", | ||
"src/NameSpace.js", | ||
"src/Namespace.js", | ||
"src/Base.js", | ||
@@ -23,3 +23,3 @@ "src/Factory.js", | ||
"src/MetaProcessors/*.js", | ||
"src/MetaProcessors/**/*.js", | ||
@@ -26,0 +26,0 @@ "src/.build", |
{ | ||
"name": "clazz-js", | ||
"title": "ClazzJS", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Portable JavaScript library for class-style OOP programming", | ||
@@ -6,0 +6,0 @@ "author": { |
var Base = function() { | ||
this.uid = ++Base.uid; | ||
if (typeof this.init === 'function') { | ||
@@ -13,2 +15,3 @@ var response = this.init.apply(this, Array.prototype.slice.call(arguments)); | ||
Base.DEPENDENCIES = []; | ||
Base.uid = 0; | ||
@@ -15,0 +18,0 @@ Base.parent = null; |
138
src/Clazz.js
@@ -1,30 +0,128 @@ | ||
var Clazz = function(name /* [dependencies] || ( [parent], [metaTypes], meta) */) { | ||
var parent, metaTypes, meta; | ||
var Clazz = function(manager, factory, namespace) { | ||
var last = arguments[arguments.length-1]; | ||
var clazz = function(name, parent, process, meta) { | ||
if (typeof last !== 'function' && Object.prototype.toString.call(last) !== '[object Object]') { | ||
return Manager.get(name, /* actually dependencies */parent || []) | ||
var last = arguments[arguments.length-1]; | ||
// Getting of existed clazz | ||
if (typeof last !== 'function' && Object.prototype.toString.call(last) !== '[object Object]') { | ||
return clazz.get(name, /* actually dependencies */ parent); | ||
} | ||
clazz.set(name, parent, process, meta); | ||
} | ||
meta = last; | ||
parent = arguments[1]; | ||
metaTypes = arguments[2]; | ||
for (var property in Clazz.prototype) { | ||
clazz[property] = Clazz.prototype[property]; | ||
} | ||
if (Object.prototype.toString.call(parent) === '[objectArray]') { | ||
metaTypes = parent; | ||
parent = null; | ||
clazz.getManager = function() { | ||
return manager; | ||
} | ||
if (metaTypes === meta) { | ||
metaTypes = null; | ||
clazz.getFactory = function() { | ||
return factory; | ||
} | ||
if (parent === meta) { | ||
parent = null; | ||
clazz.getNamespace = function() { | ||
return namespace; | ||
} | ||
Manager.setMeta(name, { | ||
parent: parent, | ||
metaTypes: metaTypes, | ||
meta: meta | ||
}); | ||
return clazz; | ||
} | ||
Clazz.prototype = { | ||
get: function(name, dependencies) { | ||
name = this.resolveName(name); | ||
if (!name) { | ||
throw new Error('Clazz with name "' + name + '" does not exits!'); | ||
} | ||
dependencies = dependencies || []; | ||
var manager = this.getManager(); | ||
var factory = this.getFactory(); | ||
if (!manager.hasClazz(name, dependencies)) { | ||
var meta = manager.getMeta(name); | ||
manager.setClazz(factory.create({ | ||
name: name, | ||
dependencies: dependencies, | ||
process: meta.process, | ||
parent: this.adjustParent(meta.parent), | ||
meta: meta.meta | ||
})); | ||
} | ||
return manager.getClazz(name, dependencies) | ||
}, | ||
has: function(name) { | ||
return !!this.resolveName(name); | ||
}, | ||
set: function(name, parent, process, meta) { | ||
var namespace = this.getNamespace(); | ||
var manager = this.getManager(); | ||
// Creation of new clazz | ||
if (typeof name === 'object') { | ||
parent = name.parent; | ||
process = name.process; | ||
meta = name.meta; | ||
name = name.name; | ||
} | ||
else { | ||
if (typeof meta === 'undefined') { | ||
meta = process; | ||
process = null; | ||
} | ||
if (typeof meta === 'undefined') { | ||
meta = parent; | ||
parent = null; | ||
} | ||
if (Object.prototype.toString.call(parent) === '[object Array]') { | ||
process = parent; | ||
parent = null; | ||
} | ||
} | ||
name = namespace.apply(name); | ||
manager.setMeta(name, { | ||
parent: parent , | ||
process: process, | ||
meta: meta | ||
}); | ||
return this; | ||
}, | ||
resolveName: function(name) { | ||
var paths, aname, i, ii; | ||
var manager = this.getManager(); | ||
var namespace = this.getNamespace(); | ||
paths = namespace.getPaths(); | ||
for (i = 0, ii = paths.length; i < ii; ++i) { | ||
aname = namespace.apply(name, paths[i]); | ||
if (manager.hasMeta(aname)) { | ||
return aname; | ||
} | ||
} | ||
return false; | ||
}, | ||
adjustParent: function(parent) { | ||
if (typeof parent === 'string') { | ||
parent = [parent]; | ||
} | ||
if (Object.prototype.toString.call(parent) === '[object Array]') { | ||
parent = this.get(parent[0], parent[1] || []) | ||
} | ||
return parent; | ||
} | ||
} |
@@ -1,38 +0,33 @@ | ||
var Factory = { | ||
var Factory = function(BaseClazz, meta) { | ||
this._clazzUID = 0; | ||
this.BaseClazz = BaseClazz; | ||
this.meta = meta; | ||
} | ||
META_TYPE: 'ClazzJS.Clazz', | ||
Factory.prototype = { | ||
DEFAULT_PROCESSORS: { | ||
clazz: ['Clazz.Clazz'], | ||
proto: ['Clazz.Proto'] | ||
}, | ||
CLASS_NAME: 'Clazz{uid}', | ||
_clazzUID: 0, | ||
create: function(params) { | ||
var clazz, i, ii; | ||
var name = params.name || this.generateName(); | ||
var parent = params.parent; | ||
var metaTypes = params.metaTypes || [this.META_TYPE]; | ||
var processors = params.process || this.DEFAULT_PROCESSORS; | ||
var meta = params.meta; | ||
var dependencies = params.dependencies || []; | ||
if (typeof parent === 'string') { | ||
parent = [parent]; | ||
} | ||
if (Object.prototype.toString.call(parent) === '[object Array]') { | ||
parent = Manager.get(parent[0], parent[1] || []) | ||
} | ||
var clazz = this.createClazz(name, parent); | ||
clazz = this.createClazz(name, parent); | ||
clazz.DEPENDENCIES = dependencies; | ||
if (typeof meta === 'function') { | ||
meta = meta.apply(clazz, dependencies); | ||
} | ||
if (meta) { | ||
if (typeof meta === 'function') { | ||
meta = meta.apply(clazz, dependencies); | ||
} | ||
for (i = 0, ii = metaTypes.length; i < ii; ++i) { | ||
if (typeof metaTypes[i] === 'string') { | ||
metaTypes[i] = Meta.Manager.getType(metaTypes[i]); | ||
} | ||
metaTypes[i].process(clazz, meta); | ||
} | ||
this.applyMeta(clazz, meta, processors); | ||
} | ||
@@ -45,3 +40,3 @@ | ||
if (!parent) { | ||
parent = Base; | ||
parent = this.BaseClazz; | ||
} | ||
@@ -78,2 +73,23 @@ | ||
applyMeta: function(clazz, meta, processors) { | ||
var types = { clazz: clazz, proto: clazz.prototype }, typeProcessors, processor, i, ii; | ||
for (var type in types) { | ||
if (type in processors) { | ||
typeProcessors = processors[type] | ||
if (Object.prototype.toString.call(typeProcessors) !== '[object Array]') { | ||
typeProcessors = [typeProcessors]; | ||
} | ||
for (i = 0, ii = typeProcessors.length; i < ii; ++i) { | ||
processor = typeProcessors[i]; | ||
if (typeof processor === 'string') { | ||
processor = this.meta.processor(processor); | ||
} | ||
processor.process(types[type], meta); | ||
} | ||
} | ||
} | ||
}, | ||
generateName: function() { | ||
@@ -80,0 +96,0 @@ return this.CLASS_NAME.replace('{uid}', ++this._clazzUID); |
@@ -1,25 +0,11 @@ | ||
var Manager = { | ||
var Manager = function() { | ||
this._clazz = {}; | ||
this._meta = {}; | ||
} | ||
_clazz: {}, | ||
_meta: {}, | ||
Manager.prototype = { | ||
adjustName: function(name, namespace) { | ||
if (typeof namespace === 'undefined') { | ||
namespace = NameSpace.current(); | ||
} | ||
return (namespace+'.'+name).replace(NameSpace.getDelimitersRegexp(), '.'); | ||
}, | ||
setMeta: function(name, meta) { | ||
this._meta[name] = meta; | ||
if (meta.metaTypes) { | ||
for (var i = 0, ii = meta.metaTypes.length; i < ii; ++i) { | ||
if (typeof meta.metaTypes[i] === 'string') { | ||
meta.metaTypes[i] = Meta.Manager.getType(meta.metaTypes[i]); | ||
} | ||
} | ||
} | ||
this._meta[this.adjustName(name)] = meta; | ||
return this; | ||
@@ -29,34 +15,16 @@ }, | ||
hasMeta: function(name) { | ||
var i, ii, namespaces = NameSpace.whereLookFor(); | ||
for (i = 0, ii = namespaces.length; i < ii; ++i) { | ||
if (this.adjustName(name, namespaces[i]) in this._meta) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return name in this._meta; | ||
}, | ||
getMeta: function(name) { | ||
var i, ii, aname, namespaces = NameSpace.whereLookFor(); | ||
for (i = 0, ii = namespaces.length; i < ii; ++i) { | ||
aname = this.adjustName(name, namespaces[i]); | ||
if (aname in this._meta) { | ||
return this._meta[aname]; | ||
} | ||
if (!this.hasMeta(name)) { | ||
throw new Error('Meta does not exists for "' + name + '"!'); | ||
} | ||
throw new Error('Meta does not exists for "' + name + '"!'); | ||
return this._meta[name]; | ||
}, | ||
getClazz: function(name, dependencies) { | ||
var i, ii, j, jj, clazz, aname, namespaces = NameSpace.whereLookFor(), isFound; | ||
var i, ii, j, jj, clazz, isFound; | ||
for (i = 0, ii = namespaces.length; i < ii; ++i) { | ||
aname = this.adjustName(name, namespaces[i]); | ||
if (aname in this._clazz) { | ||
clazz = this._clazz[aname]; | ||
break; | ||
} | ||
} | ||
clazz = this._clazz[name]; | ||
@@ -86,11 +54,5 @@ if (Object.prototype.toString.apply(clazz) === '[object Array]') { | ||
hasClazz: function(name, dependencies) { | ||
var i, ii, j, jj, clazz, aname, namespaces = NameSpace.whereLookFor(), isFound; | ||
var i, ii, j, jj, clazz, isFound; | ||
for (i = 0, ii = namespaces.length; i < ii; ++i) { | ||
aname = this.adjustName(name, namespaces[i]); | ||
if (aname in this._clazz) { | ||
clazz = this._clazz[aname]; | ||
break; | ||
} | ||
} | ||
clazz = this._clazz[name]; | ||
@@ -127,26 +89,9 @@ if (Object.prototype.toString.apply(clazz) === '[object Array]') { | ||
} | ||
var aname = this.adjustName(name); | ||
if (!(aname in this._clazz)) { | ||
this._clazz[aname] = []; | ||
if (!(name in this._clazz)) { | ||
this._clazz[name] = []; | ||
} | ||
this._clazz[aname].push(clazz); | ||
this._clazz[name].push(clazz); | ||
return this; | ||
}, | ||
get: function(name , dependencies) { | ||
if (!this.hasClazz(name, dependencies)) { | ||
var meta = this.getMeta(name); | ||
meta.name = name; | ||
meta.dependencies = dependencies; | ||
this.setClazz(Factory.create(meta)); | ||
} | ||
return this.getClazz(name, dependencies); | ||
}, | ||
has: function(name) { | ||
return this.hasClazz(name) || this.hasMeta(name); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
81941
34
1786
1