1 package org.andromda.metafacades.uml14;
2
3 import java.util.List;
4 import org.andromda.metafacades.uml.AssociationEndFacade;
5 import org.andromda.metafacades.uml.MetafacadeUtils;
6 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
7 import org.apache.commons.lang.StringUtils;
8 import org.omg.uml.foundation.core.AssociationClass;
9 import org.omg.uml.foundation.core.AssociationEnd;
10 import org.omg.uml.foundation.core.UmlAssociation;
11
12
13
14
15
16 public class AssociationFacadeLogicImpl
17 extends AssociationFacadeLogic
18 {
19 private static final long serialVersionUID = 34L;
20
21
22
23
24 public AssociationFacadeLogicImpl(
25 UmlAssociation metaObject,
26 String context)
27 {
28 super(metaObject, context);
29 }
30
31
32
33
34 @Override
35 public List<AssociationEnd> handleGetAssociationEnds()
36 {
37 return metaObject.getConnection();
38 }
39
40
41
42
43 public String handleGetName()
44 {
45 String name = super.handleGetName();
46
47
48 if (StringUtils.isEmpty(name))
49 {
50 name = this.handleGetRelationName();
51 }
52 return name;
53 }
54
55
56
57
58 @Override
59 public String handleGetRelationName()
60 {
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 final AssociationEndFacade firstEnd = this.getAssociationEndA();
79 final AssociationEndFacade secondEnd = this.getAssociationEndB();
80
81 final String nameA = firstEnd==null ? "" :firstEnd.getName();
82 final String nameB = secondEnd==null ? "" : secondEnd.getName();
83
84 return MetafacadeUtils.toRelationName(
85 nameA,
86 nameB,
87 String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.RELATION_NAME_SEPARATOR)));
88 }
89
90
91
92
93 @Override
94 protected boolean handleIsMany2Many()
95 {
96 return (this.getAssociationEnds().iterator().next()).isMany2Many();
97 }
98
99
100
101
102 @Override
103 protected boolean handleIsAssociationClass()
104 {
105 return AssociationClass.class.isAssignableFrom(this.metaObject.getClass());
106 }
107
108
109
110
111 @Override
112 protected AssociationEnd handleGetAssociationEndA()
113 {
114 List<AssociationEnd> ends = this.handleGetAssociationEnds();
115 if (!ends.isEmpty())
116 {
117 return ends.get(0);
118 }
119 else
120 {
121 return null;
122 }
123 }
124
125
126
127
128 @Override
129 protected AssociationEnd handleGetAssociationEndB()
130 {
131 List<AssociationEnd> ends = this.handleGetAssociationEnds();
132 if (ends.size()>1)
133 {
134 return ends.get(1);
135 }
136 else
137 {
138 return null;
139 }
140 }
141
142
143
144
145 @Override
146 protected boolean handleIsAbstract()
147 {
148 return this.metaObject.isAbstract();
149 }
150
151
152
153
154
155
156 @Override
157 protected boolean handleIsBinary()
158 {
159 return true;
160 }
161
162
163
164
165
166
167 @Override
168 protected boolean handleIsDerived()
169 {
170 return false;
171 }
172
173
174
175
176 @Override
177 protected boolean handleIsLeaf()
178 {
179 return this.metaObject.isLeaf();
180 }
181 }