File: xsSimpleType.php

package info (click to toggle)
collada-dom 2.4.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 17,096 kB
  • sloc: cpp: 156,849; php: 4,567; makefile: 38; sh: 32; python: 14
file content (143 lines) | stat: -rw-r--r-- 4,427 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*
* Copyright 2006 Sony Computer Entertainment Inc.
*
* Licensed under the MIT Open Source License, for details please see license.txt or the website
* http://www.opensource.org/licenses/mit-license.php
*
*/ 

require_once( 'src/TypeMeta.php' );

class xsSimpleType extends _elementSet
{
  function xsSimpleType()
  {
    $this->_addElement( 'xsRestriction', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
    $this->_addElement( 'xsExtension', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
    $this->_addElement( 'xsList', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
    $this->_addElement( 'xsUnion', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );
    
    $this->_addElement( 'xsAnnotation', array( 'minOccurs' => '1', 'maxOccurs' => '1' ) );

    $this->_addAttribute( 'name', array( 'type' => 'xs:string' ) );

    $this->type[] = 'xsSimpleType';
    parent::_elementSet();
  }
  
  function & generate()
  {
    $vars = array();
    $e = $this->getElements();
    $generator = new TypeMeta();
    
    $generator->setType( $this->getAttribute( 'name' ) );
    
    $a = $this->getElementsByType( 'xsAnnotation' );
    if ( count( $a ) > 0 )
    {
      //print "found annotation for ". $this->getAttribute( 'name' ) ."!\n";
      $d = $a[0]->getElementsByType( 'xsDocumentation' );
      if ( count( $d ) > 0 )
      {
		//print "found documentation for ". $this->getAttribute( 'name' ) ."!\n";
        $generator->setDocumentation( $d[0]->get() );
      }
      $ap = $a[0]->getElementsByType( 'xsAppinfo' );
	  if ( count( $ap ) > 0 )
	  {
	  	$generator->setAppInfo( $ap[0]->get() );
	  }
    }
    
    $idx = 0;
    if ( $e[$idx]->getType() == 'xsAnnotation' ) {
		$idx = 1;
    }
    if ( $e[$idx]->getType() == 'xsRestriction' || $e[$idx]->getType() == 'xsExtension' )
    {
      $generator->setIsExtension( $e[$idx]->getType() == 'xsExtension' );
    
      // Set base class
      $generator->setBase( $e[$idx]->getAttribute( 'base' ) );
      
      // Look for enums
      $enums = $e[$idx]->getElementsByType( 'xsEnumeration' );
      for( $i=0; $i<count( $enums ); $i++ )
      {
        $generator->addEnum( $enums[$i]->getAttribute( 'value' ) );
        $an = $enums[$i]->getElementsByType('xsAnnotation');
        if ( count( $an ) > 0 ) {
			$doc = $an[0]->getElementsByType( 'xsDocumentation' );
			if ( count( $doc ) > 0 ) {
				$generator->addEnumDoc( $i, $doc[0]->get() );
			}
			$ap = $an[0]->getElementsByType( 'xsAppinfo' );
			if ( count( $ap ) > 0 )
			{
	  			$generator->addEnumAppInfo( $i, $ap[0]->get() );
			}
        }
      }
      
      // Look for max/mins
      $array_limits = array();
      $min = $e[$idx]->getElementsByType( 'xsMinLength' );
      $max = $e[$idx]->getElementsByType( 'xsMaxLength' );
      $minIn = $e[$idx]->getElementsByType( 'xsMinInclusive' );
      $maxIn = $e[$idx]->getElementsByType( 'xsMaxInclusive' );
      $minEx = $e[$idx]->getElementsByType( 'xsMinExclusive' );
      $maxEx = $e[$idx]->getElementsByType( 'xsMaxExclusive' );
      
      if ( count( $min ) > 0 )
      {
        $generator->setRestriction( 'minLength', $min[0]->getAttribute( 'value' ) );
      }
      
      if ( count( $max ) > 0 )
      {
        $generator->setRestriction( 'maxLength', $max[0]->getAttribute( 'value' ) );
      }
      
      if ( count( $minIn ) > 0 )
      {
        $generator->setRestriction( 'minInclusive', $minIn[0]->getAttribute( 'value' ) );
      }
      
      if ( count( $maxIn ) > 0 )
      {
        $generator->setRestriction( 'maxInclusive', $maxIn[0]->getAttribute( 'value' ) );
      }
      
      if ( count( $minEx ) > 0 )
      {
        $generator->setRestriction( 'minExclusive', $minEx[0]->getAttribute( 'value' ) );
      }
      
      if ( count( $maxEx ) > 0 )
      {
        $generator->setRestriction( 'maxExclusive', $maxEx[0]->getAttribute( 'value' ) );
      }
    } else if ( $e[$idx]->getType() == 'xsList' )
    {
      //$extends = "xsList";
      $itemType = $e[$idx]->getAttribute( 'itemType' );
      $generator->setListType( $itemType );
      $generator->bag['isArray'] = true;
    } 
    else if ( $e[$idx]->getType() == 'xsUnion' ) {
		$generator->setUnionMembers( $e[$idx]->getAttribute( 'memberTypes' ) );
    }
    else
    {
      $this->log( "WARN: unexpected element in xsSimpleType code generation" );
    }

    $meta = & $generator->getMeta();
    return $meta;
  }
}


?>