1------------------------------------------------------------------------------
2--                                                                          --
3--                            Matreshka Project                             --
4--                                                                          --
5--                          Ada Modeling Framework                          --
6--                                                                          --
7--                        Runtime Library Component                         --
8--                                                                          --
9------------------------------------------------------------------------------
10--                                                                          --
11-- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com>                --
12-- All rights reserved.                                                     --
13--                                                                          --
14-- Redistribution and use in source and binary forms, with or without       --
15-- modification, are permitted provided that the following conditions       --
16-- are met:                                                                 --
17--                                                                          --
18--  * Redistributions of source code must retain the above copyright        --
19--    notice, this list of conditions and the following disclaimer.         --
20--                                                                          --
21--  * Redistributions in binary form must reproduce the above copyright     --
22--    notice, this list of conditions and the following disclaimer in the   --
23--    documentation and/or other materials provided with the distribution.  --
24--                                                                          --
25--  * Neither the name of the Vadim Godunko, IE nor the names of its        --
26--    contributors may be used to endorse or promote products derived from  --
27--    this software without specific prior written permission.              --
28--                                                                          --
29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      --
30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT        --
31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    --
32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT     --
33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   --
34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   --
36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   --
37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     --
38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS       --
39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.             --
40--                                                                          --
41------------------------------------------------------------------------------
42--  $Revision: 2937 $ $Date: 2012-05-01 21:07:27 +0400 (Tue, 01 May 2012) $
43------------------------------------------------------------------------------
44with AMF.Elements;
45with AMF.Internals.Element_Collections;
46with AMF.Internals.Helpers;
47with AMF.Internals.Tables.UML_Attributes;
48with AMF.Visitors.UML_Iterators;
49with AMF.Visitors.UML_Visitors;
50with League.Strings.Internals;
51with Matreshka.Internals.Strings;
52
53package body AMF.Internals.UML_Substitutions is
54
55   -------------------
56   -- Enter_Element --
57   -------------------
58
59   overriding procedure Enter_Element
60    (Self    : not null access constant UML_Substitution_Proxy;
61     Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
62     Control : in out AMF.Visitors.Traverse_Control) is
63   begin
64      if Visitor in AMF.Visitors.UML_Visitors.UML_Visitor'Class then
65         AMF.Visitors.UML_Visitors.UML_Visitor'Class
66          (Visitor).Enter_Substitution
67            (AMF.UML.Substitutions.UML_Substitution_Access (Self),
68           Control);
69      end if;
70   end Enter_Element;
71
72   -------------------
73   -- Leave_Element --
74   -------------------
75
76   overriding procedure Leave_Element
77    (Self    : not null access constant UML_Substitution_Proxy;
78     Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
79     Control : in out AMF.Visitors.Traverse_Control) is
80   begin
81      if Visitor in AMF.Visitors.UML_Visitors.UML_Visitor'Class then
82         AMF.Visitors.UML_Visitors.UML_Visitor'Class
83          (Visitor).Leave_Substitution
84            (AMF.UML.Substitutions.UML_Substitution_Access (Self),
85           Control);
86      end if;
87   end Leave_Element;
88
89   -------------------
90   -- Visit_Element --
91   -------------------
92
93   overriding procedure Visit_Element
94    (Self     : not null access constant UML_Substitution_Proxy;
95     Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
96     Visitor  : in out AMF.Visitors.Abstract_Visitor'Class;
97     Control  : in out AMF.Visitors.Traverse_Control) is
98   begin
99      if Iterator in AMF.Visitors.UML_Iterators.UML_Iterator'Class then
100         AMF.Visitors.UML_Iterators.UML_Iterator'Class
101          (Iterator).Visit_Substitution
102            (Visitor,
103             AMF.UML.Substitutions.UML_Substitution_Access (Self),
104             Control);
105      end if;
106   end Visit_Element;
107
108   ------------------
109   -- Get_Contract --
110   ------------------
111
112   overriding function Get_Contract
113    (Self : not null access constant UML_Substitution_Proxy)
114       return AMF.UML.Classifiers.UML_Classifier_Access is
115   begin
116      return
117        AMF.UML.Classifiers.UML_Classifier_Access
118         (AMF.Internals.Helpers.To_Element
119           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Contract
120             (Self.Element)));
121   end Get_Contract;
122
123   ------------------
124   -- Set_Contract --
125   ------------------
126
127   overriding procedure Set_Contract
128    (Self : not null access UML_Substitution_Proxy;
129     To   : AMF.UML.Classifiers.UML_Classifier_Access) is
130   begin
131      AMF.Internals.Tables.UML_Attributes.Internal_Set_Contract
132       (Self.Element,
133        AMF.Internals.Helpers.To_Element
134         (AMF.Elements.Element_Access (To)));
135   end Set_Contract;
136
137   ---------------------------------
138   -- Get_Substituting_Classifier --
139   ---------------------------------
140
141   overriding function Get_Substituting_Classifier
142    (Self : not null access constant UML_Substitution_Proxy)
143       return AMF.UML.Classifiers.UML_Classifier_Access is
144   begin
145      return
146        AMF.UML.Classifiers.UML_Classifier_Access
147         (AMF.Internals.Helpers.To_Element
148           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Substituting_Classifier
149             (Self.Element)));
150   end Get_Substituting_Classifier;
151
152   ---------------------------------
153   -- Set_Substituting_Classifier --
154   ---------------------------------
155
156   overriding procedure Set_Substituting_Classifier
157    (Self : not null access UML_Substitution_Proxy;
158     To   : AMF.UML.Classifiers.UML_Classifier_Access) is
159   begin
160      AMF.Internals.Tables.UML_Attributes.Internal_Set_Substituting_Classifier
161       (Self.Element,
162        AMF.Internals.Helpers.To_Element
163         (AMF.Elements.Element_Access (To)));
164   end Set_Substituting_Classifier;
165
166   -----------------
167   -- Get_Mapping --
168   -----------------
169
170   overriding function Get_Mapping
171    (Self : not null access constant UML_Substitution_Proxy)
172       return AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access is
173   begin
174      return
175        AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access
176         (AMF.Internals.Helpers.To_Element
177           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Mapping
178             (Self.Element)));
179   end Get_Mapping;
180
181   -----------------
182   -- Set_Mapping --
183   -----------------
184
185   overriding procedure Set_Mapping
186    (Self : not null access UML_Substitution_Proxy;
187     To   : AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access) is
188   begin
189      AMF.Internals.Tables.UML_Attributes.Internal_Set_Mapping
190       (Self.Element,
191        AMF.Internals.Helpers.To_Element
192         (AMF.Elements.Element_Access (To)));
193   end Set_Mapping;
194
195   ----------------
196   -- Get_Client --
197   ----------------
198
199   overriding function Get_Client
200    (Self : not null access constant UML_Substitution_Proxy)
201       return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
202   begin
203      return
204        AMF.UML.Named_Elements.Collections.Wrap
205         (AMF.Internals.Element_Collections.Wrap
206           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Client
207             (Self.Element)));
208   end Get_Client;
209
210   ------------------
211   -- Get_Supplier --
212   ------------------
213
214   overriding function Get_Supplier
215    (Self : not null access constant UML_Substitution_Proxy)
216       return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
217   begin
218      return
219        AMF.UML.Named_Elements.Collections.Wrap
220         (AMF.Internals.Element_Collections.Wrap
221           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Supplier
222             (Self.Element)));
223   end Get_Supplier;
224
225   ----------------
226   -- Get_Source --
227   ----------------
228
229   overriding function Get_Source
230    (Self : not null access constant UML_Substitution_Proxy)
231       return AMF.UML.Elements.Collections.Set_Of_UML_Element is
232   begin
233      return
234        AMF.UML.Elements.Collections.Wrap
235         (AMF.Internals.Element_Collections.Wrap
236           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Source
237             (Self.Element)));
238   end Get_Source;
239
240   ----------------
241   -- Get_Target --
242   ----------------
243
244   overriding function Get_Target
245    (Self : not null access constant UML_Substitution_Proxy)
246       return AMF.UML.Elements.Collections.Set_Of_UML_Element is
247   begin
248      return
249        AMF.UML.Elements.Collections.Wrap
250         (AMF.Internals.Element_Collections.Wrap
251           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Target
252             (Self.Element)));
253   end Get_Target;
254
255   -------------------------
256   -- Get_Related_Element --
257   -------------------------
258
259   overriding function Get_Related_Element
260    (Self : not null access constant UML_Substitution_Proxy)
261       return AMF.UML.Elements.Collections.Set_Of_UML_Element is
262   begin
263      return
264        AMF.UML.Elements.Collections.Wrap
265         (AMF.Internals.Element_Collections.Wrap
266           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Related_Element
267             (Self.Element)));
268   end Get_Related_Element;
269
270   ---------------------------
271   -- Get_Client_Dependency --
272   ---------------------------
273
274   overriding function Get_Client_Dependency
275    (Self : not null access constant UML_Substitution_Proxy)
276       return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency is
277   begin
278      return
279        AMF.UML.Dependencies.Collections.Wrap
280         (AMF.Internals.Element_Collections.Wrap
281           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Client_Dependency
282             (Self.Element)));
283   end Get_Client_Dependency;
284
285   -------------------------
286   -- Get_Name_Expression --
287   -------------------------
288
289   overriding function Get_Name_Expression
290    (Self : not null access constant UML_Substitution_Proxy)
291       return AMF.UML.String_Expressions.UML_String_Expression_Access is
292   begin
293      return
294        AMF.UML.String_Expressions.UML_String_Expression_Access
295         (AMF.Internals.Helpers.To_Element
296           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Name_Expression
297             (Self.Element)));
298   end Get_Name_Expression;
299
300   -------------------------
301   -- Set_Name_Expression --
302   -------------------------
303
304   overriding procedure Set_Name_Expression
305    (Self : not null access UML_Substitution_Proxy;
306     To   : AMF.UML.String_Expressions.UML_String_Expression_Access) is
307   begin
308      AMF.Internals.Tables.UML_Attributes.Internal_Set_Name_Expression
309       (Self.Element,
310        AMF.Internals.Helpers.To_Element
311         (AMF.Elements.Element_Access (To)));
312   end Set_Name_Expression;
313
314   -------------------
315   -- Get_Namespace --
316   -------------------
317
318   overriding function Get_Namespace
319    (Self : not null access constant UML_Substitution_Proxy)
320       return AMF.UML.Namespaces.UML_Namespace_Access is
321   begin
322      return
323        AMF.UML.Namespaces.UML_Namespace_Access
324         (AMF.Internals.Helpers.To_Element
325           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Namespace
326             (Self.Element)));
327   end Get_Namespace;
328
329   ------------------------
330   -- Get_Qualified_Name --
331   ------------------------
332
333   overriding function Get_Qualified_Name
334    (Self : not null access constant UML_Substitution_Proxy)
335       return AMF.Optional_String is
336   begin
337      declare
338         use type Matreshka.Internals.Strings.Shared_String_Access;
339
340         Aux : constant Matreshka.Internals.Strings.Shared_String_Access
341           := AMF.Internals.Tables.UML_Attributes.Internal_Get_Qualified_Name (Self.Element);
342
343      begin
344         if Aux = null then
345            return (Is_Empty => True);
346
347         else
348            return (False, League.Strings.Internals.Create (Aux));
349         end if;
350      end;
351   end Get_Qualified_Name;
352
353   -----------------------------------
354   -- Get_Owning_Template_Parameter --
355   -----------------------------------
356
357   overriding function Get_Owning_Template_Parameter
358    (Self : not null access constant UML_Substitution_Proxy)
359       return AMF.UML.Template_Parameters.UML_Template_Parameter_Access is
360   begin
361      return
362        AMF.UML.Template_Parameters.UML_Template_Parameter_Access
363         (AMF.Internals.Helpers.To_Element
364           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Owning_Template_Parameter
365             (Self.Element)));
366   end Get_Owning_Template_Parameter;
367
368   -----------------------------------
369   -- Set_Owning_Template_Parameter --
370   -----------------------------------
371
372   overriding procedure Set_Owning_Template_Parameter
373    (Self : not null access UML_Substitution_Proxy;
374     To   : AMF.UML.Template_Parameters.UML_Template_Parameter_Access) is
375   begin
376      AMF.Internals.Tables.UML_Attributes.Internal_Set_Owning_Template_Parameter
377       (Self.Element,
378        AMF.Internals.Helpers.To_Element
379         (AMF.Elements.Element_Access (To)));
380   end Set_Owning_Template_Parameter;
381
382   ----------------------------
383   -- Get_Template_Parameter --
384   ----------------------------
385
386   overriding function Get_Template_Parameter
387    (Self : not null access constant UML_Substitution_Proxy)
388       return AMF.UML.Template_Parameters.UML_Template_Parameter_Access is
389   begin
390      return
391        AMF.UML.Template_Parameters.UML_Template_Parameter_Access
392         (AMF.Internals.Helpers.To_Element
393           (AMF.Internals.Tables.UML_Attributes.Internal_Get_Template_Parameter
394             (Self.Element)));
395   end Get_Template_Parameter;
396
397   ----------------------------
398   -- Set_Template_Parameter --
399   ----------------------------
400
401   overriding procedure Set_Template_Parameter
402    (Self : not null access UML_Substitution_Proxy;
403     To   : AMF.UML.Template_Parameters.UML_Template_Parameter_Access) is
404   begin
405      AMF.Internals.Tables.UML_Attributes.Internal_Set_Template_Parameter
406       (Self.Element,
407        AMF.Internals.Helpers.To_Element
408         (AMF.Elements.Element_Access (To)));
409   end Set_Template_Parameter;
410
411   -------------------------
412   -- All_Owning_Packages --
413   -------------------------
414
415   overriding function All_Owning_Packages
416    (Self : not null access constant UML_Substitution_Proxy)
417       return AMF.UML.Packages.Collections.Set_Of_UML_Package is
418   begin
419      --  Generated stub: replace with real body!
420      pragma Compile_Time_Warning (Standard.True, "All_Owning_Packages unimplemented");
421      raise Program_Error with "Unimplemented procedure UML_Substitution_Proxy.All_Owning_Packages";
422      return All_Owning_Packages (Self);
423   end All_Owning_Packages;
424
425   -----------------------------
426   -- Is_Distinguishable_From --
427   -----------------------------
428
429   overriding function Is_Distinguishable_From
430    (Self : not null access constant UML_Substitution_Proxy;
431     N : AMF.UML.Named_Elements.UML_Named_Element_Access;
432     Ns : AMF.UML.Namespaces.UML_Namespace_Access)
433       return Boolean is
434   begin
435      --  Generated stub: replace with real body!
436      pragma Compile_Time_Warning (Standard.True, "Is_Distinguishable_From unimplemented");
437      raise Program_Error with "Unimplemented procedure UML_Substitution_Proxy.Is_Distinguishable_From";
438      return Is_Distinguishable_From (Self, N, Ns);
439   end Is_Distinguishable_From;
440
441   ---------------
442   -- Namespace --
443   ---------------
444
445   overriding function Namespace
446    (Self : not null access constant UML_Substitution_Proxy)
447       return AMF.UML.Namespaces.UML_Namespace_Access is
448   begin
449      --  Generated stub: replace with real body!
450      pragma Compile_Time_Warning (Standard.True, "Namespace unimplemented");
451      raise Program_Error with "Unimplemented procedure UML_Substitution_Proxy.Namespace";
452      return Namespace (Self);
453   end Namespace;
454
455   ------------------------
456   -- Is_Compatible_With --
457   ------------------------
458
459   overriding function Is_Compatible_With
460    (Self : not null access constant UML_Substitution_Proxy;
461     P : AMF.UML.Parameterable_Elements.UML_Parameterable_Element_Access)
462       return Boolean is
463   begin
464      --  Generated stub: replace with real body!
465      pragma Compile_Time_Warning (Standard.True, "Is_Compatible_With unimplemented");
466      raise Program_Error with "Unimplemented procedure UML_Substitution_Proxy.Is_Compatible_With";
467      return Is_Compatible_With (Self, P);
468   end Is_Compatible_With;
469
470   ---------------------------
471   -- Is_Template_Parameter --
472   ---------------------------
473
474   overriding function Is_Template_Parameter
475    (Self : not null access constant UML_Substitution_Proxy)
476       return Boolean is
477   begin
478      --  Generated stub: replace with real body!
479      pragma Compile_Time_Warning (Standard.True, "Is_Template_Parameter unimplemented");
480      raise Program_Error with "Unimplemented procedure UML_Substitution_Proxy.Is_Template_Parameter";
481      return Is_Template_Parameter (Self);
482   end Is_Template_Parameter;
483
484end AMF.Internals.UML_Substitutions;
485