* @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 1 * * 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_BuilderImpl1 extends PHP_UML_Output_Xmi_AbstractBuilder { const XMI_VERSION = '1.2'; const UML_VERSION = '1.4'; const DEFAULT_CLASSIFIER_ATT = ' visibility="public" isAbstract="false" isSpecification="false" isRoot="false" isLeaf="false" '; public function getXmiHeaderOpen() { return ' '.self::EXPORTER_NAME.' '; } public function getXmiHeaderClose() { return ''; } public function getModelOpen(PHP_UML_Metamodel_Package $model) { return ''; } public function getStereotypes() { $str = ''; foreach (self::$allStereotypes as $item) $str .= ''; $str .= ' Abstraction '; $str .= $this->getTagDefinition('documentation'); return $str; } public function getStereotypeInstance(PHP_UML_Metamodel_Stereotype $s) { return ''; } public function getMetadata(PHP_UML_Metamodel_Tag $tag) { return '<'.$tag->name.'>'.$tag->value.'name.'>'; } public function getModelClose() { return ''; } public function getPackageOpen(PHP_UML_Metamodel_Package $package) { $str = ''; if (isset($package->description)) { $str .= $this->getComment($package->description); } return $str; } public function getNamespaceOpen() { return ''; } public function getPackageClose() { return ''; } public function getNamespaceClose() { return ''; } public function getSubsystemOpen(PHP_UML_Metamodel_Package $package) { return ''; } public function getSubsystemClose() { return ''; } public function getDatatype(PHP_UML_Metamodel_Datatype $type) { $str = ''; if (isset($class->description)) $str .= $this->getComment($class->description); return $str.''; } public function getClass(PHP_UML_Metamodel_Class $class) { $str = ''; list($generalizable, $generalization) = $this->getGeneralizations($class); $str .= $generalizable; $str .= ''; foreach ($class->ownedAttribute as &$property) { $str .= $this->getProperty($property); } foreach ($class->ownedOperation as &$operation) { $str .= $this->getOperation($operation); } $str .= ''; if (isset($class->description)) $str .= $this->getComment($class->description); $str .= ''; return $str.$generalization.$this->getRealizations($class); } public function getInterface(PHP_UML_Metamodel_Interface $interface) { $str = ''; list($generalizable, $generalization) = $this->getGeneralizations($interface); $str .= $generalizable; $str .= ''; foreach ($interface->ownedOperation as &$operation) $str .= $this->getOperation($operation); $str .= ''; if (isset($interface->description)) $str .= $this->getComment($interface->description); $str .= ''; return $str.$generalization; } public function getGeneralizations(PHP_UML_Metamodel_Type $client) { $str = ''; $generalizable = ''; $generalization = ''; foreach ($client->superClass as &$gclass) { if (is_object($gclass)) { $id = self::getUID(); $generalizable .= ' '; $generalization .= ' '; } } return array($generalizable, $generalization); } public function getRealizations(PHP_UML_Metamodel_Class $client) { $str = ''; foreach ($client->implements as &$rclass) { if (is_object($rclass)) { $str .= ''. ''. ''. ''. ''. ''; } } return $str; } public function getProperty(PHP_UML_Metamodel_Property $property) { $str = 'isInstantiable) { $str .= ' isStatic="true" ownerScope="classifier"'; } else { $str .= ' ownerScope="instance"'; } if ($property->isReadOnly) $str .= ' changeability="frozen" isReadOnly="true" '; $str .= '>'; $str .= self::getStructuralFeatureType($property); if (isset($property->description)) $str .= $this->getComment($property->description); $str .= ''; return $str; } public function getOperation(PHP_UML_Metamodel_Operation $operation) { $str = 'isInstantiable) $str .= ' isStatic="true"'; if ($operation->isAbstract) $str .= ' isAbstract="true"'; $str .= ' isQuery="false" concurrency="sequential">'. ''; foreach ($operation->ownedParameter as &$parameter) { $str .= $this->getParameter($parameter); } $str .= ''; if (isset($operation->description)) $str .= $this->getComment($operation->description); $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(); // Exception to MOF : a PHP class can have the name of a datatype if (isset($parameter->type->id)) { $str .= ''. ''; } if ($parameter->default!='') { $str .= ''. ''. ''; } return $str; } public function getArtifact(PHP_UML_Metamodel_Artifact $file, &$mf = array()) { return ''. ''. ''. ''. ''; } public function getComponentOpen(PHP_UML_Metamodel_Package $package, array $provided, array $required) { return self::getSubsystemOpen($package); } public function getComponentClose() { return self::getSubsystemClose(); } public function getComment(PHP_UML_Metamodel_Stereotype $s, $annotatedElement='') { $tag = PHP_UML_Metamodel_Helper::getStereotypeTag($s, 'description'); if(!is_null($tag)) return $this->getTaggedValue($tag->value, self::getUID('Tag_documentation')); else return ''; } public function getTaggedValue($value, $tag) { return ''. ''. ''.htmlspecialchars($value).''. ''. ''. ''. ''. ''; } public function getTagDefinition($name) { return ' '; } public function getProfile() { } /** * Get the structural type of an element (XMI 1.x) * * @param PHP_UML_TypedElement $element Element * * @return string XMI code */ static protected function getStructuralFeatureType(PHP_UML_Metamodel_TypedElement $element) { $str = ''; $id = self::getUID(); if (!is_object($element->type)) return ''; if (get_class($element->type)=='PHP_UML_Metamodel_Class') { $str .= ''. ''; } elseif (get_class($element->type)=='PHP_UML_Metamodel_Datatype') { $str .= ''. ''; } if ($element->default!='') { $str .= ''. ''. ''; } return $str; } } ?>