예제 #1
0
 /**
  * This method returns an object matching the description specified by the element.
  *
  * @access public
  * @param Spring\Object\Parser $parser                      a reference to the parser
  * @param \SimpleXMLElement $element                        the element to be parsed
  * @return mixed                                            an object matching the description
  *                                                          specified by the element
  * @throws Throwable\Parse\Exception                        indicates that a problem occurred
  *                                                          when parsing
  */
 public function getObject(Spring\Object\Parser $parser, \SimpleXMLElement $element)
 {
     $object = new Common\Mutable\HashMap();
     $children = $parser->getElementChildren($element, Spring\Data\XML::NAMESPACE_URI);
     foreach ($children as $child) {
         $name = $parser->getElementName($child);
         switch ($name) {
             case 'entry':
                 $object->putEntries($parser->getObjectFromElement($child));
                 break;
             default:
                 throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected an "entry" element, but got an element of type ":type" instead.', array(':type' => $parser->getElementPrefixedName($child)));
                 break;
         }
     }
     return $object;
 }
예제 #2
0
 /**
  * This method returns the processed resource as a collection.
  *
  * @access public
  * @param string $path                                      the path to the value to be returned
  * @return mixed                                            the resource as a collection
  * @throws Throwable\Parse\Exception                        indicates that an invalid record was
  *                                                          encountered
  */
 public function read($path = null)
 {
     $collection = new Common\Mutable\HashMap();
     $this->each(function (Common\Mutable\HashMap $record) use($collection) {
         $collection->putEntries($record);
     });
     if ($path !== null) {
         $collection = Config\Helper::factory($collection)->getValue($path);
     }
     return $collection;
 }
예제 #3
0
 /**
  * This method parses a "struct" node.
  *
  * @access protected
  * @param \DOMElement $node                                 a reference to the "struct" node
  * @return Common\Mutable\IMap                              a hash map
  * @throws \Unicity\Throwable\Parse\Exception               indicates that problem occurred while
  *                                                          parsing
  */
 protected function parseStructElement(\DOMElement $node)
 {
     $iMap = new Common\Mutable\HashMap();
     $children = $node->childNodes;
     foreach ($children as $child) {
         $name = $child->nodeName;
         switch ($name) {
             case 'var':
                 $iMap->putEntries($this->parseVarElement($child));
                 break;
             case '#text':
                 break;
             default:
                 throw new Throwable\Parse\Exception('Invalid child node named ":name" detected.', array(':name' => $name));
                 break;
         }
     }
     return $iMap;
 }
예제 #4
0
 /**
  * This method processes a "dictionary" node.
  *
  * @access protected
  * @param \SimpleXMLElement $node                           a reference to the "dictionary" node
  * @return array                                            an associated array
  * @throws Throwable\Instantiation\Exception                indicates that problem occurred during
  *                                                          the instantiation
  */
 protected function parseDictionaryElement(\SimpleXMLElement $node)
 {
     $iMap = new Common\Mutable\HashMap();
     $children = $node->children();
     foreach ($children as $child) {
         switch ($child->getName()) {
             case 'entry':
                 $iMap->putEntries($this->parseEntryElement($child));
                 break;
             default:
                 throw new Throwable\Instantiation\Exception('Unable to initial class.');
                 break;
         }
     }
     return $iMap->toDictionary();
 }
예제 #5
0
 /**
  * This method parses an outer "object" node.
  *
  * @access protected
  * @param \SimpleXMLElement $root                           a reference to the root node
  * @param \SimpleXMLElement $node                           a reference to the "object" node
  * @return Common\Mutable\IMap                              a hash map
  */
 protected function parseOuterObjectElement(\SimpleXMLElement $root, \SimpleXMLElement $node)
 {
     $map = new Common\Mutable\HashMap();
     $node->registerXPathNamespace('spring', Spring\Data\XML::NAMESPACE_URI);
     $children = $node->xpath('./spring:property');
     foreach ($children as $child) {
         $map->putEntries($this->parsePropertyElement($root, $child));
     }
     return $map;
 }