PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/sbweb/sbweb_logica/lib/symfony/plugins/sfPropelPlugin/lib/vendor/phing/parser/TaskHandler.php

http://opac-sbweb.googlecode.com/
PHP | 234 lines | 88 code | 21 blank | 125 comment | 17 complexity | 8832da8706299259b15f6910b38b5cee MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. /*
  3. * $Id: TaskHandler.php 147 2007-02-06 20:32:22Z hans $
  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. include_once 'phing/UnknownElement.php';
  22. /**
  23. * The task handler class.
  24. *
  25. * This class handles the occurance of a <task> tag and it's possible
  26. * nested tags (datatypes and tasks) that may be unknown off bat and are
  27. * initialized on the fly.
  28. *
  29. * @author Andreas Aderhold <andi@binarycloud.com>
  30. * @copyright ??? 2001,2002 THYRELL. All rights reserved
  31. * @version $Revision: 1.10 $
  32. * @package phing.parser
  33. */
  34. class TaskHandler extends AbstractHandler {
  35. /**
  36. * Reference to the target object that contains the currently parsed
  37. * task
  38. * @var object the target instance
  39. */
  40. private $target;
  41. /**
  42. * Reference to the target object that represents the currently parsed
  43. * target. This must not necessarily be a target, hence extra variable.
  44. * @var object the target instance
  45. */
  46. private $container;
  47. /**
  48. * Reference to the task object that represents the currently parsed
  49. * target.
  50. * @var Task
  51. */
  52. private $task;
  53. /**
  54. * Wrapper for the parent element, if any. The wrapper for this
  55. * element will be added to this wrapper as a child.
  56. * @var RuntimeConfigurable
  57. */
  58. private $parentWrapper;
  59. /**
  60. * Wrapper for this element which takes care of actually configuring
  61. * the element, if this element is contained within a target.
  62. * Otherwise the configuration is performed with the configure method.
  63. * @see ProjectHelper::configure(Object,AttributeList,Project)
  64. */
  65. private $wrapper;
  66. /**
  67. * The phing project configurator object
  68. * @var ProjectConfigurator
  69. */
  70. private $configurator;
  71. /**
  72. * Constructs a new TaskHandler and sets up everything.
  73. *
  74. * @param AbstractSAXParser The ExpatParser object
  75. * @param object $parentHandler The parent handler that invoked this handler
  76. * @param ProjectConfigurator $configurator
  77. * @param TaskContainer $container The container object this task is contained in (null for top-level tasks).
  78. * @param RuntimeConfigurable $parentWrapper Wrapper for the parent element, if any.
  79. * @param Target $target The target object this task is contained in (null for top-level tasks).
  80. */
  81. function __construct(AbstractSAXParser $parser, $parentHandler, ProjectConfigurator $configurator, $container = null, $parentWrapper = null, $target = null) {
  82. parent::__construct($parser, $parentHandler);
  83. if (($container !== null) && !($container instanceof TaskContainer)) {
  84. throw new Exception("Argument expected to be a TaskContainer, got something else");
  85. }
  86. if (($parentWrapper !== null) && !($parentWrapper instanceof RuntimeConfigurable)) {
  87. throw new Exception("Argument expected to be a RuntimeConfigurable, got something else.");
  88. }
  89. if (($target !== null) && !($target instanceof Target)) {
  90. throw new Exception("Argument expected to be a Target, got something else");
  91. }
  92. $this->configurator = $configurator;
  93. $this->container = $container;
  94. $this->parentWrapper = $parentWrapper;
  95. $this->target = $target;
  96. }
  97. /**
  98. * Executes initialization actions required to setup the data structures
  99. * related to the tag.
  100. * <p>
  101. * This includes:
  102. * <ul>
  103. * <li>creation of the task object</li>
  104. * <li>calling the setters for attributes</li>
  105. * <li>adding the task to the container object</li>
  106. * <li>adding a reference to the task (if id attribute is given)</li>
  107. * <li>executing the task if the container is the &lt;project&gt;
  108. * element</li>
  109. * </ul>
  110. *
  111. * @param string $tag The tag that comes in
  112. * @param array $attrs Attributes the tag carries
  113. * @throws ExpatParseException if attributes are incomplete or invalid
  114. */
  115. function init($tag, $attrs) {
  116. // shorthands
  117. try {
  118. $configurator = $this->configurator;
  119. $project = $this->configurator->project;
  120. $this->task = $project->createTask($tag);
  121. } catch (BuildException $be) {
  122. // swallow here, will be thrown again in
  123. // UnknownElement->maybeConfigure if the problem persists.
  124. print("Swallowing exception: ".$be->getMessage() . "\n");
  125. }
  126. // the task is not known of bat, try to load it on thy fly
  127. if ($this->task === null) {
  128. $this->task = new UnknownElement($tag);
  129. $this->task->setProject($project);
  130. $this->task->setTaskType($tag);
  131. $this->task->setTaskName($tag);
  132. }
  133. // add file position information to the task (from parser)
  134. // should be used in task exceptions to provide details
  135. $this->task->setLocation($this->parser->getLocation());
  136. $configurator->configureId($this->task, $attrs);
  137. if ($this->container) {
  138. $this->container->addTask($this->task);
  139. }
  140. // Top level tasks don't have associated targets
  141. // FIXME: if we do like Ant 1.6 and create an implicitTarget in the projectconfigurator object
  142. // then we don't need to check for null here ... but there's a lot of stuff that will break if we
  143. // do that at this point.
  144. if ($this->target !== null) {
  145. $this->task->setOwningTarget($this->target);
  146. $this->task->init();
  147. $this->wrapper = $this->task->getRuntimeConfigurableWrapper();
  148. $this->wrapper->setAttributes($attrs);
  149. /*
  150. Commenting this out as per thread on Premature configurate of ReuntimeConfigurables
  151. with Matthias Pigulla: http://phing.tigris.org/servlets/ReadMsg?list=dev&msgNo=251
  152. if ($this->parentWrapper !== null) { // this may not make sense only within this if-block, but it
  153. // seems to address current use cases adequately
  154. $this->parentWrapper->addChild($this->wrapper);
  155. }
  156. */
  157. } else {
  158. $this->task->init();
  159. $configurator->configure($this->task, $attrs, $project);
  160. }
  161. }
  162. /**
  163. * Executes the task at once if it's directly beneath the <project> tag.
  164. */
  165. protected function finished() {
  166. if ($this->task !== null && $this->target === null && $this->container === null) {
  167. try {
  168. $this->task->perform();
  169. } catch (Exception $e) {
  170. $this->task->log($e->getMessage(), Project::MSG_ERR);
  171. throw $e;
  172. }
  173. }
  174. }
  175. /**
  176. * Handles character data.
  177. *
  178. * @param string $data The CDATA that comes in
  179. */
  180. function characters($data) {
  181. if ($this->wrapper === null) {
  182. $configurator = $this->configurator;
  183. $project = $this->configurator->project;
  184. try { // try
  185. $configurator->addText($project, $this->task, $data);
  186. } catch (BuildException $exc) {
  187. throw new ExpatParseException($exc->getMessage(), $this->parser->getLocation());
  188. }
  189. } else {
  190. $this->wrapper->addText($data);
  191. }
  192. }
  193. /**
  194. * Checks for nested tags within the current one. Creates and calls
  195. * handlers respectively.
  196. *
  197. * @param string $name The tag that comes in
  198. * @param array $attrs Attributes the tag carries
  199. */
  200. function startElement($name, $attrs) {
  201. $project = $this->configurator->project;
  202. if ($this->task instanceof TaskContainer) {
  203. //print("TaskHandler::startElement() (TaskContainer) name = $name, attrs = " . implode(",",$attrs) . "\n");
  204. $th = new TaskHandler($this->parser, $this, $this->configurator, $this->task, $this->wrapper, $this->target);
  205. $th->init($name, $attrs);
  206. } else {
  207. //print("TaskHandler::startElement() name = $name, attrs = " . implode(",",$attrs) . "\n");
  208. $tmp = new NestedElementHandler($this->parser, $this, $this->configurator, $this->task, $this->wrapper, $this->target);
  209. $tmp->init($name, $attrs);
  210. }
  211. }
  212. }