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