Changeset 1445

Show
Ignore:
Timestamp:
03/20/08 17:51:12 (2 months ago)
Author:
mikey
Message:

refactoring #137, part 7: page factories are now attributes of the processors, and not of the resolvers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/config/xml/processors.xml

    r1219 r1445  
    44    xmlns="http://stubbles.net/websites"> 
    55  <defaultResolver default="xml"> 
    6     <pageFactory type="net::stubbles::websites::stubPageXJConfFactory" /> 
    7     <processor name="xml" type="net::stubbles::websites::xml::stubXMLProcessor" interceptorDescriptor="interceptors" /> 
    8     <processor name="page" type="net::stubbles::websites::memphis::stubMemphisProcessor" interceptorDescriptor="interceptors" /> 
    9     <processor name="jsonrpc" type="net::stubbles::service::jsonrpc::stubJsonRpcProcessor" interceptorDescriptor="interceptors" /> 
     6    <processor name="xml" type="net::stubbles::websites::xml::stubXMLProcessor" interceptorDescriptor="interceptors" pageFactoryClass="net::stubbles::websites::stubPageXJConfFactory"/> 
     7    <processor name="page" type="net::stubbles::websites::memphis::stubMemphisProcessor" pageFactoryClass="net::stubbles::websites::stubPageXJConfFactory"/> 
     8    <processor name="jsonrpc" type="net::stubbles::service::jsonrpc::stubJsonRpcProcessor" interceptorDescriptor="interceptors"/> 
    109  </defaultResolver> 
    1110</xj:configuration> 
  • trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php

    r1442 r1445  
    77 * @subpackage  websites_processors 
    88 */ 
    9 stubClassLoader::load('net::stubbles::websites::processors::stubPageBasedProcessor', 
     9stubClassLoader::load('net::stubbles::lang::exceptions::stubConfigurationException', 
     10                      'net::stubbles::lang::exceptions::stubRuntimeException', 
     11                      'net::stubbles::websites::stubPageFactory', 
     12                      'net::stubbles::websites::processors::stubPageBasedProcessor', 
    1013                      'net::stubbles::websites::processors::stubProcessorResolver' 
    1114); 
     
    1922{ 
    2023    /** 
    21      * the page factory to use to read the page configuration 
    22      * 
    23      * @var  stubPageFactory 
    24      */ 
    25     protected $pageFactory = null; 
    26  
    27     /** 
    28      * sets the page factory to use to read the page configuration 
    29      * 
    30      * @param  stubPageFactory  $pageFactory 
    31      */ 
    32     public function setPageFactory(stubPageFactory $pageFactory) 
    33     { 
    34         $this->pageFactory = $pageFactory; 
    35     } 
    36  
    37     /** 
    38      * returns the page factory delivered within the constructor 
    39      * 
    40      * @return  stubPageFactory 
    41      */ 
    42     public function getPageFactory() 
    43     { 
    44         return $this->pageFactory; 
    45     } 
    46  
    47     /** 
    4824     * resolves the request and creates the appropriate processor 
    4925     * 
     
    5228     * @param   stubResponse   $response  the current response 
    5329     * @return  stubProcessor 
    54      * @throws  stubProcessorException 
     30     * @throws  stubConfigurationException 
     31     * @throws  stubRuntimeException 
    5532     */ 
    5633    public function resolve(stubRequest $request, stubSession $session, stubResponse $response) 
     
    5835        $processorClassName = $this->doResolve($request, $session, $response); 
    5936        if (null == $processorClassName) { 
    60             throw new stubProcessorException('Configuration error: no processor specified.'); 
     37            throw new stubConfigurationException('Configuration error: no processor specified.'); 
    6138        } 
    6239         
     
    6441        $className = stubClassLoader::getNonQualifiedClassName($processorClassName); 
    6542        $processor = new $className($request, $session, $response); 
    66         if (($processor instanceof stubProcessor) == false) { 
    67             throw new stubProcessorException($processorClassName . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); 
     43        if (($processor instanceof stubProcessor) === false) { 
     44            throw new stubRuntimeException($processorClassName . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); 
    6845        } 
    6946         
    70         $this->configureInterceptorDescriptor($processor); 
    71          
    72         if ($processor instanceof stubPageBasedProcessor) { 
    73             $processor->selectPage($this->pageFactory); 
    74         } 
    75          
     47        $this->configure($processor); 
     48        $this->handlePageBasedProcessor($processor); 
    7649        return $processor; 
    7750    } 
     
    8457     * @param   stubResponse  $response  the current response 
    8558     * @return  string        full qualified classname of the processor to create 
    86      * @throws  stubProcessorException 
    8759     */ 
    8860    protected abstract function doResolve(stubRequest $request, stubSession $session, stubResponse $response); 
    8961 
    9062    /** 
    91      * configures the processor with the interceptor descriptor 
     63     * configures the processor 
    9264     * 
    9365     * @param  stubProcessor  $processor 
    9466     */ 
    95     protected abstract function configureInterceptorDescriptor(stubProcessor $processor); 
     67    protected abstract function configure(stubProcessor $processor); 
    9668 
    9769    /** 
    98      * template method to hook into __sleep() 
     70     * returns the page factory class for the processor 
    9971     * 
    100      * @return  array<string>  list of property names that should not be serialized 
     72     * @param   stubProcessor  $processor 
     73     * @return  string 
    10174     */ 
    102     protected function __doSleep() 
    103     { 
    104         $this->_serializedProperties['pageFactory'] = $this->pageFactory->getClassName(); 
    105         return array('pageFactory'); 
    106     } 
     75    protected abstract function getPageFactoryClass(stubProcessor $processor); 
    10776 
    10877    /** 
    109      * template method to hook into __wakeup() 
     78     * helper method to handle page based processors 
     79     * 
     80     * @param   stubProcessor  $processor 
     81     * @throws  stubConfigurationException 
     82     * @throws  stubRuntimeException 
    11083     */ 
    111     protected function __doWakeUp(
     84    protected function handlePageBasedProcessor(stubProcessor $processor
    11285    { 
    113         $nqClassName = stubClassLoader::getNonQualifiedClassName($this->_serializedProperties['pageFactory']); 
    114         if (class_exists($nqClassName, false) == false) { 
    115             stubClassLoader::load($this->_serializedProperties['pageFactory']); 
     86        if (($processor instanceof stubPageBasedProcessor) === false) { 
     87            return; 
    11688        } 
    11789         
    118         $this->pageFactory = new $nqClassName(); 
    119         unset($this->_serializedProperties['pageFactory']); 
     90        $pageFactoryClass = $this->getPageFactoryClass($processor); 
     91        if (null == $pageFactoryClass) { 
     92            throw new stubConfigurationException('Configuration error: processor ' . $processor->getClassName() . ' requires page factory, but no page factory class configured.'); 
     93        } 
     94         
     95        stubClassLoader::load($pageFactoryClass); 
     96        $nqClassName = stubClassLoader::getNonQualifiedClassName($pageFactoryClass); 
     97        $pageFactory = new $nqClassName(); 
     98        if (($pageFactory instanceof stubPageFactory) === false) { 
     99            throw new stubRuntimeException($processor->getClassName() . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubPageFactory')); 
     100        } 
     101         
     102        $processor->selectPage($pageFactory); 
    120103    } 
    121104} 
  • trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php

    r1231 r1445  
    77 * @subpackage  websites_processors 
    88 */ 
    9 stubClassLoader::load('net::stubbles::websites::processors::stubAbstractProcessorResolver', 
    10                       'net::stubbles::util::validators::stubPreSelectValidator' 
     9stubClassLoader::load('net::stubbles::lang::exceptions::stubConfigurationException', 
     10                      'net::stubbles::util::validators::stubPreSelectValidator', 
     11                      'net::stubbles::websites::processors::stubAbstractProcessorResolver' 
    1112); 
    1213/** 
     
    3738     */ 
    3839    protected $interceptorDescriptors = array(); 
     40    /** 
     41     * list of page factory classes 
     42     * 
     43     * @var  array<string,string> 
     44     */ 
     45    protected $pageFactoryClasses     = array(); 
    3946 
    4047    /** 
     
    4350     * @param  string  $paramValue             value of the request parameter that identifies this processor 
    4451     * @param  string  $fqClassName            full qualified class name of the processor 
    45      * @param  string  $interceptorDescriptor  the interceptor descriptor 
     52     * @param  string  $interceptorDescriptor  optional  the interceptor descriptor 
     53     * @param  string  $pageFactoryClass       optional  page factory class for the processor 
    4654     */ 
    47     public function addProcessor($paramValue, $fqClassName, $interceptorDescriptor
     55    public function addProcessor($paramValue, $fqClassName, $interceptorDescriptor = 'interceptors', $pageFactoryClass = null
    4856    { 
    4957        $this->processors[$paramValue]              = $fqClassName; 
    5058        $this->interceptorDescriptors[$fqClassName] = $interceptorDescriptor; 
     59        if (null !== $pageFactoryClass) { 
     60            $this->pageFactoryClasses[$fqClassName] = $pageFactoryClass; 
     61        } 
    5162    } 
    5263 
     
    6879     * @param   stubResponse  $response  the current response 
    6980     * @return  string        full qualified classname of the processor to create 
    70      * @throws  stubProcessorException 
     81     * @throws  stubConfigurationException 
    7182     */ 
    7283    protected function doResolve(stubRequest $request, stubSession $session, stubResponse $response) 
    7384    { 
    7485        if (isset($this->processors[$this->defaultProcessor]) == false) { 
    75             throw new stubProcessorException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.'); 
     86            throw new stubConfigurationException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.'); 
    7687        } 
    7788         
     
    90101 
    91102    /** 
    92      * configures the processor with the interceptor descriptor 
     103     * configures the processor 
    93104     * 
    94105     * @param  stubProcessor  $processor 
    95106     */ 
    96     protected function configureInterceptorDescriptor(stubProcessor $processor) 
     107    protected function configure(stubProcessor $processor) 
    97108    { 
    98109        if (isset($this->interceptorDescriptors[$processor->getClassName()]) == true && strlen($this->interceptorDescriptors[$processor->getClassName()]) > 0) { 
     
    100111        } 
    101112    } 
     113 
     114    /** 
     115     * returns the page factory class for the processor 
     116     * 
     117     * @param   stubProcessor  $processor 
     118     * @return  string 
     119     */ 
     120    protected function getPageFactoryClass(stubProcessor $processor) 
     121    { 
     122        if (isset($this->pageFactoryClasses[$processor->getClassName()]) === true) { 
     123            return $this->pageFactoryClasses[$processor->getClassName()]; 
     124        } 
     125         
     126        return null; 
     127    } 
    102128} 
    103129?> 
  • trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolver.php

    r1231 r1445  
    1010                      'net::stubbles::ipo::response::stubResponse', 
    1111                      'net::stubbles::ipo::session::stubSession', 
    12                       'net::stubbles::websites::processors::stubProcessor', 
    13                       'net::stubbles::websites::processors::stubProcessorException', 
    14                       'net::stubbles::websites::stubPageFactory' 
     12                      'net::stubbles::websites::processors::stubProcessor' 
    1513); 
    1614/** 
     
    2321{ 
    2422    /** 
    25      * sets the page factory to use to read the page configuration 
    26      * 
    27      * @param  stubPageFactory  $pageFactory 
    28      */ 
    29     public function setPageFactory(stubPageFactory $pageFactory); 
    30  
    31     /** 
    32      * returns the page factory delivered within the constructor 
    33      * 
    34      * @return  stubPageFactory 
    35      */ 
    36     public function getPageFactory(); 
    37  
    38     /** 
    3923     * resolves the request and creates the appropriate processor 
    4024     * 
     
    4327     * @param   stubResponse   $response  the current response 
    4428     * @return  stubProcessor 
    45      * @throws  stubProcessorException 
    4629     */ 
    4730    public function resolve(stubRequest $request, stubSession $session, stubResponse $response); 
  • trunk/src/main/php/net/stubbles/websites/processors/stubSimpleProcessorResolver.php

    r1231 r1445  
    2121     * @var  string 
    2222     */ 
    23     protected $processor   = null; 
     23    protected $processor        = null; 
     24    /** 
     25     * page factory class to be used 
     26     * 
     27     * @var  string 
     28     */ 
     29    protected $pageFactoryClass = null; 
    2430 
    2531    /** 
     
    3137    { 
    3238        $this->processor = $fqClassName; 
     39    } 
     40 
     41    /** 
     42     * sets the page factory class to be used 
     43     * 
     44     * @param  string  $pageFactoryClass 
     45     */ 
     46    public function setPageFactoryClass($pageFactoryClass) 
     47    { 
     48        $this->pageFactoryClass = $pageFactoryClass; 
    3349    } 
    3450 
     
    4763 
    4864    /** 
    49      * configures the processor with the interceptor descriptor 
     65     * configures the processor 
    5066     * 
    5167     * @param  stubProcessor  $processor 
    5268     */ 
    53     protected function configureInterceptorDescriptor(stubProcessor $processor) 
     69    protected function configure(stubProcessor $processor) 
    5470    { 
    5571        $processor->setInterceptorDescriptor('interceptors'); 
    5672    } 
     73 
     74    /** 
     75     * returns the page factory class for the processor 
     76     * 
     77     * @param   stubProcessor  $processor 
     78     * @return  string 
     79     */ 
     80    protected function getPageFactoryClass(stubProcessor $processor) 
     81    { 
     82        return $this->pageFactoryClass; 
     83    } 
    5784} 
    5885?> 
  • trunk/src/main/php/net/stubbles/websites/rasmus/stubPageRasmusFactory.php

    r1438 r1445  
    6363     * returns the configured stubPage instance 
    6464     * 
    65      * @param   string          $configSource   source of the page configuration to us
    66      * @return  stubRasmusPage 
     65     * @param   string    $pageName  name of the page to retriev
     66     * @return  stubPage 
    6767     */ 
    68     public function getPage($configSource) 
     68    protected function doGetPage($configSource) 
    6969    { 
    7070        $page = new stubRasmusPage($this->configPath . $configSource . '.php'); 
  • trunk/src/main/php/net/stubbles/websites/stubPageXJConfFactory.php

    r1438 r1445  
    6565     * returns the configured stubPage instance 
    6666     * 
    67      * @param   string    $configSource   source of the page configuration to us
     67     * @param   string    $pageName  name of the page to retriev
    6868     * @return  stubPage 
    6969     */ 
    70     public function getPage($configSource) 
     70    protected function doGetPage($configSource) 
    7171    { 
    7272        $configSource = str_replace('/', DIRECTORY_SEPARATOR, $this->pagePrefix . $configSource); 
  • trunk/src/main/resources/xjconf/processors.xml

    r1219 r1445  
    33  <namespace uri="http://stubbles.net/websites"> 
    44    <tag name="defaultResolver" type="net::stubbles::websites::processors::stubDefaultProcessorResolver" key="resolver"> 
    5       <attribute name="default" type="string" setter="setDefaultProcessor" /> 
     5      <attribute name="default" type="string" setter="setDefaultProcessor"/> 
    66      <methodCallTag name="processor" method="addProcessor"> 
    7         <attribute name="name" type="string" /> 
    8         <attribute name="type" type="string" /> 
    9         <attribute name="interceptorDescriptor" type="string" /> 
     7        <attribute name="name" type="string"/> 
     8        <attribute name="type" type="string"/> 
     9        <attribute name="interceptorDescriptor" type="string"/> 
     10        <attribute name="pageFactoryClass" type="string"/> 
    1011      </methodCallTag> 
    1112    </tag> 
    1213    <tag name="simpleResolver" type="net::stubbles::websites::processors::stubSimpleProcessorResolver" key="resolver"> 
    13       <attribute name="processor" type="string" /> 
    14       <attribute name="interceptorDescriptor" type="string" /> 
     14      <attribute name="processor" type="string"/> 
     15      <attribute name="pageFactoryClass" type="string"/> 
    1516    </tag> 
    16     <abstractTag name="pageFactory" abstractType="net::stubbles::websites::stubPageFactory" concreteTypeAttribute="type" /> 
    1717  </namespace> 
    1818</defines> 
  • trunk/src/test/php/net/stubbles/integration/ProcessorTestCase.php

    r1308 r1445  
    3737        $processorResolver = $this->getProcessorResolver(); 
    3838        $this->assertType('stubProcessorResolver', $processorResolver); 
    39         $pageFactory = $processorResolver->getPageFactory(); 
    40         $this->assertType('stubPageFactory', $pageFactory); 
    4139        $processor = $processorResolver->resolve($this->getMock('stubRequest'), $this->getMock('stubSession'), $this->getMock('stubResponse')); 
    4240        $this->assertType('stubProcessor', $processor); 
     
    4543        $processorResolver = $this->getProcessorResolver(); 
    4644        $this->assertType('stubProcessorResolver', $processorResolver); 
    47         $pageFactory = $processorResolver->getPageFactory(); 
    48         $this->assertType('stubPageFactory', $pageFactory); 
    4945        $processor = $processorResolver->resolve($this->getMock('stubRequest'), $this->getMock('stubSession'), $this->getMock('stubResponse')); 
    5046        $this->assertType('stubProcessor', $processor); 
  • trunk/src/test/php/net/stubbles/websites/processors/stubAbstractProcessorResolverTestCase.php

    r1442 r1445  
    2323    protected $abstractProcessorResolver; 
    2424    /** 
    25      * mocked page factory to use 
    26      * 
    27      * @var  PHPUnit_Framework_MockObject_MockObject 
    28      */ 
    29     protected $mockPageFactory; 
    30     /** 
    3125     * mocked request to use 
    3226     * 
     
    5246    public function setUp() 
    5347    { 
    54         $this->abstractProcessorResolver = $this->getMock('stubAbstractProcessorResolver', array('doResolve', 'configureInterceptorDescriptor')); 
    55  
    56         $this->mockPageFactory = $this->getMock('stubPageFactory'); 
    57         $this->abstractProcessorResolver->setPageFactory($this->mockPageFactory); 
    58  
     48        $this->abstractProcessorResolver = $this->getMock('stubAbstractProcessorResolver', 
     49                                                          array('doResolve', 
     50                                                                'configure', 
     51                                                                'getPageFactoryClass' 
     52                                                          ) 
     53                                           ); 
    5954        $this->mockRequest  = $this->getMock('stubRequest'); 
    6055        $this->mockSession  = $this->getMock('stubSession'); 
     
    6358 
    6459    /** 
    65      * assure that the page factory stays the same 
    66      * 
    67      * @test 
    68      */ 
    69     public function getPageFactory() 
    70     { 
    71         $pageFactory = $this->abstractProcessorResolver->getPageFactory(); 
    72         $this->assertSame($this->mockPageFactory, $pageFactory); 
    73     } 
    74  
    75     /** 
    7660     * test that a missing return value of doResolve() triggers an exception 
    7761     * 
    7862     * @test 
    79      * @expectedException  stubProcessorException 
     63     * @expectedException  stubConfigurationException 
    8064     */ 
    8165    public function noProcessorThrowsException() 
     
    9276     * 
    9377     * @test 
    94      * @expectedException  stubProcessorException 
     78     * @expectedException  stubRuntimeException 
    9579     */ 
    9680    public function falseProcessorThrowsException() 
     
    123107        $this->assertSame($this->mockResponse, $response); 
    124108    } 
    125  
    126     /** 
    127      * test that __sleep() returns a list of properties without the pageFactory 
    128      * 
    129      * @test 
    130      */ 
    131     public function sleep() 
    132     { 
    133         $keys = $this->abstractProcessorResolver->__sleep(); 
    134         $this->assertFalse(in_array('pageFactory', $keys)); 
    135     } 
    136  
    137     /** 
    138      * test that the resolver is serialized and unserialized correct 
    139      * 
    140      * @test 
    141      */ 
    142     public function serialize() 
    143     { 
    144         $class = get_class($this->getMock('stubPageFactory')); 
    145         $this->mockPageFactory->expects($this->once()) 
    146                               ->method('getClassName') 
    147                               ->will($this->returnValue($class)); 
    148         $serialized = serialize($this->abstractProcessorResolver); 
    149         $unserialized = unserialize($serialized); 
    150         $this->assertType($class, $unserialized->getPageFactory()); 
    151     } 
    152109} 
    153110?> 
  • trunk/src/test/php/net/stubbles/websites/processors/stubDefaultProcessorResolverTestCase.php

    r1252 r1445  
    130130     * 
    131131     * @test 
    132      * @expectedException  stubProcessorException 
     132     * @expectedException  stubConfigurationException 
    133133     */ 
    134134    public function noProcessors() 
     
    141141     * 
    142142     * @test 
    143      * @expectedException  stubProcessorException 
     143     * @expectedException  stubConfigurationException 
    144144     */ 
    145145    public function wrongDefaultProcessors()