Changeset 552

Show
Ignore:
Timestamp:
04/17/07 21:51:01 (1 year ago)
Author:
schst
Message:

Added support for @XmlFragment? annotation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php

    r445 r552  
    88 */ 
    99stubClassLoader::load('net.stubbles.xml.serializer.annotations.stubXMLTagAnnotation', 
     10                      'net.stubbles.xml.serializer.annotations.stubXMLFragmentAnnotation', 
    1011                      'net.stubbles.xml.serializer.annotations.stubXMLAttributeAnnotation', 
    1112                      'net.stubbles.xml.serializer.annotations.stubXMLIgnoreAnnotation', 
     
    152153                continue; 
    153154            } 
     155            if ($property->hasAnnotation('XMLFragment')) { 
     156                $xmlFragment = $property->getAnnotation('XMLFragment'); 
     157                $tagName = $xmlFragment->getTagName(); 
     158                if ($tagName != null) { 
     159                    $xmlWriter->writeStartElement($tagName); 
     160                    $xmlWriter->writeXmlFragment($propValue); 
     161                    $xmlWriter->writeEndElement(); 
     162                } else { 
     163                    $xmlWriter->writeXmlFragment($propValue); 
     164                } 
     165                continue; 
     166            } 
    154167            if ($property->hasAnnotation('XMLTag')) { 
    155168                $xmlTag = $property->getAnnotation('XMLTag'); 
     
    211224                continue; 
    212225            } 
     226            if ($method->hasAnnotation('XMLFragment')) { 
     227                $xmlFragment = $method->getAnnotation('XMLFragment'); 
     228                $tagName = $xmlFragment->getTagName(); 
     229                if ($tagName != null) { 
     230                    $xmlWriter->writeStartElement($tagName); 
     231                    $xmlWriter->writeXmlFragment($returnValue); 
     232                    $xmlWriter->writeEndElement(); 
     233                } else { 
     234                    $xmlWriter->writeXmlFragment($returnValue); 
     235                } 
     236                continue; 
     237            } 
    213238            if ($method->hasAnnotation('XMLTag')) { 
    214239                $xmlTag = $method->getAnnotation('XMLTag'); 
  • trunk/src/test/php/net/stubbles/xml/stubXMLSerializerTestCase.php

    r492 r552  
    122122        return "bar"; 
    123123    } 
     124} 
     125 
     126/** 
     127 * Simple Test class to test the XMLSerializer 
     128 * 
     129 * @XMLTag(tagName='test') 
     130 */ 
     131class XMLSerializerFragmentTest { 
     132    /** 
     133     * Property containing XML 
     134     * 
     135     * @XMLFragment(tagName='xml'); 
     136     * @var string 
     137     */ 
     138    public $xml = '<foo>bar</foo>'; 
    124139} 
    125140 
     
    288303 
    289304    /** 
     305     * Test serializing an object with an xml fragment 
     306     */ 
     307    public function testObjectFragmentProperty() { 
     308        $writer = new stubDomXMLStreamWriter(); 
     309        $obj = new XMLSerializerFragmentTest(); 
     310        $this->serializer->serialize($obj, $writer); 
     311        $this->assertEqual('<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n" . '<test><xml><foo>bar</foo></xml></test>', $writer->asXML()); 
     312    } 
     313 
     314    /** 
    290315     * Test serializing an object with a method matcher 
    291316     */