use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class AadlPrototypeUtil method getPrototypeBindingContextByContainer.
public static Element getPrototypeBindingContextByContainer(final BusinessObjectContext queryable) {
BusinessObjectContext temp = queryable;
while (temp != null) {
Object bo = temp.getBusinessObject();
if (bo instanceof ComponentClassifier || bo instanceof FeatureGroupType) {
return (Classifier) bo;
} else if (bo instanceof Subcomponent) {
return (Subcomponent) bo;
} else if (bo instanceof FeatureGroup) {
if (temp.getParent() != null) {
return getFeatureGroupTypeOrActual(temp.getParent(), (FeatureGroup) bo);
}
return null;
}
temp = temp.getParent();
}
return null;
}
use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class AadlSubcomponentUtil method setClassifier.
public static void setClassifier(final Subcomponent sc, final SubcomponentType selectedSubcomponentType) {
// Import as necessary
if (selectedSubcomponentType != null) {
// Import its package if necessary
final AadlPackage pkg = (AadlPackage) sc.getElementRoot();
if (selectedSubcomponentType instanceof ComponentClassifier && selectedSubcomponentType.getNamespace() != null && pkg != null) {
final PackageSection section = pkg.getPublicSection();
final AadlPackage selectedClassifierPkg = (AadlPackage) selectedSubcomponentType.getNamespace().getOwner();
if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
}
}
}
if (sc instanceof SystemSubcomponent) {
((SystemSubcomponent) sc).setSystemSubcomponentType((SystemSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof AbstractSubcomponent) {
((AbstractSubcomponent) sc).setAbstractSubcomponentType((AbstractSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof ThreadGroupSubcomponent) {
((ThreadGroupSubcomponent) sc).setThreadGroupSubcomponentType((ThreadGroupSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof ThreadSubcomponent) {
((ThreadSubcomponent) sc).setThreadSubcomponentType((ThreadSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof SubprogramSubcomponent) {
((SubprogramSubcomponent) sc).setSubprogramSubcomponentType((SubprogramSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof SubprogramGroupSubcomponent) {
((SubprogramGroupSubcomponent) sc).setSubprogramGroupSubcomponentType((SubprogramGroupSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof DataSubcomponent) {
((DataSubcomponent) sc).setDataSubcomponentType((DataSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof VirtualBusSubcomponent) {
((VirtualBusSubcomponent) sc).setVirtualBusSubcomponentType((VirtualBusSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof VirtualProcessorSubcomponent) {
((VirtualProcessorSubcomponent) sc).setVirtualProcessorSubcomponentType((VirtualProcessorSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof BusSubcomponent) {
((BusSubcomponent) sc).setBusSubcomponentType((BusSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof ProcessSubcomponent) {
((ProcessSubcomponent) sc).setProcessSubcomponentType((ProcessSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof ProcessorSubcomponent) {
((ProcessorSubcomponent) sc).setProcessorSubcomponentType((ProcessorSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof DeviceSubcomponent) {
((DeviceSubcomponent) sc).setDeviceSubcomponentType((DeviceSubcomponentType) selectedSubcomponentType);
} else if (sc instanceof MemorySubcomponent) {
((MemorySubcomponent) sc).setMemorySubcomponentType((MemorySubcomponentType) selectedSubcomponentType);
} else {
throw new RuntimeException("Unexpected type: " + sc.getClass().getName());
}
}
use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class AadlUiUtil method getPotentialClassifiersForEditing.
/**
* Returns a list of classifiers for editing based on a specified business object.
* If the specified object is of the specified type and passes the filter, only it is returned.
* @param bo
* @return
*/
public static <ClassifierType> List<ClassifierType> getPotentialClassifiersForEditing(final Object bo, final Class<ClassifierType> classifierClass, final Predicate<ClassifierType> filter, final boolean includeAllWhenBoIsMatch) {
if (!includeAllWhenBoIsMatch) {
if (matches(bo, classifierClass, filter)) {
return Collections.singletonList(classifierClass.cast(bo));
}
}
final List<ClassifierType> results = new ArrayList<>();
if (bo instanceof ComponentType || bo instanceof FeatureGroupType) {
addSelfAndExtended((Classifier) bo, classifierClass, results);
} else if (bo instanceof ComponentImplementation) {
final ComponentImplementation ci = (ComponentImplementation) bo;
addSelfAndExtended(ci, classifierClass, results);
addSelfAndExtended(ci.getType(), classifierClass, results);
} else if (bo instanceof Subcomponent) {
final ComponentClassifier subcomponentClassifier = ((Subcomponent) bo).getAllClassifier();
addSelfAndExtended(subcomponentClassifier, classifierClass, results);
if (subcomponentClassifier instanceof ComponentImplementation) {
addSelfAndExtended(((ComponentImplementation) subcomponentClassifier).getType(), classifierClass, results);
}
} else if (bo instanceof FeatureGroup) {
final FeatureGroupType fgType = ((FeatureGroup) bo).getAllFeatureGroupType();
addSelfAndExtended(fgType, classifierClass, results);
}
return results.stream().filter(c -> classifierClass.isInstance(c)).map(classifierClass::cast).filter(filter).collect(Collectors.toList());
}
use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class DefaultCreateSelectClassifierDialogModel method validate.
private String validate(final ClassifierOperationPart op, final ClassifierOperationPart baseOperation) {
if (ClassifierOperationPartType.isCreate(op.getType())) {
// Check identifier validity
if (!AadlNamingUtil.isValidIdentifier(op.getIdentifier())) {
return "The specified identifier is not a valid AADL identifier";
}
// Check component category
if (ClassifierOperationPartType.isComponentClassifierCreate(op.getType())) {
if (op.getComponentCategory() == null) {
return "Select a component category.";
}
if (baseOperation != null && baseOperation.getType() == ClassifierOperationPartType.EXISTING) {
// Check for a compatible component category when selecting an existing base classifier
final Classifier baseClassifier = classifierCreationHelper.getResolvedClassifier(baseOperation.getSelectedClassifier());
if (baseClassifier instanceof ComponentClassifier) {
final ComponentClassifier baseCategory = (ComponentClassifier) baseClassifier;
if (baseCategory.getCategory() != op.getComponentCategory() && (op.getType() != ClassifierOperationPartType.NEW_COMPONENT_TYPE || baseCategory.getCategory() != ComponentCategory.ABSTRACT)) {
return "Base: category(" + baseCategory.getCategory() + ") of the selected classifier is not compatible with category type of the " + StringUtil.snakeCaseToLowercaseWords(op.getType().name()) + "(" + op.getComponentCategory() + ").";
}
}
}
}
// Check package.
final AadlPackage pkg = classifierCreationHelper.getResolvedPackage(op.getSelectedPackage());
if (pkg == null) {
return "Select a package.";
}
final PackageSection section = pkg.getPublicSection();
if (section == null) {
return "Unable to retrieve public section of package.";
}
// New Component Implementation validation
if (op.getType() == ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION) {
if (baseOperation == null) {
return "Base classifier is invalid";
} else if (!ClassifierOperationPartType.isCreate(baseOperation.getType()) && baseOperation.getType() != ClassifierOperationPartType.EXISTING) {
if (baseOperation.getType() == ClassifierOperationPartType.NONE) {
return "Select a base for the new component implementation.";
} else {
return "Invalid base classifier: " + baseOperation.getType();
}
}
}
final String newName = classifierCreationHelper.getName(op, baseOperation);
if (newName == null) {
return "Unable to build name. Check for model errors.";
}
// Check if the name is in use
if (AadlNamingUtil.isNameInUse(section, newName)) {
return "The specified name conflicts with an existing member of the package.";
}
} else if (op.getType() == ClassifierOperationPartType.EXISTING) {
// Check that the classifier can be resolved.
if (classifierCreationHelper.getResolvedClassifier(op.getSelectedClassifier()) == null) {
return "Select a classifier.";
}
} else if (op.getType() == null) {
return "Select a classifier type.";
}
return null;
}
use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class PrototypesModel method setPrototypeType.
@Override
public void setPrototypeType(final EditablePrototype prototype, final PrototypeType value) {
// Check if the type is different by comparing EClass values
final EClass currentEClass = prototype.prototype.eClass();
final EClass newEClass = prototypeTypeToEClass(value);
if (newEClass == currentEClass) {
return;
}
modifyOwningClassifier("Set Prototype Type", prototype, c -> {
getPrototypeByName(c, prototype.name).ifPresent(p -> {
// Store location in list
final int index = c.getOwnedPrototypes().indexOf(p);
if (index == -1) {
throw new RuntimeException("Unable to get index of prototype being modified");
}
// Store fields
final String name = p.getName();
final Prototype refined = p.getRefined();
ComponentClassifier cc = null;
FeatureGroupType fgt = null;
boolean in = false;
boolean out = false;
boolean array = false;
if (p instanceof ComponentPrototype) {
final ComponentPrototype cp = (ComponentPrototype) p;
cc = cp.getConstrainingClassifier();
array = cp.isArray();
} else if (p instanceof FeatureGroupPrototype) {
final FeatureGroupPrototype fp = (FeatureGroupPrototype) p;
fgt = fp.getConstrainingFeatureGroupType();
} else if (p instanceof FeaturePrototype) {
final FeaturePrototype fp = (FeaturePrototype) p;
cc = fp.getConstrainingClassifier();
in = fp.isIn();
out = fp.isOut();
}
// Create new prototype
final Prototype newPrototype = (Prototype) EcoreUtil.create(newEClass);
c.getOwnedPrototypes().add(index, newPrototype);
if (refined == null) {
newPrototype.setName(name);
} else {
newPrototype.setRefined(refined);
}
// Set fields
if (newPrototype instanceof ComponentPrototype) {
final ComponentPrototype cp = (ComponentPrototype) newPrototype;
cp.setConstrainingClassifier(cc);
cp.setArray(array);
} else if (newPrototype instanceof FeatureGroupPrototype) {
final FeatureGroupPrototype fp = (FeatureGroupPrototype) newPrototype;
fp.setConstrainingFeatureGroupType(fgt);
} else if (newPrototype instanceof FeaturePrototype) {
final FeaturePrototype fp = (FeaturePrototype) newPrototype;
fp.setConstrainingClassifier(cc);
fp.setIn(in);
fp.setOut(out);
}
// Move property associations
newPrototype.getOwnedPropertyAssociations().addAll(p.getOwnedPropertyAssociations());
// Remove old prototype
EcoreUtil.remove(p);
});
});
}
Aggregations