MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
xmlconfigloader.class
Ir para a documentação deste ficheiro.
1<?php
2
4{
5 private $broker;
6 private $xmlMaps = array();
7 private $classMaps = array();
8
9 public function __construct(PersistentManagerFactory $broker)
10 {
11 $this->broker = $broker; // factory
12 }
13
14 private function getAsArray($object)
15 {
16 return (is_array($object)) ? $object : array($object);
17 }
18
19 public function getClassMap($module, $name, $associative=FALSE)
20 {
21 global $MIOLO;
22
23 if (isset($this->classMaps[$module][$name]))
24 {
25 return $this->classMaps[$module][$name];
26 }
27 if (isset($this->xmlMaps[$module][$name]))
28 {
29 $xml = $this->xmlMaps[$module][$name];
30 }
31 else
32 {
33 $file = $MIOLO->GetModulePath($module,'db/map/'.$name.'.xml');
34 if (! file_exists( $file ))
35 {
36 $file = $MIOLO->GetModulePath($module,'classes/map/'.$name.'.xml');
37 }
38 $xmlTree = new MXMLTree($file);
39 $tree = $xmlTree->getTree();
40 $xml = $xmlTree->getXMLTreeElement($tree);
41 $this->xmlMaps[$module][$name] = $xml;
42 if (!$associative)
43 {
44 $MIOLO->UsesBusiness($module,$name);
45 }
46 }
47
48 $database = (string)$xml->databaseName;
49 $className = (string)$xml->moduleName . (string)$xml->className;
50 $cm = new ClassMap($className, $database, $this->broker);
51 $dm = new DatabaseMap((string)$xml->databaseName);
52 $tableMap = new TableMap();
53 $tableMap->setName((string)$xml->tableName);
54 $tableMap->setDatabaseMap($dm);
55 if (isset($xml->extends))
56 {
57 $superClassName = (string)$xml->extends->moduleName . (string)$xml->extends->className;
58 $cm->setSuperClass($superClassName, $this->broker);
59 }
60 $attributes = $this->getAsArray($xml->attribute);
61 foreach($attributes as $attr)
62 {
63 $am = new AttributeMap((string)$attr->attributeName);
64 $converter = $this->getConverter(isset($attr->converter) ? $attr->converter : null);
65 if (isset($attr->attributeIndex))
66 {
67 $am->setIndex($attr->attributeIndex);
68 }
69 if (isset($attr->columnName))
70 {
71 $colm = new ColumnMap($attr->columnName, $tableMap, $converter);
72
73 if (isset($attr->key))
74 {
75 if ($attr->key == 'primary')
76 {
77 $colm->setKeyType('primary');
78 if (isset($attr->idgenerator))
79 {
80 $idGenerator = $attr->idgenerator;
81 $colm->setIdGenerator($idGenerator);
82 }
83 }
84 elseif ($attr->key == 'foreign')
85 {
86 $colm->setKeyType('foreign');
87 }
88 }
89 else
90 {
91 $colm->setKeyType('none');
92 }
93 $am->setColumnMap($colm);
94 }
95 $am->setProxy(isset($attr->proxy) ? $attr->proxy : null);
96 if ((isset($attr->reference)) && ($cm->getSuperClass() != NULL) )
97 {
98 $referenceAttribute = $cm->getSuperClass()->getAttributeMap($attr->reference);
99 if ($referenceAttribute)
100 $am->setReference($referenceAttribute);
101 }
102 if ($attr->attributeName == 'timestamp')
103 {
104 $cm->setTimestampAttributeMap($am);
105 }
106 else
107 {
108 $cm->addAttributeMap($am);
109 }
110 }
111 $this->classMaps[$module][$name] = $cm;
112
113// Associations
114 if (isset($xml->association))
115 {
116 $fromClassMap = $cm;
117 $associations = $this->getAsArray($xml->association);
118 foreach($associations as $assoc)
119 {
120 $toModule = $assoc->toClassModule;
121 $toName = $assoc->toClassName;
122 $toClassMap = $this->getClassMap($toModule, $toName);
124 $am->setForClass($toClassMap);
125 $am->setTargetName($assoc->target);
126 $am->setTarget($fromClassMap->getAttributeMap($assoc->target));
127 $am->setDeleteAutomatic($assoc->deleteAutomatic);
128 $am->setSaveAutomatic($assoc->saveAutomatic);
129 $am->setRetrieveAutomatic($assoc->retrieveAutomatic);
130 $am->setJoinAutomatic($assoc->joinAutomatic);
131 if (isset($assoc->indexAttribute))
132 {
133 $am->setIndexAttribute($assoc->indexAttribute->indexAttributeName);
134 }
135 $am->setInverse($assoc->inverse);
136 $am->setCardinality($assoc->cardinality);
137 if ($assoc->cardinality == 'manyToMany')
138 {
139 $associativeModule = $assoc->associativeClassModule;
140 $associativeName = $assoc->associativeClassName;
141 $associativeClassMap = $this->getClassMap($associativeModule, $associativeName, true);
142 $am->setAssociativeClass($associativeClassMap);
143 foreach($assoc->direction as $direction)
144 {
145 $am->addDirection($direction);
146 }
147 }
148 else
149 {
150 $entries = $this->getAsArray($assoc->entry);
151 foreach($entries as $entry)
152 {
153 $fromAttribute = $entry->fromAttribute;
154 $toAttribute = $entry->toAttribute;
155 if ($am->isInverse())
156 {
157 $e = new UDAMapEntry($toClassMap->getAttributeMap($fromAttribute), $fromClassMap->getAttributeMap($toAttribute));
158 }
159 else
160 {
161 $e = new UDAMapEntry($fromClassMap->getAttributeMap($fromAttribute), $toClassMap->getAttributeMap($toAttribute));
162 }
163 $am->addEntry($e);
164 }
165 }
166 if (isset($assoc->orderAttribute))
167 {
168 $orderEntry = array();
169 $orderAttributes = $this->getAsArray($assoc->orderAttribute);
170 foreach($orderAttributes as $order)
171 {
172 $ascend = ($order->orderAttributeDirection == 'ascend');
173
174 $attributeMap = $am->getForClass()->getAttributeMap($order->orderAttributeName);
175 $orderEntry[] = new OrderEntry($attributeMap, $ascend);
176 }
177 if (count($orderEntry))
178 {
179 $am->setOrderAttributes($orderEntry);
180 }
181 }
182 $fromClassMap->putAssociationMap($am);
183 }
184 }
185
186 return $cm;
187 }
188
189 public function getConverter($converterNode)
190 {
191 if (!$converterNode)
192 {
194 }
195 else
196 {
197 $name = $converterNode->converterName;
198 $converter = $this->broker->getConverter($name);
199 if (!$converter)
200 {
201 $parameters = $this->getParameters($converterNode);
202 $factory = new ConverterFactory();
203 $converter = $factory->getConverter($name, $parameters);
204 $this->broker->putConverter($name, $converter);
205 }
206 }
207 return $converter;
208 }
209
210 public function getParameters($node = NULL)
211 {
212 $param = NULL;
213 if ($node)
214 {
215 $parameters = $this->getAsArray($node->parameter);
216 foreach($parameters as $parameter)
217 {
218 $param[$parameter->parameterName] = $parameter->parameterValue;
219 }
220 }
221 return $param;
222 }
223}
224?>
__construct(PersistentManagerFactory $broker)
getParameters($node=NULL)
getClassMap($module, $name, $associative=FALSE)
getConverter($converterNode)