use of org.osate.aadl2.Access in project VERDICT by ge-high-assurance.
the class ThreatModelUtil method getTypes.
/**
* Build a map from type names to types. Traverses all files
* in the current project looking for property declarations, which
* are used to populate fields for the built-in types.
*
* Built-in types are system, connection, and port (also portDirection).
*
* This method is not very efficient, and it gets called several times
* on every keystroke. Fortunately there still seems to be reasonably fast.
* A crucial optimization will be caching the results because the set of
* properties does not change that frequently.
*
* @param obj an AST node context, used to get access to project files
* @param indexProvider an index provider, may be obtained through Guice
* @return the constructed type map
*/
public static LinkedHashMap<String, VerdictType> getTypes(EObject obj, ResourceDescriptionsProvider indexProvider) {
LinkedHashMap<String, VerdictType> types = new LinkedHashMap<>();
// Three main built-in types
BuiltInType connection = new BuiltInType("connection");
BuiltInType port = new BuiltInType("port");
BuiltInType system = new BuiltInType("system");
addBuiltin(types, connection);
addBuiltin(types, port);
addBuiltin(types, system);
// Connection fields
connection.addField("inPort", port);
connection.addField("outPort", port);
connection.addField("source", system);
connection.addField("dest", system);
// Port direction
BuiltInType portDir = new BuiltInType("portDirection");
portDir.addValue("in");
portDir.addValue("out");
// Port fields
port.addField("direction", portDir);
port.addField("connections", connection.getListType());
// System fields
system.addField("subcomponents", system.getListType());
system.addField("connections", connection.getListType());
system.addField("ports", port.getListType());
// Get the path to the current resource, used to get the project path
String[] resSegments = obj.eResource().getURI().segments();
// Iterate through all resources
IResourceDescriptions index = indexProvider.getResourceDescriptions(obj.eResource());
descLoop: for (IEObjectDescription desc : index.getExportedObjectsByType(Aadl2Package.eINSTANCE.getPropertySet())) {
// Get the path to the resource we are examining
String[] propsResSegments = desc.getEObjectURI().segments();
// The project is determined by the first two URI segments
for (int i = 0; i < Math.min(2, Math.min(resSegments.length, propsResSegments.length)); i++) {
if (!resSegments[i].equals(propsResSegments[i])) {
continue descLoop;
}
}
// Load the resource into EMF-land; dynamically loads if necessary
Resource res = obj.eResource().getResourceSet().getResource(desc.getEObjectURI(), true);
if (res != null) {
// Search the AST
TreeIterator<EObject> it = res.getAllContents();
while (it.hasNext()) {
EObject next = it.next();
if (next instanceof PropertySet) {
PropertySet props = (PropertySet) next;
// Iterate the declared properties
for (Element elem : props.getOwnedElements()) {
if (elem instanceof Property) {
Property prop = (Property) elem;
// Make sure type information is present
if (prop.getPropertyType() != null) {
// the types for which the property is a field
for (MetaclassReference meta : prop.getAppliesToMetaclasses()) {
// Get type name, lowercase it because it is a class name
String appliesToMetaclass = meta.getMetaclass().getName().toLowerCase();
// Hopefully this is a type that we have accounted for
if (types.containsKey(appliesToMetaclass)) {
((BuiltInType) types.get(appliesToMetaclass)).addField(prop.getName(), new AadlTypeWrapper(prop.getName(), prop.getPropertyType()));
} else {
// If we get this error message, then perhaps need to add
// some built-in types
System.err.println("could not find built in type: " + appliesToMetaclass);
}
}
}
}
}
// Discard all children of the property set
it.prune();
}
}
}
}
// Prevent synchronization issues
portDir.lock();
connection.lock();
port.lock();
system.lock();
return types;
}
use of org.osate.aadl2.Access 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.Access in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method changeAsymConnections.
/**
* Method will remove the previous connections in the main lustre node from
* sender to receivers and add in the new connections from sender to commNode
* and from commNode to receiver. Ex: What used to be: Sender_out = reciever1.in
* Sender_out = reciever2.in Sender_out = reciever3.in Is now: Sender_out =
* asym0.in Sender_out = asym1.in Sender_out = asym2.in asym0.out = reciever1.in
* asym1.out = reciever2.in asym2.out = reciever3.in
*
* @param nb NodeBuilder for the main lustre node.
*/
private void changeAsymConnections(AgreeNodeBuilder nb) {
// Insert connections sender_output = commNode_input
for (String output : mapAsymCompOutputToCommNodeIn.keySet()) {
for (String nodeName : mapAsymCompOutputToCommNodeIn.get(output)) {
Expr eq = new BinaryExpr(new IdExpr(output), BinaryOp.EQUAL, new IdExpr(nodeName));
nb.addAssertion(new AgreeStatement("", eq, this.topNode.reference));
}
}
// Insert connections commNode_output = receiver_input.
for (String output : mapCommNodeOutputToConnections.keySet()) {
String featureName = "";
String componentName = "";
// First access name of receiving component and its input
if (mapCommNodeOutputToConnections.get(output).eContainer() instanceof SystemInstanceImpl) {
FeatureInstanceImpl fi = (FeatureInstanceImpl) mapCommNodeOutputToConnections.get(output);
componentName = "";
featureName = fi.getName();
} else if (mapCommNodeOutputToConnections.get(output) instanceof FeatureInstanceImpl) {
FeatureInstanceImpl fi = (FeatureInstanceImpl) mapCommNodeOutputToConnections.get(output);
featureName = fi.getName();
if (fi.eContainer() instanceof ComponentInstanceImpl) {
ComponentInstanceImpl ci = (ComponentInstanceImpl) fi.eContainer();
componentName = ci.getName() + "__";
} else {
new SafetyException("Asymmetric fault must be connected to a component instance.");
}
} else {
new SafetyException("Asymmetric fault must have an allowable connection.");
}
// Create lustre connection name, add to builder.
IdExpr connectionName = new IdExpr(componentName + featureName);
Expr eq = new BinaryExpr(new IdExpr(output), BinaryOp.EQUAL, connectionName);
nb.addAssertion(new AgreeStatement("", eq, this.topNode.reference));
}
}
use of org.osate.aadl2.Access in project osate2 by osate.
the class AccessPropertySection method refresh.
@Override
public void refresh() {
final Set<Access> selectedAccesses = selectedBos.boStream(Access.class).collect(Collectors.toSet());
// Get initial value for buttons
final AccessType accessType = getAccessType(selectedAccesses);
// Set selection
providesBtn.setSelection(accessType == AccessType.PROVIDES);
requiresBtn.setSelection(accessType == AccessType.REQUIRES);
}
use of org.osate.aadl2.Access in project osate2 by osate.
the class CreateAadlConnectionPaletteCommand method buildCreateOperation.
public Operation buildCreateOperation(final BusinessObjectContext ownerBoc, final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
return Operation.createWithBuilder(createOp -> {
// Create the subcomponent
getClassifierOpBuilder().buildOperation(createOp, ownerBoc.getBusinessObject()).modifyPreviousResult(owner -> {
// Create the appropriate type of connection object
final org.osate.aadl2.Connection newAadlConnection = AadlConnectionUtil.createConnection(owner, connectionType);
if (newAadlConnection == null) {
return null;
}
// Reset the no connections flag
owner.setNoConnections(false);
// Set the source and destination
final ConnectedElement src = getConnectedElementForBusinessObjectContext(srcBoc, connectionType, false, ownerBoc);
newAadlConnection.setSource(src);
final ConnectedElement dst = getConnectedElementForBusinessObjectContext(dstBoc, connectionType, !(src.getContext() instanceof Subcomponent), ownerBoc);
newAadlConnection.setDestination(dst);
// Determine the name for the new connection
final String newConnectionName = AadlNamingUtil.buildUniqueIdentifier(owner, "new_connection");
newAadlConnection.setName(newConnectionName);
// Set type of access connection
if (newAadlConnection instanceof AccessConnection) {
final AccessConnection ac = (AccessConnection) newAadlConnection;
if (src.getConnectionEnd() instanceof SubprogramAccess || dst.getConnectionEnd() instanceof SubprogramAccess) {
ac.setAccessCategory(AccessCategory.SUBPROGRAM);
} else if (src.getConnectionEnd() instanceof SubprogramGroupAccess || dst.getConnectionEnd() instanceof SubprogramGroupAccess) {
ac.setAccessCategory(AccessCategory.SUBPROGRAM_GROUP);
} else if (src.getConnectionEnd() instanceof BusAccess || dst.getConnectionEnd() instanceof BusAccess) {
ac.setAccessCategory(AccessCategory.BUS);
} else if (src.getConnectionEnd() instanceof DataAccess || dst.getConnectionEnd() instanceof DataAccess) {
ac.setAccessCategory(AccessCategory.DATA);
}
}
return StepResultBuilder.create().showNewBusinessObject(ownerBoc, newAadlConnection).build();
});
});
}
Aggregations