use of org.geotoolkit.sml.xml.v101.Classifier in project VERDICT by ge-high-assurance.
the class VerdictJavaValidator method checkStatement.
/**
* Check that cyber relations/requirements have unique, non-empty IDs
* and they are only located in subsystems/top-level systems, respectively.
*
* @param statement
*/
@Check(CheckType.FAST)
public void checkStatement(Statement statement) {
String statementType;
boolean shouldBeSubcomponent;
if (statement instanceof CyberRel) {
statementType = "Cyber relation";
shouldBeSubcomponent = true;
} else if (statement instanceof CyberReq) {
statementType = "Cyber requirement";
shouldBeSubcomponent = false;
} else if (statement instanceof CyberMission) {
statementType = "Mission";
shouldBeSubcomponent = false;
} else if (statement instanceof SafetyReq) {
statementType = "Safety requirement";
shouldBeSubcomponent = false;
} else if (statement instanceof SafetyRel) {
statementType = "Safety relation";
shouldBeSubcomponent = true;
} else if (statement instanceof Event) {
statementType = "Event";
shouldBeSubcomponent = true;
} else {
throw new RuntimeException("statement is not CyberRel, or CyberReq, or Mission, or SafetyReq, or SafetyRel, or Event!?");
}
if (statement.getId().length() == 0) {
error(statementType + " must specify an ID", VerdictPackage.Literals.STATEMENT__ID);
return;
}
// Find enclosing system
EObject container = statement;
while (container != null && !(container instanceof SystemType || container instanceof PublicPackageSection)) {
container = container.eContainer();
}
/*
* Within the same component, we need to make sure that cyber relations, cyber requirements,
* safety relations, safety missions, events do not have naming conflicts respectively.
*/
Set<String> otherIds = new HashSet<>();
if (container instanceof SystemType) {
SystemType currentSystem = (SystemType) container;
// Get enclosing file
while (!(container instanceof PublicPackageSection)) {
container = container.eContainer();
}
// Get all verdict annexes for this system
for (AnnexSubclause annex : currentSystem.getOwnedAnnexSubclauses()) {
if ("verdict".equals(annex.getName())) {
Verdict subclause = VerdictUtil.getVerdict(annex);
// We only check that within the same statement category, there should not be naming conflicts.
for (Statement other : subclause.getElements()) {
// Don't double-count self
if (!statement.equals(other)) {
if ((statement instanceof CyberRel) && (other instanceof CyberRel)) {
otherIds.add(other.getId());
} else if ((statement instanceof CyberReq) && (other instanceof CyberReq)) {
otherIds.add(other.getId());
} else if ((statement instanceof CyberMission) && (other instanceof CyberMission)) {
otherIds.add(other.getId());
} else if ((statement instanceof SafetyReq) && (other instanceof SafetyReq)) {
otherIds.add(other.getId());
} else if ((statement instanceof SafetyRel) && (other instanceof SafetyRel)) {
otherIds.add(other.getId());
} else if ((statement instanceof Event) && (other instanceof Event)) {
otherIds.add(other.getId());
}
}
}
}
}
/*
* A system is a top-level system if it is not a subcomponent
* of any other system (cyber/safety requirements are valid).
*
* If it is a subcomponent of another system, then it is a
* subcomponent (cyber/safety relations are valid).
*/
PublicPackageSection pack = (PublicPackageSection) container;
// Find all system impls
for (Classifier cls : pack.getOwnedClassifiers()) {
if (cls instanceof SystemImplementation) {
// Grab the dependency/subcomponent tree
SystemImplementation systemImpl = (SystemImplementation) cls;
for (Subcomponent sub : systemImpl.getAllSubcomponents()) {
if (sub.getComponentImplementation() != null) {
subcomponents.add(sub.getComponentImplementation().getType());
}
subcomponents.add(sub.getSubcomponentType());
}
}
}
boolean isSubcomponent = subcomponents.contains(currentSystem);
if (isSubcomponent && !shouldBeSubcomponent) {
warning(statementType + " not allowed in subcomponent system");
} else if (!isSubcomponent && shouldBeSubcomponent) {
warning(statementType + " not allowed in top-level system");
}
if (otherIds.contains(statement.getId())) {
error("Duplicate ID " + statement.getId(), VerdictPackage.Literals.STATEMENT__ID);
}
}
// Perform extra checks for missions
if (statement instanceof CyberMission) {
checkMission((CyberMission) statement);
}
// And cyber reqs
if (statement instanceof CyberReq) {
checkCyberReq((CyberReq) statement);
}
}
use of org.geotoolkit.sml.xml.v101.Classifier in project VERDICT by ge-high-assurance.
the class VerdictUtil method getEvents.
/**
* Get the (linked) set of all cyber requirements in the AADL AST of which obj is part.
*
* @param obj
* @return
*/
public static Set<String> getEvents(EObject obj) {
Set<String> cyberReqs = new LinkedHashSet<>();
// Find public package section
EObject container = obj;
while (container != null && !(container instanceof PublicPackageSection)) {
container = container.eContainer();
}
PublicPackageSection pack = (PublicPackageSection) container;
if (pack != null && pack.getOwnedClassifiers() != null) {
// Find all systems
for (Classifier cls : pack.getOwnedClassifiers()) {
if (cls instanceof SystemType) {
SystemType system = (SystemType) cls;
// Get all verdict annexes for this system
for (AnnexSubclause annex : system.getOwnedAnnexSubclauses()) {
if ("verdict".equals(annex.getName())) {
Verdict subclause = VerdictUtil.getVerdict(annex);
// Get all cyber req IDs
for (Statement statement : subclause.getElements()) {
if (statement instanceof CyberReq) {
cyberReqs.add(statement.getId());
}
}
}
}
}
}
}
return cyberReqs;
}
use of org.geotoolkit.sml.xml.v101.Classifier in project VERDICT by ge-high-assurance.
the class VerdictUtil method getAllReqs.
/**
* Get the (linked) set of all cyber requirements in the AADL AST of which obj is part.
*
* @param obj
* @return
*/
public static Set<String> getAllReqs(EObject obj) {
Set<String> reqs = new LinkedHashSet<>();
// Find public package section
EObject container = obj;
while (container != null && !(container instanceof PublicPackageSection)) {
container = container.eContainer();
}
PublicPackageSection pack = (PublicPackageSection) container;
if (pack != null && pack.getOwnedClassifiers() != null) {
// Find all systems
for (Classifier cls : pack.getOwnedClassifiers()) {
if (cls instanceof SystemType) {
SystemType system = (SystemType) cls;
// Get all verdict annexes for this system
for (AnnexSubclause annex : system.getOwnedAnnexSubclauses()) {
if ("verdict".equals(annex.getName())) {
Verdict subclause = VerdictUtil.getVerdict(annex);
// Get all cyber req IDs
for (Statement statement : subclause.getElements()) {
if (statement instanceof CyberReq) {
reqs.add(statement.getId());
} else if (statement instanceof SafetyReq) {
reqs.add(statement.getId());
}
}
}
}
}
}
}
return reqs;
}
use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.
the class ModelVerifications method sameVoltage.
/**
* returns true if two incoming (requires) abstract feature instances in component 'ci' have same voltage
* @param ci
* @return
*/
public static boolean sameVoltage(ComponentInstance ci) {
EList<FeatureInstance> inlets = new BasicEList<FeatureInstance>();
for (FeatureInstance fi : ci.getAllFeatureInstances(FeatureCategory.ABSTRACT_FEATURE)) {
Classifier cl = fi.getFeature().getAllClassifier();
if (fi.getFlowDirection().incoming() && cl.getName().equalsIgnoreCase("power")) {
inlets.add(fi);
}
}
if (inlets.size() == 2) {
double v1 = getVoltage(inlets.get(0));
double v2 = getVoltage(inlets.get(1));
return v1 == v2;
}
return false;
}
use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.
the class ModelVerifications method samePowerBudget.
/**
* returns true if two incoming (requires) abstract feature instances in component 'ci' have same power budget
* @param ci
* @return
*/
public static boolean samePowerBudget(ComponentInstance ci) {
EList<FeatureInstance> inlets = new BasicEList<FeatureInstance>();
for (FeatureInstance fi : ci.getAllFeatureInstances(FeatureCategory.ABSTRACT_FEATURE)) {
Classifier cl = fi.getFeature().getAllClassifier();
if (fi.getFlowDirection().incoming() && cl.getName().equalsIgnoreCase("power")) {
inlets.add(fi);
}
}
if (inlets.size() == 2) {
double pb1 = GetProperties.getPowerBudget(inlets.get(0), 0.0);
double pb2 = GetProperties.getPowerBudget(inlets.get(1), 0.0);
return pb1 == pb2;
}
return false;
}
Aggregations