Changeset 446

Show
Ignore:
Timestamp:
03/29/07 23:24:48 (2 years ago)
Author:
mikey
Message:

reworked net.stubbles.ipo.request.stubRequestValueErrorXJConfFactory to be more simple and less resource consuming
dropped unit test for this class as this will not work any more, added integration test instead

Files:

Legend:

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

    r142 r446  
    2020     * 
    2121     * @param   string                 $id      id of RequestValueError to create 
    22      * @param   string                 $source  optional  source where RequestValueError is defined 
    2322     * @return  stubRequestValueError 
    2423     * @throws  stubRequestValueErrorException 
    2524     */ 
    26     public function create($id, $source = null); 
     25    public function create($id); 
    2726} 
    2827?> 
  • trunk/src/main/php/net/stubbles/ipo/request/stubRequestValueErrorXJConfFactory.php

    r444 r446  
    2424     * switches whether initialization has been done 
    2525     * 
    26      * @var  array<bool
     26     * @var  array<string,stubRequestValueError
    2727     */ 
    28     protected $initDone  = array(); 
     28    protected static $requestValueErrors = null; 
     29     
    2930    /** 
    30      * instance of the parser that parses the xml configuration files 
    31      * 
    32      * @var  stubXJConfFacade 
     31     * constructor 
     32     *  
     33     * @throws  stubRequestValueErrorException 
    3334     */ 
    34     protected $xjconf; 
     35    public function __construct() 
     36    { 
     37        if (null == self::$requestValueErrors) { 
     38            self::$requestValueErrors = array(); 
     39            $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 
     40            $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/request.xml')); 
     41            $sources = stubFactory::getResourceURIs('ipo/request.xml'); 
     42            foreach ($sources as $source) { 
     43                try { 
     44                    $xjconf->parse($source); 
     45                } catch (stubXJConfException $xjce) { 
     46                    throw new stubRequestValueErrorException($xjce->getMessage()); 
     47                } 
     48                 
     49                self::$requestValueErrors = array_merge(self::$requestValueErrors, $xjconf->getConfigValues()); 
     50            } 
     51        } 
     52    } 
    3553     
    3654    /** 
     
    4058     * 
    4159     * @param   string                 $id      id of RequestValueError to create 
    42      * @param   string                 $source  optional  source where RequestValueError is defined 
    4360     * @return  stubRequestValueError 
    4461     * @throws  stubRequestValueErrorException 
    4562     */ 
    46     public function create($id, $source = null
     63    public function create($id
    4764    { 
    48         if (null == $source) { 
    49             $source = stubFactory::getResourceURIs('ipo/request.xml')
     65        if (isset(self::$requestValueErrors[$id]) == true) { 
     66            return clone self::$requestValueErrors[$id]
    5067        } 
    5168         
    52         if (is_array($source) == false) { 
    53             $source = array($source); 
    54         } 
    55          
    56         foreach ($source as $sourceURI) { 
    57             if (isset($this->initDone[$sourceURI]) == false) { 
    58                 $this->init($sourceURI); 
    59             } 
    60         } 
    61          
    62         return clone $this->xjconf->getConfigValue($id); 
    63     } 
    64      
    65     /** 
    66      * initialize the XJConf stuff and parse the given configuration source file 
    67      * 
    68      * @param   string  $source  source where RequestValueErrors are defined 
    69      * @throws  stubRequestValueErrorException 
    70      */ 
    71     protected function init($source = null) 
    72     { 
    73         if (count($this->initDone) == 0) { 
    74             $this->xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 
    75             $this->xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/request.xml')); 
    76         } 
    77          
    78         try { 
    79             $this->xjconf->parse($source); 
    80         } catch (stubXJConfException $xjce) { 
    81             $this->initDone[$source] = false; 
    82             throw new stubRequestValueErrorException($xjce->getMessage()); 
    83         } 
    84          
    85         $this->initDone[$source] = true; 
     69        throw new stubRequestValueErrorException('RequestValueError with id ' . $id . ' does not exist.'); 
    8670    } 
    8771} 
  • trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfFacade.php

    r440 r446  
    171171     
    172172    /** 
     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    /** 
    173189     * returns the data structure associated with this name 
    174190     * 
     
    185201        return $this->xmlParser->getConfigValue($name); 
    186202    } 
     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(); 
     217    } 
    187218} 
    188219?> 
  • trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php

    r444 r446  
    2525        $this->addTestFile($dir . '/request/stubRequestPrefixDecoratorTestCase.php'); 
    2626        $this->addTestFile($dir . '/request/stubRequestValueErrorTestCase.php'); 
    27         $this->addTestFile($dir . '/request/stubRequestValueErrorXJConfFactoryTestCase.php'); 
    2827         
    2928        $this->addTestFile($dir . '/request/filters/stubFloatFilterTestCase.php'); 
  • trunk/src/test/runIntegration.php

    r400 r446  
    3535        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/ProcessorTestCase.php'); 
    3636        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/RegistryTestCase.php'); 
     37        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/stubRequestValueErrorXJConfFactoryTestCase.php'); 
    3738        $testSuite->addTestFile(TEST_SRC_PATH . '/php/net/stubbles/integration/VariantManagerTestCase.php'); 
    3839        if (PHP_SAPI == 'cli') {