Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(ParamString $args)
 {
     $this->uri = $args->value(0);
     $this->package = $args->value('package', 'p', 'soap');
     $this->processor = new DomXSLProcessor();
     $this->processor->setXSLBuf($this->getClass()->getPackage()->getResource($args->value('lang', 'l', 'xp5.php') . '.xsl'));
     $this->processor->setParam('collection', $this->package);
     $this->processor->setParam('prefix', $args->value('prefix', 'P', ''));
     $this->processor->setParam('boundary', self::BOUNDARY);
 }
Exemplo n.º 2
0
function runnable()
{
    $p = new ParamString();
    $class = xp::reflect(basename($p->value(0), '.class.php'));
    $target = array($class, 'main');
    if (!is_callable($target)) {
        xp::error('Target ' . $class . '::main() is not runnable');
        // Bails out
    }
    xp::$cn[$class] = 'Runnable$' . $class;
    exit(call_user_func($target, $p));
}
Exemplo n.º 3
0
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(ParamString $args)
 {
     $url = new URL($args->value(0));
     // If protocol string does not contain port number, set default.
     if (self::ESDL_PORT === $url->getPort(self::ESDL_PORT)) {
         $url->setPort(self::ESDL_PORT);
     }
     // Check given URL to inform user if invalid port used.
     if (self::ESDL_PORT !== $url->getPort()) {
         Console::$err->writeLine('Notice: using non-standard port ' . $url->getPort() . ', ESDL services are usually available at port 6449.');
     }
     $this->remote = Remote::forName($url->getURL());
     $this->jndi = $args->value(1);
     $this->processor = new DomXSLProcessor();
     $this->processor->setXSLBuf($this->getClass()->getPackage()->getResource($args->value('lang', 'l', 'xp5') . '.xsl'));
 }
