예제 #1
0
 /**
  * This method processes an "entry" node.
  *
  * @access protected
  * @param \SimpleXMLElement $node                           a reference to the "entry" node
  * @return array                                            a key/value map
  * @throws Throwable\Instantiation\Exception                indicates that problem occurred during
  *                                                          the instantiation
  */
 protected function parseEntryElement(\SimpleXMLElement $node)
 {
     $entry = array();
     $attributes = $node->attributes();
     if (!isset($attributes['key'])) {
         throw new Throwable\Instantiation\Exception('Unable to initial class.');
     }
     $key = $this->__valueOf($attributes['key']);
     if (!Spring\Data\XML\Syntax::isKey($key)) {
         throw new Throwable\Instantiation\Exception('Unable to initial class.');
     }
     $children = $node->children();
     if (count($children) > 0) {
         foreach ($children as $child) {
             switch ($child->getName()) {
                 case 'array':
                     $entry[$key] = $this->parseArrayElement($child);
                     break;
                 case 'dictionary':
                     $entry[$key] = $this->parseDictionaryElement($child);
                     break;
                 case 'expression':
                     $entry[$key] = $this->parseExpressionElement($child);
                     break;
                 case 'null':
                     $entry[$key] = $this->parseNullElement($child);
                     break;
                 case 'undefined':
                     $entry[$key] = $this->parseUndefinedElement($child);
                     break;
                 case 'value':
                     $entry[$key] = $this->parseValueElement($child);
                     break;
                 default:
                     throw new Throwable\Instantiation\Exception('Unable to initial class.');
                     break;
             }
         }
     } else {
         if (isset($attributes['value'])) {
             $value = $this->__valueOf($attributes['value']);
             if (isset($attributes['type'])) {
                 $type = $this->__valueOf($attributes['type']);
                 if (!Spring\Data\XML\Syntax::isPrimitiveType($type)) {
                     throw new Throwable\Instantiation\Exception('Unable to initial class.');
                 }
                 $value = Core\Convert::changeType($value, $type);
             }
             $entry[$key] = $value;
         } else {
             throw new Throwable\Instantiation\Exception('Unable to initial class.');
         }
     }
     return $entry;
 }
예제 #2
0
 /**
  * This method parses an "entry" node.
  *
  * @access protected
  * @param \SimpleXMLElement $root                           a reference to the root node
  * @param \SimpleXMLElement $node                           a reference to the "entry" node
  * @return array                                            a key/value map
  * @throws Throwable\Parse\Exception                        indicates that problem occurred while
  *                                                          parsing
  */
 protected function parseEntryElement(\SimpleXMLElement $root, \SimpleXMLElement $node)
 {
     $entry = array();
     $attributes = $node->attributes();
     if (!isset($attributes['key'])) {
         throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute', array(':tag' => 'entry', ':attribute' => 'key'));
     }
     $key = Spring\Data\XML::valueOf($attributes['key']);
     if (!Spring\Data\XML\Syntax::isKey($key)) {
         throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid entry key, but got ":key".', array(':key' => $key));
     }
     $children = $node->children();
     if (count($children) > 0) {
         foreach ($children as $child) {
             $name = $child->getName();
             switch ($name) {
                 case 'array':
                     $entry[$key] = $this->parseArrayElement($root, $child);
                     break;
                 case 'dictionary':
                     $entry[$key] = $this->parseDictionaryElement($root, $child);
                     break;
                 case 'expression':
                     $entry[$key] = $this->parseExpressionElement($root, $child);
                     break;
                 case 'idref':
                     $entry[$key] = $this->parseIdRefElement($root, $child);
                     break;
                 case 'list':
                     $entry[$key] = $this->parseListElement($root, $child);
                     break;
                 case 'map':
                     $entry[$key] = $this->parseMapElement($root, $child);
                     break;
                 case 'null':
                     $entry[$key] = $this->parseNullElement($root, $child);
                     break;
                 case 'object':
                     $entry[$key] = $this->parseInnerObjectElement($root, $child);
                     break;
                 case 'ref':
                     $entry[$key] = $this->parseRefElement($root, $child);
                     break;
                 case 'set':
                     $entry[$key] = $this->parseSetElement($root, $child);
                     break;
                 case 'undefined':
                     $entry[$key] = $this->parseUndefinedElement($root, $child);
                     break;
                 case 'value':
                     $entry[$key] = $this->parseValueElement($root, $child);
                     break;
                 default:
                     throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" has invalid child node ":child".', array(':tag' => 'entry', ':child' => $name));
                     break;
             }
         }
     } else {
         if (isset($attributes['value-ref'])) {
             $idref = Spring\Data\XML::valueOf($attributes['value-ref']);
             $nodes = $this->find($root, $idref);
             if (empty($nodes)) {
                 throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid "value-ref" token, but got ":token".', array(':token' => $idref));
             }
             $entry[$key] = $this->parseOuterObjectElement($root, $nodes[0]);
         } else {
             if (isset($attributes['value'])) {
                 $value = Spring\Data\XML::valueOf($attributes['value']);
                 if (isset($attributes['type'])) {
                     $type = Spring\Data\XML::valueOf($attributes['type']);
                     if (!Spring\Data\XML\Syntax::isPrimitiveType($type)) {
                         throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid primitive type, but got ":type".', array(':type' => $type));
                     }
                     $value = Core\Convert::changeType($value, $type);
                 }
                 $entry[$key] = $value;
             } else {
                 throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute', array(':tag' => 'entry', ':attribute' => 'value'));
             }
         }
     }
     return $entry;
 }