/**
  * Get XML tree
  *
  * @return  xml.Tree
  */
 public function getTree()
 {
     $indexes = array();
     // Attributes
     with($t = $this->doc->root()->nodeAt(0));
     if ($attr = $this->table->getFirstAttribute()) {
         do {
             $a = $t->addChild(new Node('attribute', NULL, array('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 Node('index', NULL, array('name' => trim($index->getName()), 'unique' => $index->isUnique() ? 'true' : 'false', 'primary' => $index->isPrimaryKey() ? 'true' : 'false')));
             foreach ($index->getKeys() as $key) {
                 $n->addChild(new 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 = array();
     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 Node('constraint', NULL, array('name' => trim($constraint->getName()))));
             $fgn = $cn->addChild(new Node('reference', NULL, array('table' => $constraint->getSource(), 'role' => DBXMLNamingContext::foreignKeyConstraintName($this->table, $constraint))));
             foreach ($constraint->getKeys() as $attribute => $sourceattribute) {
                 $fgn->addChild(new Node('key', NULL, array('attribute' => $attribute, 'sourceattribute' => $sourceattribute)));
             }
         } while ($constraint = $this->table->getNextForeignKeyConstraint());
     }
     return $this->doc;
 }
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(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);
     $xsls = array();
     $lang = $args->value('lang', 'l', 'xp5.php');
     if ($this->getClass()->getPackage()->providesPackage(strtr($lang, '.', '_'))) {
         $resources = $this->getClass()->getPackage()->getPackage(strtr($lang, '.', '_'))->getResources();
         foreach ($resources as $resource) {
             $filename = substr($resource, strrpos($resource, DIRECTORY_SEPARATOR) + 1);
             if (substr($filename, -8, 8) !== '.php.xsl') {
                 continue;
             }
             $xsls[] = $resource;
         }
     } else {
         $packagepath = strtr($this->getClass()->getPackage()->getName(), '.', DIRECTORY_SEPARATOR);
         $xsls[] = $packagepath . DIRECTORY_SEPARATOR . $lang . '.xsl';
     }
     foreach ($xsls as $resource) {
         $processor = new DomXSLProcessor();
         $processor->setBase(__DIR__);
         $processor->setXSLBuf(ClassLoader::getDefault()->getResource($resource));
         $processor->setParam('package', $this->package);
         if ($this->prefix) {
             $processor->setParam('prefix', $this->prefix);
             $processor->setParam($this->pexclude ? 'exprefix' : 'incprefix', implode(',', $this->ptargets));
         }
         $this->processor[] = $processor;
     }
 }
 /**
  * Get XML tree
  *
  * @return  xml.Tree
  */
 public function getTree()
 {
     foreach ($this->tables as $t) {
         $constKeyList = array();
         $tn = $this->doc->root()->nodeAt(0)->addChild(new Node('table', NULL, array('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 Node('constraint', NULL, array('name' => trim($constraint->getName()))));
                 $fgn = $cn->addChild(new Node('reference', NULL, array('table' => $constraint->getSource(), 'role' => DBXMLNamingContext::referencingForeignKeyConstraintName($t, $constraint))));
                 foreach ($constraint->getKeys() as $attribute => $sourceattribute) {
                     $fgn->addChild(new Node('key', NULL, array('attribute' => $attribute, 'sourceattribute' => $sourceattribute)));
                 }
             } while ($constraint = $t->getNextForeignKeyConstraint());
         }
     }
     return $this->doc;
 }
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(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));
     }
 }
 /**
  * set strategy
  *
  * @param   rdbms.DBXMLNamingStrategy s
  */
 static function setStrategy(DBXMLNamingStrategy $s)
 {
     self::$strategy = $s;
 }