Exemplo n.º 1
0
 function visitElementNode(PiBX_ParseTree_Tree $tree)
 {
     $this->plowTypesForLevel($tree->getLevel());
     $logMessage = $tree->getLevel() . str_pad("  ", $tree->getLevel()) . " element";
     if ($tree->isAnonym()) {
         $logMessage .= " <anonym>";
     } else {
         $logMessage .= " (" . $tree->getName() . ")";
     }
     if ($tree->getLevel() > 0) {
         if ($this->currentType() instanceof PiBX_AST_Type) {
             $ta = new PiBX_AST_TypeAttribute($tree->getName());
             $ta->setType($tree->getType());
             $schemaType = $tree->getType();
             $sf = new PiBX_CodeGen_ASTStackFrame($tree->getLevel(), $ta);
             array_push($this->stack, $sf);
             // elements with maxOccurs "unbounded" are collections/lists
             // with no parent collection element.
             if ($tree->getMaxOccurs() == 'unbounded') {
                 $ci = new PiBX_AST_CollectionItem($tree->getName());
                 $ci->setType($tree->getType());
                 $sf = new PiBX_CodeGen_ASTStackFrame($tree->getLevel(), $ci);
                 array_push($this->stack, $sf);
             }
         } elseif ($this->currentType() instanceof PiBX_AST_Collection) {
             $ci = new PiBX_AST_CollectionItem($tree->getName());
             $ci->setType($tree->getType());
             $sf = new PiBX_CodeGen_ASTStackFrame($tree->getLevel(), $ci);
             array_push($this->stack, $sf);
         } elseif ($this->currentType() instanceof PiBX_AST_Structure) {
             $se = new PiBX_AST_StructureElement($tree->getName(), $tree->getType());
             $sf = new PiBX_CodeGen_ASTStackFrame($tree->getLevel(), $se);
             array_push($this->stack, $sf);
         }
     } elseif ($tree->getLevel() == 0) {
         $logMessage .= " - global";
         $t = new PiBX_AST_Type($tree->getName());
         if ($this->countTypes() == 0) {
             // the first type is the XSD-root.
             $t->setAsRoot();
             $t->setTargetNamespace($tree->getParent()->getTargetNamespace());
             $t->setNamespaces($tree->getNamespaces());
         }
         $sf = new PiBX_CodeGen_ASTStackFrame(-1, $t);
         array_push($this->stack, $sf);
         /*
          * Yes, add it two times.
          * It's a limitation that exist in the current implementation
          * of the TypeUsage-class.
          * The concrete class (which is the root element/type of a schema)
          * will not be referenced more than one time (at the definition).
          * But it must not be removed in an AST optimization afterwards,
          * so we just increase the usage-counter by one.
          */
         $this->typeUsage->addType($tree->getName());
         $this->typeUsage->addType($tree->getName());
     } else {
         throw new RuntimeException('invalid element state');
     }
     $this->lastLevel = $tree->getLevel();
     $this->log($logMessage);
 }