C:\xampp\php\pear\PHP\UML\Output\Xmi\Exporter.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
 * PHP_UML
 *
 * PHP version 5
 *
 * @category PHP
 * @package  PHP_UML
 * @author   Baptiste Autin <ohlesbeauxjours@yahoo.fr> 
 * @license  http://www.gnu.org/licenses/lgpl.html LGPL License 3
 * @version  SVN: $Revision: 176 $
 * @link     http://pear.php.net/package/PHP_UML
 * @since    $Date: 2011-09-19 00:03:11 +0200 (lun., 19 sept. 2011) $
 */

/**
 * This class generates the XMI from a UML model (PHP_UML_Metamodel)
 *
 * @category   PHP
 * @package    PHP_UML
 * @subpackage Output
 * @subpackage Xmi
 * @author     Baptiste Autin <ohlesbeauxjours@yahoo.fr> 
 * @license    http://www.gnu.org/licenses/lgpl.html LGPL License 3
 */
class PHP_UML_Output_Xmi_Exporter extends PHP_UML_Output_ExporterAPI
{    
    
/**
     * Reference to an XmiDocument object. Such an object is needed by the export()
     * method of Xmi_Exporter and its subclasses (unlike the ExporterAPI implementations,
     * which work on the metamodel directly, and don't need to know anything about XMI).
     * 
     * @var PHP_UML_Output_XmiDocument
     */
    
protected $xmiDocument;
    
    
/**
     * Default XMI version used for serialization. Note that all XSL-based
     * exporters will generate XMI with the default xmiVersion and encoding.
     * 
     * @var float
     */
    
protected $xmiVersion 2;
    
    
/**
     * Default XML encoding of the XMI document.
     * 
     * @var string
     */
    
protected $encoding 'iso-8859-1';
    
    
/**
     * A logical view is included in the model by default.
     * 
     * @var boolean
     */
    
protected $logicalView true;
    
    
/**
     * A deployment view is not included in the model by default.
     * 
     * @var boolean
     */
    
protected $deploymentView false;
    
    
/**
     * A component view is not included in the model by default.
     * 
     * @var boolean
     */
    
protected $componentView false;
    
    
/**
     * Stereotypes are not included in the model by default.
     * 
     * @var boolean
     */
    
protected $stereotypes false;
    
    
    
/**
     * Setter for the XML encoding
     *
     * @param string $encoding Encoding
     */
    
public function setEncoding($encoding)
    {
        
$this->encoding $encoding;
    }
    
    
/**
     * Setter for the XMI version
     *
     * @param float $version XMI version
     */
    
public function setXmiVersion($version)
    {
        
$this->xmiVersion $version;
    }
    
    
/**
     * Enables the inclusion of a logical view in the serialized model
     *
     * @param boolean $value True/False
     */
    
public function setLogicalView($value)
    {
        
$this->logicalView $value;
    }
    
    
/**
     * Enables the inclusion of a deployment view in the serialized model
     *
     * @param boolean $value True/False
     */
    
public function setDeploymentView($value)
    {
        
$this->deploymentView $value;
    }
    
    
/**
     * Enables the inclusion of a component view in the serialized model
     *
     * @param boolean $value True/False
     */
    
public function setComponentView($value)
    {
        
$this->componentView $value;
    }
    
    
/**
     * Enables the inclusion of the stereotypes in the serialized model
     * If true, all the stereotypes related to the UML model (currently, these
     * data correspond to the PHP docblocks) will be added to the XMI model.
     *
     * @param boolean $value True/False
     */
    
public function setStereotypes($value)
    {
        
$this->stereotypes $value;
    }
    
    
/**
     * Setter for the XmiDocument
     * 
     * @param PHP_UML_Output_XmiDocument $xmiDocument XMI Document
     */
    
public function setXmiDocument(PHP_UML_Output_XmiDocument $xmiDocument)
    {
        
$this->xmiDocument $xmiDocument;
    }
    
    
/**
     * Getter for the XmiDocument
     * 
     * @return PHP_UML_Output_XmiDocument
     */
    
public function getXmiDocument()
    {
        return 
$this->xmiDocument;
    }
    
    public function 
export($outDir)
    {
        if (empty(
$this->structure))
            throw new 
PHP_UML_Exception('No model given.'); 
        
        
//if (empty($this->xmiDocument)) {
        
$this->generateXmi();
        
//}

        
if ($outDir=='')
            return 
$this->xmiDocument->dump();
        else {
            if (!
is_dir($outDir))
                
$this->save($outDir);
            else
            {
                
$fileName = empty($this->structure->packages) ? 'undefined' $this->structure->packages->name;
                
$this->save($outDir.DIRECTORY_SEPARATOR.$fileName.'.xmi');
            }
        }
    }

    
/**
     * Internal method to save the generated XMI to a file.
     * Use export() instead if you need to save from outside the Exporter object.
     *
     * @param string $outputFile Filename
     */
    
protected function save($outputFile)
    {        
        if (
$ptr fopen($outputFile'w+')) {
            
fwrite($ptr$this->xmiDocument->dump());
            
fclose($ptr);
        } else {
            throw new 
PHP_UML_Exception(
                
'File '.$outputFile.' could not be created.'
            
);
        }
    }

    
    
/**
     * Serialize the metamodel (contained in the property $structure) into XMI code
     * 
     * It is not necessary to call this method before calling export();
     */
    
public function generateXmi()
    {
        
$builder $this->getXmiBuilder();
        
        
$this->xmiDocument $builder->getXmiDocument($this->structure);
    }
    
    
/**
     * Getter for the XMI factory
     * 
     * @return PHP_UML_Output_Xmi_Builder An XMI builder object
     */
    
protected function getXmiBuilder()
    {
        
$builder PHP_UML_Output_Xmi_AbstractBuilder::getInstance($this->xmiVersion);
        
$builder->setEncoding($this->encoding);
        
$builder->setLogicalView($this->logicalView);
        
$builder->setComponentView($this->componentView);
        
$builder->setDeploymentView($this->deploymentView);
        
$builder->setStereotypes($this->stereotypes);
        return 
$builder;
    }
    

    
/**
     * Read the content of an existing XMI file.
     * If the file is UML/XMI 1, a conversion to version 2 is automatically applied.
     *
     * @param string $filepath Filename
     */
    
public function loadXmi($filepath)
    {
        if (empty(
$this->xmiDocument)) {
            
$this->xmiDocument = new PHP_UML_Output_XmiDocument();
        }
        
$this->xmiDocument->load($filepath);
    }
}
?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586