1
2
3
4
5 package org.andromda.metafacades.uml14;
6
7 import java.util.Collection;
8 import org.andromda.core.metafacade.MetafacadeBase;
9 import org.andromda.core.metafacade.ModelValidationMessage;
10 import org.andromda.metafacades.uml.Role;
11 import org.andromda.translation.ocl.validation.OCLCollections;
12 import org.andromda.translation.ocl.validation.OCLIntrospector;
13 import org.andromda.translation.ocl.validation.OCLResultEnsurer;
14 import org.apache.commons.collections.Transformer;
15 import org.apache.log4j.Logger;
16 import org.omg.uml.behavioralelements.usecases.Actor;
17
18
19
20
21
22
23
24
25 public abstract class RoleLogic
26 extends ActorFacadeLogicImpl
27 implements Role
28 {
29
30
31
32
33 protected Object metaObject;
34
35
36
37
38
39 protected RoleLogic(Object metaObjectIn, String context)
40 {
41 super((Actor)metaObjectIn, getContext(context));
42 this.metaObject = metaObjectIn;
43 }
44
45
46
47
48 private static final Logger logger = Logger.getLogger(RoleLogic.class);
49
50
51
52
53
54
55 private static String getContext(String context)
56 {
57 if (context == null)
58 {
59 context = "org.andromda.metafacades.uml.Role";
60 }
61 return context;
62 }
63
64
65
66
67 @Override
68 public void resetMetafacadeContext(String context)
69 {
70 if (!this.contextRoot)
71 {
72 context = getContext(context);
73 setMetafacadeContext (context);
74 }
75 }
76
77
78
79
80
81 public boolean isRoleMetaType()
82 {
83 return true;
84 }
85
86
87
88
89
90
91
92 protected abstract boolean handleIsReferencesPresent();
93
94 private boolean __referencesPresent1a;
95 private boolean __referencesPresent1aSet = false;
96
97
98
99
100
101
102 public final boolean isReferencesPresent()
103 {
104 boolean referencesPresent1a = this.__referencesPresent1a;
105 if (!this.__referencesPresent1aSet)
106 {
107
108 referencesPresent1a = handleIsReferencesPresent();
109
110 this.__referencesPresent1a = referencesPresent1a;
111 if (isMetafacadePropertyCachingEnabled())
112 {
113 this.__referencesPresent1aSet = true;
114 }
115 }
116 return referencesPresent1a;
117 }
118
119
120
121
122
123
124
125
126
127
128 @Override
129 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
130 {
131 super.validateInvariants(validationMessages);
132 try
133 {
134 final Object contextElement = this.THIS();
135 boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"name"))&&OCLCollections.isUnique(OCLIntrospector.invoke(contextElement,"model.allActors"),new Transformer(){public Object transform(Object object){return OCLIntrospector.invoke(object,"name");}}));
136 if (!constraintValid)
137 {
138 validationMessages.add(
139 new ModelValidationMessage(
140 (MetafacadeBase)contextElement ,
141 "org::andromda::metafacades::uml::Role::non-empty unique role name",
142 "Each role must have a non-empty name that is unique among all other roles."));
143 }
144 }
145 catch (Throwable th)
146 {
147 Throwable cause = th.getCause();
148 int depth = 0;
149 while (cause != null && depth < 7)
150 {
151 th = cause;
152 depth++;
153 }
154 logger.error("Error validating constraint 'org::andromda::metafacades::uml::Role::non-empty unique role name' ON "
155 + this.THIS().toString() + ": " + th.getMessage(), th);
156 }
157 }
158 }