File: UmlRelation.cpp

package info (click to toggle)
bouml 4.21-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 73,336 kB
  • ctags: 55,459
  • sloc: cpp: 290,644; makefile: 228; sh: 13
file content (300 lines) | stat: -rw-r--r-- 6,396 bytes parent folder | download
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

#include "UmlRelation.h"
#include "UmlClass.h"
#include "File.h"

#include "UmlCom.h"
#include "CppSettings.h"
#include "JavaSettings.h"
#include "IdlSettings.h"
void UmlRelation::Role::import(File & f) {
  f.read("(");
  f.read("object");
  f.read("Role");
  if (f.read(name) != STRING)
    f.syntaxError(name, "role name");
    if (*name == '$')
      // unnamed
      name = "";

  visibility = PublicVisibility;
  is_navigable = FALSE;
  is_aggregate = FALSE;
  is_static = FALSE;
  is_byvalue = FALSE;
  
  QCString ste; 
  QCString s;
  int k; 
     
  do { 
    k = f.readDefinitionBeginning(s, id, ste, doc, prop); 
  } while (id.isEmpty()); 
  
  for (;;) {
    switch (k) {
    case ')':
      target = 0;
      return;
    case ATOM:
      break;
    default:
      f.syntaxError(s);
    }
    
    // atom
    if (s == "quid") {
      if (f.read(id) != STRING)
	f.syntaxError(id, "quid value");
    }
    else if (s == "quidu") {
      if (f.read(target_id) != STRING)
	f.syntaxError(target_id, "quidu value");
      target = (UmlClass *) UmlItem::findItem(target_id, aClass);
    }
    else if (s == "client_cardinality") {
      f.read("(");
      f.read("value");
      f.read("cardinality");
      if (f.read(cardinality) != STRING)
	f.syntaxError(cardinality, "the cardinality");
      f.read(")");
    }
    else if (s == "exportControl")
      visibility = f.readVisibility();
    else if (s == "is_navigable") 
      is_navigable = f.readBool(); 
    else if (s == "is_aggregate") 
      is_aggregate = f.readBool(); 
    else if (s == "Containment") {
      if (f.read(s) != STRING)
        f.syntaxError(s, "containment value");
      is_byvalue = (s == "By Value");
    }
    else if (s == "static")
      is_static = f.readBool();
    else
      f.skipNextForm();

    k = f.read(s);
  }
}

aRelationKind UmlRelation::Role::rel_kind(bool bidir) {
  if (bidir) {
    if (is_byvalue)
      return anAggregationByValue;
    if (is_aggregate)
      return anAggregation;
    return anAssociation;
  }
  
  if (is_byvalue)
    return aDirectionalAggregationByValue;
  if (is_aggregate)
    return aDirectionalAggregation;
  return aDirectionalAssociation;
}

