Changeset 1042

Show
Ignore:
Timestamp:
11/15/07 17:10:19 (8 months ago)
Author:
mikey
Message:

implemented enhancement #96 for request broker: every filter annotation now supports the errorMapping argument, in format 'OLD_ERROR_ID1=>NEW_ERROR_ID1:OLD_ERROR_ID2=>NEW_ERROR_ID2'

Files:

Legend:

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

    r731 r1042  
    4444     */ 
    4545    protected $defaultValue    = null; 
     46    /** 
     47     * list of error mappings 
     48     * 
     49     * @var  array<array<string,string>> 
     50     */ 
     51    protected $mappings        = array(); 
    4652 
    4753    /** 
     
    96102 
    97103    /** 
     104     * sets the error mapping 
     105     * 
     106     * @param  string  $errorMapping 
     107     */ 
     108    public function setErrorMapping($errorMapping) 
     109    { 
     110        $mappings = explode(':', $errorMapping); 
     111        foreach ($mappings as $mapping) { 
     112            $errorIds         = explode('=>', $mapping); 
     113            $this->mappings[trim($errorIds[0])] = trim($errorIds[1]); 
     114        } 
     115    } 
     116 
     117    /** 
    98118     * returns the filter defined by the annotation 
    99119     * 
     
    127147        if (null != $this->rveFactoryClass) { 
    128148            $rveFactory = $this->rveFactoryClass->newInstance(); 
    129             if (($rveFactory instanceof stubRequestValueErrorFactory) == false) { 
     149            if (($rveFactory instanceof stubRequestValueErrorFactory) === false) { 
    130150                throw new stubRequestBrokerException('Created request value error factory is not an instance of stubRequestValueErrorFactory'); 
    131151            } 
     
    135155        } 
    136156         
    137         return $rveFactory; 
     157        if (count($this->mappings) === 0) { 
     158            return $rveFactory; 
     159        } 
     160         
     161        stubClassLoader::load('net.stubbles.ipo.request.stubRequestValueErrorFactoryMappingDecorator'); 
     162        $rveMappingDecorator = new stubRequestValueErrorFactoryMappingDecorator($rveFactory); 
     163        foreach ($this->mappings as $oldErrorId => $newErrorId) { 
     164            $rveMappingDecorator->addMapping($oldErrorId, $newErrorId); 
     165        } 
     166         
     167        return $rveMappingDecorator; 
    138168    } 
    139169 
     
    147177        return stubAnnotation::TARGET_METHOD + stubAnnotation::TARGET_PROPERTY; 
    148178    } 
    149  
    150179} 
    151180?> 
  • trunk/src/main/php/net/stubbles/ipo/request/stubRequestValueErrorFactoryMappingDecorator.php

    r1037 r1042  
    5353 
    5454    /** 
     55     * returns current mappings where key is old error id and value is new error id 
     56     * 
     57     * @return  array<string,string> 
     58     */ 
     59    public function getMappings() 
     60    { 
     61        return $this->mappings; 
     62    } 
     63 
     64    /** 
    5565     * creates the  RequestValueError with the id from the given source 
    5666     * 
  • trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubAbstractFilterAnnotationTestCase.php

    r731 r1042  
    105105 
    106106    /** 
     107     * test that mapping is added correct 
     108     */ 
     109    public function testMappedRequestErrorValueFactory() 
     110    { 
     111        $abstractFilterAnnotation = new TeststubAbstractFilterAnnotation(); 
     112        $abstractFilterAnnotation->setErrorMapping('FIELD_EMPTY=>FOO_EMPTY:TOO_SMALL=>TOO_GREAT'); 
     113        $rveFactory = $abstractFilterAnnotation->getRVEFactory(); 
     114        $this->assertIsA($rveFactory, 'stubRequestValueErrorFactoryMappingDecorator'); 
     115        $this->assertEqual($rveFactory->getMappings(), array('FIELD_EMPTY' => 'FOO_EMPTY', 
     116                                                             'TOO_SMALL'   => 'TOO_GREAT' 
     117                                                       ) 
     118        ); 
     119    } 
     120 
     121    /** 
    107122     * test that the correct RequestErrorValueFactory is created 
    108123     */