summaryrefslogtreecommitdiffstats
path: root/src/mof/qmofnamespace.cpp
blob: 3a7fa758ab7a0c98dead5e9ce248ab1914b15c10 (plain)
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
/****************************************************************************
**
** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtMof module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmofnamespace.h"

#include <QtMof/QMofClass>
#include <QtMof/QMofComment>
#include <QtMof/QMofConstraint>
#include <QtMof/QMofElement>
#include <QtMof/QMofElementImport>
#include <QtMof/QMofPackageableElement>
#include <QtMof/QMofPackageImport>

#include <QtMof/QMofPackage>

QT_BEGIN_NAMESPACE

/*!
    \class QMofNamespace

    \inmodule QtMof

    \brief A namespace is an element in a model that contains a set of named elements that can be identified by name.

    \b {QMofNamespace is an abstract class.}
 */

/*!
    Creates a new QMofNamespace.
*/
QMofNamespace::QMofNamespace()
{
}

/*!
    Destroys the QMofNamespace.
 */
QMofNamespace::~QMofNamespace()
{
    QModelingElement::deleteQModelingObject();
}

/*!
    Returns a deep-copied clone of the QMofNamespace.
*/
QModelingElement *QMofNamespace::clone() const
{
    QMofNamespace *c = new QMofNamespace;
    foreach (QMofComment *element, ownedComments())
        c->addOwnedComment(dynamic_cast<QMofComment *>(element->clone()));
    c->setName(name());
    c->setVisibility(visibility());
    foreach (QMofElementImport *element, elementImports())
        c->addElementImport(dynamic_cast<QMofElementImport *>(element->clone()));
    foreach (QMofConstraint *element, ownedRules())
        c->addOwnedRule(dynamic_cast<QMofConstraint *>(element->clone()));
    foreach (QMofPackageImport *element, packageImports())
        c->addPackageImport(dynamic_cast<QMofPackageImport *>(element->clone()));
    return c;
}

// OWNED ATTRIBUTES

/*!
    References the ElementImports owned by the Namespace.

    \sa addElementImport(), removeElementImport()

    \b {Subsetted property(ies):} QMofElement::ownedElements().

    \b {Opposite property(ies):} QMofElementImport::importingNamespace().
 */
const QSet<QMofElementImport *> QMofNamespace::elementImports() const
{
    // This is a read-write association end

    return _elementImports;
}

/*!
    Adds \a elementImport to elementImports.

    \sa elementImports(), removeElementImport()
 */
void QMofNamespace::addElementImport(QMofElementImport *elementImport)
{
    // This is a read-write association end

    if (!_elementImports.contains(elementImport)) {
        _elementImports.insert(elementImport);
        if (elementImport && elementImport->asQModelingObject() && this->asQModelingObject())
            QObject::connect(elementImport->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeElementImport(QObject *)));
        elementImport->asQModelingObject()->setParent(this->asQModelingObject());

        // Adjust subsetted properties
        addOwnedElement(elementImport);

        // Adjust opposite properties
        if (elementImport) {
            elementImport->setImportingNamespace(this);
        }
    }
}

/*!
    Removes \a elementImport from elementImports.

    \sa elementImports(), addElementImport()
 */
void QMofNamespace::removeElementImport(QMofElementImport *elementImport)
{
    // This is a read-write association end

    if (_elementImports.contains(elementImport)) {
        _elementImports.remove(elementImport);
        if (elementImport->asQModelingObject())
            elementImport->asQModelingObject()->setParent(0);

        // Adjust subsetted properties
        removeOwnedElement(elementImport);

        // Adjust opposite properties
        if (elementImport) {
            elementImport->setImportingNamespace(0);
        }
    }
}

/*!
    References the PackageableElements that are members of this Namespace as a result of either PackageImports or ElementImports.

    \b {This is a read-only derived property.}

    \b {Subsetted property(ies):} QMofNamespace::members().
 */
const QSet<QMofPackageableElement *> QMofNamespace::importedMembers() const
{
    // This is a read-only derived association end

    QSet<QMofPackageableElement *> importedMembers_;
    foreach (QMofElementImport *elementImport, _elementImports)
        importedMembers_.insert(elementImport->importedElement());
    foreach (QMofPackageImport *packageImport, _packageImports)
        if (packageImport->importedPackage())
            importedMembers_.unite(packageImport->importedPackage()->packagedElements());
    return importedMembers_;
}

/*!
    Adds \a importedMember to importedMembers.

    \sa importedMembers(), removeImportedMember()
 */
