/** * This method processes the key for use by the hash map. * * @access protected * @param mixed $key the key to be processed * @return string the key to be used * @throws \Unicity\Throwable\InvalidArgument\Exception indicates an invalid key was specified */ protected function getKey($key) { $key = parent::getKey($key); if (!$this->case_sensitive) { $key = strtolower($key); } return $key; }
/** * This method processes the models and returns the status. * * @access public * @param BT\Exchange $exchange the exchange given to process * @return integer the status code */ public function process(BT\Exchange $exchange) { $body = $exchange->getIn()->getBody(); if ($body instanceof IO\File) { try { $reader = new Config\JSON\Reader($body, array('assoc' => false)); $models = new Common\Mutable\HashMap(); $models->putEntry('Order', OrderCalc\Engine\Model\Marshaller::unmarshal($reader)); $exchange->getIn()->setBody($models); return BT\Task\Status::SUCCESS; } catch (Throwable\Runtime\Exception $ex) { $exchange->getOut()->setBody($ex); return BT\Task\Status::ERROR; } } return BT\Task\Status::FAILED; }
/** * 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 sets the header with specified name. * * @access public * @param string $name the name of the header * @param string $value the value of the header */ public function setHeader($name, $value) { $name = strtolower($name); if (!in_array($name, array('content-length'))) { if ($value !== null) { $this->headers->putEntry($name, Core\Convert::toString($value)); } else { $this->headers->removeKey($name); } } }
/** * 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; }
/** * This method parses a "dictionary" node. * * @access protected * @param \SimpleXMLElement &$node a reference to the "dictionary" node * @return \Unicity\Common\Mutable\IMap the value as a map * @throws \Unicity\Throwable\Parse\Exception indicates that an unrecognized child * node was encountered */ protected function parseDictElement(\SimpleXMLElement $node) { $element = new Common\Mutable\HashMap(); $children = $node->children(); $key = null; foreach ($children as $child) { $name = $child->getName(); if ($key !== null) { switch ($name) { case 'array': $element->putEntry($key, $this->parseArrayElement($child)); break; case 'data': $element->putEntry($key, $this->parseDataElement($child)); break; case 'date': $element->putEntry($key, $this->parseDateElement($child)); break; case 'dict': $element->putEntry($key, $this->parseDictElement($child)); break; case 'false': $element->putEntry($key, $this->parseFalseElement($child)); break; case 'integer': $element->putEntry($key, $this->parseIntegerElement($child)); break; case 'real': $element->putEntry($key, $this->parseRealElement($child)); break; case 'string': $element->putEntry($key, $this->parseStringElement($child)); break; case 'true': $element->putEntry($key, $this->parseTrueElement($child)); break; default: throw new Throwable\Parse\Exception('Invalid child node named ":name" detected.', array(':name' => $name)); break; } $key = null; } else { if ($name == 'key') { $key = $this->parseKeyElement($child); } else { throw new Throwable\Parse\Exception('Invalid child node named ":name" detected.', array(':name' => $name)); } } } if ($key !== null) { throw new Throwable\Parse\Exception('Failed to match the key ":key" with a value.', array(':key' => $key)); } return $element; }
/** * This method registers a parser with the specified name. * * @access public * @param string $name the name to associate with the specified * parser * @param Spring\Object\Definition\Parser $parser the parser to be registered */ public function registerObjectDefinitionParser($name, Spring\Object\Definition\Parser $parser) { $this->parsers->putEntry($name, $parser); }
/** * This method parses a "wddxPacket" node. * * @access protected * @param \DOMDocument $document a reference to the "wddxPacket" node * @return \Unicity\Common\String the value as a string */ protected function parseWDDXPacketElement(\DOMDocument $document) { $map = new Common\Mutable\HashMap(); $xpath = new \DOMXPath($document); $children = $xpath->query('/wddxPacket/header'); foreach ($children as $child) { $map->putEntry('header', $this->parseHeaderElement($child)); } $children = $xpath->query('/wddxPacket/data'); foreach ($children as $child) { $map->putEntry('data', $this->parseDataElement($child)); } return $map; }
/** * 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(); }
/** * This method puts the key/value mapping to the collection. * * @access public * @override * @param mixed $key the key to be mapped * @param mixed $value the value to be mapped * @return boolean whether the key/value pair was set */ public function putEntry($key, $value) { if (Core\Data\Undefined::instance()->__equals($value)) { return $this->removeKey($key); } else { return parent::putEntry($key, $value); } }
/** * This method converts a collection to use collections. * * @access public * @static * @param mixed $data the data to be converted * @return mixed the converted data */ public static function useCollections($data) { if (is_object($data)) { if ($data instanceof Common\IList) { $ilist = $data instanceof Common\Mutable\IList ? get_class($data) : '\\Unicity\\Common\\Mutable\\ArrayList'; $buffer = new $ilist(); foreach ($data as $value) { $buffer->addValue(static::useCollections($value)); } return $buffer; } else { if ($data instanceof Common\ISet) { $iset = $data instanceof Common\Mutable\ISet ? get_class($data) : '\\Unicity\\Common\\Mutable\\HashSet'; $buffer = new $iset(); foreach ($data as $value) { $buffer->putValue(static::useCollections($value)); } return $buffer; } else { if ($data instanceof Common\IMap) { $imap = $data instanceof Common\Mutable\IMap ? get_class($data) : '\\Unicity\\Common\\Mutable\\HashMap'; $buffer = new $imap(); foreach ($data as $key => $value) { $buffer->putEntry($key, static::useCollections($value)); } return $buffer; } else { if ($data instanceof \stdClass) { $data = get_object_vars($data); $buffer = new Common\Mutable\HashMap(); foreach ($data as $key => $value) { $buffer->putEntry($key, static::useCollections($value)); } return $buffer; } } } } } if (is_array($data)) { if (static::isDictionary($data)) { $buffer = new Common\Mutable\HashMap(); foreach ($data as $key => $value) { $buffer->putEntry($key, static::useCollections($value)); } return $buffer; } else { $buffer = new Common\Mutable\ArrayList(); foreach ($data as $value) { $buffer->addValue(static::useCollections($value)); } return $buffer; } } return $data; }
/** * This method sets which nodes are to be treated as ArrayLists. * * @access public * @param Common\HashSet $properties the properties that will be * considered expandable */ public function setExpandableProperties(Common\HashSet $properties) { $this->directives->putEntry('expandableProperties', $properties); }
/** * 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; }