public function getComplexAttributes(AttributeBag $bag)
    {
        $complexAttributes = array();

        if($this->complexAttributeFactory !== null)
        {
            foreach($bag->getAll() as $id => $parameters)
            {
                if(!isset($parameters['name']))
                {
                    throw new InvalidArgumentException('"name" attribute is required.');
                }

                $name = $parameters['name'];
                unset($parameters['name']);
                
                $complexAttribute = $this->complexAttributeFactory->create($name, $parameters);
                
                if(!$complexAttribute->isEmpty())
                {
                    $complexAttributes[] = $complexAttribute;
                }
            }
        }

        return $complexAttributes;
    }