void QMofNamespace::addImportedMember(QMofPackageableElement *importedMember)
{
    // This is a read-only derived association end

    qWarning("QMofNamespace::addImportedMember(): to be implemented (this is a derived association end)");
    Q_UNUSED(importedMember);

    if (false /* <derivedexclusion-criteria> */) {
        // <derived-code>

        // Adjust subsetted properties
        addMember(importedMember);
    }
}

/*!
    Removes \a importedMember from importedMembers.

    \sa importedMembers(), addImportedMember()
 */
void QMofNamespace::removeImportedMember(QMofPackageableElement *importedMember)
{
    // This is a read-only derived association end

    qWarning("QMofNamespace::removeImportedMember(): to be implemented (this is a derived association end)");
    Q_UNUSED(importedMember);

    if (false /* <derivedexclusion-criteria> */) {
        // <derived-code>

        // Adjust subsetted properties
        removeMember(importedMember);
    }
}

/*!
    A collection of NamedElements identifiable within the Namespace, either by being owned or by being introduced by importing or inheritance.

    \b {This is a read-only derived union property.}
 */
const QSet<QMofNamedElement *> QMofNamespace::members() const
{
    // This is a read-only derived union association end

    return _members;
}

/*!
    Adds \a member to members.

    \sa members(), removeMember()
 */
void QMofNamespace::addMember(QMofNamedElement *member)
{
    // This is a read-only derived union association end

    if (!_members.contains(member)) {
        _members.insert(member);
        if (member && member->asQModelingObject() && this->asQModelingObject())
            QObject::connect(member->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeMember(QObject *)));
    }
}

/*!
    Removes \a member from members.

    \sa members(), addMember()
 */
void QMofNamespace::removeMember(QMofNamedElement *member)
{
    // This is a read-only derived union association end

    if (_members.contains(member)) {
        _members.remove(member);
    }
}

/*!
    A collection of NamedElements owned by the Namespace.

    \b {This is a read-only derived union property.}

    \b {Subsetted property(ies):} QMofElement::ownedElements(), QMofNamespace::members().

    \b {Opposite property(ies):} QMofNamedElement::namespace_().
 */
const QSet<QMofNamedElement *> QMofNamespace::ownedMembers() const
{
    // This is a read-only derived union association end

    return _ownedMembers;
}

/*!
    Adds \a ownedMember to ownedMembers.

    \sa ownedMembers(), removeOwnedMember()
 */
void QMofNamespace::addOwnedMember(QMofNamedElement *ownedMember)
{
    // This is a read-only derived union association end

    if (!_ownedMembers.contains(ownedMember)) {
        _ownedMembers.insert(ownedMember);
        if (ownedMember && ownedMember->asQModelingObject() && this->asQModelingObject())
            QObject::connect(ownedMember->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeOwnedMember(QObject *)));
        ownedMember->asQModelingObject()->setParent(this->asQModelingObject());

        // Adjust subsetted properties
        addOwnedElement(ownedMember);
        addMember(ownedMember);

        // Adjust opposite properties
        if (ownedMember) {
            ownedMember->setNamespace(this);
        }
    }
}

/*!
    Removes \a ownedMember from ownedMembers.

    \sa ownedMembers(), addOwnedMember()
 */
void QMofNamespace::removeOwnedMember(QMofNamedElement *ownedMember)
{
    // This is a read-only derived union association end

    if (_ownedMembers.contains(ownedMember)) {
        _ownedMembers.remove(ownedMember);
        if (ownedMember->asQModelingObject())
            ownedMember->asQModelingObject()->setParent(0);

        // Adjust subsetted properties
        removeOwnedElement(ownedMember);
        removeMember(ownedMember);

        // Adjust opposite properties
        if (ownedMember) {
            ownedMember->setNamespace(0);
        }
    }
}

/*!
    Specifies a set of Constraints owned by this Namespace.

    \sa addOwnedRule(), removeOwnedRule()

    \b {Subsetted property(ies):} QMofNamespace::ownedMembers().

    \b {Opposite property(ies):} QMofConstraint::context().
 */
const QSet<QMofConstraint *> QMofNamespace::ownedRules() const
{
    // This is a read-write association end

    return _ownedRules;
}

/*!
    Adds \a ownedRule to ownedRules.

    \sa ownedRules(), removeOwnedRule()
 */