Exemplo n.º 4
0
 /**
  * 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;
     }
 }
Exemplo n.º 5
0
 /**
  * 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));
     }
 }
Exemplo n.º 6
0
 /**
  * Main method
  *
  * @param   util.cmd.ParamString params
  * @return  int
  */
 public function run(ParamString $params)
 {
     // No arguments given - show our own usage
     if ($params->count < 1) {
         self::$err->writeLine(self::textOf(XPClass::forName(xp::nameOf(__CLASS__))->getComment()));
         return 1;
     }
     // Configure properties
     $pm = PropertyManager::getInstance();
     // Separate runner options from class options
     for ($offset = 0, $i = 0; $i < $params->count; $i++) {
         switch ($params->list[$i]) {
             case '-c':
                 if (0 == strncmp('res://', $params->list[$i + 1], 6)) {
                     $pm->appendSource(new ResourcePropertySource(substr($params->list[$i + 1], 6)));
                 } else {
                     $pm->appendSource(new FilesystemPropertySource($params->list[$i + 1]));
                 }
                 $offset += 2;
                 $i++;
                 break;
             case '-cp':
                 ClassLoader::registerPath($params->list[$i + 1], NULL);
                 $offset += 2;
                 $i++;
                 break;
             case '-v':
                 $this->verbose = TRUE;
                 $offset += 1;
                 $i++;
                 break;
             default:
                 break 2;
         }
     }
     // Sanity check
     if (!$params->exists($offset)) {
         self::$err->writeLine('*** Missing classname');
         return 1;
     }
     // Use default path for PropertyManager if no sources set
     if (!$pm->getSources()) {
         $pm->configure(self::DEFAULT_CONFIG_PATH);
     }
     unset($params->list[-1]);
     $classname = $params->value($offset);
     $classparams = new ParamString(array_slice($params->list, $offset + 1));
     // Class file or class name
     if (strstr($classname, xp::CLASS_FILE_EXT)) {
         $file = new File($classname);
         if (!$file->exists()) {
             self::$err->writeLine('*** Cannot load class from non-existant file ', $classname);
             return 1;
         }
         $uri = $file->getURI();
         $path = dirname($uri);
         $paths = array_flip(array_map('realpath', xp::$classpath));
         $class = NULL;
         while (FALSE !== ($pos = strrpos($path, DIRECTORY_SEPARATOR))) {
             if (isset($paths[$path])) {
                 $class = XPClass::forName(strtr(substr($uri, strlen($path) + 1, -10), DIRECTORY_SEPARATOR, '.'));
                 break;
             }
             $path = substr($path, 0, $pos);
         }
         if (!$class) {
             self::$err->writeLine('*** Cannot load class from ', $file);
             return 1;
         }
     } else {
         try {
             $class = XPClass::forName($classname);
         } catch (ClassNotFoundException $e) {
             self::$err->writeLine('*** ', $this->verbose ? $e : $e->getMessage());
             return 1;
         }
     }
     // Check whether class is runnable
     if (!$class->isSubclassOf('lang.Runnable')) {
         self::$err->writeLine('*** ', $class->getName(), ' is not runnable');
         return 1;
     }
     // Usage
     if ($classparams->exists('help', '?')) {
         self::showUsage($class);
         return 0;
     }
     // Load, instantiate and initialize
     $l = Logger::getInstance();
     $pm->hasProperties('log') && $l->configure($pm->getProperties('log'));
     $cm = ConnectionManager::getInstance();
     $pm->hasProperties('database') && $cm->configure($pm->getProperties('database'));
     // Setup logger context for all registered log categories
     foreach (Logger::getInstance()->getCategories() as $category) {
         if (NULL === ($context = $category->getContext()) || !$context instanceof EnvironmentAware) {
             continue;
         }
         $context->setHostname(System::getProperty('host.name'));
         $context->setRunner($this->getClassName());
         $context->setInstance($class->getName());
         $context->setResource(NULL);
         $context->setParams($params->string);
     }
     $instance = $class->newInstance();
     $instance->in = self::$in;
     $instance->out = self::$out;
     $instance->err = self::$err;
     $methods = $class->getMethods();
     // Injection
     foreach ($methods as $method) {
         if (!$method->hasAnnotation('inject')) {
             continue;
         }
         $inject = $method->getAnnotation('inject');
         if (isset($inject['type'])) {
             $type = $inject['type'];
         } else {
             if ($restriction = $method->getParameter(0)->getTypeRestriction()) {
                 $type = $restriction->getName();
             } else {
                 $type = $method->getParameter(0)->getType()->getName();
             }
         }
         try {
             switch ($type) {
                 case 'rdbms.DBConnection':
                     $args = array($cm->getByHost($inject['name'], 0));
                     break;
                 case 'util.Properties':
                     $p = $pm->getProperties($inject['name']);
                     // If a PropertyAccess is retrieved which is not a util.Properties,
                     // then, for BC sake, convert it into a util.Properties
                     if ($p instanceof PropertyAccess && !$p instanceof Properties) {
                         $convert = Properties::fromString('');
                         $section = $p->getFirstSection();
                         while ($section) {
                             // HACK: Properties::writeSection() would first attempts to
                             // read the whole file, we cannot make use of it.
                             $convert->_data[$section] = $p->readSection($section);
                             $section = $p->getNextSection();
                         }
                         $args = array($convert);
                     } else {
                         $args = array($p);
                     }
                     break;
                 case 'util.log.LogCategory':
                     $args = array($l->getCategory($inject['name']));
                     break;
                 default:
                     self::$err->writeLine('*** Unknown injection type "' . $type . '" at method "' . $method->getName() . '"');
                     return 2;
             }
             $method->invoke($instance, $args);
         } catch (TargetInvocationException $e) {
             self::$err->writeLine('*** Error injecting ' . $type . ' ' . $inject['name'] . ': ' . $e->getCause()->compoundMessage());
             return 2;
         } catch (Throwable $e) {
             self::$err->writeLine('*** Error injecting ' . $type . ' ' . $inject['name'] . ': ' . $e->compoundMessage());
             return 2;
         }
     }
     // Arguments
     foreach ($methods as $method) {
         if ($method->hasAnnotation('args')) {
             // Pass all arguments
             if (!$method->hasAnnotation('args', 'select')) {
                 $begin = 0;
                 $end = $classparams->count;
                 $pass = array_slice($classparams->list, 0, $end);
             } else {
                 $pass = array();
                 foreach (preg_split('/, ?/', $method->getAnnotation('args', 'select')) as $def) {
                     if (is_numeric($def) || '-' == $def[0]) {
                         $pass[] = $classparams->value((int) $def);
                     } else {
                         sscanf($def, '[%d..%d]', $begin, $end);
                         isset($begin) || ($begin = 0);
                         isset($end) || ($end = $classparams->count - 1);
                         while ($begin <= $end) {
                             $pass[] = $classparams->value($begin++);
                         }
                     }
                 }
             }
             try {
                 $method->invoke($instance, array($pass));
             } catch (Throwable $e) {
                 self::$err->writeLine('*** Error for arguments ' . $begin . '..' . $end . ': ', $this->verbose ? $e : $e->getMessage());
                 return 2;
             }
         } else {
             if ($method->hasAnnotation('arg')) {
                 // Pass arguments
                 $arg = $method->getAnnotation('arg');
                 if (isset($arg['position'])) {
                     $name = '#' . ($arg['position'] + 1);
                     $select = intval($arg['position']);
                     $short = NULL;
                 } else {
                     if (isset($arg['name'])) {
                         $name = $select = $arg['name'];
                         $short = isset($arg['short']) ? $arg['short'] : NULL;
                     } else {
                         $name = $select = strtolower(preg_replace('/^set/', '', $method->getName()));
                         $short = isset($arg['short']) ? $arg['short'] : NULL;
                     }
                 }
                 if (0 == $method->numParameters()) {
                     if (!$classparams->exists($select, $short)) {
                         continue;
                     }
                     $args = array();
                 } else {
                     if (!$classparams->exists($select, $short)) {
                         list($first, ) = $method->getParameters();
                         if (!$first->isOptional()) {
                             self::$err->writeLine('*** Argument ' . $name . ' does not exist!');
                             return 2;
                         }
                         $args = array();
                     } else {
                         $args = array($classparams->value($select, $short));
                     }
                 }
                 try {
                     $method->invoke($instance, $args);
                 } catch (TargetInvocationException $e) {
                     self::$err->writeLine('*** Error for argument ' . $name . ': ', $this->verbose ? $e->getCause() : $e->getCause()->compoundMessage());
                     return 2;
                 }
             }
         }
     }
     try {
         $instance->run();
     } catch (Throwable $t) {
         self::$err->writeLine('*** ', $t->toString());
         return 70;
         // EX_SOFTWARE according to sysexits.h
     }
     return 0;
 }
