PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/dom/codeGen/1.4/om/xsComplexType.php

http://github.com/sbarthelemy/collada-dom
PHP | 222 lines | 170 code | 20 blank | 32 comment | 40 complexity | c3bda838c549d853ce4c92094a04ea98 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. * Copyright 2006 Sony Computer Entertainment Inc.
  4. *
  5. * Licensed under the MIT Open Source License, for details please see license.txt or the website
  6. * http://www.opensource.org/licenses/mit-license.php
  7. *
  8. */
  9. class xsComplexType extends _elementSet
  10. {
  11. function xsComplexType()
  12. {
  13. $this->_addElement( 'xsAnnotation', array( 'minOccurs' => '0', 'maxOccurs' => 'unbounded' ) );
  14. $this->_addElement( 'xsChoice', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
  15. $this->_addElement( 'xsAttribute', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
  16. $this->_addElement( 'xsSequence', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
  17. $this->_addElement( 'xsAll', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
  18. $this->_addElement( 'xsGroup', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
  19. $this->_addElement( 'xsSimpleContent', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
  20. $this->_addElement( 'xsComplexContent', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
  21. $this->_addAttribute( 'name', array( 'type' => 'xs:string' ) );
  22. $this->_addAttribute( 'mixed', array( 'type' => 'xs:string', 'default' => 'false' ) );
  23. $this->type[] = 'xsComplexType';
  24. parent::_elementSet();
  25. }
  26. function & generate( $element_context, & $global_elements )
  27. {
  28. $element_context[] = $this->getAttribute( "name" );
  29. print implode( ",", $element_context ) . "\n";
  30. // Get new factory
  31. $generator = new ElementMeta( $global_elements );
  32. $generator->setIsAComplexType( true );
  33. // Load the class name and a context pre-fix (in case we're inside another element)
  34. $generator->setName( $this->getAttribute( 'name' ) );
  35. $generator->setContext( $element_context );
  36. // Extract any documentation for this node
  37. $a = $this->getElementsByType( 'xsAnnotation' );
  38. if ( count( $a ) > 0 )
  39. {
  40. $d = $a[0]->getElementsByType( 'xsDocumentation' );
  41. if ( count( $d ) > 0 )
  42. {
  43. $generator->setDocumentation( $d[0]->get() );
  44. }
  45. }
  46. if ( $this->getAttribute( 'mixed' ) == 'true' )
  47. {
  48. $generator->setMixed( true );
  49. }
  50. $content = $this; // Should only be one
  51. $this->generateComplexType( $content, $generator, $element_context );
  52. if ( count( $generator->bag['elements'] ) == 0 ) {
  53. $generator->setIsEmptyContent( true );
  54. }
  55. $meta = & $generator->getMeta();
  56. if ( count( $element_context ) == 1 )
  57. {
  58. $global_elements[ $element_context[0] ] = & $meta;
  59. }
  60. return $meta;
  61. }
  62. // Flatten choice/all/sequence groups into a single list of contained elements
  63. function flatten( & $element, & $generator, & $context, $maxOccurs )
  64. {
  65. //print "in flatten ";
  66. $e_list = $element->getElements();
  67. for( $i=0; $i<count( $e_list ); $i++ )
  68. {
  69. switch( $e_list[$i]->getType() )
  70. {
  71. case 'xsChoice':
  72. $generator->setHasChoice( true );
  73. $generator->addContentModel( 1, $e_list[$i]->getAttribute( 'minOccurs' ), $e_list[$i]->getAttribute( 'maxOccurs' ) );
  74. // Propagate the maxOccurs down through choice hierarchy (while flattening)
  75. $local_max = $e_list[$i]->getAttribute( 'maxOccurs' );
  76. if ( $maxOccurs == 'unbounded' || (is_int( $local_max ) && ($maxOccurs > $local_max)) )
  77. {
  78. $this->flatten( $e_list[$i], $generator, $context, $maxOccurs );
  79. } else
  80. {
  81. $this->flatten( $e_list[$i], $generator, $context, $local_max );
  82. }
  83. break;
  84. case 'xsSequence':
  85. $generator->addContentModel( 0, $e_list[$i]->getAttribute( 'minOccurs' ), $e_list[$i]->getAttribute( 'maxOccurs' ) );
  86. // Propagate the maxOccurs down through choice hierarchy (while flattening)
  87. $local_max = $e_list[$i]->getAttribute( 'maxOccurs' );
  88. if ( $maxOccurs == 'unbounded' || (is_int( $local_max ) && ($maxOccurs > $local_max)) )
  89. {
  90. $this->flatten( $e_list[$i], $generator, $context, $maxOccurs );
  91. } else
  92. {
  93. $this->flatten( $e_list[$i], $generator, $context, $local_max );
  94. }
  95. break;
  96. case 'xsAll':
  97. $generator->addContentModel( 3, $e_list[$i]->getAttribute( 'minOccurs' ), $e_list[$i]->getAttribute( 'maxOccurs' ) );
  98. // Propagate the maxOccurs down through choice hierarchy (while flattening)
  99. $local_max = $e_list[$i]->getAttribute( 'maxOccurs' );
  100. if ( $maxOccurs == 'unbounded' || (is_int( $local_max ) && ($maxOccurs > $local_max)) )
  101. {
  102. $this->flatten( $e_list[$i], $generator, $context, $maxOccurs );
  103. } else
  104. {
  105. $this->flatten( $e_list[$i], $generator, $context, $local_max );
  106. }
  107. break;
  108. case 'xsGroup':
  109. $generator->addContentModel( 2, $e_list[$i]->getAttribute( 'minOccurs' ), $e_list[$i]->getAttribute( 'maxOccurs' ) );
  110. $generator->addGroup( $e_list[$i] );
  111. case 'xsElement':
  112. $nm = $e_list[$i]->getAttribute( 'name' );
  113. if ( $nm == '' ) { $nm = $e_list[$i]->getAttribute( 'ref' ); }
  114. $generator->addContentModel( $nm, $e_list[$i]->getAttribute( 'minOccurs' ), $e_list[$i]->getAttribute( 'maxOccurs' ) );
  115. //print "found element!\n";
  116. // If a containing element/group has a maxOccurs > 1, then inherit it (will flag as array in code gen)
  117. if ( $maxOccurs == 'unbounded' || $maxOccurs > 1 )
  118. {
  119. $e_list[$i]->setAttribute( 'maxOccurs', $maxOccurs );
  120. }
  121. $generator->addElement( $e_list[$i], $context );
  122. break;
  123. case 'xsAttribute':
  124. //print "found attribute!\n";
  125. $generator->addAttribute( $e_list[$i] );
  126. break;
  127. case 'xsAny':
  128. print "found an any\n";
  129. $generator->addContentModel( 4, $e_list[$i]->getAttribute( 'minOccurs' ), $e_list[$i]->getAttribute( 'maxOccurs' ) );
  130. $generator->bag['has_any'] = true;
  131. break;
  132. default:
  133. break;
  134. }
  135. }
  136. $generator->addContentModel( 5, 0, 0 ); //END content model - There will be one extra on every element
  137. }
  138. //function that reads complex types. will recurse complex type derived heirarchies.
  139. function generateComplexType( $content, & $generator, & $context ) {
  140. //print "in generatecomplextype\n";
  141. if ( count( $content->getElementsByType( 'xsSimpleContent' ) ) > 0 ) {
  142. //print "found simpleContent!\n";
  143. $temp = $content->getElementsByType( 'xsSimpleContent' );
  144. $content = $temp[0]; // Should only be one - now we now find out element's parent class
  145. $temp = & $content->getElements();
  146. $content = $temp[0]; // Should either be an xsExtension or xsRestriction
  147. $type = $content->getAttribute( 'base' );
  148. //print "setting extends to ". $type ."\n";
  149. $generator->setContentType( $type );
  150. $temp = & $content->getElementsByType( 'xsAttribute' );
  151. for( $i=0; $i<count( $temp ); $i++ ) {
  152. $generator->addAttribute( $temp[$i] );
  153. }
  154. } else if ( count( $content->getElementsByType( 'xsComplexContent' ) ) > 0 ) {
  155. //print "found complexContent!\n";
  156. //ComplexContent specified means type is derived
  157. $temp = $content->getElementsByType( 'xsComplexContent' );
  158. $content = $temp[0]; // Should only be one - now we now find out element's parent class
  159. $temp = & $content->getElements();
  160. $content = $temp[0]; // Should either be an xsExtension or xsRestriction
  161. if ( $content->getType() == 'xsExtension' ) {
  162. $generator->bag['isExtension'] = true;
  163. }
  164. if ( $content->getType() == 'xsRestriction' ) {
  165. $generator->bag['isRestriction'] = true;
  166. }
  167. $type = $content->getAttribute( 'base' );
  168. //print "setting extends to ". $type ."\n";
  169. $generator->bag['base_type'] = $type;
  170. //Generate the complex type this is derived from
  171. //*************CHANGE NEEDED HERE 8-25 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  172. for ( $i = 0; $i < count( $GLOBALS['_globals']['complex_types'] ); $i++ ) {
  173. if ( $type == $GLOBALS['_globals']['complex_types'][$i]->getAttribute('name') ) {
  174. $generator->setComplexType( true );
  175. $generator->bag['ref_elements'][] = $type;
  176. //$this->generateComplexType( $GLOBALS['_globals']['complex_types'][$i], $generator, $context );
  177. break;
  178. }
  179. }
  180. // Parse element context
  181. $this->flatten( $content, $generator, $element_context, $content->getAttribute( 'maxOccurs' ) );
  182. } else {
  183. //print "found nothing so doing complex content flatten\n";
  184. // The alternative to xsSimpleContent is xsComplexContent - if it is not specified, it is implied
  185. // Parse element context
  186. $this->flatten( $content, $generator, $element_context, $content->getAttribute( 'maxOccurs' ) );
  187. if ( count( $generator->bag['elements'] ) == 0 ) {
  188. $generator->setIsEmptyContent( true );
  189. }
  190. }
  191. }
  192. function & generateType() {
  193. $vars = array();
  194. $e = $this->getElements();
  195. $generator = new TypeMeta();
  196. $generator->setType( $this->getAttribute( 'name' ) );
  197. $generator->setIsComplex( true );
  198. $meta = & $generator->getMeta();
  199. return $meta;
  200. }
  201. }
  202. ?>