use of org.geotoolkit.sml.xml.v100.ComponentType in project AMASE by loonwerks.
the class SafetyValidator method checkActivationStatement.
/**
* Checks for empty hw fault description string and makes sure hw fault
* is declared in system type, not implementation.
*
* @param hwStmt
*/
// @Check(CheckType.FAST)
// public void checkHWFaultStmt(HWFaultStatement hwStmt) {
// // Check on fault description
// if (hwStmt.getStr().isEmpty()) {
// warning(hwStmt, "HW fault description is optional, but should not be an empty string.");
// }
// ComponentImplementation compImpl = EcoreUtil2.getContainerOfType(hwStmt, ComponentImplementation.class);
// if (!(compImpl == null)) {
// error(hwStmt, "HW faults can only be defined in component type, not implementations.");
// }
// }
/**
* Checks that propagate stmt defined in implementation,
* source fault names correct for designated component names,
* destination faults correct for designated component names,
* and the source faults are indeed hw faults.
* @param pStmt
*/
// @Check(CheckType.FAST)
// public void checkPropagateStmt(PropagateStatement pStmt) {
// List<NamedElement> destinationList = pStmt.getDestComp_path();
// List<NamedElement> sourceList = pStmt.getSrcComp_path();
// List<String> sourceFaults = pStmt.getSrcFaultList();
// List<String> destFaults = pStmt.getDestFaultList();
// ComponentImplementation compImpl = EcoreUtil2.getContainerOfType(pStmt, ComponentImplementation.class);
//
// // Test for propagate stmt in non-implementation
// if (compImpl == null) {
// error(pStmt, "Propagation statements can only be defined in component implementation");
// } else {
// // Get all faults and comp names in program
// Map<String, List<String>> mapCompNameToFaultName = collectFaultsInProgram(compImpl);
// // Check length of source and dest lists
// if (sourceList.size() != sourceFaults.size()) {
// error(pStmt, "Each source fault name must have an associated component name.");
// } else if (destinationList.size() != destFaults.size()) {
// error(pStmt, "Each destination fault name must have an associated component name.");
// } else {
// for(NamedElement dest : destinationList) {
// if (!mapCompNameToFaultName.containsKey(dest.getName())) {
// error(pStmt, "Component: " + dest.getName() + " is undefined in program.");
// } else {
// int i = destinationList.indexOf(dest);
// List<String> faultList = mapCompNameToFaultName.get(dest.getName());
// if (!faultList.contains(destFaults.get(i))) {
// error(pStmt,
// "Fault: " + destFaults.get(i) + " is undefined in component: " + dest.getName());
// }
// }
// }
// for(NamedElement source : sourceList) {
// if (!mapCompNameToFaultName.containsKey(source.getName())) {
// error(pStmt, "Component: " + source.getName() + " is undefined in program.");
// } else {
// int i = sourceList.indexOf(source);
// List<String> faultList = mapCompNameToFaultName.get(source.getName());
// if (!faultList.contains(sourceFaults.get(i))) {
// error(pStmt, "Fault: " + sourceFaults.get(i) + " is undefined in component: "
// + source.getName());
// }
// }
// }
// }
// // Check that all source faults are hw faults
// for (String sf : sourceFaults) {
// if (!definedHWFaultsInProgram.contains(sf)) {
// error(pStmt,
// "The fault: " + sf + " is not a HW fault. All source faults must be defined as HW Faults.");
// }
// }
// }
// }
/**
* Checks that activation stmt defined in implementation,
* the agree var is defined in agree annex of this implementation,
* the type of agree var is boolean,
* and the faults are defined on the designated components.
* @param actStmt
*/
@Check(CheckType.FAST)
public void checkActivationStatement(ActivationStatement actStmt) {
NamedElement faultComp = actStmt.getFaultComp_Path();
String faultName = actStmt.getFaultName();
String agreeVarName = actStmt.getAgreeBoolVarName();
ComponentImplementation compImpl = EcoreUtil2.getContainerOfType(actStmt, ComponentImplementation.class);
// Test for propagate stmt in non-implementation
if (compImpl == null) {
error(actStmt, "Activation statements can only be defined in component implementation");
} else {
ComponentType compType = compImpl.getType();
if (compType != null) {
Map<String, List<String>> mapCompNameToFaultNames = collectFaultsInProgram(compImpl);
List<EObject> assignableElements = collectAssignableElementsInTypeAndImpl(compImpl);
boolean found = false;
for (EObject assignableElement : assignableElements) {
if (assignableElement instanceof NamedElement) {
NamedElement namedEl = (NamedElement) assignableElement;
if (agreeVarName.contentEquals(namedEl.getName())) {
found = true;
break;
}
}
}
if (found == false) {
error(actStmt, "The eq statement: " + agreeVarName + " does not match an eq statement defined in the Agree annex.");
}
// Check fault names and components
if (!mapCompNameToFaultNames.containsKey(faultComp.getName())) {
error(actStmt, "The fault component: " + faultComp.getName() + " is not a valid component name for the fault: " + faultName);
} else {
if (!mapCompNameToFaultNames.get(faultComp.getName()).contains(faultName)) {
error(actStmt, "The fault: " + faultName + " does not match a fault defined in component: " + faultComp.getName());
}
}
}
}
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project AMASE by loonwerks.
the class SafetyScopeProvider method getNamedElementsFromClassifier.
private Set<NamedElement> getNamedElementsFromClassifier(Classifier ctx, boolean fromCompImpl) {
Set<NamedElement> components = new HashSet<>();
for (AnnexSubclause annex : AnnexUtil.getAllAnnexSubclauses(ctx, AgreePackage.eINSTANCE.getAgreeContractSubclause())) {
AgreeContract contract = (AgreeContract) ((AgreeContractSubclause) annex).getContract();
components.addAll(getNamedElementsFromSpecs(contract.getSpecs()));
}
if (ctx instanceof ComponentImplementation) {
components.addAll(((ComponentImplementation) ctx).getAllSubcomponents());
components.addAll(((ComponentImplementation) ctx).getAllConnections());
components.addAll(getNamedElementsFromClassifier(((ComponentImplementation) ctx).getType(), true));
} else if (ctx instanceof ComponentType) {
if (fromCompImpl) {
List<Feature> fs = ((ComponentType) ctx).getAllFeatures();
components.addAll(fs);
} else {
List<Feature> fs = ((ComponentType) ctx).getOwnedFeatures();
components.addAll(fs);
}
}
components.addAll(getNamedElements(getAadlContainer(ctx)));
return components;
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class FlowLatencyUtil method getContributorType.
public static String getContributorType(EObject relatedElement) {
if (relatedElement instanceof ComponentInstance) {
ComponentInstance relatedComponentInstance = (ComponentInstance) relatedElement;
if (relatedComponentInstance.getCategory() == ComponentCategory.VIRTUAL_BUS) {
return "protocol";
}
if (relatedComponentInstance.getCategory() == ComponentCategory.VIRTUAL_PROCESSOR) {
return "partition";
}
return relatedComponentInstance.getCategory().getName();
}
if (relatedElement instanceof VirtualBus) {
return "protocol";
}
if (relatedElement instanceof ComponentClassifier) {
ComponentType relatedComponentType = (ComponentType) relatedElement;
return relatedComponentType.getCategory().getName();
}
if (relatedElement instanceof ConnectionInstance) {
final ConnectionKind connectionKind = ((ConnectionInstance) relatedElement).getKind();
Timing connectionType;
try {
connectionType = connectionKind == ConnectionKind.PORT_CONNECTION ? CommunicationProperties.getTiming((ConnectionInstance) relatedElement).orElse(Timing.SAMPLED) : Timing.SAMPLED;
} catch (final PropertyLookupException e) {
// Property association semantics for FEATURE connections are missing
connectionType = Timing.SAMPLED;
}
if (connectionType == Timing.DELAYED) {
return "delayed connection";
}
if (connectionType == Timing.IMMEDIATE) {
return "immediate connection";
}
if (connectionType == Timing.SAMPLED) {
return "connection";
}
return "connection";
}
return "component";
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class LatencyContributorComponent method getContributorType.
@Override
protected String getContributorType() {
ComponentInstance relatedComponentInstance;
ComponentType relatedComponentType;
if (relatedElement instanceof ComponentInstance) {
relatedComponentInstance = (ComponentInstance) relatedElement;
if (relatedComponentInstance.getCategory() == ComponentCategory.VIRTUAL_BUS) {
return "protocol";
}
if (relatedComponentInstance.getCategory() == ComponentCategory.VIRTUAL_PROCESSOR) {
return "partition";
}
return relatedComponentInstance.getCategory().getName();
}
if (relatedElement instanceof VirtualBus) {
return "protocol";
}
if (relatedElement instanceof ComponentClassifier) {
relatedComponentType = (ComponentType) relatedElement;
return relatedComponentType.getCategory().getName();
}
return "component";
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class PropertyUtils method findPropertyAssociation.
/**
* Returns the latest definition of the property association that matches to
* the given propertyName for the given named element. Otherwise it returns
* {@code null}.
* <br><br>
* Property association evaluation order is as follow:
* <br><br>
* 1. Find the property association within the given named element itself.
* <br>
* 2. Find the property association that applies to the given named element
* within the named element's parent containers.
* <br>
* 3. If the named element is a component instance, find the property
* association within the component instance's component implementation.
* <br>
* 4. If the named element is a component implementation, first look within
* it and its ancestors then its component type (and the component type
* 's ancestors).
* <br>
* 5. If the named element is a component type, find the property association
* within it and its ancestors.
*
* @param propertyName a given property name
* @param owner a given named element
* @return the latest definition of the property association that matches
* the given propertyName or {@code null}.
*/
public static PropertyAssociation findPropertyAssociation(String propertyName, NamedElement owner) {
// 1. Look within the owner.
for (PropertyAssociation pa : owner.getOwnedPropertyAssociations()) {
// Sometime property doesn't have name.
if (pa.getProperty().getName() == null) {
continue;
}
if (pa.getProperty().getName().equalsIgnoreCase(propertyName)) {
return pa;
}
}
PropertyAssociation result = null;
// 2. Look within parent containers if they defined an property that applies
// the given property.
result = isInAppliesTo(owner, propertyName);
if (result == null) {
List<PropertyAssociation> pas = new ArrayList<PropertyAssociation>();
if (owner instanceof ComponentInstance) {
ComponentInstance inst = (ComponentInstance) owner;
ComponentImplementation ci = inst.getContainingComponentImpl();
if (ci != null) {
owner = ci;
}
}
if (owner instanceof ComponentImplementation) {
ComponentImplementation ci = (ComponentImplementation) owner;
pas.addAll(ci.getAllPropertyAssociations());
owner = ci.getType();
}
if (owner instanceof ComponentType) {
ComponentType type = (ComponentType) owner;
pas.addAll(type.getAllPropertyAssociations());
}
if (false == pas.isEmpty()) {
// of the given property.
for (PropertyAssociation pa : pas) {
Property p = pa.getProperty();
// Sometime, properties don't have name.
if (p.getName() != null && p.getName().equalsIgnoreCase(propertyName)) {
result = pa;
break;
}
}
}
}
return result;
}
Aggregations