From 01bc363ac789cfb9d644ce82a949da5cd7e1c220 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 31 Jan 2006 00:01:49 +0000 Subject: Modified TList and TMap implementation so that they can be more easily extended. --- framework/Data/TXmlDocument.php | 47 +++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'framework/Data/TXmlDocument.php') diff --git a/framework/Data/TXmlDocument.php b/framework/Data/TXmlDocument.php index 0b37258d..bb22b254 100644 --- a/framework/Data/TXmlDocument.php +++ b/framework/Data/TXmlDocument.php @@ -416,36 +416,41 @@ class TXmlElementList extends TList return $this->_o; } - /** - * Overrides the parent implementation with customized processing of the newly added item. - * @param mixed the newly added item - */ - protected function addedItem($item) - { - if($item->getParent()!==null) - $item->getParent()->getElements()->remove($item); - $item->setParent($this->_o); - } /** - * Overrides the parent implementation with customized processing of the removed item. - * @param mixed the removed item + * Inserts an item at the specified position. + * This overrides the parent implementation by performing additional + * operations for each newly added TXmlElement object. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TXmlElement object. */ - protected function removedItem($item) + public function insertAt($index,$item) { - $item->setParent(null); + if($item instanceof TXmlElement) + { + parent::insertAt($index,$item); + if($item->getParent()!==null) + $item->getParent()->getElements()->remove($item); + $item->setParent($this->_o); + } + else + throw new TInvalidDataTypeException('xmlelementlist_xmlelement_required'); } /** - * This method is invoked before adding an item to the map. - * If it returns true, the item will be added to the map, otherwise not. - * You can override this method to decide whether a specific can be added. - * @param mixed item to be added - * @return boolean whether the item can be added to the map + * Removes an item at the specified position. + * This overrides the parent implementation by performing additional + * cleanup work when removing a TXmlElement object. + * @param integer the index of the item to be removed. + * @return mixed the removed item. */ - protected function canAddItem($item) + public function removeAt($index) { - return ($item instanceof TXmlElement); + $item=parent::removeAt($index); + if($item instanceof TXmlElement) + $item->setParent(null); + return $item; } } -- cgit v1.2.3