public function getObject(Spring\Object\Parser $parser, \SimpleXMLElement $element) { $object = new Common\Mutable\HashSet(); $children = $parser->getElementChildren($element, null); foreach ($children as $child) { $object->putValue($parser->getObjectFromElement($child)); } return $object; }
/** * 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\ArrayList(); $children = $parser->getElementChildren($element, null); if (!empty($children)) { foreach ($children as $child) { $task = $parser->getObjectFromElement($child); if (!$task instanceof BT\Task) { throw new Throwable\Parse\Exception('Invalid type defined. Expected a task, but got an element of type ":type" instead.', array(':type' => Core\DataType::info($object)->type)); } $object->addValue($task); } } return $object; }
/** * 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) { $attributes = $element->attributes(); if (isset($attributes['local'])) { $object = $parser->getObjectFromIdRef($parser->valueOf($attributes['local'])); return $object; } else { if (isset($attributes['object'])) { $object = $parser->getObjectFromIdRef($parser->valueOf($attributes['object'])); return $object; } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute.', array(':tag' => 'ref', ':attribute' => 'object')); } } }
/** * 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; }
/** * 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) { $attributes = $element->attributes(); if (!isset($attributes['type'])) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute.', array(':tag' => $parser->getElementPrefixedName($element), ':attribute' => 'type')); } $type = $parser->valueOf($attributes['type']); $element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI); $children = $element->xpath('./spring-bt:blackboard'); $blackboard = !empty($children) ? $parser->getObjectFromElement($children[0]) : null; $element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI); $children = $element->xpath('./spring-bt:policy'); $policy = !empty($children) ? $parser->getObjectFromElement($children[0]) : null; $object = new $type($blackboard, $policy); if (!$object instanceof BT\Task\Decorator) { throw new Throwable\Parse\Exception('Invalid type defined. Expected a task decorator, but got an element of type ":type" instead.', array(':type' => $type)); } if (isset($attributes['title'])) { $object->setTitle($parser->valueOf($attributes['title'])); } $element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI); $children = $element->xpath('./spring-bt:tasks'); if (!empty($children)) { foreach ($children as $child) { $object->addTasks($parser->getObjectFromElement($child)); } } return $object; }
/** * 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) { $attributes = $element->attributes(); if (isset($attributes['local'])) { $object = $parser->valueOf($attributes['local']); if (!$parser->isIdref($object, $parser->getResource())) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid "idref" token, but got ":token".', array(':token' => $object)); } return $object; } else { if (isset($attributes['object'])) { $object = $parser->valueOf($attributes['object']); return $object; } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute.', array(':tag' => 'idref', ':attribute' => 'object')); } } }
/** * 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) { $attributes = $element->attributes(); if (isset($attributes['delegate-object']) && isset($attributes['delegate-method'])) { $delegate_object = $parser->valueOf($attributes['delegate-object']); if ($parser->isClassName($delegate_object) && class_exists($delegate_object)) { $delegate_method = $parser->valueOf($attributes['delegate-method']); if ($parser->isMethodName($delegate_method) && method_exists($delegate_object, $delegate_method)) { return array($delegate_object, $delegate_method); } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid method name, but got ":name".', array(':name' => $delegate_method)); } } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid class name, but got ":name".', array(':name' => $delegate_object)); } } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing a valid class name and/or method name.', array(':tag' => 'function')); } }
/** * 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) { $attributes = $element->attributes(); $type = isset($attributes['type']) ? $parser->valueOf($attributes['type']) : '\\Unicity\\BT\\Task\\Stub'; $element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI); $children = $element->xpath('./spring-bt:blackboard'); $blackboard = !empty($children) ? $parser->getObjectFromElement($children[0]) : null; $element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI); $children = $element->xpath('./spring-bt:policy'); $policy = !empty($children) ? $parser->getObjectFromElement($children[0]) : null; $object = new $type($blackboard, $policy); if (!$object instanceof BT\Task\Stub) { throw new Throwable\Parse\Exception('Invalid type defined. Expected a task stub, but got an element of type ":type" instead.', array(':type' => $type)); } if (isset($attributes['title'])) { $object->setTitle($parser->valueOf($attributes['title'])); } return $object; }
/** * 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) { $attributes = $element->attributes(); $expression = $parser->valueOf($element[0]); $value = null; /* @eval('$value = ' . $expression . ';'); if (isset($attributes['type'])) { $type = $parser->valueOf($attributes['type']); if (!$parser->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); } */ return $value; }
/** * 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 = array(); $attributes = $element->attributes(); if (!isset($attributes['key'])) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute.', array(':tag' => $parser->getElementPrefixedName($element), ':attribute' => 'key')); } $key = $parser->valueOf($attributes['key']); if (!$parser->isKey($key)) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid entry key, but got ":key".', array(':key' => $key)); } $children = $parser->getElementChildren($element, null); if (!empty($children)) { foreach ($children as $child) { $object[$key] = $parser->getObjectFromElement($child); } } else { if (isset($attributes['value-ref'])) { $object[$key] = $parser->getObjectFromIdRef($parser->valueOf($attributes['value-ref'])); } else { if (isset($attributes['value'])) { $value = $parser->valueOf($attributes['value']); if (isset($attributes['value-type'])) { $type = $parser->valueOf($attributes['value-type']); if (!$parser->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); } $object[$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 $object; }
/** * This method assigns any property values to the specified object. * * @access protected * @param \SimpleXMLElement $element a reference to the "object" node * @param mixed &$object a reference to the object * @throws Throwable\Parse\Exception indicates that a problem occurred * when parsing */ protected function getProperties(Spring\Object\Parser $parser, \SimpleXMLElement $element, &$object) { $class = new \ReflectionClass($object); $element->registerXPathNamespace('spring', Spring\Data\XML::NAMESPACE_URI); $fields = $element->xpath('./spring:property'); foreach ($fields as $field) { $attributes = $field->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 = $parser->valueOf($attributes['name']); if (!$parser->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 = $parser->getElementChildren($field, null); if (!empty($children)) { foreach ($children as $child) { $value = $parser->getObjectFromElement($child); } } else { if (isset($attributes['expression'])) { $expression = $parser->valueOf($attributes['expression']); $value = null; /* @eval('$value = ' . $expression . ';'); if (isset($attributes['type'])) { $type = $parser->valueOf($attributes['type']); if (!$parser->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'])) { $value = $parser->getObjectFromIdRef($parser->valueOf($attributes['ref'])); } else { if (isset($attributes['value'])) { $value = $parser->valueOf($attributes['value']); if (isset($attributes['type'])) { $type = $parser->valueOf($attributes['type']); if (!$parser->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')); } } } } if ($class->hasProperty($name)) { $property = $class->getProperty($name); if (!$property->isPublic()) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid property name, but got ":name".', array(':name' => $name)); } $property->setValue($object, $value); } else { if ($object instanceof \stdClass) { $object->{$name} = $value; } else { if ($class->hasMethod('__set')) { $method = $class->getMethod('__set'); if ($method->isAbstract() || !$method->isPublic()) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid property name, but got ":name".', array(':name' => $name)); } $method->invoke($object, $name, $value); } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid property name, but got ":name" for class ":class".', array(':class' => get_class($object), ':name' => $name)); } } } } }
/** * 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) { $children = $parser->getElementChildren($element, null); if (!empty($children)) { $value = ''; foreach ($children as $child) { $name = $parser->getElementPrefixedName($child); switch ($name) { case 'spring:null': $value = $parser->getObjectFromElement($child); break; default: throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" has invalid child node ":child"', array(':tag' => 'value', ':child' => $name)); break; } } if (is_string($value)) { return Core\Data\Charset::encode($value, $parser->getEncoding($parser->getResource()), Core\Data\Charset::UTF_8_ENCODING); } return $value; } else { $attributes = $element->attributes(); $value = dom_import_simplexml($element)->textContent; if (isset($attributes['type'])) { $type = $parser->valueOf($attributes['type']); if (!$parser->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); } if (is_string($value)) { $attributes = $element->attributes('xml', true); if (isset($attributes['space'])) { $space = $parser->valueOf($attributes['space']); if (!$parser->isSpacePreserved($space)) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid space token, but got ":token".', array(':token' => $space)); } } else { $value = trim($value); } } if (is_string($value)) { return Core\Data\Charset::encode($value, $parser->getEncoding($parser->getResource()), Core\Data\Charset::UTF_8_ENCODING); } return $value; } }
/** * This method determines whether an object with the specified id has been defined * in the container. * * @access public * @param string $id the object's id * @return boolean whether an object with the specified id has * been defined in the container */ public function hasObject($id) { return $this->parser->hasObject($id); }