use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class CombinedErrorModelSubclause method create.
/**
* Creates an instance for the specified classifier. Processes error model subclauses owned or inherited by the classifier.
* @param classifier the classifier for which to create the instance.
* @return the new instance
*/
public static CombinedErrorModelSubclause create(final Classifier classifier) {
final Map<String, PropagationPoint> points = new HashMap<>();
final Map<String, PropagationPath> paths = new HashMap<>();
final Map<String, ErrorFlow> flows = new HashMap<>();
final PropagationNode propagations = new PropagationNode();
final Set<KeywordPropagationPointType> usedKeywordPointTypes = new HashSet<>();
final EList<Classifier> classifiers = classifier.getSelfPlusAllExtended();
if (classifier instanceof ComponentImplementation) {
final ComponentType ct = ((ComponentImplementation) classifier).getType();
if (ct != null) {
classifiers.addAll(ct.getSelfPlusAllExtended());
}
}
final boolean[] subclauseFound = { false };
for (final Classifier tmpClassifier : Lists.reverse(classifiers)) {
ErrorModelGeUtil.getAllErrorModelSubclauses(tmpClassifier).forEachOrdered(subclause -> {
subclauseFound[0] = true;
addAllToMap(subclause.getPoints(), points);
addAllToMap(subclause.getPaths(), paths);
addAllToMap(subclause.getFlows(), flows);
// Create a tree for error propagations
for (final ErrorPropagation propagation : subclause.getPropagations()) {
propagations.put(propagation);
}
//
for (final ErrorPropagation propagation : subclause.getPropagations()) {
if (propagation.getKind() != null) {
usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(propagation.getKind()));
}
}
for (final ErrorFlow errorFlow : subclause.getFlows()) {
if (errorFlow instanceof ErrorPath) {
final ErrorPath errorPath = (ErrorPath) errorFlow;
if (errorPath.isAllIncoming() || errorPath.isAllOutgoing()) {
usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
}
if (errorPath.getIncoming() != null) {
usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorPath.getIncoming().getKind()));
}
if (errorPath.getOutgoing() != null) {
usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorPath.getOutgoing().getKind()));
}
} else if (errorFlow instanceof ErrorSink) {
final ErrorSink errorSink = (ErrorSink) errorFlow;
if (errorSink.isAllIncoming()) {
usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
} else if (errorSink.getIncoming() != null) {
usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorSink.getIncoming().getKind()));
}
} else if (errorFlow instanceof ErrorSource) {
final ErrorSource errorSrc = (ErrorSource) errorFlow;
if (errorSrc.isAll()) {
usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
} else if (errorSrc.getSourceModelElement() instanceof ErrorPropagation) {
usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(((ErrorPropagation) errorSrc.getSourceModelElement()).getKind()));
}
}
}
});
}
return new CombinedErrorModelSubclause(subclauseFound[0], points, paths, flows, usedKeywordPointTypes, propagations);
}
use of org.geotoolkit.sml.xml.v100.ComponentType 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.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class ClassifierOperationExecutor method addStep.
/**
* @param operation
* @param part
* @param basePart
* @param pkgBoc if non-null then the operation result will indicate that the object should be added to the diagram.
* @return
*/
private OperationBuilder<Classifier> addStep(final OperationBuilder<?> operation, final ClassifierOperationPart part, final ClassifierOperationPart basePart, final BusinessObjectContext pkgBoc) {
Objects.requireNonNull(part, "part must not be null");
Objects.requireNonNull(part.getType(), "operation part type must not be null");
switch(part.getType()) {
case EXISTING:
return operation.supply(() -> StepResultBuilder.create(classifierCreationHelper.getResolvedClassifier(part.getSelectedClassifier())).build());
case NEW_COMPONENT_IMPLEMENTATION:
case NEW_COMPONENT_TYPE:
case NEW_FEATURE_GROUP_TYPE:
final EClass creationEClass = getCreationEClass(part);
final PackageSection unmodifiableSection = classifierCreationHelper.getResolvedPublicSection(part.getSelectedPackage());
return operation.modifyModel(unmodifiableSection, (tag, prevResult) -> tag, (tag, section, prevResult) -> {
// Create the new classifier
final Classifier newClassifier = section.createOwnedClassifier(creationEClass);
// Set name
newClassifier.setName(classifierCreationHelper.getName(part, basePart));
final Classifier baseOperationResult = resolveWithLiveResourceSetOrThrowIfProxy((Classifier) prevResult);
// Handle component implementations
if (newClassifier instanceof ComponentImplementation) {
final ComponentImplementation newImpl = (ComponentImplementation) newClassifier;
final ComponentType baseComponentType;
if (baseOperationResult instanceof ComponentType) {
final Realization realization = newImpl.createOwnedRealization();
baseComponentType = (ComponentType) baseOperationResult;
realization.setImplemented(baseComponentType);
} else if (baseOperationResult instanceof ComponentImplementation) {
final ComponentImplementation baseImpl = (ComponentImplementation) baseOperationResult;
final ImplementationExtension extension = newImpl.createOwnedExtension();
extension.setExtended(baseImpl);
final Realization realization = newImpl.createOwnedRealization();
realization.setImplemented(baseImpl.getType());
baseComponentType = baseImpl.getType();
// Import the base implementation's package
final AadlPackage baseImplPkg = (AadlPackage) baseImpl.getNamespace().getOwner();
AadlImportsUtil.addImportIfNeeded(section, baseImplPkg);
} else {
throw new RuntimeException("Invalid base classifier: " + baseOperationResult);
}
// Get the base component type
if (baseComponentType == null) {
throw new RuntimeException("Unable to determine base component type");
}
if (!AadlNameUtil.namesAreEqual(section, baseComponentType.getNamespace())) {
// Import the package if necessary
final AadlPackage baseComponentTypePkg = (AadlPackage) baseComponentType.getNamespace().getOwner();
AadlImportsUtil.addImportIfNeeded(section, baseComponentTypePkg);
// Create an alias for the component type
final ClassifierCreationHelper.RenamedTypeDetails aliasDetails = classifierCreationHelper.getRenamedType(section, baseComponentTypePkg, baseComponentType.getName());
if (!aliasDetails.exists) {
final ComponentTypeRename ctr = section.createOwnedComponentTypeRename();
ctr.setName(aliasDetails.aliasName);
ctr.setCategory(baseComponentType.getCategory());
ctr.setRenamedComponentType(baseComponentType);
}
}
} else if (newClassifier instanceof ComponentType && baseOperationResult instanceof ComponentType) {
final ComponentType newType = (ComponentType) newClassifier;
final TypeExtension extension = newType.createOwnedExtension();
extension.setExtended((ComponentType) baseOperationResult);
} else if (newClassifier instanceof FeatureGroupType && baseOperationResult instanceof FeatureGroupType) {
final FeatureGroupType newFgt = (FeatureGroupType) newClassifier;
final GroupExtension extension = newFgt.createOwnedExtension();
extension.setExtended((FeatureGroupType) baseOperationResult);
}
final StepResultBuilder<Classifier> resultBuilder = StepResultBuilder.create(newClassifier);
// Hint for adding to diagram
if (pkgBoc != null && newClassifier != null) {
resultBuilder.showNewBusinessObject(pkgBoc, newClassifier);
}
return resultBuilder.build();
});
case NONE:
return operation.map(prevResult -> StepResultBuilder.create((Classifier) null).build());
default:
throw new RuntimeException("Unexpected operation: " + part.getType());
}
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class InstantiateModel method populateComponentInstance.
// --------------------------------------------------------------------------------------------
// Methods for instantiating the component hierarchy
// --------------------------------------------------------------------------------------------
/*
* Fill in modes, transitions, subcomponent instances, features, flow specs.
*/
protected void populateComponentInstance(ComponentInstance ci, int index) throws InterruptedException {
ComponentImplementation impl = getComponentImplementation(ci);
ComponentType type = getComponentType(ci);
if (ci.getContainingComponentInstance() instanceof SystemInstance) {
monitor.subTask("Creating instances in " + ci.getName());
}
/*
* Add modes. Must do this before adding subcomponents
* because we need to know what are the ModeInstances when processing
* modal subcomponents.
*/
if (impl != null) {
fillModes(ci, impl.getAllModes());
} else if (type != null) {
fillModes(ci, type.getAllModes());
}
if (impl != null) {
// Recursively add subcomponents
instantiateSubcomponents(ci, impl);
// TODO now add subprogram calls
// EList callseqlist = compimpl.getXAllCallSequence();
// for (Iterator it = callseqlist.iterator(); it.hasNext();) {
// CallSequence cseq = (CallSequence) it.next();
//
// EList calllist = cseq.getCall();
// for (Iterator iit = calllist.iterator(); iit.hasNext();) {
// final SubprogramSubcomponent call =
// (SubprogramSubcomponent) iit.next();
// instantiateSubcomponent(ci, cseq, call);
// }
// }
}
// do it only if subcomponent has type
if (type != null) {
instantiateFeatures(ci);
}
/*
* Add mode transitions. Must do this after adding subcomponents
* because we need reference subcomponent features as triggers.
*/
if (impl != null) {
fillModeTransitions(ci, impl.getAllModeTransitions());
} else if (type != null) {
fillModeTransitions(ci, type.getAllModeTransitions());
}
if (type != null) {
instantiateFlowSpecs(ci);
}
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.
the class PropertiesValidator method checkInheritedMissingModes.
public void checkInheritedMissingModes(Classifier classifier) {
List<Mode> allModes = new ArrayList<Mode>();
List<PropertyAssociation> propertyAssociations = new ArrayList<PropertyAssociation>();
List<PropertyAssociation> ownedPropertyAssociations = new ArrayList<PropertyAssociation>();
List<Property> ownedProperties = new ArrayList<Property>();
Element warningTarget = null;
if (classifier instanceof ComponentImplementation) {
ComponentImplementation componentImpl = (ComponentImplementation) classifier;
if (null == componentImpl.getExtended()) {
return;
}
allModes = componentImpl.getAllModes();
propertyAssociations = componentImpl.getAllPropertyAssociations();
ownedPropertyAssociations = componentImpl.getOwnedPropertyAssociations();
ownedProperties = new ArrayList<Property>();
warningTarget = componentImpl.getOwnedExtension();
} else if (classifier instanceof ComponentType) {
ComponentType componentType = (ComponentType) classifier;
if (null == componentType.getExtended()) {
return;
}
allModes = componentType.getAllModes();
propertyAssociations = componentType.getAllPropertyAssociations();
ownedPropertyAssociations = componentType.getOwnedPropertyAssociations();
ownedProperties = new ArrayList<Property>();
warningTarget = componentType.getOwnedExtension();
}
for (PropertyAssociation ownedPropertyAssociation : ownedPropertyAssociations) {
ownedProperties.add(ownedPropertyAssociation.getProperty());
}
Map<Property, List<Mode>> propModesMap = buildPropertySetForModeMap(allModes, propertyAssociations);
for (Property keyProperty : propModesMap.keySet()) {
if (ownedProperties.contains(keyProperty)) {
continue;
}
List<Mode> mappedModes = propModesMap.get(keyProperty);
for (Mode nextMode : allModes) {
if (!mappedModes.contains(nextMode)) {
warning(warningTarget, "Value not set for mode " + nextMode.getName() + " for property " + keyProperty.getQualifiedName());
}
}
}
}
Aggregations