11const assert = require ( 'assert' ) ;
22
3+ const Annotation = require ( './Annotation' ) ;
34const Property = require ( './Property' ) ;
45const NavigationProperty = require ( './NavigationProperty' ) ;
56
67function ComplexType ( metadata , xml ) {
78 this . _metadata = metadata ;
89 this . Properties = { } ;
10+ this . Annotations = { } ;
911 var name = xml . attr ( 'Name' ) . value ( ) ;
1012 var children = xml . childNodes ( ) ;
1113 for ( var i = 0 ; i < children . length ; i ++ )
1214 {
1315 var elemType = children [ i ] . type ( ) ;
14- if ( elemType === 'element' )
15- {
16+ if ( elemType === 'element' ) {
1617 this . parseElement ( children [ i ] , name ) ;
1718 }
18- else
19- {
20- throw new Error ( 'Unknown element type in EntityType ' + name + '!' ) ;
19+ else if ( elemType === 'text' ) {
20+ var text = children [ i ] . toString ( ) . trim ( ) ;
21+ if ( text . length !== 0 ) {
22+ throw new Error ( 'Unknown text element in ComplexType! Text = "' + text + '"' ) ;
23+ }
24+ }
25+ else {
26+ throw new Error ( 'Unknown element type in EntityType ' + elemType + '!' ) ;
2127 }
2228 }
2329 var attributes = xml . attrs ( ) ;
@@ -37,7 +43,11 @@ ComplexType.prototype.parseElement = function(element, entityName) {
3743 break ;
3844 case 'NavigationProperty' :
3945 var name = element . attr ( 'Name' ) . value ( ) ;
40- this . NavigationProperty [ name ] = new NavigationProperty ( this , element ) ;
46+ this . Properties [ name ] = new NavigationProperty ( this , element ) ;
47+ break ;
48+ case 'Annotation' :
49+ var name = element . attr ( 'Term' ) . value ( ) ;
50+ this . Annotations [ name ] = new Annotation ( element ) ;
4151 break ;
4252 default :
4353 throw new Error ( 'Unknown element name ' + elemName ) ;
@@ -54,18 +64,17 @@ ComplexType.prototype.parseAttribute = function(attribute, entityName) {
5464 case 'BaseType' :
5565 this . BaseType = attribute . value ( ) ;
5666 break ;
67+ case 'Abstract' :
68+ this . parseBooleanAttribute ( attribute , attrName ) ;
69+ break ;
5770 default :
5871 throw new Error ( 'Unknown attribute name ' + attrName + ' in ComplexType ' + entityName ) ;
5972 break ;
6073 }
6174}
6275
6376ComplexType . prototype . parseBooleanAttribute = function ( xml , name ) {
64- var attr = xml . attr ( name ) ;
65- if ( attr === null ) {
66- return ;
67- }
68- var value = attr . value ( ) ;
77+ var value = xml . value ( ) ;
6978 if ( value === 'true' ) {
7079 this [ name ] = true ;
7180 }
0 commit comments