-
Notifications
You must be signed in to change notification settings - Fork 85
/
ComponentExchangesCreator.java
173 lines (159 loc) · 7.32 KB
/
ComponentExchangesCreator.java
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
/*******************************************************************************
* Copyright (c) 2006, 2020 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.projection.exchanges;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.polarsys.capella.common.data.modellingcore.InformationsExchanger;
import org.polarsys.capella.common.data.modellingcore.TraceableElement;
import org.polarsys.capella.common.platform.sirius.ted.SemanticEditingDomainFactory.SemanticEditingDomain;
import org.polarsys.capella.common.tools.report.EmbeddedMessage;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.cs.CsFactory;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.cs.PhysicalLink;
import org.polarsys.capella.core.data.cs.PhysicalPort;
import org.polarsys.capella.core.data.ctx.SystemComponent;
import org.polarsys.capella.core.data.fa.ComponentExchange;
import org.polarsys.capella.core.data.fa.ComponentExchangeAllocation;
import org.polarsys.capella.core.data.fa.ComponentPortAllocation;
import org.polarsys.capella.core.data.fa.FaFactory;
import org.polarsys.capella.core.data.information.AbstractEventOperation;
import org.polarsys.capella.core.data.la.LogicalComponent;
import org.polarsys.capella.core.model.helpers.CapellaElementExt;
import org.polarsys.capella.core.model.helpers.PhysicalLinkExt;
/**
* This class is the <code>IExchangesCreator</code> implementation specific to node physical components.<br>
* This implementation creates physical links.
*/
public class ComponentExchangesCreator extends DefaultExchangesCreator {
/**
* Constructor
*
* @param component_p
*/
public ComponentExchangesCreator(Component component_p, Part part_p) {
super(component_p);
}
/**
* This implementation creates physical links.
*
* @see org.polarsys.capella.core.projection.commands.utils.DefaultExchangesCreator#createExchanges()
*/
@Override
public void createExchanges() {
if ((_component instanceof LogicalComponent) || (_component instanceof SystemComponent)) {
super.createExchanges();
}
}
/**
* @see org.polarsys.capella.core.projection.exchanges.DefaultExchangesCreator#isValidCreation(org.polarsys.capella.core.data.fa.FunctionalExchange,
* org.polarsys.capella.core.data.cs.Component, org.polarsys.capella.core.data.cs.Component)
*/
@Override
protected boolean isValidCreation(AbstractEventOperation fe_p, Component component_p, Component allocating_p) {
return isValidBound(component_p) && isValidBound(allocating_p);
}
/**
* Create a physical link corresponding to the given component exchange, between the given components
*
* @param componentExchange_p
* the source component exchange
* @param exchangeOutput_p
* the output component
* @param exchangeInput_p
* the input component
*/
protected void doCreatePhysicalLink(ComponentExchange componentExchange_p, Component exchangeOutput_p,
Component exchangeInput_p) {
// Precondition:
if (exchangeOutput_p == exchangeInput_p) {
// Not necessary to create a physical link for exchanges inside the
// same container.
return;
}
PhysicalLink physicalLink = CsFactory.eINSTANCE.createPhysicalLink(componentExchange_p.getLabel());
PhysicalPort outP = CsFactory.eINSTANCE.createPhysicalPort(componentExchange_p.getSource().getLabel());
PhysicalPort inP = CsFactory.eINSTANCE.createPhysicalPort(componentExchange_p.getTarget().getLabel());
physicalLink.getLinkEnds().add(outP);
physicalLink.getLinkEnds().add(inP);
exchangeInput_p.getOwnedFeatures().add(inP);
exchangeOutput_p.getOwnedFeatures().add(outP);
CapellaElementExt.creationService(inP);
CapellaElementExt.creationService(outP);
PhysicalLinkExt.attachToDefaultContainer(physicalLink);
CapellaElementExt.creationService(physicalLink);
// Creates the exchange allocation
ComponentExchangeAllocation cea = FaFactory.eINSTANCE.createComponentExchangeAllocation();
cea.setSourceElement(physicalLink);
cea.setTargetElement(componentExchange_p);
physicalLink.getOwnedComponentExchangeAllocations().add(cea);
CapellaElementExt.creationService(cea);
// source side delegation
InformationsExchanger target = componentExchange_p.getTarget();
createComponentPortAllocation(target, inP);
// target side Delegation
InformationsExchanger source = componentExchange_p.getSource();
createComponentPortAllocation(source, outP);
String message = "The Physical link " + physicalLink.getName() + " has been succefully created between the source "
+ exchangeInput_p.getLabel() + " and the target " + exchangeOutput_p.getLabel();
EmbeddedMessage eMessage = new EmbeddedMessage(message, logger.getName(),
Arrays.asList(physicalLink, exchangeInput_p, exchangeOutput_p));
logger.info(eMessage);
}
/**
* @param informationExchange_p
* @param physicalPort_p
* @param connection_p
*/
private ComponentPortAllocation createComponentPortAllocation(InformationsExchanger informationExchange_p,
PhysicalPort physicalPort_p) {
ComponentPortAllocation allocation = FaFactory.eINSTANCE.createComponentPortAllocation();
allocation.setSourceElement(physicalPort_p);
allocation.setTargetElement((TraceableElement) informationExchange_p);
physicalPort_p.getOwnedComponentPortAllocations().add(allocation);
CapellaElementExt.creationService(allocation);
return allocation;
}
/**
* This method allows to know if the given component exchange has already been allocated to a physical link linked to
* the given physical component.
*
* @param physicalComponent_p
* the physical component
* @param componentExchange_p
* the component exchange
* @return true if its has already been allocated, false otherwise
*/
protected boolean doesNodeAlreadyHaveAPhysicalLinkForComponentExchange(Component physicalComponent_p,
ComponentExchange componentExchange_p) {
boolean result = false;
// Get the semantic editing domain to access the cross referencer.
SemanticEditingDomain editingDomain = (SemanticEditingDomain) AdapterFactoryEditingDomain
.getEditingDomainFor(componentExchange_p);
// Get the cross referencer.
ECrossReferenceAdapter crossReferencer = editingDomain.getCrossReferencer();
// Search inverses relations on given component exchange.
Collection<Setting> inverseReferences = crossReferencer.getInverseReferences(componentExchange_p, true);
for (Setting setting : inverseReferences) {
// Search for a relation targeting the ComponentExchangeAllocation metaclass.
if (setting.getEObject() instanceof ComponentExchangeAllocation) {
result = true;
break;
}
}
return result;
}
}