C:\xampp\php\pear\PHP\UML\Output\ExporterAPI.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
<?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: 169 $
 * @link     http://pear.php.net/package/PHP_UML
 * @since    $Date: 2011-09-12 01:28:43 +0200 (lun., 12 sept. 2011) $
 */

/**
 * This is the exportation class relying on the API (= on the full hierarchy of
 * metaclasses stored in the model). Note that another way to export a model would
 * be to use ExporterXSL, which is based on an XSL transformation of XMI. 
 * A class implementing ExporterAPI must reside in a subfolder containing a class
 * named PHP_UML_<name of the output format>_Exporter. This class must also have a
 * public method "generate", which is used to start the serialization process.
 *
 * @category   PHP
 * @package    PHP_UML
 * @subpackage Output
 * @author     Baptiste Autin <ohlesbeauxjours@yahoo.fr> 
 * @license    http://www.gnu.org/licenses/lgpl.html LGPL License 3
 */
abstract class PHP_UML_Output_ExporterAPI extends PHP_UML_Output_Exporter
{
    
/**
     * Object storing some contextual data
     * 
     * @var PHP_UML_Output_ApiContextPackage
     */
    
protected $ctx;
        
    public function 
export($outDir)
    {
        if (!
file_exists($outDir))
            throw new 
PHP_UML_Exception('Export directory ('.$outDir.') does not exist.');
        if (empty(
$this->structure) || empty($this->structure->packages)) {
            throw new 
PHP_UML_Exception('No model to export');
        }
    }
    
    
/**
     * Return the ApiContextPackage currently associated to the rendering
     * 
     * @return PHP_UML_Output_ApiContextPackage
     */
    
public function getContextPackage()
    {
        return 
$this->ctx;
    }
    
    
/**
    * Sets the allInherited/-ing arrays with all the classifiers that a given
    * classifier inherits from
    *
    * @param PHP_UML_Metamodel_Classifier $s The initial reference classifier
    * @param PHP_UML_Metamodel_Classifier $t The current classifier to check
    */
    
protected function setAllInherited(PHP_UML_Metamodel_Classifier $sPHP_UML_Metamodel_Classifier $t)
    {
        if (!empty(
$t->superClass) && is_object($t->superClass[0])) {
            
$h $t->superClass[0];
            
$this->setAllInherited($s$h);
            
$this->ctx->allInherited[$s->id][]  = $h;
            
$this->ctx->allInheriting[$h->id][] = $s;
        }
    }
    
    
/**
     * Sets the allImplemented/-ing arrays with all the interfaces that a given
     * class implements (including those of the inherited classes)
     *
     * @param PHP_UML_Metamodel_Class      $s The initial reference class
     * @param PHP_UML_Metamodel_Classifier $t The current classifier to check
     */
    
protected function setAllImplemented(PHP_UML_Metamodel_Class $sPHP_UML_Metamodel_Classifier $t)
    {
        if (!empty(
$t->superClass) && is_object($t->superClass[0])) {
            
$this->setAllImplemented($s$t->superClass[0]);
        }
        if (isset(
$t->implements) && is_array($t->implements)) {
            foreach (
$t->implements as $impl) {
                if (
is_object($impl)) {
                    
$this->setAllImplemented($s$impl);
                    
$this->ctx->allImplemented[$s->id][]     = $impl;
                    
$this->ctx->allImplementing[$impl->id][] = $s;
                }
            }
        }
    }
    
    
/**
     * Recurses into all the packages to build a list of all the generalizations
     * and realizations between elements.
     * We normally do this before creating the detailed files.
     *
     * @param PHP_UML_Metamodel_Package $pkg Starting package
     */
    
protected function setAllSuperClassifiers(PHP_UML_Metamodel_Package $pkg)
    {
        foreach (
$pkg->ownedType as $type) {
            switch (
get_class($type)) {
            case 
PHP_UML_Metamodel_Superstructure::META_CLASS:
                
$this->setAllImplemented($type$type);
            case 
PHP_UML_Metamodel_Superstructure::META_INTERFACE:
                
$this->setAllInherited($type$type);
            }
        }
        foreach (
$pkg->nestedPackage as $np) {
            
$this->setAllSuperClassifiers($np);
        }
    }
    
    protected function 
initContextPackage(PHP_UML_Metamodel_Package $pkg$dir$rpt)
    {
        
$this->ctx->classes    = array();
        
$this->ctx->interfaces = array();
        
$this->ctx->datatypes  = array();
        
        
$this->ctx->dir $dir;
        
$this->ctx->rpt $rpt;
        
        foreach (
$pkg->ownedType as $type) {
            switch (
get_class($type)) {
            case 
PHP_UML_Metamodel_Superstructure::META_INTERFACE:
                
$this->ctx->interfaces[] = $type;
                break;
            case 
PHP_UML_Metamodel_Superstructure::META_DATATYPE:
                
$this->ctx->datatypes[] = $type;
                break;
            default:
                
$this->ctx->classes[] = $type;
            }
        }
    }
}
?>
x

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