Changeset 1747

Show
Ignore:
Timestamp:
07/28/08 23:10:11 (4 months ago)
Author:
mikey
Message:

reworked mapping for exceptions and stack trace elements, test for exception mapping will follow

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/mapping/stubEASCExceptionMapping.php

    r1718 r1747  
    55 * @author      Frank Kleine <mikey@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  remote_protocol_easc 
     7 * @subpackage  remote_protocol_easc_mapping 
    88 * @version     $Id$ 
    99 */ 
     
    1212                      'net::stubbles::php::serializer::stubExceptionReference', 
    1313                      'net::stubbles::php::serializer::stubPHPSerializerMapping', 
    14                       'net::stubbles::remote::protocol::easc::stubEASCStackTraceMapping' 
     14                      'net::stubbles::remote::protocol::easc::mapping::stubEASCStackTraceMapping' 
    1515); 
    1616/** 
     
    1818 *  
    1919 * @package     stubbles 
    20  * @subpackage  remote_protocol_easc 
     20 * @subpackage  remote_protocol_easc_mapping 
    2121 */ 
    2222class stubEASCExceptionMapping extends stubBaseObject implements stubPHPSerializerMapping 
     
    2828     */ 
    2929    protected static $handledClass = null; 
    30     /** 
    31      * mapping for stack trace elements 
    32      * 
    33      * @var  stubEASCStackTraceMapping 
    34      */ 
    35     protected $stackTraceMapping   = null; 
    3630 
    3731    /** 
     
    7872            $s = 'e:' . strlen($originException) . ':"' . $originException . '":3:{'; 
    7973        } else { 
     74            $exceptionClassName = str_replace('::', '.', $exceptionClassName); 
    8075            $s = 'E:' . strlen($exceptionClassName) . ':"' . $exceptionClassName . '":3:{'; 
    8176        } 
    8277         
    83         $s    .= 's:7:"message";'; 
    84         $s    .= $serializer->serialize($object->getMessage()); 
     78        $s    .= 's:7:"message";' . $serializer->serialize($object->getMessage()); 
    8579        $trace = $object->getTrace(); 
    8680        $s    .= 's:5:"trace";a:' . sizeof($trace) . ':{'; 
    8781        $i     = 0; 
    88         $stackTraceMapping = $this->getStackTraceMapping(); 
    8982        foreach ($trace as $element) { 
    90             $s .= 'i:' . $i++ . ';' . $stackTraceMapping->serialize($serializer, $element, $context); 
     83            $s .= 'i:' . $i++ . ';' . $serializer->serialize(new stubEASCStackTraceElement($element), $context); 
    9184        } 
    9285         
    93         // transfer cause 
    94         $s .= '}s:5:"cause";'.(($object instanceof stubChainedException)  
    95             ? $serializer->serialize($object->getCause(), $context) 
    96             : 'N;' 
    97         ); 
     86        $s .= '}s:5:"cause";'; 
     87        if ($object instanceof stubChainedException) { 
     88            $s .= $serializer->serialize($object->getCause(), $context); 
     89        } else { 
     90            $s .= 'N;'; 
     91        } 
    9892         
    9993        return $s . '}'; 
     
    112106    { 
    113107        $serialized->moveOffset(2); // token 
    114         $fqClassName = $serializer->getMappedException($serialized->consumeString()); 
    115         $nqClassName = stubClassLoader::getNonQualifiedClassName($fqClassName); 
    116         if (class_exists($nqClassName, false) == false) { 
    117             try { 
    118                 stubClassLoader::load($fqClassName); 
    119             } catch (stubClassNotFoundException $e) { 
    120                 throw $e; 
    121             } 
    122         } 
    123          
     108        $remoteExceptionName = $serialized->consumeString(); 
     109        $localeExceptionName = $serializer->getMappedException($remoteExceptionName); 
     110        stubClassLoader::load($localeExceptionName); 
    124111        $size = $serialized->consumeSize(); 
    125112        $serialized->moveOffset();  // opening "{" 
     
    131118         
    132119        $serialized->moveOffset(); // closing "}" 
    133         $isChainedException = false; 
    134         if ('net::stubbles::lang::exceptions::::stubChainedException' == $fqClassName) { 
    135             $isChainedException = true; 
    136         } else { 
    137             $parentClasses = class_parents($nqClassName, false); 
    138             foreach ($parentClasses as $parentClass) { 
    139                 if ('stubChainedException' == $nqClassName) { 
    140                     $isChainedException = true; 
    141                     break; 
    142                 } 
    143             } 
    144         } 
    145          
    146         if (true === $isChainedException && isset($data['cause']) == true) { 
     120        $nqClassName = stubClassLoader::getNonQualifiedClassName($localeExceptionName);  
     121        if (is_subclass_of($nqClassName, 'stubChainedException') == true && isset($data['cause']) === true) { 
    147122            $exception = new $nqClassName($data['message'], $data['cause']); 
    148123        } else { 
     
    150125        } 
    151126         
    152         unset($data['message']); 
    153         if (isset($data['cause']) == true) { 
    154             unset($data['cause']); 
    155         } 
    156          
    157         if (isset($data['trace']) == true && $exception instanceof stubExceptionReference) { 
     127        if (isset($data['trace']) === true && $exception instanceof stubExceptionReference) { 
     128            $exception->setReferencedExceptionName(str_replace('.', '::', $remoteExceptionName)); 
    158129            $exception->setReferencedStackTrace($data['trace']); 
    159130        } 
     
    161132        return $exception; 
    162133    } 
    163  
    164     /** 
    165      * creates and returns the stack trace mapping 
    166      * 
    167      * @return  stubEASCStackTraceMapping 
    168      */ 
    169     protected function getStackTraceMapping() 
    170     { 
    171         if (null !== $this->stackTraceMapping) { 
    172             $this->stackTraceMapping = new stubEASCStackTraceMapping(); 
    173         } 
    174          
    175         return $this->stackTraceMapping; 
    176     } 
    177134} 
    178135?> 
  • labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/mapping/stubEASCStackTraceMapping.php

    r1718 r1747  
    55 * @author      Frank Kleine <mikey@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  remote_protocol_easc 
     7 * @subpackage  remote_protocol_easc_mapping 
    88 * @version     $Id$ 
    99 */ 
     
    1616 *  
    1717 * @package     stubbles 
    18  * @subpackage  remote_protocol_easc 
     18 * @subpackage  remote_protocol_easc_mapping 
    1919 */ 
    2020class stubEASCStackTraceMapping extends stubBaseObject implements stubPHPSerializerMapping 
     
    4545    { 
    4646        if (null === self::$handledClass) { 
    47             // hack: pretend that this handler serializes itself to pretend 
    48             // that it is called to handle other classes 
    49             self::$handledClass = new ReflectionClass(__CLASS__); 
     47            self::$handledClass = new ReflectionClass('stubEASCStackTraceElement'); 
    5048        } 
    5149         
     
    6058     * @param   array<string,mixed>  $context     optional  context data 
    6159     * @return  string 
     60     * @throws  stubIllegalArgumentException 
    6261     */ 
    6362    public function serialize(stubPHPSerializer $serializer, $object, array $context = array()) 
    6463    { 
    65         if (is_array($object) === false) { 
     64        if (($object instanceof stubEASCStackTraceElement) === false) { 
    6665            throw new stubIllegalArgumentException($this->getClassName() . ' can only serialize stack trace elements.'); 
    6766        } 
    6867         
    6968        return 't:4:{' . 
    70             's:4:"file";'   . $serializer->serialize((isset($object['file']) === true) ? ($object['file']) : (null)) . 
    71             's:5:"class";'  . $serializer->serialize((isset($object['class']) === true) ? ($object['class']) : (null)) . 
    72             's:6:"method";' . $serializer->serialize((isset($object['function']) === true) ? ($object['function']) : (null)) . 
    73             's:4:"line";'   . $serializer->serialize((isset($object['line']) === true) ? ($object['line']) : (null)) . 
     69            's:4:"file";'   . $serializer->serialize($object->getFileInfo()) . 
     70            's:5:"class";'  . $serializer->serialize($object->getClassInfo()) . 
     71            's:6:"method";' . $serializer->serialize($object->getFunctionInfo()) . 
     72            's:4:"line";'   . $serializer->serialize($object->getLineInfo()) . 
    7473            '}'; 
    7574    } 
     
    8180     * @param   stubPHPSerializedData  $serialized  the serialized data 
    8281     * @param   array<string,mixed>    $context     optional  context data 
    83      * @return  stubException 
    84      * @throws  stubClassNotFoundException 
    8582     */ 
    8683    public function unserialize(stubPHPSerializer $serializer, stubPHPSerializedData $serialized, array $context = array()) 
  • labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/stubEASCSerializer.php

    r1718 r1747  
    99 */ 
    1010stubClassLoader::load('net::stubbles::php::serializer::stubPHPSerializer', 
    11                       'net::stubbles::remote::protocol::easc::stubEASCExceptionMapping' 
     11                      'net::stubbles::remote::protocol::easc::mapping::stubEASCExceptionMapping' 
    1212); 
    1313/** 
  • labs/incubator/src/test/php/net/stubbles/remote/RemoteTestSuite.php

    r1735 r1747  
    3636        $suite->addTestFile($dir . '/protocol/easc/mapping/stubEASCLongMappingTestCase.php'); 
    3737        $suite->addTestFile($dir . '/protocol/easc/mapping/stubEASCShortMappingTestCase.php'); 
     38        $suite->addTestFile($dir . '/protocol/easc/mapping/stubEASCStackTraceElementTestCase.php'); 
     39        $suite->addTestFile($dir . '/protocol/easc/mapping/stubEASCStackTraceMappingTestCase.php'); 
    3840        return $suite; 
    3941    }