use of org.osate.aadl2.ComponentCategory.BUS in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method getConnectionKind.
/**
* Returns the VDM ConnectionKind
* @param kind
* @return
*/
verdict.vdm.vdm_model.ConnectionKind getConnectionKind(Connection aConn) {
String kindString = "port";
if (aConn.getClass().getSimpleName().equalsIgnoreCase("AccessConnectionImpl")) {
AccessConnectionImpl accessConnImpl = (AccessConnectionImpl) aConn;
if (accessConnImpl.getAccessCategory().getName().equalsIgnoreCase("data")) {
kindString = "dataAccess";
} else if (accessConnImpl.getAccessCategory().getName().equalsIgnoreCase("bus")) {
kindString = "busAccess";
}
} else if (aConn.getClass().getSimpleName().equalsIgnoreCase("PortConnectionImpl")) {
kindString = "port";
} else if (aConn.getClass().getSimpleName().equalsIgnoreCase("ParameterConnectionImpl")) {
kindString = "parameter";
}
verdict.vdm.vdm_model.ConnectionKind returnKind = verdict.vdm.vdm_model.ConnectionKind.fromValue(kindString);
return returnKind;
}
use of org.osate.aadl2.ComponentCategory.BUS in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method translateDeviceTypeObjects.
// End of translateMemoryTypeObjects
/**
* Analyzing each deviceType:
* 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 deviceTypes
* @param m1
* @return
*/
public Model translateDeviceTypeObjects(List<DeviceType> deviceTypes, Model m1, HashSet<String> dataTypeDecl) {
for (DeviceType devType : deviceTypes) {
// variables for unpacking devType
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 devType
for (AnnexSubclause annex : devType.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 DeviceType,
* 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 memType 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 memoryType
packComponent.setId(devType.getQualifiedName());
// populating "name"
packComponent.setName(devType.getName());
// populating "compCateg"
packComponent.setCompCateg(devType.getCategory().getName());
// get all bus accesses and store them as ports
List<BusAccess> busAccesses = devType.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 deviceType
// get all ports
List<DataPort> dataPorts = devType.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 = devType.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 = devType.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 componenmemTypes 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(devType.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, devType.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, devType.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.ComponentCategory.BUS in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method translateAbstractTypeObjects.
// End of translateDeviceTypeObjects
/**
* Analyzing each abstractType:
* 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 abstractTypes
* @param m1
* @return
*/
public Model translateAbstractTypeObjects(List<AbstractType> abstractTypes, Model m1, HashSet<String> dataTypeDecl) {
for (AbstractType absType : abstractTypes) {
// variables for unpacking absType
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 absType
for (AnnexSubclause annex : absType.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 AbstractType,
* 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 memType 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 memoryType
packComponent.setId(absType.getQualifiedName());
// populating "name"
packComponent.setName(absType.getName());
// populating "compCateg"
packComponent.setCompCateg(absType.getCategory().getName());
// get all bus accesses and store them as ports
List<BusAccess> busAccesses = absType.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
// get all data accesses and store them as ports
List<DataAccess> dataAccesses = absType.getOwnedDataAccesses();
// checking each dataAccess's details and adding it to the port list
for (DataAccess dataAccess : dataAccesses) {
String portName = dataAccess.getName();
String modeString = "in";
if (dataAccess.getKind() == AccessType.PROVIDES) {
modeString = "providesDataAccess";
} else if (dataAccess.getKind() == AccessType.REQUIRES) {
modeString = "requiresDataAccess";
}
verdict.vdm.vdm_model.Port newPort = createVdmPort(portName, modeString, dataAccess.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 dataAccess
// get all ports
List<DataPort> dataPorts = absType.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 = absType.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 = absType.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 componenmemTypes 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(absType.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, absType.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, absType.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.ComponentCategory.BUS in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method translateComponentImplObjects.
// End of translateProcessorTypeObjects
/**
* Analyzing each component implementation
* @param comImpls
* @param m2
* @return
*/
public Model translateComponentImplObjects(List<ComponentImplementation> comImpls, Map<Property, String> componentPropertyToName, Map<Property, String> connPropertyToName, Model m2, HashSet<String> dataTypeDecl) {
Map<String, String> connectionToBusMap = new HashMap<>();
// creating an object for each implementation first as we will need it later
for (ComponentImplementation aSystemImpl : comImpls) {
// to pack the sysImpl as a VDM componentImpl
verdict.vdm.vdm_model.ComponentImpl packCompImpl = new verdict.vdm.vdm_model.ComponentImpl();
// setting "name" field of packCompImpl, will need later
packCompImpl.setName(aSystemImpl.getName());
// Note: Will skip "Nodebody" field for now
// ISSUE: No "id" field in Component implementations
packCompImpl.setId(aSystemImpl.getQualifiedName());
// adding object to "componentImpl" field of m2
m2.getComponentImpl().add(packCompImpl);
// update map (connection-name -> bus-Instance-Name)
for (PropertyAssociation propAssoc : aSystemImpl.getOwnedPropertyAssociations()) {
if (!(propAssoc.getProperty().getName().equalsIgnoreCase("Actual_Connection_Binding"))) {
System.out.println("System Implementation contains property " + propAssoc.getProperty().getName() + " which is not currently handled.");
continue;
}
if (propAssoc.getOwnedValues().size() != 1) {
throw new RuntimeException("Unexpected number of property owned values: " + propAssoc.getOwnedValues().size());
}
if (!(propAssoc.getOwnedValues().get(0).getOwnedValue() instanceof ListValueImpl)) {
throw new RuntimeException("Unexpected type of property owned value");
} else {
ListValueImpl listVal = (ListValueImpl) propAssoc.getOwnedValues().get(0).getOwnedValue();
if (listVal.getOwnedListElements().size() != 1) {
throw new RuntimeException("Unexpected number of list elements are associated with the property owned value");
} else if (!(listVal.getOwnedListElements().get(0) instanceof ReferenceValueImpl)) {
throw new RuntimeException("Unexpected number of list elements are associated with the property owned value");
} else {
ReferenceValueImpl refVal = (ReferenceValueImpl) listVal.getOwnedListElements().get(0);
ContainmentPathElement pathEle = refVal.getPath();
while (!(pathEle.getNamedElement() instanceof BusSubcomponent)) {
pathEle = pathEle.getPath();
}
String busInstanceName = pathEle.getNamedElement().getQualifiedName();
for (ContainedNamedElement connection : propAssoc.getAppliesTos()) {
// updating map (connection name -> bus name)
connectionToBusMap.put(connection.getPath().getNamedElement().getQualifiedName(), busInstanceName);
}
}
}
}
}
// Getting the reference of the object previously created and populating
for (ComponentImplementation aCompImpl : comImpls) {
// variable to refer to previously created object
verdict.vdm.vdm_model.ComponentImpl packCompImpl = new verdict.vdm.vdm_model.ComponentImpl();
// finding previously created object
for (verdict.vdm.vdm_model.ComponentImpl anImplObj : m2.getComponentImpl()) {
if (anImplObj.getId().equalsIgnoreCase(aCompImpl.getQualifiedName())) {
packCompImpl = anImplObj;
}
}
// setting "type" field of packCompImpl
for (verdict.vdm.vdm_model.ComponentType cType : m2.getComponentType()) {
if (aCompImpl.getType().getQualifiedName().equals(cType.getId())) {
packCompImpl.setType(cType);
}
}
// End of setting "type"
// a BlockImpl object to pack all info for packCompImpl.blockImpl
verdict.vdm.vdm_model.BlockImpl packBlockImpl = new verdict.vdm.vdm_model.BlockImpl();
// adding all subcomponents to "subcomponent" field of packBlockImpl
for (Subcomponent aSubComp : aCompImpl.getOwnedSubcomponents()) {
// to pack all information of a subcomponent
verdict.vdm.vdm_model.ComponentInstance packSubComp = new verdict.vdm.vdm_model.ComponentInstance();
// ISSUE: No "id" field in subcomponents
packSubComp.setId(aSubComp.getQualifiedName());
// setting "name" field of packSubComp
packSubComp.setName(aSubComp.getFullName());
// setting "specification" field of packSubComp
for (verdict.vdm.vdm_model.ComponentType cType : m2.getComponentType()) {
if (aSubComp.getComponentType().getName().equals(cType.getName())) {
packSubComp.setSpecification(cType);
}
}
// setting the "implementation" field of packSubComp
for (verdict.vdm.vdm_model.ComponentImpl cImpl : m2.getComponentImpl()) {
// if(aSubComp.getSubcomponentType().getName().equals(cImpl.getName())){
if (aSubComp.getSubcomponentType().getQualifiedName().equals(cImpl.getId())) {
packSubComp.setImplementation(cImpl);
}
}
// setting "attribute" field of packSubComp
// category of subComponent
String aSubCompCatName = aSubComp.getCategory().getName().toLowerCase();
// checking all collected properties in componentPropertyToName
for (Property prop : componentPropertyToName.keySet()) {
if (isApplicableToCat(prop, aSubCompCatName)) {
// create a GenericAttribute object to pack the property
verdict.vdm.vdm_data.GenericAttribute anAttribute = new verdict.vdm.vdm_data.GenericAttribute();
String value = "";
PropertyAcc propAcc = aSubComp.getPropertyValue(prop);
PropertyExpression defPropExpr = prop.getDefaultValue();
if (propAcc != null && !propAcc.getAssociations().isEmpty()) {
value = getStrRepofPropVal(aSubComp.getPropertyValue(prop));
} else if (defPropExpr != null) {
value = getStrRepofExpr(defPropExpr)[0];
}
if (!value.equals("")) {
// setting the "name" and "value" field of anAttribute
anAttribute.setName(componentPropertyToName.get(prop));
anAttribute.setValue(value);
// get the property type
PropertyType propType = prop.getPropertyType();
QName type = new QName("String");
if (propType instanceof AadlBooleanImpl) {
type = new QName("Bool");
} else if (propType instanceof AadlIntegerImpl) {
type = new QName("Int");
} else if (propType instanceof EnumerationTypeImpl) {
type = new QName("String");
} else {
if (!(propType instanceof AadlStringImpl)) {
type = new QName(propType.toString());
}
}
// parse propertyType fetched using prop.getOwnedPropertyType() and map it to "Bool", "Int", or "String"
anAttribute.setType(type);
// adding asAttribute to packSubComp
packSubComp.getAttribute().add(anAttribute);
}
} else {
// for outer if
continue;
}
}
// adding packSubComp to packBlockImpl
packBlockImpl.getSubcomponent().add(packSubComp);
packCompImpl.setBlockImpl(packBlockImpl);
}
// adding all connections to "connections" field of packBlockImpl
if (aCompImpl.getOwnedConnections() != null && !aCompImpl.getOwnedConnections().isEmpty()) {
for (Connection aConn : aCompImpl.getOwnedConnections()) {
// to pack all information of a connection
verdict.vdm.vdm_model.Connection packConn = new verdict.vdm.vdm_model.Connection();
// populate connectionKind
packConn.setConnectionKind(getConnectionKind(aConn));
// variables to unpack information from AADL object
String srcCompInstName = "";
String destCompInstName = "";
Context srcConnContext = aConn.getAllSourceContext();
Context destConnContext = aConn.getAllDestinationContext();
ConnectionEnd srcConnectionEnd = aConn.getAllSource();
ConnectionEnd destConnectionEnd = aConn.getAllDestination();
if (srcConnContext != null) {
srcCompInstName = srcConnContext.getName();
}
if (destConnContext != null) {
destCompInstName = destConnContext.getName();
}
String srcPortTypeName = "";
String destPortTypeName = "";
String srcPortName = srcConnectionEnd.getName();
String destPortName = destConnectionEnd.getName();
// variables to capture data type information
DataSubcomponentType srcDataSubCompType = null;
DataSubcomponentType destDataSubCompType = null;
if (srcConnectionEnd instanceof DataPort) {
srcPortTypeName = ((DataPort) srcConnectionEnd).isIn() ? (((DataPort) srcConnectionEnd).isOut() ? "inOut" : "in") : "out";
srcDataSubCompType = ((DataPort) srcConnectionEnd).getDataFeatureClassifier();
} else if (srcConnectionEnd instanceof EventDataPort) {
srcPortTypeName = ((EventDataPort) srcConnectionEnd).isIn() ? (((EventDataPort) srcConnectionEnd).isOut() ? "inOut" : "in") : "out";
srcDataSubCompType = ((EventDataPort) srcConnectionEnd).getDataFeatureClassifier();
} else if (srcConnectionEnd instanceof DataAccess) {
AccessType type = ((DataAccess) srcConnectionEnd).getKind();
if (type == AccessType.PROVIDES) {
srcPortTypeName = "providesDataAccess";
} else if (type == AccessType.REQUIRES) {
srcPortTypeName = "requiresDataAccess";
} else {
throw new RuntimeException("Unexpected access type: " + type);
}
srcDataSubCompType = ((DataAccess) srcConnectionEnd).getDataFeatureClassifier();
} else if (srcConnectionEnd instanceof DataSubcomponent) {
srcDataSubCompType = ((DataSubcomponent) srcConnectionEnd).getDataSubcomponentType();
srcPortTypeName = "data";
} else if (srcConnectionEnd instanceof BusAccess) {
// AccessType type = ((BusAccess) srcConnectionEnd).getKind();
// if(type == AccessType.PROVIDES) {
// srcPortTypeName = "providesBusAccess";
// } else if(type == AccessType.REQUIRES) {
// srcPortTypeName = "requiresBusAccess";
// } else {
// throw new RuntimeException("Unexpected access type: " + type);
// }
// BusFeatureClassifier busfeatureClassifier = ((BusAccess) srcConnectionEnd).getBusFeatureClassifier();
// if(busfeatureClassifier instanceof BusImplementation) {
// srcBusImpl = (BusImplementation)busfeatureClassifier;
// }
System.out.println("Warning: Unsupported AADL component element type: " + srcConnectionEnd);
continue;
} else if (srcConnectionEnd instanceof BusSubcomponent) {
// srcBusSubCompType = ((BusSubcomponent)srcConnectionEnd).getBusSubcomponentType();
// srcPortTypeName = "bus";
System.out.println("Warning: Unsupported AADL component element type: " + srcConnectionEnd);
continue;
} else if (srcConnectionEnd instanceof EventPort) {
srcPortTypeName = ((EventPort) srcConnectionEnd).isIn() ? (((EventPort) srcConnectionEnd).isOut() ? "inOut" : "in") : "out";
} else {
throw new RuntimeException("Unsupported AADL component element type: " + srcConnectionEnd + "encountered while processing connections");
}
if (destConnectionEnd instanceof DataPort) {
destPortTypeName = ((DataPort) destConnectionEnd).isIn() ? (((DataPort) destConnectionEnd).isOut() ? "inOut" : "in") : "out";
destDataSubCompType = ((DataPort) destConnectionEnd).getDataFeatureClassifier();
} else if (destConnectionEnd instanceof EventDataPort) {
destPortTypeName = ((EventDataPort) destConnectionEnd).isIn() ? (((EventDataPort) destConnectionEnd).isOut() ? "inOut" : "in") : "out";
destDataSubCompType = ((EventDataPort) destConnectionEnd).getDataFeatureClassifier();
} else if (destConnectionEnd instanceof DataAccess) {
AccessType type = ((DataAccess) destConnectionEnd).getKind();
if (type == AccessType.PROVIDES) {
destPortTypeName = "providesDataAccess";
} else if (type == AccessType.REQUIRES) {
destPortTypeName = "requiresDataAccess";
}
destDataSubCompType = ((DataAccess) destConnectionEnd).getDataFeatureClassifier();
} else if (destConnectionEnd instanceof DataSubcomponent) {
destDataSubCompType = ((DataSubcomponent) destConnectionEnd).getDataSubcomponentType();
destPortTypeName = "data";
} else if (destConnectionEnd instanceof BusAccess) {
// AccessType type = ((BusAccess) destConnectionEnd).getKind();
// if(type == AccessType.PROVIDES) {
// destPortTypeName = "providesBusAccess";
// } else if(type == AccessType.REQUIRES) {
// destPortTypeName = "requiresBusAccess";
// } else {
// throw new RuntimeException("Unexpected access type: " + type);
// }
// BusFeatureClassifier busfeatureClassifier = ((BusAccess) destConnectionEnd).getBusFeatureClassifier();
// if(busfeatureClassifier instanceof BusImplementation) {
// destBusImpl = (BusImplementation)busfeatureClassifier;
// }
System.out.println("Warning: Unsupported AADL component element type: " + destConnectionEnd);
continue;
} else if (destConnectionEnd instanceof BusSubcomponent) {
// destBusSubCompType = ((BusSubcomponent)destConnectionEnd).getBusSubcomponentType();
// destPortTypeName = "bus";
System.out.println("Warning: Unsupported AADL component element type: " + destConnectionEnd);
continue;
} else if (destConnectionEnd instanceof EventPort) {
destPortTypeName = ((EventPort) destConnectionEnd).isIn() ? (((EventPort) destConnectionEnd).isOut() ? "inOut" : "in") : "out";
} else {
throw new RuntimeException("Unsupported AADL component element type: " + destConnectionEnd + "encountered while processing connections");
}
// setting name
packConn.setName(aConn.getFullName());
packConn.setQualifiedName(aConn.getQualifiedName());
if (connectionToBusMap.containsKey(aConn.getQualifiedName())) {
packConn.setActualConnectionBinding(connectionToBusMap.get(aConn.getQualifiedName()));
}
// --- Populate packConn below ---
// to pack source
verdict.vdm.vdm_model.ConnectionEnd packSrcEnd = new verdict.vdm.vdm_model.ConnectionEnd();
// to pack "componentPort" of packSrcEnd
verdict.vdm.vdm_model.Port packSrcEndPort = new verdict.vdm.vdm_model.Port();
// } else
if (srcConnectionEnd instanceof EventPort) {
packSrcEndPort = createVdmConnectionEventPort(srcPortName, srcPortTypeName, srcConnectionEnd.getQualifiedName());
} else {
// if not a bus access port or bus implementation port or event port
packSrcEndPort = createVdmConnectionPort(srcPortName, srcPortTypeName, srcConnectionEnd.getQualifiedName(), srcDataSubCompType, m2, dataTypeDecl);
}
// If source port is independent of a component instance
if (srcCompInstName.equals("")) {
packSrcEnd.setComponentPort(packSrcEndPort);
} else {
// to pack "subcomponentPort" of packSrcEnd
verdict.vdm.vdm_model.CompInstancePort packSrcEndCompInstPort = new verdict.vdm.vdm_model.CompInstancePort();
// putting a reference to appropriate "subcomponent" from packBlockImpl in "subcomponent" of packSrcEndCompInstPort
for (verdict.vdm.vdm_model.ComponentInstance checkCompInst : packBlockImpl.getSubcomponent()) {
if (checkCompInst.getName().equals(srcCompInstName)) {
packSrcEndCompInstPort.setSubcomponent(checkCompInst);
break;
} else {
continue;
}
}
packSrcEndCompInstPort.setPort(packSrcEndPort);
// setting "subcomponentPort" of packSrcEnd
packSrcEnd.setSubcomponentPort(packSrcEndCompInstPort);
}
// adding to "source" of packConn
packConn.setSource(packSrcEnd);
// to pack destination
verdict.vdm.vdm_model.ConnectionEnd packDestEnd = new verdict.vdm.vdm_model.ConnectionEnd();
// to pack "componentPort" of packDestEnd
verdict.vdm.vdm_model.Port packDestEndPort = new verdict.vdm.vdm_model.Port();
// } else
if (destConnectionEnd instanceof EventPort) {
packDestEndPort = createVdmConnectionEventPort(destPortName, destPortTypeName, destConnectionEnd.getQualifiedName());
} else {
// if not a bus access port or bus implementation port or eventport
packDestEndPort = createVdmConnectionPort(destPortName, destPortTypeName, destConnectionEnd.getQualifiedName(), destDataSubCompType, m2, dataTypeDecl);
}
// If source port is independent of a component instance
if (destCompInstName.equals("")) {
packDestEnd.setComponentPort(packDestEndPort);
} else {
// to pack "subcomponentPort" of packSrcEnd
verdict.vdm.vdm_model.CompInstancePort packDestEndCompInstPort = new verdict.vdm.vdm_model.CompInstancePort();
// putting a reference to appropriate "subcomponent" from packBlockImpl in "subcomponent" of packSrcEndCompInstPort
for (verdict.vdm.vdm_model.ComponentInstance checkCompInst : packBlockImpl.getSubcomponent()) {
if (checkCompInst.getName().equals(destCompInstName)) {
packDestEndCompInstPort.setSubcomponent(checkCompInst);
break;
} else {
continue;
}
}
packDestEndCompInstPort.setPort(packDestEndPort);
// setting "subcomponentPort" of packDestEnd
packDestEnd.setSubcomponentPort(packDestEndCompInstPort);
}
// adding to "source" of packConn
packConn.setDestination(packDestEnd);
// adding connection properties from connProperty.ToName
for (Property prop : connPropertyToName.keySet()) {
// create a GenericAttribute object to pack the property
verdict.vdm.vdm_data.GenericAttribute aConnAttribute = new verdict.vdm.vdm_data.GenericAttribute();
String value = "";
PropertyAcc propAcc = aConn.getPropertyValue(prop);
PropertyExpression defPropExpr = prop.getDefaultValue();
if (propAcc != null && !propAcc.getAssociations().isEmpty()) {
value = getStrRepofPropVal(propAcc);
} else if (defPropExpr != null) {
value = getStrRepofExpr(defPropExpr)[0];
}
if (!value.equals("")) {
// setting the "name" and "value" field of anAttribute
aConnAttribute.setName(connPropertyToName.get(prop));
aConnAttribute.setValue(value);
PropertyType propType = prop.getPropertyType();
QName type = new QName("String");
if (propType instanceof AadlBooleanImpl) {
type = new QName("Bool");
} else if (propType instanceof AadlIntegerImpl) {
type = new QName("Int");
} else if (propType instanceof EnumerationTypeImpl) {
type = new QName("String");
} else {
if (!(propType instanceof AadlStringImpl)) {
type = new QName(propType.toString());
}
}
// parse propertyType fetched using prop.getOwnedPropertyType() and map it to "Bool", "Int", or "String"
aConnAttribute.setType(type);
// adding asAttribute to packSubComp
packConn.getAttribute().add(aConnAttribute);
}
}
if (aConn.isBidirectional()) {
packConn.setDirection(verdict.vdm.vdm_model.Direction.fromValue("bidirectional"));
// to pack reverse connection
verdict.vdm.vdm_model.Connection packReverseConn = new verdict.vdm.vdm_model.Connection();
packReverseConn.setName(packConn.getName() + "_reverse");
packReverseConn.setSource(packConn.getDestination());
packReverseConn.setDestination(packConn.getSource());
for (verdict.vdm.vdm_data.GenericAttribute anAttribute : packConn.getAttribute()) {
packReverseConn.getAttribute().add(anAttribute);
}
packReverseConn.setDirection(verdict.vdm.vdm_model.Direction.fromValue("bidirectional"));
// add packReverseConn to packBlockImpl
packBlockImpl.getConnection().add(packReverseConn);
} else {
packConn.setDirection(verdict.vdm.vdm_model.Direction.fromValue("unidirectional"));
}
// add packConn to packBlockImpl
packBlockImpl.getConnection().add(packConn);
packCompImpl.setBlockImpl(packBlockImpl);
}
}
// End of adding all connections
// setting "blackImpl" field of packCompImpl
// packCompImpl.setBlockImpl(packBlockImpl);
}
// return populated Model
return m2;
}
use of org.osate.aadl2.ComponentCategory.BUS in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method getObjectNames.
/**
* @author Vidhya Tekken Valapil
* Fetch names of objects and return the list of names
*/
private HashSet<String> getObjectNames(List<EObject> objects) {
HashSet<String> objNames = new HashSet<String>();
for (EObject obj : objects) {
// process only those objects in files in the project and not in the imported files
if (obj instanceof SystemType) {
objNames.add(((SystemType) obj).getName());
} else if (obj instanceof BusType) {
objNames.add(((BusType) obj).getName());
} else if (obj instanceof SubprogramType) {
objNames.add(((SubprogramType) obj).getName());
} else if (obj instanceof ThreadType) {
objNames.add(((ThreadType) obj).getName());
} else if (obj instanceof MemoryType) {
objNames.add(((MemoryType) obj).getName());
} else if (obj instanceof DeviceType) {
objNames.add(((DeviceType) obj).getName());
} else if (obj instanceof AbstractType) {
objNames.add(((AbstractType) obj).getName());
} else if (obj instanceof ProcessType) {
objNames.add(((ProcessType) obj).getName());
} else if (obj instanceof ThreadGroupType) {
objNames.add(((ThreadGroupType) obj).getName());
} else if (obj instanceof VirtualProcessorType) {
objNames.add(((VirtualProcessorType) obj).getName());
} else if (obj instanceof ProcessorType) {
objNames.add(((ProcessorType) obj).getName());
} else if (obj instanceof SystemImplementation) {
objNames.add(((SystemImplementation) obj).getName());
} else if (obj instanceof SubprogramImplementation) {
objNames.add(((SubprogramImplementation) obj).getName());
} else if (obj instanceof ThreadImplementation) {
objNames.add(((ThreadImplementation) obj).getName());
} else if (obj instanceof MemoryImplementation) {
objNames.add(((MemoryImplementation) obj).getName());
} else if (obj instanceof BusImplementation) {
objNames.add(((BusImplementation) obj).getName());
} else if (obj instanceof AbstractImplementation) {
objNames.add(((AbstractImplementation) obj).getName());
} else if (obj instanceof DeviceImplementation) {
objNames.add(((DeviceImplementation) obj).getName());
} else if (obj instanceof ProcessImplementation) {
objNames.add(((ProcessImplementation) obj).getName());
} else if (obj instanceof ThreadGroupImplementation) {
objNames.add(((ThreadGroupImplementation) obj).getName());
} else if (obj instanceof VirtualProcessorImplementation) {
objNames.add(((VirtualProcessorImplementation) obj).getName());
} else if (obj instanceof ProcessorImplementation) {
objNames.add(((ProcessorImplementation) obj).getName());
} else if (obj instanceof PropertySetImpl) {
for (Property prop : ((PropertySetImpl) obj).getOwnedProperties()) {
// Save property owner to be used later
for (PropertyOwner po : prop.getAppliesTos()) {
String propCat = ((MetaclassReferenceImpl) po).getMetaclass().getName().toLowerCase();
String propName = prop.getName();
switch(propCat) {
case "system":
{
objNames.add(propName);
break;
}
case "thread":
{
objNames.add(propName);
break;
}
case "processor":
{
objNames.add(propName);
break;
}
case "memory":
{
objNames.add(propName);
break;
}
case "connection":
{
objNames.add(propName);
break;
}
case "process":
{
objNames.add(propName);
break;
}
case "abstract":
{
objNames.add(propName);
break;
}
case "device":
{
objNames.add(propName);
break;
}
case "threadgroup":
{
objNames.add(propName);
break;
}
case "virtualprocessor":
{
objNames.add(propName);
break;
}
case "bus":
{
objNames.add(propName);
break;
}
case "port":
{
objNames.add(propName);
break;
}
default:
{
System.out.println("Warning: unsupported property: " + propName + ", applies to: " + propCat);
break;
}
}
}
}
}
}
return objNames;
}
Aggregations