/**
  * Get XML tree
  *
  * @return  xml.Tree
  */
 public function getTree()
 {
     foreach ($this->tables as $t) {
         $constKeyList = [];
         $tn = $this->doc->root()->nodeAt(0)->addChild(new \xml\Node('table', null, ['name' => $t->name]));
         if ($constraint = $t->getFirstForeignKeyConstraint()) {
             do {
                 if (isset($constKeyList[$this->constraintKey($constraint)])) {
                     $this->cat && $this->cat->warn($t->name, 'has a double constraint' . "\n" . \xp::stringOf($constraint));
                     continue;
                 }
                 $constKeyList[$this->constraintKey($constraint)] = true;
                 $cn = $tn->addChild(new \xml\Node('constraint', null, ['name' => trim($constraint->getName())]));
                 $fgn = $cn->addChild(new \xml\Node('reference', null, ['table' => $constraint->getSource(), 'role' => DBXMLNamingContext::referencingForeignKeyConstraintName($t, $constraint)]));
                 foreach ($constraint->getKeys() as $attribute => $sourceattribute) {
                     $fgn->addChild(new \xml\Node('key', null, ['attribute' => $attribute, 'sourceattribute' => $sourceattribute]));
                 }
             } while ($constraint = $t->getNextForeignKeyConstraint());
         }
     }
     return $this->doc;
 }
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(\util\cmd\ParamString $args)
 {
     $dsn = new DSN($args->value(0));
     $this->adapter = self::$adapters[$dsn->getDriver()]->newInstance(DriverManager::getInstance()->getConnection($dsn->dsn));
     $this->package = $args->value('package', 'p', 'db');
     $this->host = $args->value('host', 'h', $dsn->getHost());
     $this->naming = $args->value('nstrategy', 'n', '');
     if ('' != $this->naming) {
         DBXMLNamingContext::setStrategy(XPClass::forName($this->naming)->newInstance());
     }
     $this->prefix = $args->value('prefix', 'pv', '');
     $this->ptargets = explode('|', $args->value('ptargets', 'pt', ''));
     $this->pexclude = $args->value('pexclude', 'pe', false);
     // Setup generator
     $this->processor = new DomXSLProcessor();
     $this->processor->setXSLBuf($this->getClass()->getPackage()->getResource($args->value('lang', 'l', 'xp5.php') . '.xsl'));
     $this->processor->setParam('package', $this->package);
     if ($this->prefix) {
         $this->processor->setParam('prefix', $this->prefix);
         $this->processor->setParam($this->pexclude ? 'exprefix' : 'incprefix', implode(',', $this->ptargets));
     }
 }
 /**
  * Get XML tree
  *
  * @return  xml.Tree
  */
 public function getTree()
 {
     $indexes = [];
     // Attributes
     with($t = $this->doc->root()->nodeAt(0));
     if ($attr = $this->table->getFirstAttribute()) {
         do {
             $a = $t->addChild(new \xml\Node('attribute', null, ['name' => trim($attr->getName()), 'type' => $attr->getTypeString(), 'identity' => $attr->isIdentity() ? 'true' : 'false', 'typename' => $attr->typeName(), 'nullable' => $attr->isNullable() ? 'true' : 'false']));
             // Only add length attribute if length is set - "bool" does not
             // have a length, whereas varchar(255) does.
             $attr->getLength() && $a->setAttribute('length', $attr->getLength());
         } while ($attr = $this->table->getNextAttribute());
     }
     // Indexes
     if ($index = $this->table->getFirstIndex()) {
         do {
             $n = $t->addChild(new \xml\Node('index', null, ['name' => trim($index->getName()), 'unique' => $index->isUnique() ? 'true' : 'false', 'primary' => $index->isPrimaryKey() ? 'true' : 'false']));
             foreach ($index->getKeys() as $key) {
                 $n->addChild(new \xml\Node('key', $key));
             }
             if (isset($indexes[implode('|', $index->getKeys())]) && $this->cat) {
                 $this->cat->warn('(' . implode('|', $index->getKeys()) . ')', 'has been indexed twice');
             }
             $indexes[implode('|', $index->getKeys())] = true;
         } while ($index = $this->table->getNextIndex());
     }
     // constraints
     $constKeyList = [];
     if ($constraint = $this->table->getFirstForeignKeyConstraint()) {
         do {
             if (isset($constKeyList[$this->constraintKey($constraint)])) {
                 $this->cat && $this->cat->warn($this->table->name, 'has a double constraint' . "\n" . \xp::stringOf($constraint));
                 continue;
             }
             $constKeyList[$this->constraintKey($constraint)] = true;
             $cn = $t->addChild(new \xml\Node('constraint', null, ['name' => trim($constraint->getName())]));
             $fgn = $cn->addChild(new \xml\Node('reference', null, ['table' => $constraint->getSource(), 'role' => DBXMLNamingContext::foreignKeyConstraintName($this->table, $constraint)]));
             foreach ($constraint->getKeys() as $attribute => $sourceattribute) {
                 $fgn->addChild(new \xml\Node('key', null, ['attribute' => $attribute, 'sourceattribute' => $sourceattribute]));
             }
         } while ($constraint = $this->table->getNextForeignKeyConstraint());
     }
     return $this->doc;
 }