UNPKG

2.91 kBJavaScriptView Raw
1/*
2 Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17"use strict";
18
19var pm = require('./platform'),
20 scxml = require('./core/scxml/SCXML'),
21 documentToModel = require('./core/util/docToModel');
22
23/*
24 *@url URL of the SCXML document to retrieve and convert to a model
25 *@cb callback to invoke with an error or the model
26 *@context Optional. host-specific data passed along to the platform-specific resource-fetching API (e.g. to provide better traceability)
27 */
28function urlToModel(url,cb,context){
29 if(!pm.platform.getDocumentFromUrl) throw new Error("Platform does not support getDocumentFromUrl");
30
31 pm.platform.getDocumentFromUrl(url,function(err,doc){
32 if(err){
33 cb(err,null);
34 }else{
35 documentToModel(url,doc,cb,context);
36 }
37 },context);
38}
39
40/*
41 *@url file system path of the SCXML document to retrieve and convert to a model
42 *@cb callback to invoke with an error or the model
43 *@context Optional. host-specific data passed along to the platform-specific resource-fetching API (e.g. to provide better traceability)
44 */
45function pathToModel(url,cb,context){
46 if(!pm.platform.getDocumentFromFilesystem) throw new Error("Platform does not support getDocumentFromFilesystem");
47
48 pm.platform.getDocumentFromFilesystem(url,function(err,doc){
49 if(err){
50 cb(err,null);
51 }else{
52 documentToModel(url,doc,cb,context);
53 }
54 },context);
55}
56
57/*
58 *@s SCXML document string to convert to a model
59 *@cb callback to invoke with an error or the model
60 *@context Optional. host-specific data passed along to the platform-specific resource-fetching API (e.g. to provide better traceability)
61 */
62function documentStringToModel(s,cb,context){
63 if(!pm.platform.parseDocumentFromString) throw new Error("Platform does not support parseDocumentFromString");
64
65 documentToModel(null,pm.platform.parseDocumentFromString(s),cb,context);
66}
67
68//export standard interface
69var scion = module.exports = {
70 pathToModel : pathToModel,
71 urlToModel : urlToModel,
72 documentStringToModel : documentStringToModel,
73 documentToModel : documentToModel,
74 SCXML : scxml.SimpleInterpreter,
75 ext : {
76 platformModule : pm,
77 actionCodeGeneratorModule : require('./core/util/code-gen')
78 }
79};