Changeset 10

Show
Ignore:
Timestamp:
08/26/06 21:23:14 (2 years ago)
Author:
mikey
Message:

fixed creation of ValueConverter?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/XJConf/definitions/CDataDefinition.php

    r6 r10  
    11<?php 
    2 XJConfLoader::load('converters.ObjectValueConverter', 
    3                    'converters.PrimitiveValueConverter', 
     2/** 
     3 * Definition for the character data inside a tag. 
     4 * 
     5 * @author  Stephan Schmidt <stephan.schmidt@schlund.de> 
     6 * @author  Frank Kleine <frank.kleine@schlund.de> 
     7 */ 
     8XJConfLoader::load('converters.factories.ValueConverterFactoryChain', 
    49                   'definitions.Definition' 
    510); 
     
    1015 * of the tag, while casting it to the desired class. 
    1116 * 
    12  * @author Stephan Schmidt <stephan.schmidt@schlund.de> 
     17 * @package     XJConf 
     18 * @subpackage  definitions 
    1319 */ 
    1420class CDataDefinition implements Definition 
     
    4147    { 
    4248        if (null == $type) { 
    43             $this->type           = 'string'; 
    44             $this->valueConverter = new ObjectValueConverter('string'); 
    45         } else { 
    46             $this->type = $type; 
    47  
    48             if (in_array($type, get_declared_classes()) == false) { 
    49                 $this->valueConverter = new PrimitiveValueConverter($this->type); 
    50                 } else { 
    51                     $this->valueConverter = new ObjectValueConverter($this->type); 
    52                 } 
     49            $type = 'string';  
    5350        } 
     51         
     52        $this->type = $type; 
    5453    } 
    5554 
     
    8180    /** 
    8281     * Character data cannot have any child definitions 
     82     *  
     83     * @param  Definition  $def 
    8384     */ 
    8485    public function addChildDefinition(Definition $def) 
     
    9596    public function convertValue(Tag $tag) 
    9697    { 
    97         if (in_array($this->type, get_declared_classes()) == false) { 
    98             $this->valueConverter = new PrimitiveValueConverter($this->type); 
    99         } else { 
    100                 $this->valueConverter = new ObjectValueConverter($this->type); 
    101         } 
    102         $instance = $this->valueConverter->convertValue(array($tag->getContent())); 
     98        $instance = $this->getValueConverter()->convertValue(array($tag->getContent())); 
    10399                return $instance; 
    104100    } 
     
    121117     */ 
    122118    public function getValueType(Tag $tag) { 
    123         return $this->valueConverter->getType(); 
     119        return $this->getValueConverter()->getType(); 
    124120    } 
    125121 
     
    137133     * Return all child definitions. 
    138134     * 
    139      * Currently, it is not possible to add any child 
     135     * Currently it is not possible to add any child 
    140136     * definitions to cdata 
    141137     * 
    142      * @return array 
     138     * @return array 
    143139     */ 
    144140    public function getChildDefinitions() { 
    145141        return array(); 
    146142    } 
     143     
     144    /** 
     145     * Get the value converter for this character data 
     146     * 
     147     * @return  ValueConverter 
     148     */ 
     149    private function getValueConverter() 
     150    { 
     151        if ($this->valueConverter == null) { 
     152            $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 
     153        } 
     154         
     155        return $this->valueConverter; 
     156    } 
    147157} 
    148158?>