void UmlRelation::import(File & f)
{
  if (scanning)
    f.skipBlock();
  else {
    QCString s;
    
    if (f.read(s) != STRING)
      f.syntaxError(s, "relation's name");
    else if (*s == '$')
      // unnamed
      s = "";
    
    QCString id;
    QCString ste;
    QCString doc;
    QDict<QCString> prop;
    QCString s2;
    int k;
    
    do {
      k = f.readDefinitionBeginning(s2, id, ste, doc, prop);
    } while (id.isEmpty());
    
    for (;;) {
      if (k == ATOM) {
	if (s2 == "roles")
	  break;
	f.skipNextForm();
	k = f.read(s2);
      }
      else
	f.syntaxError(s);
    }
    
    f.read("(");
    f.read("list");
    f.read("role_list");
    
    Role role_1; 
    Role role_2; 
    Role * role1 = &role_1; 
    Role * role2 = &role_2; 
    
    role_1.import(f);
    role_2.import(f);
    
    UmlRelation * r = 0; 
    bool bidir = role_1.is_navigable && role_2.is_navigable;

    // place information in the logical side !
    bool b = role_1.is_aggregate;

    role_1.is_aggregate = role_2.is_aggregate;
    role_2.is_aggregate = b;

    role_1.is_aggregate |= role_1.is_byvalue;
    role_2.is_aggregate |= role_2.is_byvalue;

    if (bidir && role_2.is_aggregate) {
      // manage bouml limitation : only role1 may be an aggregate
      if (role_1.is_aggregate)
        bidir = FALSE;
      else {
	// exchange roles
	role1 = &role_2;
	role2 = &role_1;
      }
    }

    if ((role1->target != 0) && (role2->target != 0)) { 
      if (role1->is_navigable) {
	r = UmlRelation::create(role1->rel_kind(bidir), role2->target, role1->target);
	
	if (r == 0) {
	  UmlCom::trace("<br>cannot create relation '" + role1->name + "' from '" +
			role2->target->fullName() + "' to '" +
			role1->target->fullName() + "'");
	  f.read(")");
	  f.skipBlock();
	  return;
	}
	
	if (!ste.isEmpty())
	  r->set_Stereotype(ste);
	
	if (! s.isEmpty())
	  r->set_Name(s);
	
	r->import(role1);
      }
      
      if (role2->is_navigable) {
	if (bidir) {
	  const QVector<UmlItem> ch = role2->target->children();
	  
	  r = (UmlRelation *) ch.at(ch.count() - 1);
	}
	else {
	  r = UmlRelation::create(role2->rel_kind(FALSE),role1->target, role2->target);
	  
	  if (r == 0) {
	    UmlCom::trace("<br>cannot create relation '" + role2->name +
			  "' from '" +
			  role1->target->fullName() + "' to '" +
			  role2->target->fullName() + "'");
	    f.read(")");
	    f.skipBlock();
	    return;
	  }
	  
	  if (!ste.isEmpty())
	    r->set_Stereotype(ste);
	   
	  if (! s.isEmpty()) 
	    r->set_Name(s); 
	}
	  
	r->import(role2);
      }
    }

    f.read(")");
    f.skipBlock();
  }
}

void UmlRelation::import(UmlRelation::Role * role) {
  if (!role->doc.isEmpty())
    set_Description(role->doc);
  
  if (! role->cardinality.isEmpty())
    set_Multiplicity(role->cardinality);
  
  if (role->is_static)
    set_isClassMember(TRUE);
  
  if (!role->name.isEmpty())
    set_RoleName(role->name);
  
  set_Visibility(role->visibility);
  
  switch (((UmlClass *) parent())->language()) {
  case Cplusplus:
  case AnsiCplusplus:
  case VCplusplus:
    cplusplus(role);
    break;
  case Oracle8:
    oracle8(role);
    break;
  case Corba:
    corba(role);
    break;
  case Java:
    java(role);
    break;
  default:
    break;
  }
  
  setProperties(role->prop);
}

void UmlRelation::cplusplus(UmlRelation::Role * role) {
  set_CppDecl(CppSettings::relationDecl(role->is_byvalue,
					role->cardinality));
}

void UmlRelation::oracle8(UmlRelation::Role *) {
}

void UmlRelation::corba(UmlRelation::Role * role) {
  set_IdlDecl(IdlSettings::relationDecl(role->cardinality));
}

void UmlRelation::java(UmlRelation::Role * role) {
  QCString * v;
    
  if ((v = role->prop.find("Java/Final")) != 0) {
    if (*v == "TRUE")
      set_isReadOnly(TRUE);
    role->prop.remove("Java/Final");
  }

  if ((v = role->prop.find("Java/Transient")) != 0) {
    if (*v == "TRUE")
      set_isJavaTransient(TRUE);
    role->prop.remove("Java/Transient");
  }

  if ((v = role->prop.find("Java/Volatile")) != 0) {
    if (*v == "TRUE")
      set_isVolatile(TRUE);
    role->prop.remove("Java/Volatile");
  }

  role->prop.remove("Java/IsNavigable");

  set_JavaDecl(JavaSettings::relationDecl(role->cardinality));
}