* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 * @version SVN: $Revision: 174 $ * @link http://pear.php.net/package/PHP_UML * @since $Date: 2011-09-15 03:17:32 +0200 (jeu., 15 sept. 2011) $ */ /** * Implementation class to create XMI in version 2 * * See the interface PHP_UML_Output_Xmi_Builder for the comments. * * @category PHP * @package PHP_UML * @subpackage Output * @subpackage Xmi * @see PHP_UML_Output_Xmi_Builder * @author Baptiste Autin * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ class PHP_UML_Output_Xmi_BuilderImpl2 extends PHP_UML_Output_Xmi_AbstractBuilder { const XMI_VERSION = '2.1'; const UML_VERSION = '2.1.2'; const DEFAULT_CLASSIFIER_ATT = ' visibility="public" isAbstract="false" '; /** * PHP_UML UML Profile (TODO) * @var string */ public $profile = ''; public function getXmiHeaderOpen() { return ' '; } public function getModelOpen(PHP_UML_Metamodel_Package $model) { return ''; } public function getModelClose() { return ''; } public function getXmiHeaderClose() { return ''; } public function getPackageOpen(PHP_UML_Metamodel_Package $package) { $str = ''; if (isset($package->description)) { $str .= $this->getComment($package->description, $package->id); } return $str; } public function getPackageClose() { return ''; } public function getNamespaceOpen() { return ''; } public function getNamespaceClose() { return ''; } public function getDatatype(PHP_UML_Metamodel_Datatype $type) { $str = ''; if (isset($type->description)) $str .= $this->getComment($type->description, $type->id); return $str.''; } public function getSubsystemOpen(PHP_UML_Metamodel_Package $package) { return ''; } public function getSubsystemClose() { return ''; } public function getClass(PHP_UML_Metamodel_Class $class) { $strRealization = ''; $str = ''; $str .= $this->getGeneralizations($class); $strRealization .= $this->getRealizations($class); foreach ($class->ownedAttribute as &$property) $str .= $this->getProperty($property); foreach ($class->ownedOperation as &$operation) $str .= $this->getOperation($operation); if (isset($class->description)) $str .= $this->getComment($class->description, $class->id); $str .= ''; return $str.$strRealization; } public function getInterface(PHP_UML_Metamodel_Interface $interface) { $str = ''; foreach ($interface->ownedOperation as &$operation) $str .= $this->getOperation($operation); $str .= $this->getGeneralizations($interface); if (isset($interface->description)) $str .= $this->getComment($interface->description, $interface->id); $str .= ''; return $str; } public function getRealizations(PHP_UML_Metamodel_Class $client) { $str = ''; foreach ($client->implements as &$rclass) { if (is_object($rclass)) { $str .= ''; } } return $str; } public function getGeneralizations(PHP_UML_Metamodel_Type $client) { $str = ''; foreach ($client->superClass as &$gclass) { if (is_object($gclass)) { $str .= ' '; } } return $str; } public function getProperty(PHP_UML_Metamodel_Property $property) { $str = 'isInstantiable) $str .= ' isStatic="true"'; if ($property->isReadOnly) $str .= ' isReadOnly="true" '; $str .= '>'.$this->getParameterType($property); if (isset($property->description)) $str .= $this->getComment($property->description, $property->id); $str .= ''; return $str; } public function getOperation(PHP_UML_Metamodel_Operation $operation) { $str = 'isInstantiable) $str .= ' isStatic="true"'; if ($operation->isAbstract) $str .= ' isAbstract="true"'; $str .= '>'; foreach ($operation->ownedParameter as &$parameter) { $str .= $this->getParameter($parameter); } if (isset($operation->description)) $str .= $this->getComment($operation->description, $operation->id); $str .= ''; return $str; } public function getParameter(PHP_UML_Metamodel_Parameter $parameter) { return ''. $this->getParameterType($parameter). ''; } public function getParameterType(PHP_UML_Metamodel_TypedElement $parameter) { $str = ''; $id = self::getUID(); if (isset($parameter->type->id)) $str = ''; if ($parameter->default!='') $str .= ''; return $str; } public function getArtifact(PHP_UML_Metamodel_Artifact $file, &$mf = array()) { $id = $file->id; $file = htmlspecialchars($file->name); $name = basename($file); $str = ' '; foreach ($mf as $class) { if ($class instanceof PHP_UML_Metamodel_Classifier) { $id_supplier = $class->id; $str .= self::getManifestation($id, $id_supplier, 'source'); } } $str .= ''; return $str; } public function getComponentOpen(PHP_UML_Metamodel_Package $package, array $provided, array $required) { $str = ' '; foreach ($provided as $c) { switch (get_class($c)) { case 'PHP_UML_Metamodel_Interface': case 'PHP_UML_Metamodel_Class': $id = self::getUID('CV_provided_'.$c->name); $id_provided = $c->id; $str .= ''; } } foreach ($required as $c) { $id = self::getUID('CV_required_'.$c->name); $id_provided = $c->id; $str .= ''; } return $str; } public function getComponentClose() { return ''; } /** * Formates a Profile adapted to PHP_UML. * * TODO. Experimental. * * @return string XMI Code */ public function getProfile() { return file_get_contents('../Metamodel/phpdoc.profile.xmi'). ''. ''. ''; } public function getComment(PHP_UML_Metamodel_Stereotype $s, $annotatedElement='') { $tag = PHP_UML_Metamodel_Helper::getStereotypeTag($s, 'description'); if(!is_null($tag)) return ''.htmlspecialchars($tag->value).''; else return ''; } public function getStereotypes() { return ''; } /** * Gets all the elements contained in a stereotype * Note: the property "documentation" is not discarded (we will have * it as an "ownedComent" tag, instead; see getComment()) * * @param PHP_UML_Metamodel_Stereotype $s Stereotype * * @return string */ public function getStereotypeInstance(PHP_UML_Metamodel_Stereotype $s) { $str = ''; foreach ($s->ownedAttribute as $tag) { if($tag->value!='' && $tag->name!='description') $str .= $this->getMetadata($tag); } if ($str!='') return '<'.$s->profile.':'.$s->name. ' base_Element="'.$s->element->id.'">'. $str.'profile.':'.$s->name.'>'; else return ''; } public function getMetadata(PHP_UML_Metamodel_Tag $tag) { return '<'.$tag->name.'>'.htmlspecialchars($tag->value).'name.'>'; } /** * Generates a manifestation element (= the link between a class and the * artifact where the class is defined) * * @param string $client Name of the client * @param string $supplier Name of the supplier * @param string $name Name of the relation * * @return string XMI code */ public function getManifestation($client, $supplier, $name) { return ''; } } ?>