Exemplo n.º 7
0
<?php

require 'lang.base.php';
uses('util.cmd.Console', 'util.cmd.ParamString', 'org.dia.DiaUnmarshaller', 'io.File');
// TODO: => unittest!
$Param = new ParamString();
$diagram = $Param->value(1);
try {
    $Dia = DiaUnmarshaller::unmarshal($diagram);
} catch (Exception $e) {
    $e->printStackTrace();
    exit(-1);
}
$Dia->saveTo('test_out.dia', FALSE);
Exemplo n.º 8
0
 /**
  * Main runner method
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     if (!$args) {
         self::usage();
     }
     // Parse arguments
     $output = '-';
     for ($i = 0, $s = sizeof($args); $i < $s; $i++) {
         if ('-O' == $args[$i]) {
             $output = $args[++$i];
         } else {
             if ('-?' == $args[$i] || '--help' == $args[$i]) {
                 self::usage();
             } else {
                 $package = $args[$i];
                 break;
             }
         }
     }
     // Load generator class
     try {
         $class = Package::forName('xp.codegen')->getPackage($package)->loadClass('Generator');
     } catch (ElementNotFoundException $e) {
         Console::$err->writeLine('*** No generator named "' . $package . '"');
         exit(2);
     }
     $params = new ParamString(array_slice($args, $i + 1));
     if ($params->exists('help', '?')) {
         Console::$err->writeLine(self::textOf($class->getComment()));
         exit(1);
     }
     // Instantiate generator
     $generator = $class->newInstance($params);
     $generator->storage = new FileSystemStorage(System::tempDir());
     // Output
     if ('-' === $output) {
         $generator->output = new ConsoleOutput(Console::$err);
     } else {
         if (strstr($output, '.xar')) {
             $generator->output = new ArchiveOutput($output);
         } else {
             $generator->output = new FileSystemOutput($output);
         }
     }
     $generator->output->addObserver(newinstance('util.Observer', array(), '{
     public function update($obs, $arg= NULL) { Console::writeLine("     >> ", $arg); }
   }'));
     Console::writeLine('===> Starting ', $generator);
     // Compile target chain
     $empty = new ArrayList();
     $targets = create('new util.collections.HashTable<lang.reflect.Method, util.collections.HashTable<string, lang.Generic>>()');
     foreach ($class->getMethods() as $method) {
         if (!$method->hasAnnotation('target')) {
             continue;
         }
         $target = create('new util.collections.HashTable<string, lang.Generic>()');
         // Fetch dependencies
         if ($method->hasAnnotation('target', 'depends')) {
             $depends = create('new util.collections.Vector<lang.reflect.Method>()');
             foreach ((array) $method->getAnnotation('target', 'depends') as $dependency) {
                 $depends[] = $class->getMethod($dependency);
             }
             $target['depends'] = $depends;
         }
         // Fetch input
         if ($method->hasAnnotation('target', 'input')) {
             $arguments = create('new util.collections.Vector<lang.reflect.Method>()');
             foreach ((array) $method->getAnnotation('target', 'input') as $input) {
                 $arguments[] = $class->getMethod($input);
             }
             $target['arguments'] = $arguments;
         }
         $targets->put($method, $target);
     }
     // Invoke
     try {
         foreach ($targets->keys() as $method) {
             self::invoke($generator, $method, $targets);
         }
     } catch (TargetInvocationException $e) {
         Console::$err->writeLine('*** ', $e->getCause());
         exit(3);
     }
     $generator->output->commit();
     Console::writeLine('===> Done');
 }
Exemplo n.º 9
0
<?php

/* This script creates or updates diagrams
 *
 *
 */
