Skip to content

Commit a926387

Browse files
authored
Merge pull request #11 from pboyd04/NativeParser
Switch to Non-Native XML Parser
2 parents 3098c91 + 6a991e0 commit a926387

35 files changed

+1098
-667
lines changed

.travis.yml

-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
---
22
language: node_js
3-
env:
4-
- CXX=g++-4.8
5-
addons:
6-
apt:
7-
sources:
8-
- ubuntu-toolchain-r-test
9-
packages:
10-
- g++-4.8
113
sudo: false
124
node_js:
135
- "stable"

lib/Action.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
const ParserCommon = require('./ParserCommon');
22

3-
function Action(xml) {
4-
this.Annotations = {};
5-
this.Parameters = {};
6-
this.ReturnType = null;
3+
class Action extends ParserCommon {
4+
constructor(element) {
5+
super();
6+
this.Annotations = {};
7+
this.Parameters = {};
8+
this.ReturnType = null;
79

8-
this.validElements = {
9-
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
10-
'Parameter': {parent: this.Parameters, nameProp: 'Name'},
11-
'ReturnType': {name: 'ReturnType'}
12-
};
13-
this.validAttributes = {
14-
'IsBound': {bool: true},
15-
'Name': {alreadyHandeled: true}
16-
};
10+
this.validElements = {
11+
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
12+
'Parameter': {parent: this.Parameters, nameProp: 'Name'},
13+
'ReturnType': {name: 'ReturnType'}
14+
};
15+
this.validAttributes = {
16+
'IsBound': {bool: true},
17+
'Name': {alreadyHandeled: true}
18+
};
1719

18-
var init = ParserCommon.initEntity.bind(this);
19-
init(xml, 'Action', 'Name');
20-
21-
return this;
20+
this.init(element, 'Name');
21+
}
2222
}
2323

2424
module.exports = Action;

lib/ActionImport.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
const ParserCommon = require('./ParserCommon');
22

3-
const Annotation = require('./Annotation');
3+
class ActionImport extends ParserCommon {
4+
constructor(element) {
5+
super();
6+
this.Annotations = {};
47

5-
function ActionImport(xml) {
6-
this.Annotations = {};
7-
8-
this.validElements = {
9-
'Annotation': {parent: this.Annotations, nameProp: 'Term'}
10-
};
11-
this.validAttributes = {
12-
'Action': {},
13-
'EntitySet': {},
14-
'Name': {alreadyHandeled: true}
15-
};
16-
17-
var init = ParserCommon.initEntity.bind(this);
18-
init(xml, 'ActionImport', 'Name');
19-
return this;
8+
this.validElements = {
9+
'Annotation': {parent: this.Annotations, nameProp: 'Term'}
10+
};
11+
this.validAttributes = {
12+
'Action': {},
13+
'EntitySet': {},
14+
'Name': {alreadyHandeled: true}
15+
};
16+
this.init(element, 'Name');
17+
}
2018
}
2119

2220
module.exports = ActionImport;

lib/Annotation.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
const ParserCommon = require('./ParserCommon');
22

3-
function Annotation(xml) {
4-
this.validElements = {
5-
'Collection': {parent: this, name: 'Collection'},
6-
'Record': {parent: this, name: 'Record'},
7-
'String': {parent: this, name: 'String', getText: true}
8-
};
9-
this.validAttributes = {
10-
'Term': {alreadyHandeled: true},
11-
'Qualifier': {},
12-
'String': {},
13-
'EnumMember': {},
14-
'Bool': {bool: true},
15-
'Int': {integer: true}
16-
};
17-
18-
var init = ParserCommon.initEntity.bind(this);
19-
init(xml, 'Action', 'Term');
20-
return this;
3+
class Annotation extends ParserCommon {
4+
constructor(element) {
5+
super();
6+
this.validElements = {
7+
'Collection': {parent: this, name: 'Collection'},
8+
'Record': {parent: this, name: 'Record'},
9+
'String': {parent: this, name: 'String', getText: true}
10+
};
11+
this.validAttributes = {
12+
'Term': {alreadyHandeled: true},
13+
'Qualifier': {},
14+
'String': {},
15+
'EnumMember': {},
16+
'Bool': {bool: true},
17+
'Int': {integer: true}
18+
};
19+
this.init(element, 'Term');
20+
}
2121
}
2222

2323
module.exports = Annotation;

lib/CSDLSearch.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ function findByType(metadata, typeName) {
9494
var namespace = typeName.substring(0, index);
9595
var justType = typeName.substring(index+1);
9696
var schema = metadata[namespace];
97-
if(schema === undefined) {
98-
schema = metadata._options.cache.getSchema(namespace);
99-
if(schema === undefined) {
97+
if(schema === undefined) {
98+
let schemas = metadata._options.cache.getSchemas(namespace);
99+
if(schemas.length === 0) {
100100
if(metadata.References === undefined) {
101101
return null;
102102
}
@@ -108,6 +108,17 @@ function findByType(metadata, typeName) {
108108
return null;
109109
}
110110
}
111+
else if(schemas.length === 1) {
112+
schema = schemas[0];
113+
}
114+
else {
115+
for(let i = 0; i < schemas.length; i++) {
116+
if(schemas[i][justType] !== undefined) {
117+
return schemas[i][justType];
118+
}
119+
}
120+
return null;
121+
}
111122
}
112123
return schema[justType];
113124
}

lib/Collection.js

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
const ParserCommon = require('./ParserCommon');
22

3-
function Collection(xml) {
4-
this.PropertyPaths = [];
5-
this.Records = [];
6-
this.Strings = [];
3+
class Collection extends ParserCommon {
4+
constructor(element) {
5+
super();
6+
this.PropertyPaths = [];
7+
this.Records = [];
8+
this.Strings = [];
79

8-
this.validElements = {
9-
'PropertyPath': {parent: this.PropertyPaths, getText: true},
10-
'Record': {parent: this.Records},
11-
'String': {parent: this.Strings, passthru: true}
12-
};
13-
this.validAttributes = {
14-
};
10+
this.validElements = {
11+
'PropertyPath': {parent: this.PropertyPaths, getText: true},
12+
'Record': {parent: this.Records},
13+
'String': {parent: this.Strings, passthru: true}
14+
};
1515

16-
var init = ParserCommon.initEntity.bind(this);
17-
init(xml, 'Collection');
18-
19-
if(this.PropertyPaths.length === 0) {
20-
delete this.PropertyPaths;
21-
}
22-
if(this.Records.length === 0) {
23-
delete this.Records;
16+
this.init(element);
17+
18+
if(this.PropertyPaths.length === 0) {
19+
delete this.PropertyPaths;
20+
}
21+
if(this.Records.length === 0) {
22+
delete this.Records;
23+
}
2424
}
25-
return this;
2625
}
2726

2827
module.exports = Collection;

lib/ComplexType.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const ParserCommon = require('./ParserCommon');
22

3-
function ComplexType(xml) {
4-
this.Properties = {};
5-
this.Annotations = {};
3+
class ComplexType extends ParserCommon {
4+
constructor(element) {
5+
super();
66

7-
this.validElements = {
8-
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
9-
'Property': {parent: this.Properties, nameProp: 'Name'},
10-
'NavigationProperty': {parent: this.Properties, nameProp: 'Name'}
11-
};
12-
this.validAttributes = {
13-
'Abstract': {bool: true},
14-
'OpenType': {bool: true},
15-
'BaseType': {},
16-
'Name': {alreadyHandeled: true}
17-
};
7+
this.Properties = {};
8+
this.Annotations = {};
189

19-
var init = ParserCommon.initEntity.bind(this);
20-
init(xml, 'ComplexType', 'Name');
21-
return this;
10+
this.validElements = {
11+
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
12+
'Property': {parent: this.Properties, nameProp: 'Name'},
13+
'NavigationProperty': {parent: this.Properties, nameProp: 'Name'}
14+
};
15+
this.validAttributes = {
16+
'Abstract': {bool: true},
17+
'OpenType': {bool: true},
18+
'BaseType': {},
19+
'Name': {alreadyHandeled: true}
20+
};
21+
22+
this.init(element, 'Name');
23+
}
2224
}
2325

2426
module.exports = ComplexType;

lib/EntityContainer.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
const ParserCommon = require('./ParserCommon');
22

3-
function EntityContainer(xml) {
4-
this.validElements = {
5-
'EntitySet': {parent: this, nameProp: 'Name'},
6-
'Singleton': {parent: this, nameProp: 'Name'},
7-
'ActionImport': {parent: this, nameProp: 'Name'},
8-
'FunctionImport': {parent: this, nameProp: 'Name'}
9-
};
10-
this.validAttributes = {
11-
'Extends': {},
12-
'Name': {alreadyHandeled: true}
13-
};
3+
class EntityContainer extends ParserCommon {
4+
constructor(element) {
5+
super();
146

15-
var init = ParserCommon.initEntity.bind(this);
16-
init(xml, 'EntityContainer', 'Name');
17-
return this;
7+
this.validElements = {
8+
'EntitySet': {parent: this, nameProp: 'Name'},
9+
'Singleton': {parent: this, nameProp: 'Name'},
10+
'ActionImport': {parent: this, nameProp: 'Name'},
11+
'FunctionImport': {parent: this, nameProp: 'Name'}
12+
};
13+
this.validAttributes = {
14+
'Extends': {},
15+
'Name': {alreadyHandeled: true}
16+
};
17+
18+
this.init(element, 'Name');
19+
}
1820
}
1921

2022
module.exports = EntityContainer;

lib/EntitySet.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
const ParserCommon = require('./ParserCommon');
22

3-
function EntitySet(xml) {
4-
this.Annotations = {};
5-
this.NaviagtionPropertyBindings = {};
3+
class EntitySet extends ParserCommon {
4+
constructor(element) {
5+
super();
6+
this.Annotations = {};
7+
this.NaviagtionPropertyBindings = {};
68

7-
this.validElements = {
8-
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
9-
'NavigationPropertyBinding': {parent: this.NaviagtionPropertyBindings, nameProp: 'Path'}
10-
};
11-
this.validAttributes = {
12-
'EntityType': {},
13-
'Name': {alreadyHandeled: true}
14-
};
9+
this.validElements = {
10+
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
11+
'NavigationPropertyBinding': {parent: this.NaviagtionPropertyBindings, nameProp: 'Path'}
12+
};
13+
this.validAttributes = {
14+
'EntityType': {},
15+
'Name': {alreadyHandeled: true}
16+
};
1517

16-
var init = ParserCommon.initEntity.bind(this);
17-
init(xml, 'EntitySet', 'Name');
18-
19-
return this;
18+
this.init(element, 'Name');
19+
}
2020
}
2121

2222
module.exports = EntitySet;

lib/EntityType.js

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
const ParserCommon = require('./ParserCommon');
22

3-
function EntityType(xml) {
4-
this._key = null;
5-
this.Annotations = {};
6-
this.Properties = {};
3+
class EntityType extends ParserCommon {
4+
constructor(element) {
5+
super();
76

8-
this.validElements = {
9-
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
10-
'Property': {parent: this.Properties, nameProp: 'Name'},
11-
'NavigationProperty': {parent: this.Properties, nameProp: 'Name'},
12-
'Key': {parent: this, name: '_key', passthru: true}
13-
};
14-
this.validAttributes = {
15-
'Abstract': {bool: true},
16-
'BaseType': {},
17-
'Name': {alreadyHandeled: true}
18-
};
7+
this._key = null;
8+
this.Annotations = {};
9+
this.Properties = {};
1910

20-
var init = ParserCommon.initEntity.bind(this);
21-
init(xml, 'EntityType', 'Name');
11+
this.validElements = {
12+
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
13+
'Property': {parent: this.Properties, nameProp: 'Name'},
14+
'NavigationProperty': {parent: this.Properties, nameProp: 'Name'},
15+
'Key': {parent: this, name: '_key', passthru: true}
16+
};
17+
this.validAttributes = {
18+
'Abstract': {bool: true},
19+
'BaseType': {},
20+
'Name': {alreadyHandeled: true}
21+
};
2222

23-
if(this._key !== null)
24-
{
25-
var propNames = this._key.find('.//*[local-name()="PropertyRef"]/@Name');
26-
for(var i = 0; i < propNames.length; i++)
27-
{
28-
var name = propNames[i].value();
29-
if(this.Properties[name] !== undefined) {
30-
this.Properties[name].IsKey = true;
31-
}
23+
this.init(element, 'Name');
24+
25+
if(this._key !== null) {
26+
let propRefs = this._key.childrenNamed('PropertyRef');
27+
for(let i = 0; i < propRefs.length; i++) {
28+
let name = propRefs[i].attr['Name'];
29+
if(this.Properties[name] !== undefined) {
30+
this.Properties[name].IsKey = true;
31+
}
32+
}
3233
}
34+
delete this._key;
3335
}
34-
delete this._key;
35-
return this;
3636
}
3737

3838
module.exports = EntityType;

0 commit comments

Comments
 (0)