[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: NestedElementHandler.php 3076 2006-12-18 08:52:12Z fabien $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://phing.info>. 20 */ 21 22 include_once 'phing/IntrospectionHelper.php'; 23 include_once 'phing/TaskContainer.php'; 24 25 /** 26 * The nested element handler class. 27 * 28 * This class handles the occurance of runtime registered tags like 29 * datatypes (fileset, patternset, etc) and it's possible nested tags. It 30 * introspects the implementation of the class and sets up the data structures. 31 * 32 * @author Andreas Aderhold <andi@binarycloud.com> 33 * @copyright © 2001,2002 THYRELL. All rights reserved 34 * @version $Revision: 1.10 $ $Date: 2005/10/04 19:13:44 $ 35 * @access public 36 * @package phing.parser 37 */ 38 39 class NestedElementHandler extends AbstractHandler { 40 41 /** 42 * Reference to the parent object that represents the parent tag 43 * of this nested element 44 * @var object 45 */ 46 private $parent; 47 48 /** 49 * Reference to the child object that represents the child tag 50 * of this nested element 51 * @var object 52 */ 53 private $child; 54 55 /** 56 * Reference to the parent wrapper object 57 * @var object 58 */ 59 private $parentWrapper; 60 61 /** 62 * Reference to the child wrapper object 63 * @var object 64 */ 65 private $childWrapper; 66 67 /** 68 * Reference to the related target object 69 * @var object the target instance 70 */ 71 private $target; 72 73 /** 74 * Constructs a new NestedElement handler and sets up everything. 75 * 76 * @param object the ExpatParser object 77 * @param object the parent handler that invoked this handler 78 * @param object the ProjectConfigurator object 79 * @param object the parent object this element is contained in 80 * @param object the parent wrapper object 81 * @param object the target object this task is contained in 82 * @access public 83 */ 84 function __construct($parser, $parentHandler, $configurator, $parent, $parentWrapper, $target) { 85 parent::__construct($parser, $parentHandler); 86 $this->configurator = $configurator; 87 if ($parent instanceof TaskAdapter) { 88 $this->parent = $parent->getProxy(); 89 } else { 90 $this->parent = $parent; 91 } 92 $this->parentWrapper = $parentWrapper; 93 $this->target = $target; 94 } 95 96 /** 97 * Executes initialization actions required to setup the data structures 98 * related to the tag. 99 * <p> 100 * This includes: 101 * <ul> 102 * <li>creation of the nested element</li> 103 * <li>calling the setters for attributes</li> 104 * <li>adding the element to the container object</li> 105 * <li>adding a reference to the element (if id attribute is given)</li> 106 * </ul> 107 * 108 * @param string the tag that comes in 109 * @param array attributes the tag carries 110 * @throws ExpatParseException if the setup process fails 111 * @access public 112 */ 113 function init($propType, $attrs) { 114 $configurator = $this->configurator; 115 $project = $this->configurator->project; 116 117 // introspect the parent class that is custom 118 $parentClass = get_class($this->parent); 119 $ih = IntrospectionHelper::getHelper($parentClass); 120 try { 121 if ($this->parent instanceof UnknownElement) { 122 $this->child = new UnknownElement(strtolower($propType)); 123 $this->parent->addChild($this->child); 124 } else { 125 $this->child = $ih->createElement($project, $this->parent, strtolower($propType)); 126 } 127 128 $configurator->configureId($this->child, $attrs); 129 130 if ($this->parentWrapper !== null) { 131 $this->childWrapper = new RuntimeConfigurable($this->child, $propType); 132 $this->childWrapper->setAttributes($attrs); 133 $this->parentWrapper->addChild($this->childWrapper); 134 } else { 135 $configurator->configure($this->child, $attrs, $project); 136 $ih->storeElement($project, $this->parent, $this->child, strtolower($propType)); 137 } 138 } catch (BuildException $exc) { 139 throw new ExpatParseException("Error initializing nested element <$propType>", $exc, $this->parser->getLocation()); 140 } 141 } 142 143 /** 144 * Handles character data. 145 * 146 * @param string the CDATA that comes in 147 * @throws ExpatParseException if the CDATA could not be set-up properly 148 * @access public 149 */ 150 function characters($data) { 151 152 $configurator = $this->configurator; 153 $project = $this->configurator->project; 154 155 if ($this->parentWrapper === null) { 156 try { 157 $configurator->addText($project, $this->child, $data); 158 } catch (BuildException $exc) { 159 throw new ExpatParseException($exc->getMessage(), $this->parser->getLocation()); 160 } 161 } else { 162 $this->childWrapper->addText($data); 163 } 164 } 165 166 /** 167 * Checks for nested tags within the current one. Creates and calls 168 * handlers respectively. 169 * 170 * @param string the tag that comes in 171 * @param array attributes the tag carries 172 * @access public 173 */ 174 function startElement($name, $attrs) { 175 //print(get_class($this) . " name = $name, attrs = " . implode(",",$attrs) . "\n"); 176 if ($this->child instanceof TaskContainer) { 177 // taskcontainer nested element can contain other tasks - no other 178 // nested elements possible 179 $tc = new TaskHandler($this->parser, $this, $this->configurator, $this->child, $this->childWrapper, $this->target); 180 $tc->init($name, $attrs); 181 } else { 182 $neh = new NestedElementHandler($this->parser, $this, $this->configurator, $this->child, $this->childWrapper, $this->target); 183 $neh->init($name, $attrs); 184 } 185 } 186 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |