Changeset 580

Show
Ignore:
Timestamp:
04/20/07 00:47:12 (1 year ago)
Author:
mikey
Message:

first steps on the way to the target of loading XJConf classes only when really necessary
added foreign class loader for XJConf classes
moved contents of stubXJConfFacade to XJConf, is now only a decorator around XJConfFacade
needs more work:

  • replace direct use of stubXJConfFacade with stubXJConfProxy in stubRequestValueErrorXJConfFactory, stubPageXJConfFactory and stubJsonRpcProcessor
  • net.stubbles.xjconf.xjconfReal is more than ugly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/request/stubRequestValueErrorXJConfFactory.php

    r446 r580  
    1010                      'net.stubbles.ipo.request.stubRequestValueErrorException', 
    1111                      'net.stubbles.util.stubFactory', 
    12                       'net.stubbles.util.xjconf.xjconf' 
     12                      'net.stubbles.util.xjconf.xjconf', 
     13                      'net.stubbles.util.xjconf.xjconfReal' 
    1314); 
    1415/** 
     
    3738        if (null == self::$requestValueErrors) { 
    3839            self::$requestValueErrors = array(); 
    39             $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 
    40             $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/request.xml')); 
     40            $xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 
     41            $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/request.xml')); 
    4142            $sources = stubFactory::getResourceURIs('ipo/request.xml'); 
    4243            foreach ($sources as $source) { 
  • trunk/src/main/php/net/stubbles/util/xjconf/stubConfigXJConfExtension.php

    r312 r580  
    77 * @subpackage  util_xjconf 
    88 */ 
    9 stubClassLoader::load('net.stubbles.util.xjconf.xjconf'); 
    10 XJConfLoader::load('ext.Extension'); 
     9stubClassLoader::load('net.xjconf.ext.Extension'); 
    1110/** 
    1211 * Extension for XJConf to load values from stubConfig. 
  • trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfFacade.php

    r446 r580  
    11<?php 
    22/** 
    3  * Facade for XJConf. 
     3 * Decorator arround the facade for XJConf. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    77 * @subpackage  util_xjconf 
    88 */ 
    9 stubClassLoader::load('net.stubbles.util.xjconf.xjconf'); 
    10 XJConfLoader::load('DefinitionParser', 
    11                    'XmlParser' 
    12 ); 
    139/** 
    14  * Facade for XJConf. 
     10 * Decorator arround the facade for XJConf. 
    1511 * 
    1612 * @package     stubbles 
     
    2016{ 
    2117    /** 
    22      * list of class loaders to us
     18     * the real facad
    2319     * 
    24      * @var  array<string,XJConfClassLoader> 
     20     * @var  XJConfFacade 
    2521     */ 
    26     protected $classLoaders         = array(); 
    27     /** 
    28      * list of extensions to use 
    29      * 
    30      * @var  array<string,Extension> 
    31      */ 
    32     protected $extensions           = array(); 
    33     /** 
    34      * list of namespace definitions to merge with default one 
    35      * 
    36      * @var  array<NamespaceDefinition> 
    37      */ 
    38     protected $namespaceDefinitions = array(); 
    39     /** 
    40      * the definition parser 
    41      * 
    42      * @var  DefinitionParser 
    43      */ 
    44     protected $definitionParser; 
    45     /** 
    46      * the xml parser 
    47      * 
    48      * @var  XmlParser 
    49      */ 
    50     protected $xmlParser; 
    51      
     22    protected $realFacade; 
     23 
    5224    /** 
    5325     * construct the facade 
    5426     * 
    55      * @param  array  $classLoaders<string,XJConfClassLoader>  optional  list of class loaders for given namespaces 
     27     * @param  XJConfFacade  $realFacade  the real facade 
    5628     */ 
    57     public function __construct(array $classLoaders = array()
     29    public function __construct($realFacade
    5830    { 
    59         $this->classLoaders = $classLoaders
     31        $this->realFacade = $realFacade
    6032    } 
    6133 
    6234    /** 
    63      * add an extension that handles all tags in given namespace 
     35     * call interceptor 
    6436     * 
    65      * @param  Extension  $ext        use this extension to handle all tags in given namespace 
    66      * @param  string     $namespace  optional  handle all tags in this namespace with given extension 
    67      */ 
    68     public function addExtension(Extension $ext, $namespace = null) 
    69     { 
    70         if (null == $namespace) { 
    71             $namespace = $ext->getNamespace(); 
    72         } 
    73          
    74         $this->extensions[$namespace] = $ext; 
    75     } 
    76      
    77     /** 
    78      * enables xinclude 
    79      */ 
    80     public function enableXIncludes() 
    81     { 
    82         XJConfLoader::load('ext.xinc.XInclude'); 
    83         $xincludeExtension = new XInclude(); 
    84         $this->addExtension($xincludeExtension); 
    85     } 
    86      
    87     /** 
    88      * add a namespace definition 
    89      * 
    90      * @param  NamespaceDefinition  $namespaceDefinition 
    91      */ 
    92     public function addNamespaceDefinition(NamespaceDefinition $namespaceDefinition) 
    93     { 
    94         $this->namespaceDefinitions[$namespaceDefinition->getNamespaceURI()] = $namespaceDefinition; 
    95     } 
    96      
    97     /** 
    98      * add a namespace definition 
    99      * 
    100      * @param  NamespaceDefinitions  $namespaceDefinitions 
    101      */ 
    102     public function addNamespaceDefinitions(NamespaceDefinitions $namespaceDefinitions) 
    103     { 
    104         $this->namespaceDefinitions = array_merge($this->namespaceDefinitions, $namespaceDefinitions->getDefinedNamespaces()); 
    105     } 
    106      
    107     /** 
    108      * parses a definition and returns the namespace definitions 
    109      * 
    110      * @param   string                $definitionFile 
    111      * @return  NamespaceDefinitions 
    112      */ 
    113     public function parseDefinition($definitionFile) 
    114     { 
    115         if (null == $this->definitionParser) { 
    116             $this->definitionParser = new DefinitionParser($this->classLoaders); 
    117         } 
    118          
    119         return $this->definitionParser->parse($definitionFile); 
    120     } 
    121      
    122     /** 
    123      * parses a definition file and adds its definitions 
    124      * 
    125      * @param  string  $definitionFile 
    126      */ 
    127     public function parseAndAddDefinition($definitionFile) 
    128     { 
    129         $this->addNamespaceDefinitions($this->parseDefinition($definitionFile)); 
    130     } 
    131      
    132     /** 
    133      * parses a definition file and adds its definitions 
    134      * 
    135      * @param  array  $definitions 
    136      */ 
    137     public function parseAndAddDefinitions(array $definitions) 
    138     { 
    139         foreach ($definitions as $definition) { 
    140             $this->addNamespaceDefinitions($this->parseDefinition($definition)); 
    141         } 
    142     } 
    143      
    144     /** 
    145      * parses a given file and creates the data structure described in this file 
    146      * 
    147      * @param   string               $filename 
    148      * @throws  stubXJConfException 
    149      */ 
    150     public function parse($filename) 
    151     { 
    152         if (null == $this->xmlParser) { 
    153             $this->xmlParser = new XmlParser(); 
    154         } 
    155          
    156         $namespaceDefinitions = new NamespaceDefinitions(); 
    157         foreach ($this->namespaceDefinitions as $namespaceURI => $namespaceDefintion) { 
    158             $namespaceDefinitions->addNamespaceDefinition($namespaceURI, $namespaceDefintion); 
    159         } 
    160         $this->xmlParser->setTagDefinitions($namespaceDefinitions); 
    161         foreach ($this->extensions as $namespace => $extension) { 
    162             $this->xmlParser->addExtension($extension, $namespace); 
    163         } 
    164          
    165         try { 
    166             $this->xmlParser->parse($filename); 
    167         } catch (XJConfException $xjce) { 
    168             throw new stubXJConfException('Could not parse ' . $filename, $xjce); 
    169         } 
    170     } 
    171      
    172     /** 
    173      * checks whether a data structure associated with this name exists 
    174      * 
    175      * @param   string               $name 
    176      * @return  bool 
    177      * @throws  stubXJConfException 
    178      */ 
    179     public function hasConfigValue($name) 
    180     { 
    181         if (null == $this->xmlParser) { 
    182             throw new stubXJConfException('Invalid state: needs to parse first.'); 
    183         } 
    184          
    185         return $this->xmlParser->hasConfigValue($name); 
    186     } 
    187      
    188     /** 
    189      * returns the data structure associated with this name 
    190      * 
    191      * @param   string               $name 
     37     * @param   string  $method     name of the method to call 
     38     * @param   array   $arguments  arguments to call 
    19239     * @return  mixed 
    19340     * @throws  stubXJConfException 
    19441     */ 
    195     public function getConfigValue($name
     42    public function __call($method, $arguments
    19643    { 
    197         if (null == $this->xmlParser) { 
    198             throw new stubXJConfException('Invalid state: needs to parse first.'); 
     44        try { 
     45            return call_user_method_array($method, $this->realFacade, $arguments); 
     46        } catch (Exception $e) { 
     47            throw new stubXJConfException($e->getMessage, $e); 
    19948        } 
    200          
    201         return $this->xmlParser->getConfigValue($name); 
    202     } 
    203      
    204     /** 
    205      * returns a list of all data structures 
    206      * 
    207      * @return  mixed 
    208      * @throws  stubXJConfException 
    209      */ 
    210     public function getConfigValues() 
    211     { 
    212         if (null == $this->xmlParser) { 
    213             throw new stubXJConfException('Invalid state: needs to parse first.'); 
    214         } 
    215          
    216         return $this->xmlParser->getConfigValues(); 
    21749    } 
    21850} 
  • trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfLoader.php

    r312 r580  
    88 * @subpackage  util_xjconf 
    99 */ 
    10 stubClassLoader::load('net.stubbles.util.xjconf.xjconf'); 
    11 XJConfLoader::load('XJConfClassLoader'); 
     10stubClassLoader::load('net.xjconf.XJConfClassLoader'); 
    1211/** 
    1312 * Class loader to use for XJConf. 
  • trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfProxy.php

    r562 r580  
    11<?php 
    22/** 
    3  * Proxy for the XJConfFacade
     3 * Proxy for XJConf
    44 *  
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    77 * @subpackage  util_xjconf 
    88 */ 
    9 stubClassLoader::load('net.stubbles.util.stubFactory', 
    10                       'net.stubbles.util.xjconf.xjconf' 
    11 ); 
     9stubClassLoader::load('net.stubbles.util.stubFactory'); 
    1210/** 
    13  * Proxy for the XJConfFacade
     11 * Proxy for XJConf
    1412 * 
    1513 * @package     stubbles 
     
    7371        } 
    7472         
    75         $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 
    76         $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/' . $this->initializer->getDescriptor() . '.xml')); 
     73        stubClassLoader::load('net.stubbles.util.xjconf.xjconfReal'); 
     74        $xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 
     75        $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/' . $this->initializer->getDescriptor() . '.xml')); 
    7776        $xjconf->enableXIncludes(); 
    7877        foreach ($extensions as $extension) { 
  • trunk/src/main/php/net/stubbles/util/xjconf/xjconf.php

    r538 r580  
    77 * @subpackage  util_xjconf 
    88 */ 
    9 $xjConfUri = StarClassRegistry::getUriForClass('net.xjconf.XJConfLoader'); 
    10 if (null === $xjConfUri) { 
    11     /** 
    12      * Try to include XJConf from PEAR installation 
    13      */ 
    14     if (!@include 'XJConf/XJConfLoader.php') { 
    15         throw new stubException('XJConf could not be found in lib nor in include path.'); 
    16     } 
    17 } else { 
    18     /** 
    19      * Include XJConf via Star 
    20      */ 
    21     require $xjConfUri; 
    22 
    23 stubClassLoader::load('net.stubbles.util.xjconf.stubXJConfLoader', 
     9stubClassLoader::load('net.stubbles.util.xjconf.stubXJConfException', 
    2410                      'net.stubbles.util.xjconf.stubXJConfFacade', 
    25                       'net.stubbles.util.xjconf.stubXJConfException', 
    2611                      'net.stubbles.util.xjconf.stubXJConfInitializer', 
    27                       'net.stubbles.util.xjconf.stubXJConfProxy', 
    28                       'net.stubbles.util.xjconf.stubConfigXJConfExtension' 
     12                      'net.stubbles.util.xjconf.stubXJConfProxy' 
    2913); 
    3014?> 
  • trunk/src/main/php/net/stubbles/websites/processors/stubJsonRpcProcessor.php

    r542 r580  
    1414                      'net.stubbles.service.annotations.stubWebMethodAnnotation', 
    1515                      'net.stubbles.service.stubStatefulService', 
    16                       'net.stubbles.util.encoding.stubEncodingHelper'); 
     16                      'net.stubbles.util.encoding.stubEncodingHelper', 
     17                      'net.stubbles.util.xjconf.xjconf', 
     18                      'net.stubbles.util.xjconf.xjconfReal' 
     19); 
    1720 
    1821/** 
     
    6972    public function doProcess() { 
    7073 
    71         $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 
    72         $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/json-rpc-service.xml')); 
     74        $xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 
     75        $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/json-rpc-service.xml')); 
    7376        $configFile = stubConfig::getConfigPath() . '/xml/json-rpc-service.xml'; 
    7477        $xjconf->parse($configFile); 
  • trunk/src/main/php/net/stubbles/websites/stubPageFactory.php

    r557 r580  
    77 * @subpackage  websites 
    88 */ 
    9 stubClassLoader::load('net.stubbles.util.stubFactory', 
    10                       'net.stubbles.util.xjconf.stubXJConfLoader', 
    11                       'net.stubbles.websites.stubPage', 
     9stubClassLoader::load('net.stubbles.websites.stubPage', 
    1210                      'net.stubbles.websites.stubPageConfigurationException' 
    1311); 
  • trunk/src/main/php/net/stubbles/websites/stubPageXJConfFactory.php

    r447 r580  
    99stubClassLoader::load('net.stubbles.util.stubFactory', 
    1010                      'net.stubbles.util.xjconf.xjconf', 
     11                      'net.stubbles.util.xjconf.xjconfReal', 
    1112                      'net.stubbles.websites.stubPageConfigurationException', 
    1213                      'net.stubbles.websites.stubPageFactory' 
     
    3334    { 
    3435        if (null == self::$xjconf) { 
    35             self::$xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 
    36             self::$xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/websites.xml')); 
     36            self::$xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 
     37            self::$xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/websites.xml')); 
    3738        } 
    3839    } 
  • trunk/src/test/php/net/stubbles/util/xjconf/stubXJConfProxyTestCase.php

    r538 r580  
    99stubClassLoader::load('net.stubbles.util.xjconf.stubXJConfProxy'); 
    1010Mock::generate('stubXJConfInitializer'); 
    11 Mock::generate('stubXJConfFacade'); 
    1211/** 
    1312 * Tests for net.stubbles.util.xjconf.stubXJConfProxy 
     
    9392     * assure that values are taken from cache is cache file is newer than data file 
    9493     */ 
    95    public function testIsCachedAndCacheIsNewer() 
    96    
    97        file_put_contents($this->cacheFile, serialize(array('foo' => 'bar'))); 
    98        touch($this->configFile, (time() - 100)); 
    99        touch($this->cacheFile, time()); 
    100        $this->xjConfInitializer->expectOnce('setCacheData', array(array('foo' => 'bar'))); 
    101        $this->xjConfInitializer->expectNever('getCacheData'); 
    102        $this->xjConfProxy->process(); 
    103    
    104      
    105    /** 
     94    public function testIsCachedAndCacheIsNewer() 
     95   
     96        file_put_contents($this->cacheFile, serialize(array('foo' => 'bar'))); 
     97        touch($this->configFile, (time() - 100)); 
     98        touch($this->cacheFile, time()); 
     99        $this->xjConfInitializer->expectOnce('setCacheData', array(array('foo' => 'bar'))); 
     100        $this->xjConfInitializer->expectNever('getCacheData'); 
     101        $this->xjConfProxy->process(); 
     102   
     103 
     104    /** 
    106105     * assure that values are created and cached if the cache file is older than the data file 
    107106     */ 
    108    public function testIsCachedAndCacheIsOlder() 
    109    
    110        file_put_contents($this->cacheFile, serialize(array('foo' => 'bar'))); 
    111        touch($this->configFile, (time())); 
    112        touch($this->cacheFile, time() - 100); 
    113        $this->xjConfInitializer->expectNever('setCacheData'); 
    114        $this->xjConfInitializer->expectOnce('loadData'); 
    115        $this->xjConfInitializer->expectOnce('getCacheData'); 
    116        $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bar')); 
    117        $this->xjConfProxy->process(); 
    118        $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bar')); 
    119    
    120      
    121    /** 
     107    public function testIsCachedAndCacheIsOlder() 
     108   
     109        file_put_contents($this->cacheFile, serialize(array('foo' => 'bar'))); 
     110        touch($this->configFile, (time())); 
     111        touch($this->cacheFile, time() - 100); 
     112        $this->xjConfInitializer->expectNever('setCacheData'); 
     113        $this->xjConfInitializer->expectOnce('loadData'); 
     114        $this->xjConfInitializer->expectOnce('getCacheData'); 
     115        $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bar')); 
     116        $this->xjConfProxy->process(); 
     117        $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bar')); 
     118   
     119 
     120    /** 
    122121     * assure that values are created and cached if they were not cached before 
    123122     */ 
    124    public function testIsNotCached() 
    125    
    126        $this->xjConfInitializer->expectNever('setCacheData'); 
    127        $this->xjConfInitializer->expectOnce('loadData'); 
    128        $this->xjConfInitializer->expectOnce('getCacheData'); 
    129        $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bum')); 
    130        $this->xjConfProxy->process(); 
    131        $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bum')); 
    132    
     123    public function testIsNotCached() 
     124   
     125        $this->xjConfInitializer->expectNever('setCacheData'); 
     126        $this->xjConfInitializer->expectOnce('loadData'); 
     127        $this->xjConfInitializer->expectOnce('getCacheData'); 
     128        $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bum')); 
     129        $this->xjConfProxy->process(); 
     130        $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bum')); 
     131   
    133132} 
    134133?> 
  • trunk/src/test/php/net/stubbles/websites/stubFrontControllerProcessTestCase.php

    r473 r580  
    1515Mock::generate('stubProcessor'); 
    1616Mock::generate('stubProcessorResolver'); 
    17 Mock::generate('stubXJConfFacade'); 
    1817Mock::generate('stubInterceptorInitializer'); 
    1918Mock::generate('stubProcessorResolverFactory');