require 'lang.base.php';
uses('util.cmd.Console', 'util.cmd.ParamString', 'org.dia.DiaMarshaller', 'org.dia.DiaUnmarshaller', 'org.dia.UpdateVisitor');
$P = new ParamString();
if (!$P->exists('classes') or !$P->exists('diagram')) {
    die('Parameters "--classes=ful.qal.class[,oth.qual.class,...]" and "--diagram=file.dia" are required!');
} else {
    if ($P->exists('recurse')) {
        $recurse = $P->value('recurse');
    }
    if ($P->exists('depend')) {
        $depend = $P->value('depend');
    }
    $classes = explode(',', $P->value('classes'));
    $file = $P->value('diagram');
    // if file does not exist: generate diagram
    if (!file_exists($file)) {
        Console::writeLine('File not found! Generating new diagram...');
        if (!isset($recurse)) {
            $recurse = 2;
            Console::writeLine('Using default "recurse=2"...');
        }
        if (!isset($depend)) {
            $depend = TRUE;
            Console::writeLine('Using default "depend=TRUE"...');
        }
Exemplo n.º 10
0
<?php

/* This script updates all classes found in a diagram
 *
 * $Id$
 */
require 'lang.base.php';
uses('util.cmd.ParamString', 'org.dia.DiaUnmarshaller', 'org.dia.UpdateVisitor');
$P = new ParamString();
$diagram = $P->value(1);
if (!file_exists($diagram)) {
    Console::writeLine("You need to specify an existing dia diagram file as first parameter!");
    exit(0);
}
// parse diagram
try {
    $Dia = DiaUnmarshaller::unmarshal($diagram);
} catch (Exception $e) {
    $e->printStackTrace();
    exit(-1);
}
// visitor that updates all existing classes in the diagram
try {
    $V = new UpdateVisitor(array(), FALSE, TRUE);
} catch (Exception $e) {
    $e->printStackTrace();
    exit(-1);
}
$Dia->accept($V);
$V->finalize();
// only needed when adding classes...
Exemplo n.º 11
0
 public function whitespaceInParameter()
 {
     $p = new ParamString(array('--realm=That is a realm'));
     $this->assertTrue($p->exists('realm'));
     $this->assertEquals('That is a realm', $p->value('realm'));
 }
Exemplo n.º 12
0
    // ???
    $p->writeInteger($key, 'ut', @$ut);
    // Desc??? array('Ascent'=>899,'Descent'=>-234,'CapHeight'=>731,'Flags'=>32,'FontBBox'=>'[-50 -234 1328 899]','ItalicAngle'=>0,'StemV'=>70,'MissingWidth'=>800);
    if (isset($desc)) {
        foreach ($desc as $k => $v) {
            if (is_int($v)) {
                $p->writeInteger($key . '.desc', $k, $v);
            } else {
                $p->writeString($key . '.desc', $k, $v);
            }
        }
    }
}
$core_names = array('courier' => 'Courier', 'courierB' => 'Courier-Bold', 'courierI' => 'Courier-Oblique', 'courierBI' => 'Courier-BoldOblique', 'helvetica' => 'Helvetica', 'helveticaB' => 'Helvetica-Bold', 'helveticaI' => 'Helvetica-Oblique', 'helveticaBI' => 'Helvetica-BoldOblique', 'times' => 'Times-Roman', 'timesB' => 'Times-Bold', 'timesI' => 'Times-Italic', 'timesBI' => 'Times-BoldItalic', 'symbol' => 'Symbol', 'zapfdingbats' => 'ZapfDingbats');
// Kommandozeilen-Parameter
$param = new ParamString($_SERVER['argv']);
$search = $param->exists('search') ? $param->value('search') : './src/font/.*';
$propertyFile = $param->exists('conf') ? $param->value('conf') : 'core_fonts.ini';
$pattern = basename($search);
$base = dirname($search);
printf("===> Start for %s [allfiles %s]\n", $base, $pattern);
$prop = new Properties($propertyFile);
if (!$prop->exists()) {
    try {
        printf("---> Creating configfile %s\n", $propertyFile);
        $prop->create();
    } catch (IOException $e) {
        $e->printStackTrace();
        exit;
    }
}
Exemplo n.º 13
0
<?php

require 'lang.base.php';
uses('text.doclet.RootDoc', 'util.cmd.Console');
$P = new ParamString();
if (!$P->exists('doclet')) {
    die('Parameter "--doclet" is required!');
} else {
    $doclet_name = $P->value('doclet');
    try {
        $Class = XPClass::forName($doclet_name)->newInstance();
        if (!is('Doclet', $Instance)) {
            throw new IllegalArgumentException('Given classname is not a "Doclet" class!');
        }
    } catch (Exception $e) {
        die($e->toString());
    }
    // remove '--doclet' argument and pass the rest to RootDoc
    while (list($key, $val) = each($P->list)) {
        if (0 == strncmp('--doclet', $val, 7)) {
            continue;
        }
        $list[$key] = $val;
    }
    RootDoc::start($Instance, new ParamString($list));
}
Exemplo n.º 14
0
 /**
  * Runner method
  *
  */
 public static function main(array $args)
 {
     // Show command usage if invoked without arguments
     if (!$args) {
         exit(self::usage(XPClass::forName(xp::nameOf(__CLASS__))));
     }
     $root = new RootDoc();
     for ($i = 0, $s = sizeof($args); $i < $s; $i++) {
         if ('-sp' === $args[$i]) {
             $root->setSourcePath(explode(PATH_SEPARATOR, $args[++$i]));
         } else {
             if ('-cp' === $args[$i]) {
                 foreach (explode(PATH_SEPARATOR, $args[++$i]) as $element) {
                     $root->addSourcePath(ClassLoader::registerPath($element, NULL)->path);
                 }
             } else {
                 try {
                     $class = XPClass::forName($args[$i]);
                 } catch (ClassNotFoundException $e) {
                     Console::$err->writeLine('*** ', $e->getMessage());
                     exit(2);
                 }
                 if (!$class->isSubclassOf('text.doclet.Doclet')) {
                     Console::$err->writeLine('*** ', $class, ' is not a doclet');
                     exit(2);
                 }
                 $doclet = $class->newInstance();
                 $params = new ParamString(array_slice($args, $i));
                 // Show doclet usage if the command line contains "-?" (at any point).
                 if ($params->exists('help', '?')) {
                     self::usage($class);
                     if ($valid = $doclet->validOptions()) {
                         Console::$err->writeLine();
                         Console::$err->writeLine('Options:');
                         foreach ($valid as $name => $value) {
                             Console::$err->writeLine('  * --', $name, OPTION_ONLY == $value ? '' : '=<value>');
                         }
                     }
                     exit(3);
                 }
                 $root->start($doclet, $params);
                 exit(0);
             }
         }
     }
     Console::$err->writeLine('*** No doclet classname given');
     exit(1);
 }