/**
  * Internally, the factory uses a {@link __ComponentSpec} instance to create a component.
  *
  * @param __ComponentSpec $component_spec The component spec
  * @return __IComponent
  */
 private function &_doCreateComponent(__ComponentSpec $component_spec, $component_index = null)
 {
     $component_class = $component_spec->getClass();
     //create an empty component
     $return_value = new $component_class();
     //setup component identifiers
     $return_value->setId($this->_resolveComponentId($component_spec, $component_index));
     $return_value->setName($component_spec->getName());
     $return_value->setIndex($component_index);
     //setup component properties
     $default_values = $component_spec->getDefaultValues();
     foreach ($default_values as $property_name => $property_value) {
         $return_value->{$property_name} = $property_value;
     }
     $component_interface_spec = $component_spec->getComponentInterfaceSpec();
     if ($component_interface_spec != null) {
         if ($return_value instanceof __ICompositeComponent) {
             $return_value->setComponentInterfaceSpec($component_interface_spec);
         } else {
             throw __ExceptionFactory::getInstance()->createException('Can not set a component interface spec to a non-composite component:' . $component_spec->getName());
         }
     }
     //return the component:
     return $return_value;
 }
 protected function _getComponentEndTagCode(__ComponentSpec &$component_spec)
 {
     $return_value = "<?php\n";
     $return_value .= '$component_render_' . $this->_view_code . '->markComponentEndTag($component_specs_' . $this->_view_code . '["' . $component_spec->getId() . '"]);' . "\n";
     $return_value .= "?>";
     return $return_value;
 }
 public function &createComponentSpec($tag_name)
 {
     $return_value = null;
     $tag_name = strtolower($tag_name);
     if (key_exists($tag_name, $this->_component_tags)) {
         $component_tag = $this->_component_tags[$tag_name];
         $component_class = $component_tag->getComponentClass();
         $component_writer_class = $component_tag->getComponentWriterClass($this->_client);
         $component_writer_decorators_classes = $component_tag->getComponentWriterDecoratorClasses($this->_client);
         $return_value = new __ComponentSpec($tag_name, $component_class);
         if ($component_writer_class != null) {
             $component_writer = new $component_writer_class();
             foreach ($component_writer_decorators_classes as $component_writer_decorators_class) {
                 $component_decorator = new $component_writer_decorators_class($component_writer);
                 $component_writer = $component_decorator;
                 unset($component_decorator);
             }
             $view_definition = $component_tag->getViewDefinition($this->_client);
             if ($view_definition != null) {
                 if ($component_writer instanceof __ICompositeWriter) {
                     $component_writer->setViewDefinition($view_definition);
                 } else {
                     throw __ExceptionFactory::getInstance()->createException('Class ' . $component_writer_class . ' must implement __ICompositeWriter in order to have a view assigned to.');
                 }
             }
             $return_value->setWriter($component_writer);
         }
         $component_interface_spec = $component_tag->getComponentInterfaceSpec();
         if ($component_interface_spec != null) {
             $return_value->setComponentInterfaceSpec($component_interface_spec);
         }
     } else {
         throw __ExceptionFactory::getInstance()->createException('ERR_UNKNOW_UI_COMPONENT_TAG', array($tag_name));
     }
     return $return_value;
 }
 protected function &_wakeupComponent(__ComponentSpec $component_spec)
 {
     $component_name = $component_spec->getName();
     if ($component_spec->isArray()) {
         $component_index = $this->_getNextIndex($component_name);
     } else {
         $component_index = null;
     }
     //if the component exists, will get it from the component handler
     if ($this->_component_handler->hasComponent($component_name, $component_index)) {
         $component = $this->_component_handler->getComponent($component_name, $component_index);
     } else {
         $component = $this->_createComponent($component_spec, $component_index);
         $this->_created_components[$component->getId()] = true;
     }
     return $component;
 }
 protected function _registerComponentSpec(__ComponentSpec &$component_spec)
 {
     if ($this->_properties_stack->count() == 0 && $this->_component_specs_stack->count() > 0) {
         $current_component_spec = $this->_component_specs_stack->peek();
         $current_component_class = $current_component_spec->getClass();
         if (!is_subclass_of($current_component_class, '__IContainer')) {
             throw __ExceptionFactory::getInstance()->createException('ERR_UI_COMPONENT_IS_NOT_CONTAINER', array($current_component_spec->getTag(), $component_spec->getTag()));
         }
     }
     $this->_component_specs[$component_spec->getId()] =& $component_spec;
 }