use of org.osate.aadl2.BusType in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method translateBusTypeObjects.
// End of translateSystemTypeObjects
/**
* Analyzing each busType:
* 1. Determine if it is a lower-level system or higher-level system
* 2. If lower-level, add to componentType list attribute of Model
* 2.1 Populate the port, contract, cyberRel, safetyRel, event, id, compCategory
* fields of componentType of the Model object
* 3. If higher-level, assign to Model
* 3.1 Populate the safetyReq
* cyberReq, mission fields of Model object
* @param busTypes
* @param m1
* @return
*/
public Model translateBusTypeObjects(List<BusType> busTypes, Model m1, HashSet<String> dataTypeDecl) {
for (BusType bType : busTypes) {
// variables for unpacking bType
List<Event> events = new ArrayList<>();
List<CyberMission> missionReqs = new ArrayList<>();
List<CyberRel> cyberRels = new ArrayList<>();
List<SafetyRel> safetyRels = new ArrayList<>();
List<CyberReq> cyberReqs = new ArrayList<>();
List<SafetyReq> safetyReqs = new ArrayList<>();
// a flag to check if a higher -level component has already been found
boolean higher_flag = false;
// unpacking bType
for (AnnexSubclause annex : bType.getOwnedAnnexSubclauses()) {
if (annex.getName().equalsIgnoreCase("verdict")) {
Verdict verdictAnnex = VerdictUtil.getVerdict(annex);
for (Statement statement : verdictAnnex.getElements()) {
if (statement instanceof Event) {
events.add((Event) statement);
} else if (statement instanceof CyberMission) {
missionReqs.add((CyberMission) statement);
} else if (statement instanceof CyberReq) {
cyberReqs.add((CyberReq) statement);
} else if (statement instanceof CyberRel) {
cyberRels.add((CyberRel) statement);
} else if (statement instanceof SafetyReq) {
safetyReqs.add((SafetyReq) statement);
} else if (statement instanceof SafetyRel) {
safetyRels.add((SafetyRel) statement);
}
}
}
}
/**
* For every BusType,
* populate the id, name, compCateg, port, event,
* cyberRel, and safetyRel fields of componentType
* and add it to the list of componentType
* of the Model object
*/
if (true) {
// No Filter-- do for all System Types
// to pack the bType as a VDM component
verdict.vdm.vdm_model.ComponentType packComponent = new verdict.vdm.vdm_model.ComponentType();
// Note: Not populating "contract" for now
// ISSUE: There is no getId() function for busType
packComponent.setId(bType.getQualifiedName());
// populating "name"
packComponent.setName(bType.getName());
// populating "compCateg"
packComponent.setCompCateg(bType.getCategory().getName());
// get all bus accesses and store them as ports
List<BusAccess> busAccesses = bType.getOwnedBusAccesses();
// checking each busAccess's details and adding it to the port list
for (BusAccess busAccess : busAccesses) {
String portName = busAccess.getName();
String modeString = "in";
if (busAccess.getKind() == AccessType.PROVIDES) {
modeString = "providesBusAccess";
} else if (busAccess.getKind() == AccessType.REQUIRES) {
modeString = "requiresBusAccess";
}
verdict.vdm.vdm_model.Port newPort = createVdmPort(portName, modeString, busAccess.getQualifiedName());
// Note: Not populating "type" for now
// ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
// add to port list of component
packComponent.getPort().add(newPort);
}
// End of checking each busAccess
// ISSUE: no getOwnedDataAccesses for busType
// get all ports
List<DataPort> dataPorts = bType.getOwnedDataPorts();
// checking each port's mode and name and adding it to the port list
for (DataPort dataPort : dataPorts) {
verdict.vdm.vdm_model.Port newPort = createVdmPort(dataPort, m1, dataTypeDecl);
// ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
// add to port list of component
packComponent.getPort().add(newPort);
}
// End of checking each port
// get all event data ports
List<EventDataPort> eventDataPorts = bType.getOwnedEventDataPorts();
for (EventDataPort eventDataPort : eventDataPorts) {
verdict.vdm.vdm_model.Port newPort = createVdmPort(eventDataPort, m1, dataTypeDecl);
// add to port list of component
packComponent.getPort().add(newPort);
}
// get all event ports
List<EventPort> eventPorts = bType.getOwnedEventPorts();
for (EventPort eventPort : eventPorts) {
verdict.vdm.vdm_model.Port newPort = createVdmEventPort(eventPort);
// add to port list of component
packComponent.getPort().add(newPort);
}
// packing all events and adding to component
for (Event anEvent : events) {
// To pack the event as a VDM event
verdict.vdm.vdm_model.Event packEvent = createVdmEvent(anEvent);
// adding to the list of component's events
packComponent.getEvent().add(packEvent);
}
// packing all cyberRels and adding to component
for (CyberRel aCyberRel : cyberRels) {
// To pack the cyberRel as a VDM event
verdict.vdm.vdm_model.CyberRel packCyberRel = createVdmCyberRel(aCyberRel);
// adding to the list of component's Cyber relations
packComponent.getCyberRel().add(packCyberRel);
}
// packing all safetyRels and adding to component
for (SafetyRel aSafetyRel : safetyRels) {
// To pack the safetyRel as a VDM event
verdict.vdm.vdm_model.SafetyRel packSafetyRel = createVdmSafetyRel(aSafetyRel);
// adding to the list of component's Safety relations
packComponent.getSafetyRel().add(packSafetyRel);
}
// End of packing all safetyRels
// adding to the list of componentTypes of the Model object
m1.getComponentType().add(packComponent);
}
/**
* If a high-level system
* populate the name, safetyReq, cyberReq, and mission
* for the model object
*/
if (!cyberReqs.isEmpty() || !safetyReqs.isEmpty() || !missionReqs.isEmpty()) {
// checking if a high-level system has already been found
if (higher_flag == false) {
higher_flag = true;
} else {
System.out.println("Warning: Multiple high-level systems detected!");
}
// populating name
m1.setName(bType.getName());
// packing all safetyReqs and adding to model
for (SafetyReq aSafetyReq : safetyReqs) {
// To pack the safettReq as a VDM event
verdict.vdm.vdm_model.SafetyReq packSafetyReq = createVdmSafetyReq(aSafetyReq, bType.getFullName());
// adding to the list of model's Safety requirements
m1.getSafetyReq().add(packSafetyReq);
}
// packing all cyberReqs and adding to model
for (CyberReq aCyberReq : cyberReqs) {
// To pack the safettReq as a VDM event
verdict.vdm.vdm_model.CyberReq packCyberReq = createVdmCyberReq(aCyberReq, bType.getFullName());
// adding to the list of model's Cyber requirements
m1.getCyberReq().add(packCyberReq);
}
// packing all missionReqs and adding to model
for (CyberMission aMission : missionReqs) {
// To pack the safettReq as a VDM event
verdict.vdm.vdm_model.Mission packMission = createVdmMission(aMission);
// adding to the list of model's Mission
m1.getMission().add(packMission);
}
// End of packing all missionReqs
}
// End of if a higher-level system
}
// returning the populated Model
return m1;
}
use of org.osate.aadl2.BusType in project AGREE by loonwerks.
the class EphemeralImplementationUtil method createComponentImplementationInternal.
/**
* Internal method to actually create the ephemeral component implementation and containing resource.
* <p>
* This method is intended to by invoked only from the command stack so that editing permissions are managed
* through the transactional editing domain.
*
* @param ct The {@link ComponentType} for which to create an ephemeral implementation.
* @param aadlResource The {@link Resource} in which to place the ephemeral implementation and it containing
* {@link AadlPackage}.
* @return A {@link ComponentImplementation} matching the given component type.
* @throws InterruptedException
*/
private ComponentImplementation createComponentImplementationInternal(ComponentType ct, Resource aadlResource) throws InterruptedException {
// Create a package and public section to contain the created
// component implementation
AadlPackage aadlPackage = Aadl2Factory.eINSTANCE.createAadlPackage();
aadlPackage.setName(aadlResource.getURI().trimFragment().trimFileExtension().lastSegment().toString());
PublicPackageSection publicSection = aadlPackage.createOwnedPublicSection();
// Add import for package containing ct
AadlPackage ctPackage = (AadlPackage) AgreeUtils.getClosestContainerOfType(ct, AadlPackage.class);
publicSection.getImportedUnits().add(ctPackage);
// Add renames clause to make linking to ct easy
PackageRename ctRename = publicSection.createOwnedPackageRename();
ctRename.setName("");
ctRename.setRenamedPackage(ctPackage);
ctRename.setRenameAll(true);
// Create the component implementation in the public section
ComponentImplementation compImpl;
if (ct instanceof ThreadType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getThreadImplementation());
} else if (ct instanceof ThreadGroupType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getThreadGroupImplementation());
} else if (ct instanceof ProcessType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getProcessImplementation());
} else if (ct instanceof SubprogramType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getSubprogramImplementation());
} else if (ct instanceof ProcessorType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getProcessorImplementation());
} else if (ct instanceof BusType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getBusImplementation());
} else if (ct instanceof DeviceType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getDeviceImplementation());
} else if (ct instanceof SystemType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getSystemImplementation());
} else {
throw new AgreeException("Unhandled component type: " + ct.getClass().toString());
}
compImpl.setType(ct);
compImpl.setName(ct.getName() + ".wrapper");
// Add the package and its contents to the resource
aadlResource.getContents().add(aadlPackage);
// IResource as we build it.
try {
aadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
} catch (NullPointerException npe) {
npe.printStackTrace();
setErrorMessage(npe.getMessage());
npe.getMessage();
return null;
// } catch (InterruptedException e) {
// throw e;
} catch (Exception e) {
e.printStackTrace();
errorMessage = e.getMessage();
e.getMessage();
return null;
}
return compImpl;
}
Aggregations