UmlSequenceDiagramFactoryFromXml.class.php

Go to the documentation of this file.
00001 <?php
00011 class UmlSequenceDiagramFactoryFromXml implements UmlSequenceDiagramFactoryInterface
00012 {
00019         protected static $objInstance;
00020 
00027         protected $objUmlSequenceDiagram;
00028 
00034     protected $objXml;
00035 
00041         public static function getInstance()
00042         {
00043                 if( self::$objInstance == null )
00044                 {
00045                         self::$objInstance = new UmlSequenceDiagramFactoryFromXml();
00046                 }
00047                 return self::$objInstance;
00048         }
00049 
00050 
00059     public function setXml( $strXml )
00060     {
00061         $this->objXml = simplexml_load_string( $strXml );
00062         return $this;
00063     }
00064 
00073     public function getXml()
00074     {
00075         return $this->objXml;
00076     }
00077 
00085     public function setUmlSequenceDiagram( UmlSequenceDiagram $objUmlSequenceDiagram )
00086     {
00087         $this->objUmlSequenceDiagram = $objUmlSequenceDiagram;
00088         return $this;
00089     }
00090 
00097     public function getUmlSequenceDiagram()
00098     {
00099         return $this->objUmlSequenceDiagram;
00100     }
00101 
00108     public function perform()
00109     {
00110         $this->setUmlSequenceDiagram( new UmlSequenceDiagram() );
00111         $this->loadActors();
00112         $this->loadMessages();
00113         return $this->getUmlSequenceDiagram();
00114     }
00115 
00120     protected function loadActors()
00121     {
00122         $arrActors = $this->getUmlSequenceDiagram()->getActors();
00123 
00124         foreach( $this->objXml->actors->actor as $xmlActor )
00125         {
00126             $strId = (string)$xmlActor['id'];
00127             $strType = (string)$xmlActor['type'];
00128             $strName = (string)$xmlActor;
00129 
00130             $objActor = new UmlSequenceDiagramActor();
00131             $objActor->setId( $strId );
00132             $objActor->setType( $strType );
00133             $objActor->setName( $strName );
00134 
00135             $arrActors[ $objActor->getId() ] = $objActor;
00136         }
00137         $this->getUmlSequenceDiagram()->setActors( $arrActors );
00138     }
00139 
00144     protected function loadMessages()
00145     {
00146         $arrMessages = $this->getUmlSequenceDiagram()->getMessages();
00147         $arrActors = $this->getUmlSequenceDiagram()->getActors();
00148 
00149         foreach( $this->objXml->messages->message as $xmlMessage )
00150         {
00151             $strFrom    = (string)$xmlMessage[ 'from' ];
00152             $strTo      = (string)$xmlMessage[ 'to' ];
00153             $strType    = (string) $xmlMessage[ 'type' ];
00154             $strText = (string) $xmlMessage[ 'text' ];
00155 
00156             $objMessage = new UmlSequenceDiagramMessage();
00157             $objMessage->setType( $strType );
00158             $objMessage->setText( $strText );
00159 
00160            if( !array_key_exists( $strFrom , $arrActors ) )
00161             {
00162                 throw new Exception( ' Actor From ' . $strFrom . ' not Found ' );
00163             }
00164             $objMessage->setActorFrom( $arrActors[ $strFrom ] );
00165 
00166            if( !array_key_exists( $strTo , $arrActors ) )
00167             {
00168                 throw new Exception( ' Actor To ' . $strTo . ' not Found ' );
00169             }
00170             $objMessage->setActorTo( $arrActors[ $strTo ] );
00171 
00172             if( isset( $xmlMessage->values->value ) )
00173             foreach( $xmlMessage->values->value as $xmlValue )
00174             {
00175                 $strName = (string)$xmlValue['name'];
00176                 $strValue = (string)$xmlValue['value'];
00177                 $objValue = new UmlSequenceDiagramValue();
00178                 $objValue->setName( $strName );
00179                 $objValue->setValue( $strValue );
00180 
00181                 $objMessage->addValue( $objValue );
00182             }
00183 
00184             $arrMessages[] = $objMessage;
00185         }
00186         $this->getUmlSequenceDiagram()->setMessages( $arrMessages );
00187     }
00188 }
00189 ?>

Generated on Sat Apr 7 14:19:10 2012 for CodeToDiagram by  doxygen 1.5.9