| |
---|
| | import models.dataConstraintModel.Selector; |
---|
| | import models.dataFlowModel.DataTransferChannel; |
---|
| | |
---|
| | public class Event { |
---|
| | private DataTransferChannel channel; |
---|
| | private ChannelState channelState; |
---|
| | private Expression message; |
---|
| | private boolean isInput = false; |
---|
| | private ResourcePath inputResourcePath = null; |
---|
| | |
---|
| | private Map<Selector, Constant> channelParameters = new HashMap<>(); |
---|
| | private Set<Resource> inputResources; |
---|
| | private Set<Resource> outputResources; |
---|
| | private Map<Expression, Expression> dependentParameters = new HashMap<>(); |
---|
| | private Set<Resource> inputResources = new HashSet<>(); |
---|
| | private Set<Resource> outputResources = new HashSet<>(); |
---|
| | private Set<Event> succEvents = new HashSet<>(); |
---|
| | private Map<Selector, Map<ResourcePath, Integer>> channelSelectorToInputResourcePathParam = new HashMap<>(); |
---|
| | private Map<Selector, Map<ResourcePath, Integer>> channelSelectorToOutputResourcePathParam = new HashMap<>(); |
---|
| | |
---|
| | public Event(DataTransferChannel channel, ChannelState channelState, Expression message, Resource outputResource) { |
---|
| | this.channel = channel; |
---|
| | public Event(ChannelState channelState, Expression message, Resource outputResource) { |
---|
| | this.channelState = channelState; |
---|
| | this.message = message; |
---|
| | this.isInput = true; |
---|
| | this.outputResources.add(outputResource); |
---|
| | connectChannelSelectorAndPathParameters(); |
---|
| | |
---|
| | // Extract channel parameters from the output resource. |
---|
| | DataTransferChannel channel = channelState.getChannel(); |
---|
| | List<Selector> channelSelectors = channel.getAllSelectors(); |
---|
| | Set<ResourcePath> outputResPathSet = null; |
---|
| | for (Selector sel: channelSelectors) { |
---|
| | if (outputResPathSet == null) { |
---|
| |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | public Event(DataTransferChannel channel, ChannelState channelState, ResourcePath inputResPath, Resource inputResource) { |
---|
| | this.channel = channel; |
---|
| | public Event(ChannelState channelState, ResourcePath inputResPath, Resource inputResource) { |
---|
| | this.channelState = channelState; |
---|
| | this.isInput = false; |
---|
| | this.inputResourcePath = inputResPath; |
---|
| | this.inputResources.add(inputResource); |
---|
| | connectChannelSelectorAndPathParameters(); |
---|
| | |
---|
| | // Extract channel parameters from the input resource. |
---|
| | DataTransferChannel channel = channelState.getChannel(); |
---|
| | List<Selector> channelSelectors = channel.getAllSelectors(); |
---|
| | for (Selector sel: channelSelectors) { |
---|
| | if (inputResPath != null) { |
---|
| | int paramIdx = channelSelectorToInputResourcePathParam.get(sel).get(inputResPath); |
---|
| |
---|
| | } |
---|
| | channelParameters.put(sel, ancestor.getParameter()); |
---|
| | } |
---|
| | } |
---|
| | channelParameters.putAll(channelState.getDependentParams(channelParameters)); |
---|
| | updateAllDependentParameters(channelState); |
---|
| | } |
---|
| | |
---|
| | private void connectChannelSelectorAndPathParameters() { |
---|
| | DataTransferChannel channel = channelState.getChannel(); |
---|
| | List<Selector> channelSelectors = channel.getAllSelectors(); |
---|
| | for (Selector sel: channelSelectors) { |
---|
| | for (ResourcePath resPath: channel.getInputResources()) { |
---|
| | int paramIdx = resPath.getPathParams().indexOf(sel.getExpression()); |
---|
| |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |
---|
| | public DataTransferChannel getChannel() { |
---|
| | return channel; |
---|
| | return channelState.getChannel(); |
---|
| | } |
---|
| | |
---|
| | public ChannelState getChannelState() { |
---|
| | return channelState; |
---|
| | } |
---|
| | |
---|
| | public Expression getMessage() { |
---|
| | return message; |
---|
| |
---|
| | public boolean isInput() { |
---|
| | return isInput; |
---|
| | } |
---|
| | |
---|
| | public Map<Selector, Constant> getChannelParameters() { |
---|
| | return channelParameters; |
---|
| | } |
---|
| | |
---|
| | public void updateDependentParameter(Expression variable, Expression value) { |
---|
| | dependentParameters.put(variable, value); |
---|
| | } |
---|
| | |
---|
| | public void updateAllDependentParameters(ChannelState channelState) { |
---|
| | dependentParameters.putAll(channelState.getDependentParams(channelParameters)); |
---|
| | } |
---|
| | |
---|
| | public ResourcePath getInputResourcePath() { |
---|
| | return inputResourcePath; |
---|
| | } |
---|
| | |
---|
| | public Set<Resource> getInputResources() { |
---|
| | return inputResources; |
---|
| | } |
---|
| | |
---|
| |
---|
| | for (Selector sel: channelParameters.keySet()) { |
---|
| | int paramIdx = channelSelectorToInputResourcePathParam.get(sel).get(inputResPath); |
---|
| | resId.setPathParam(paramIdx, channelParameters.get(sel)); |
---|
| | } |
---|
| | for (Expression var: dependentParameters.keySet()) { |
---|
| | int paramIdx = resId.getPathParams().indexOf(var); |
---|
| | if (paramIdx >= 0) { |
---|
| | resId.setPathParam(paramIdx, (Constant) dependentParameters.get(var)); |
---|
| | } |
---|
| | } |
---|
| | return resId; |
---|
| | } |
---|
| | |
---|
| | public ResourceIdentifier getOutputResourceIdentifier(ResourcePath outputResPath) { |
---|
| |
---|
| | for (Selector sel: channelParameters.keySet()) { |
---|
| | int paramIdx = channelSelectorToOutputResourcePathParam.get(sel).get(outputResPath); |
---|
| | resId.setPathParam(paramIdx, channelParameters.get(sel)); |
---|
| | } |
---|
| | for (Expression var: dependentParameters.keySet()) { |
---|
| | int paramIdx = resId.getPathParams().indexOf(var); |
---|
| | if (paramIdx >= 0) { |
---|
| | resId.setPathParam(paramIdx, (Constant) dependentParameters.get(var)); |
---|
| | } |
---|
| | } |
---|
| | return resId; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |