예제 #1
0
 /**
  * This method processes an "assign" node.
  *
  * @access protected
  * @param \SimpleXMLElement $node                           a reference to the "assign" node
  * @throws Throwable\Instantiation\Exception                indicates that problem occurred during
  *                                                          the instantiation
  */
 protected function parseAssignElement(\SimpleXMLElement $node)
 {
     $attributes = $node->attributes();
     if (!isset($attributes['location'])) {
         throw new Throwable\Instantiation\Exception('Unable to initial class.');
     }
     $segments = explode('.', $this->__valueOf($attributes['location']));
     if (count($segments) > 0) {
         $value = Core\Data\Undefined::instance();
         $children = $node->children();
         if (count($children) > 0) {
             foreach ($children as $child) {
                 switch ($child->getName()) {
                     case 'array':
                         $value = $this->parseArrayElement($child);
                         break;
                     case 'dictionary':
                         $value = $this->parseDictionaryElement($child);
                         break;
                     case 'expression':
                         $value = $this->parseExpressionElement($child);
                         break;
                     case 'null':
                         $value = $this->parseNullElement($child);
                         break;
                     case 'undefined':
                         $value = $this->parseUndefinedElement($child);
                         break;
                     case 'value':
                         $value = $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);
                 }
             } else {
                 throw new Throwable\Instantiation\Exception('Unable to initial class.');
             }
         }
         $property = $this->models;
         foreach ($segments as $segment) {
             if (!Spring\Data\XML\Syntax::isPropertyName($segment)) {
                 throw new Throwable\Instantiation\Exception('Unable to initial class.');
             }
             $property =& $property->{$segment};
         }
         $property = $value;
     }
 }
예제 #2
0
 /**
  * This method parses a "property" node.
  *
  * @access protected
  * @param \SimpleXMLElement $root                           a reference to the root node
  * @param \SimpleXMLElement $node                           a reference to the "property" node
  * @return Common\Mutable\IMap                              a hash map
  * @throws Throwable\Parse\Exception                        indicates that problem occurred while
  *                                                          parsing
  */
 protected function parsePropertyElement(\SimpleXMLElement $root, \SimpleXMLElement $node)
 {
     $map = new Common\Mutable\HashMap();
     $attributes = $node->attributes();
     if (!isset($attributes['name'])) {
         throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute', array(':tag' => 'property', ':attribute' => 'name'));
     }
     $name = Spring\Data\XML::valueOf($attributes['name']);
     if (!Spring\Data\XML\Syntax::isPropertyName($name)) {
         throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid property name, but got ":name".', array(':name' => $name));
     }
     $value = null;
     $children = $node->children();
     if (count($children) > 0) {
         foreach ($children as $child) {
             $child_name = $child->getName();
             switch ($child_name) {
                 case 'array':
                     $value = $this->parseArrayElement($root, $child);
                     break;
                 case 'dictionary':
                     $value = $this->parseDictionaryElement($root, $child);
                     break;
                 case 'expression':
                     $value = $this->parseExpressionElement($root, $child);
                     break;
                 case 'idref':
                     $value = $this->parseIdRefElement($root, $child);
                     break;
                 case 'list':
                     $value = $this->parseListElement($root, $child);
                     break;
                 case 'map':
                     $value = $this->parseMapElement($root, $child);
                     break;
                 case 'null':
                     $value = $this->parseNullElement($root, $child);
                     break;
                 case 'object':
                     $value = $this->parseInnerObjectElement($root, $child);
                     break;
                 case 'ref':
                     $value = $this->parseRefElement($root, $child);
                     break;
                 case 'set':
                     $value = $this->parseSetElement($root, $child);
                     break;
                 case 'undefined':
                     $value = $this->parseUndefinedElement($root, $child);
                     break;
                 case 'value':
                     $value = $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' => 'property', ':child' => $child_name));
                     break;
             }
         }
     } else {
         if (isset($attributes['expression'])) {
             $expression = Spring\Data\XML::valueOf($attributes['expression']);
             $value = null;
             @eval('$value = ' . $expression . ';');
             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));
                 }
                 if (!isset($value)) {
                     $type = 'NULL';
                     $value = null;
                 }
                 $value = Core\Convert::changeType($value, $type);
             }
         } else {
             if (isset($attributes['ref'])) {
                 $idref = Spring\Data\XML::valueOf($attributes['ref']);
                 $nodes = $this->find($root, $idref);
                 if (empty($nodes)) {
                     throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid "ref" token, but got ":token".', array(':token' => $idref));
                 }
                 $value = $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);
                     }
                 } else {
                     throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute', array(':tag' => 'property', ':attribute' => 'value'));
                 }
             }
         }
     }
     $map->putEntry($name, $value);
     return $map;
 }