void QMofNamespace::addOwnedRule(QMofConstraint *ownedRule)
{
    // This is a read-write association end

    if (!_ownedRules.contains(ownedRule)) {
        _ownedRules.insert(ownedRule);
        if (ownedRule && ownedRule->asQModelingObject() && this->asQModelingObject())
            QObject::connect(ownedRule->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeOwnedRule(QObject *)));
        ownedRule->asQModelingObject()->setParent(this->asQModelingObject());

        // Adjust subsetted properties
        addOwnedMember(ownedRule);

        // Adjust opposite properties
        if (ownedRule) {
            ownedRule->setContext(this);
        }
    }
}

/*!
    Removes \a ownedRule from ownedRules.

    \sa ownedRules(), addOwnedRule()
 */
void QMofNamespace::removeOwnedRule(QMofConstraint *ownedRule)
{
    // This is a read-write association end

    if (_ownedRules.contains(ownedRule)) {
        _ownedRules.remove(ownedRule);
        if (ownedRule->asQModelingObject())
            ownedRule->asQModelingObject()->setParent(0);

        // Adjust subsetted properties
        removeOwnedMember(ownedRule);

        // Adjust opposite properties
        if (ownedRule) {
            ownedRule->setContext(0);
        }
    }
}

/*!
    References the PackageImports owned by the Namespace.

    \sa addPackageImport(), removePackageImport()

    \b {Subsetted property(ies):} QMofElement::ownedElements().

    \b {Opposite property(ies):} QMofPackageImport::importingNamespace().
 */
const QSet<QMofPackageImport *> QMofNamespace::packageImports() const
{
    // This is a read-write association end

    return _packageImports;
}

/*!
    Adds \a packageImport to packageImports.

    \sa packageImports(), removePackageImport()
 */
void QMofNamespace::addPackageImport(QMofPackageImport *packageImport)
{
    // This is a read-write association end

    if (!_packageImports.contains(packageImport)) {
        _packageImports.insert(packageImport);
        if (packageImport && packageImport->asQModelingObject() && this->asQModelingObject())
            QObject::connect(packageImport->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removePackageImport(QObject *)));
        packageImport->asQModelingObject()->setParent(this->asQModelingObject());

        // Adjust subsetted properties
        addOwnedElement(packageImport);

        // Adjust opposite properties
        if (packageImport) {
            packageImport->setImportingNamespace(this);
        }
    }
}

/*!
    Removes \a packageImport from packageImports.

    \sa packageImports(), addPackageImport()
 */
void QMofNamespace::removePackageImport(QMofPackageImport *packageImport)
{
    // This is a read-write association end

    if (_packageImports.contains(packageImport)) {
        _packageImports.remove(packageImport);
        if (packageImport->asQModelingObject())
            packageImport->asQModelingObject()->setParent(0);

        // Adjust subsetted properties
        removeOwnedElement(packageImport);

        // Adjust opposite properties
        if (packageImport) {
            packageImport->setImportingNamespace(0);
        }
    }
}

// OPERATIONS

/*!
    The query excludeCollisions() excludes from a set of PackageableElements any that would not be distinguishable from each other in this namespace.
 */
QSet<QMofPackageableElement *> QMofNamespace::excludeCollisions(QMofPackageableElement *imps) const
{
    qWarning("QMofNamespace::excludeCollisions(): to be implemented (operation)");

    Q_UNUSED(imps);
    return QSet<QMofPackageableElement *> ();
}

/*!
    The query getNamesOfMember() gives a set of all of the names that a member would have in a Namespace. In general a member can have multiple names in a Namespace if it is imported more than once with different aliases. The query takes account of importing. It gives back the set of names that an element would have in an importing namespace, either because it is owned, or if not owned then imported individually, or if not individually then from a package.
 */
QSet<QString> QMofNamespace::getNamesOfMember(QMofNamedElement *element) const
{
    qWarning("QMofNamespace::getNamesOfMember(): to be implemented (operation)");

    Q_UNUSED(element);
    return QSet<QString> ();
}

/*!
    The query importMembers() defines which of a set of PackageableElements are actually imported into the namespace. This excludes hidden ones, i.e., those which have names that conflict with names of owned members, and also excludes elements which would have the same name when imported.
 */
QSet<QMofPackageableElement *> QMofNamespace::importMembers(QMofPackageableElement *imps) const
{
    qWarning("QMofNamespace::importMembers(): to be implemented (operation)");

    Q_UNUSED(imps);
    return QSet<QMofPackageableElement *> ();
}

/*!
    The Boolean query membersAreDistinguishable() determines whether all of the namespace's members are distinguishable within it.
 */
bool QMofNamespace::membersAreDistinguishable() const
{
    qWarning("QMofNamespace::membersAreDistinguishable(): to be implemented (operation)");

    return bool ();
}

QT_END_NAMESPACE