private List<Resource> addEventPort(final SoftPkg spd) throws CoreException { final Descriptor desc = spd.getDescriptor(); if (desc != null) { final SoftwareComponent scd = desc.getComponent(); ComponentFeatures features = scd.getComponentFeatures(); if (features == null) { features = ScdFactory.eINSTANCE.createComponentFeatures(); scd.setComponentFeatures(features); } Ports ports = features.getPorts(); if (ports == null) { ports = ScdFactory.eINSTANCE.createPorts(); features.setPorts(ports); } Interfaces interfaces = scd.getInterfaces(); boolean found = false; if (interfaces != null) { for (final Interface i : interfaces.getInterface()) { if (EventChannelHelper.id().equals(i.getRepid())) { found = true; break; } } } else { interfaces = ScdFactory.eINSTANCE.createInterfaces(); scd.setInterfaces(interfaces); } if (!found) { final Interface i = ScdFactory.eINSTANCE.createInterface(); i.setName("EventChannel"); i.setRepid(EventChannelHelper.id()); interfaces.getInterface().add(i); } final Uses uses = ScdFactory.eINSTANCE.createUses(); ports.getUses().add(uses); uses.setName(Uses.PORT_NAME_PROP_EVENTS); uses.setRepID(EventChannelHelper.id()); final PortTypeContainer ptc = ScdFactory.eINSTANCE.createPortTypeContainer(); ptc.setType(PortType.RESPONSES); uses.getPortType().add(ptc); return Collections.singletonList(scd.eResource()); } else { throw new CoreException( new Status( IStatus.ERROR, ComponentUiPlugin.PLUGIN_ID, "No descriptor, quick fix failed for " + spd.eResource().getURI().path(), null)); } }
@Override protected String getRepId() { return EventChannelHelper.id(); }