C:\xampp2_not used\php\pear\PHP\UML\Output\Xmi\BuilderImpl1.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<?php
/**
 * PHP_UML (PHP_UML_Output_Xmi_BuilderImpl1)
 *
 * 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: 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 <ohlesbeauxjours@yahoo.fr> 
 * @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 
'<XMI xmi.version="'.self::XMI_VERSION.'"
            xmlns:UML="http://www.omg.org/spec/UML/1.4">
            <XMI.header>
                <XMI.documentation>
                    <XMI.exporter>'
.self::EXPORTER_NAME.'</XMI.exporter>
                </XMI.documentation>
                <XMI.metamodel XMI.name="UML" XMI.version="'
.self::XMI_VERSION.'" />
            </XMI.header>
            <XMI.content>'
;
    }
    
    public function 
getXmiHeaderClose()
    {
        return 
'</XMI.content></XMI>';
    }
    
    public function 
getModelOpen(PHP_UML_Metamodel_Package $model)
    {
        return 
'<UML:Model name="'.$model->name.'" xmi.id="'.$model->id.'" '.
            
self::DEFAULT_CLASSIFIER_ATT.'>';         
    }

    public function 
getStereotypes()
    {
        
$str '';
        foreach (
self::$allStereotypes as $item)
            
$str .= '<UML:Stereotype xmi.id="'.self::getUID('stereotype_'.$item).'"
                name="'
.$item.'" '.self::DEFAULT_CLASSIFIER_ATT.' />';
        
        
$str .= '<UML:Stereotype xmi.id="'.self::getUID('stereotype_realize').'"
            name="realize" '
.self::DEFAULT_CLASSIFIER_ATT.'>
            <UML:Stereotype.baseClass>Abstraction</UML:Stereotype.baseClass>
            </UML:Stereotype>'
;
        
        
$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.'</'.$tag->name.'>'
    }
    
    public function 
getModelClose()
    {
        return 
'</UML:Model>';
    }
    
    public function 
getPackageOpen(PHP_UML_Metamodel_Package $package)
    {
        
$str '<UML:Package xmi.id="'.$package->id.'" name="'.$package->name.'">';
        if (isset(
$package->description)) {
            
$str .= $this->getComment($package->description);
        }
        return 
$str;
    }

    public function 
getNamespaceOpen()
    {
        return 
'<UML:Namespace.ownedElement>';
    }
    
    public function 
getPackageClose()
    {
        return 
'</UML:Package>';
    }

    public function 
getNamespaceClose()
    {
        return 
'</UML:Namespace.ownedElement>';
    }
    
    public function 
getSubsystemOpen(PHP_UML_Metamodel_Package $package)
    {
        return 
'<UML:Subsystem name="'.$package->name.'" xmi.id="'.
            
$package->id.'" isInstantiable="false"><UML:Namespace.ownedElement>';
    }

    public function 
getSubsystemClose()
    {
        return 
'</UML:Namespace.ownedElement></UML:Subsystem>';
    }
    
    public function 
getDatatype(PHP_UML_Metamodel_Datatype $type)
    {
        
$str '<UML:DataType xmi.id="'.$type->id.'"'.
            
' name="'.$type->name.'" visibility="public" isRoot="false" '.
            
' isLeaf="false" isAbstract="false">';
        if (isset(
$class->description))
            
$str .= $this->getComment($class->description);
        return 
$str.'</UML:DataType>';
    }

    public function 
getClass(PHP_UML_Metamodel_Class $class)
    { 
        
$str '<UML:Class name="'.$class->name.'" xmi.id="'.
            
$class->id.'" visibility="package"
            isAbstract="'
.($class->isAbstract?'true':'false').'">';

        list(
$generalizable$generalization) = $this->getGeneralizations($class);

        
$str .= $generalizable;
        
$str .= '<UML:Classifier.feature>';

        foreach (
$class->ownedAttribute as &$property) {
            
$str .= $this->getProperty($property);
        }

        foreach (
$class->ownedOperation as &$operation) {
            
$str .= $this->getOperation($operation);
        }

        
$str .= '</UML:Classifier.feature>';
        
        if (isset(
$class->description))
            
$str .= $this->getComment($class->description);
        
        
$str .= '</UML:Class>';

        return 
$str.$generalization.$this->getRealizations($class);
    }

    public function 
getInterface(PHP_UML_Metamodel_Interface $interface)
    {
        
$str '<UML:Interface name="'.$interface->name.'"'.
            
' xmi.id="'.$interface->id.'"'.
            
' visibility="package" isAbstract="true">';

        list(
$generalizable$generalization) = $this->getGeneralizations($interface);

        
$str .= $generalizable;
        
$str .= '<UML:Classifier.feature>';
 
        foreach (
$interface->ownedOperation as &$operation)
            
$str .= $this->getOperation($operation);

        
$str .= '</UML:Classifier.feature>';

        if (isset(
$interface->description))
            
$str .= $this->getComment($interface->description);

        
$str .= '</UML:Interface>';
        
        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 .= '<UML:GeneralizableElement.generalization>
                    <UML:Generalization xmi.idref="'
.$id.'"/>
                    </UML:GeneralizableElement.generalization>'
;

                
$generalization .= '<UML:Generalization xmi.id="'.$id.'">
                    <UML:Generalization.child><UML:Class xmi.idref="'
.
                    
$client->id.
                    
'" /></UML:Generalization.child>
                    <UML:Generalization.parent><UML:Class xmi.idref="'
.
                    
$gclass->id.'"/>
                    </UML:Generalization.parent></UML:Generalization>'
;
            }
        }
        return array(
$generalizable$generalization);
    }

    public function 
getRealizations(PHP_UML_Metamodel_Class $client)
    {
        
$str '';
        foreach (
$client->implements as &$rclass) {
            if (
is_object($rclass)) {
                
$str .= '<UML:Abstraction '.
                    
'xmi.id="'.self::getUID().'" isSpecification="false">'.
                    
'<UML:ModelElement.stereotype><UML:Stereotype xmi.idref="'.
                    
self::getUID('stereotype_realize').'"/>'.
                    
'</UML:ModelElement.stereotype>'.
                    
'<UML:Dependency.client><UML:Class xmi.idref="'.
                    
$client->id.
                    
'"/></UML:Dependency.client>'.
                    
'<UML:Dependency.supplier><UML:Interface xmi.idref="'.
                    
$rclass->id.'"/>'.
                    
'</UML:Dependency.supplier></UML:Abstraction>';
            }
        }
        return 
$str;
    }

    public function 
getProperty(PHP_UML_Metamodel_Property $property)
    {
        
$str '<UML:Attribute xmi.id="'.$property->id.'"'.
            
' name="'.$property->name.'" '.
            
' visibility="'.$property->visibility.'" ';

        if (!
$property->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 .= '</UML:Attribute>';
        return 
$str;
    }
    
    public function 
getOperation(PHP_UML_Metamodel_Operation $operation)
    {
        
$str '<UML:Operation xmi.id="'.$operation->id.'"'.
            
' name="'.$operation->name.'"'.
            
' visibility="'.$operation->visibility.'"';
        if (!
$operation->isInstantiable)
            
$str .= ' isStatic="true"';
        if (
$operation->isAbstract)
            
$str .= ' isAbstract="true"';

        
$str .= ' isQuery="false" concurrency="sequential">'.
            
'<UML:BehavioralFeature.parameter>';

        foreach (
$operation->ownedParameter as &$parameter) {
            
$str .= $this->getParameter($parameter);
        }

        
$str .= '</UML:BehavioralFeature.parameter>';

        if (isset(
$operation->description))
            
$str .= $this->getComment($operation->description);

        
$str .= '</UML:Operation>';

        return 
$str;
    }

    public function 
getParameter(PHP_UML_Metamodel_Parameter $parameter)
    {
        return 
'<UML:Parameter xmi.id="'.$parameter->id.'" '.
            
' name="'.$parameter->name.'"'.
            
' kind="'.$parameter->direction.'">'.
            
$this->getParameterType($parameter).
            
'</UML: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 .= '<UML:Parameter.type>'.
                
'<UML:DataType xmi.idref="'.$parameter->type->id.
                
'"/></UML:Parameter.type>';
        }

        if (
$parameter->default!='') {
            
$str .= '<UML:Parameter.defaultValue>'.
                
'<UML:Expression xmi.id="'.$id.'"'.
                
' body="'.htmlspecialchars($parameter->defaultENT_QUOTES).'" />'.
                
'</UML:Parameter.defaultValue>';
        }
        return 
$str;
    }

    public function 
getArtifact(PHP_UML_Metamodel_Artifact $file, &$mf = array())
    {
        return 
'<UML:Artifact '.
            
' xmi.id="'.$file->id.'"'.
            
' name="'.basename(htmlspecialchars($file->name)).'">'.
            
'<UML:ModelElement.stereotype>'.
            
'<UML:Stereotype xmi.idref="'.self::getUID('stereotype_'.self::PHP_FILE).'"/>'.
            
'</UML:ModelElement.stereotype>'.
            
'</UML:Artifact>';
    }

    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->valueself::getUID('Tag_documentation'));
        else
            return 
'';
    }
    
    public function 
getTaggedValue($value$tag)
    {
        return 
'<UML:ModelElement.taggedValue>'.
            
'<UML:TaggedValue xmi.id="'.self::getUID().'" visibility="public">'.
            
'<UML:TaggedValue.dataValue>'.htmlspecialchars($value).'</UML:TaggedValue.dataValue>'.
            
'<UML:TaggedValue.type>'.
                
'<UML:TagDefinition xmi.idref="'.$tag.'"/>'.
            
'</UML:TaggedValue.type>'.
            
'</UML:TaggedValue>'.
            
'</UML:ModelElement.taggedValue>';
    }
    
    public function 
getTagDefinition($name)
    {
        return 
'<UML:TagDefinition xmi.id="'.self::getUID('Tag_'.$name).'" '.
            
'name="'.$name.'" isSpecification="false" tagType="string">
            <UML:TagDefinition.multiplicity>
            <UML:Multiplicity xmi.id="'
.self::getUID('TagMultiplicity_'.$name).'">
              <UML:Multiplicity.range>
                <UML:MultiplicityRange xmi.id="'
.self::getUID('TagMultiRange_'.$name).'"
                  lower="0" upper="1"/>
              </UML:Multiplicity.range>
            </UML:Multiplicity>
          </UML:TagDefinition.multiplicity>
        </UML:TagDefinition>'
;
    }
    
    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 .= '<UML:StructuralFeature.type>'.
                
'<UML:DataType xmi.idref="'.$element->type->id.
                
'"/></UML:StructuralFeature.type>';

        } elseif (
get_class($element->type)=='PHP_UML_Metamodel_Datatype') {

            
$str .= '<UML:StructuralFeature.type>'.
                
'<UML:DataType xmi.idref="'.$element->type->id.
                
'"/></UML:StructuralFeature.type>';
        }

        if (
$element->default!='') {
            
$str .= '<UML:Attribute.initialValue>'.
                
'<UML:Expression xmi.id="'.$id.'"'.
                
' body="'.htmlspecialchars($element->defaultENT_QUOTES).'" />'.
                
'</UML:Attribute.initialValue>';
        }
        return 
$str;
    }
}
?>
x

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