Commit 5872d31a authored by Nicolas Biri's avatar Nicolas Biri

Add license to source files

parent f46d97ee
/**
* @license
* ©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
* JavaScript Modelling Framework (JSMF)
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author J.S. Sottet
* @author N. Biri
* @author A. Vagner
*/
var _ = require('lodash');
const _ = require('lodash')
function Cardinality(min, max) {
this.min = min
this.max = max
this.min = min
this.max = max
}
Cardinality.optional = new Cardinality(0,1)
......@@ -12,8 +33,9 @@ Cardinality.any = new Cardinality(0)
Cardinality.some = new Cardinality(1)
Cardinality.check = function(v) {
if (_.isNumber(v) && v >= 0) { return {min: 0, max: v} }
else { return {min: _.get(v, 'min', 0), max: _.get(v, 'max', undefined)}}
return (_.isNumber(v) && v >= 0)
? {min: 0, max: v}
: {min: _.get(v, 'min', 0), max: _.get(v, 'max', undefined)}
}
module.exports = {Cardinality}
/**
* JavaScript Modelling Framework (JSMF)
* @license
* ©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
* JavaScript Modelling Framework (JSMF)
*
*
©2015 Luxembourg Institute of Science and Technology All Rights Reserved
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author J.S. Sottet
* @author N. Biri
* @author A. Vagner
*/
Authors : J.S. Sottet, A. Vagner, N. Biri
*/
'use strict'
const _ = require('lodash')
......
/**
* @license
* ©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
* JavaScript Modelling Framework (JSMF)
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author J.S. Sottet
* @author N. Biri
* @author A. Vagner
*/
'use strict'
const _ = require('lodash')
......
/**
* @license
* ©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
* JavaScript Modelling Framework (JSMF)
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author J.S. Sottet
* @author N. Biri
* @author A. Vagner
*/
'use strict'
const _ = require('lodash')
const check = require('jsmf-check')
let Class, hasClass
(function() {const C = require('./Class')
Class = C.Class
hasClass = C.hasClass
}).call()
const Model = require('./Model').Model
, hasClass = require('./Class').hasClass
, Model = require('./Model').Model
let isJSMFElement, conformsTo
(function() {const Common = require('./Common')
......@@ -22,8 +37,8 @@ let isJSMFElement, conformsTo
const attributesTypeRule = new check.Rule(
[ check.all(check.Reference('elements'))
, check.all(check.ContextualReference(function () {
return _.map(conformsTo(this[0]).getAllAttributes(), (desc, name) => {return {name, desc}})
}))
return _.map(conformsTo(this[0]).getAllAttributes(), (desc, name) => {return {name, desc}})
}))
],
(e, a) => {
const value = e[a.name]
......@@ -34,8 +49,8 @@ const attributesTypeRule = new check.Rule(
const referenceMinCardinalityRule = new check.Rule(
[ check.all(check.Reference('elements'))
, check.all(check.ContextualReference(function () {
return _.map(conformsTo(this[0]).getAllReferences(), (props, name) => {return {name, cardinality: props.cardinality}})
}))
return _.map(conformsTo(this[0]).getAllReferences(), (props, name) => {return {name, cardinality: props.cardinality}})
}))
],
(e, r) => e[r.name].length >= r.cardinality.min
)
......@@ -43,8 +58,8 @@ const referenceMinCardinalityRule = new check.Rule(
const referenceMaxCardinalityRule = new check.Rule(
[ check.all(check.Reference('elements'))
, check.all(check.ContextualReference(function () {
return _.map(conformsTo(this[0]).getAllReferences(), (props, name) => {return {name, cardinality: props.cardinality}})
}))
return _.map(conformsTo(this[0]).getAllReferences(), (props, name) => {return {name, cardinality: props.cardinality}})
}))
],
(e, r) => e[r.name].length <= r.cardinality.max
)
......@@ -52,11 +67,11 @@ const referenceMaxCardinalityRule = new check.Rule(
const referencesTypeRule = new check.Rule(
[ check.all(check.Reference('elements'))
, check.all(check.ContextualReference(function () {
return _.map(conformsTo(this[0]).getAllReferences(), (props, name) => {return {name, type: props.type}})
}))
return _.map(conformsTo(this[0]).getAllReferences(), (props, name) => {return {name, type: props.type}})
}))
, check.all(check.ContextualReference(function () {
return this[0][this[1].name]
}))
return this[0][this[1].name]
}))
],
(e, r, v) => {try { return hasClass(v, r.type) } catch (err) { return false }}
)
......@@ -64,32 +79,33 @@ const referencesTypeRule = new check.Rule(
const associatedTypeRule = new check.Rule(
[ check.all(check.Reference('elements'))
, check.all(check.ContextualReference(function () {
return _.map(this[0].getAssociated(), (value, key) => {return {key, value}})
}))
return _.map(this[0].getAssociated(), (value, key) => {return {key, value}})
}))
, check.all(check.ContextualReference(function () { return this[1].value }))
],
(e, as, v) => {
const refs = conformsTo(e).getAllReferences()
const refType = refs[as.key].associated
try { return hasClass(v.associated, refType) } catch (err) { return false }
const refs = conformsTo(e).getAllReferences()
const refType = refs[as.key].associated
try { return hasClass(v.associated, refType) } catch (err) { return false }
}
)
const nonExtraProperties = new check.Rule(
[ check.all(check.Reference('elements'))
, check.all(check.ContextualReference(function () {
return _.map(this[0], (value, name) => name)
}))
return _.map(this[0], (value, name) => name)
}))
, check.raw(check.ContextualReference(function () {
const attrs = _.map(conformsTo(this[0]).getAllAttributes(), (type, name) => name)
const refs = _.map(conformsTo(this[0]).getAllReferences(), (type, name) => name)
return attrs.concat(refs)
}))
const attrs = _.map(conformsTo(this[0]).getAllAttributes(), (type, name) => name)
const refs = _.map(conformsTo(this[0]).getAllReferences(), (type, name) => name)
return attrs.concat(refs)
}))
],
(e, elemA, classAs) => _.includes(classAs, elemA)
)
const conformance = new check.Checker()
conformance.rules =
{ attributesTypeRule
, referenceMinCardinalityRule
......@@ -98,14 +114,15 @@ conformance.rules =
, associatedTypeRule
, nonExtraProperties
}
conformance.helpers.elements = e => {
if (e instanceof Model) {
return e.elements()
}
if (isJSMFElement(e)) {
return (new Model('tmp', {}, e, true)).elements()
}
throw new TypeError(`Invalid argument for conformance: ${e}`)
if (e instanceof Model) {
return e.elements()
}
if (isJSMFElement(e)) {
return (new Model('tmp', {}, e, true)).elements()
}
throw new TypeError(`Invalid argument for conformance: ${e}`)
}
module.exports = _.assign(conformance.rules, { conformance })
/**
* @license
* ©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
* JavaScript Modelling Framework (JSMF)
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author J.S. Sottet
* @author N. Biri
* @author A. Vagner
*/
'use strict'
const _ = require('lodash')
......
/**
* @license
* ©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
* JavaScript Modelling Framework (JSMF)
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author J.S. Sottet
* @author N. Biri
* @author A. Vagner
*/
'use strict'
const _ = require('lodash')
......
/**
* @license
* ©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
* JavaScript Modelling Framework (JSMF)
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author J.S. Sottet
* @author N. Biri
* @author A. Vagner
*/
'use strict'
const _ = require('lodash')
......
/**
* JavaScript Modelling Framework (JSMF)
* @license
* ©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
* JavaScript Modelling Framework (JSMF)
*
*
©2015-2016 Luxembourg Institute of Science and Technology All Rights Reserved
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors : J.S. Sottet, N. Biri, A Vagner
*/
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author J.S. Sottet
* @author N. Biri
* @author A. Vagner
*/
'use strict'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment