use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.
the class AadlBusinessObjectProvider method getChildBusinessObjects.
@Override
public Stream<?> getChildBusinessObjects(final BusinessObjectProviderContext ctx) {
final Object bo = ctx.getBusinessObjectContext().getBusinessObject();
// An IProject is specified as the business object for contextless diagrams.
if (bo instanceof IProject) {
// Special handling for project
final IProject project = (IProject) bo;
// Perform an incremental project build to ensure new packages are included.
try {
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
} catch (CoreException e) {
throw new RuntimeException(e);
}
Stream<Object> packages = getPackages(project);
// If no packages were found, assume that the project needs to be built. This can happen if the Eclipse process is forcefully terminated.
if (packages == null) {
try {
project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
} catch (CoreException e) {
throw new RuntimeException(e);
}
packages = getPackages(project);
}
return packages;
} else if (bo instanceof AadlPackage) {
return getChildren((AadlPackage) bo, ctx.getExtensionRegistry());
} else if (bo instanceof Classifier) {
return getChildren((Classifier) bo, true, ctx.getExtensionRegistry());
} else if (bo instanceof FeatureGroup) {
final FeatureGroupType fgt = AadlFeatureUtil.getFeatureGroupType(ctx.getBusinessObjectContext(), (FeatureGroup) bo);
return fgt == null ? Stream.empty() : AadlFeatureUtil.getAllFeatures(fgt).stream();
} else if (bo instanceof Subcomponent) {
return getChildren((Subcomponent) bo, ctx.getBusinessObjectContext(), ctx.getExtensionRegistry());
} else if (bo instanceof SubprogramCall) {
return getChildren((SubprogramCall) bo);
} else if (bo instanceof SubprogramCallSequence) {
return getChildren((SubprogramCallSequence) bo);
} else if (bo instanceof ModeTransition) {
final ModeTransition mt = ((ModeTransition) bo);
final String modeTransitionTriggersDesc = mt.getOwnedTriggers().stream().map(mtt -> mttHandler.getName(mtt)).collect(Collectors.joining(","));
return Stream.concat(mt.getOwnedTriggers().stream(), Stream.of(new Tag(Tag.KEY_MODE_TRANSITION_TRIGGERS, modeTransitionTriggersDesc)));
} else if (bo instanceof ComponentInstance) {
return getChildren((ComponentInstance) bo);
} else if (bo instanceof FeatureInstance) {
return ((FeatureInstance) bo).getFeatureInstances().stream();
} else if (bo instanceof Connection) {
if (!((Connection) bo).isAllBidirectional()) {
return Stream.of(new Tag(Tag.KEY_UNIDIRECTIONAL, null));
}
} else if (bo instanceof ConnectionInstance) {
if (!((ConnectionInstance) bo).isBidirectional()) {
return Stream.of(new Tag(Tag.KEY_UNIDIRECTIONAL, null));
}
}
return Stream.empty();
}
use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.
the class AnnexHandler method getAnnexSubclauseIndex.
/**
* Returns a 0 based index for referencing an annex subclause in a list that contains only annex subclauses with the same type and owner
* @return
*/
public static int getAnnexSubclauseIndex(AnnexSubclause annexSubclause, final boolean useExtended) {
// Get the default annex library if a parsed annex subclause was specified. This is needed for the comparison later in the function.
if (!(annexSubclause instanceof DefaultAnnexSubclause)) {
if (annexSubclause.eContainer() instanceof DefaultAnnexSubclause) {
annexSubclause = (AnnexSubclause) annexSubclause.eContainer();
} else {
return -1;
}
}
final String annexName = annexSubclause.getName();
if (annexName == null) {
return -1;
}
final Classifier cl = annexSubclause.getContainingClassifier();
final List<Classifier> classifiers;
if (useExtended) {
classifiers = cl.getSelfPlusAllExtended();
// Get all related classifiers
if (cl instanceof ComponentImplementation) {
final ComponentType ct = ((ComponentImplementation) cl).getType();
if (ct != null) {
classifiers.addAll(ct.getSelfPlusAllExtended());
}
}
} else {
classifiers = Arrays.asList(cl);
}
int index = 0;
// Use reversed view of list so that base classifiers will be first. This is needed to ensure subclauses have unique indices
for (final Classifier tmpClassifier : Lists.reverse(classifiers)) {
for (final AnnexSubclause tmpSubclause : tmpClassifier.getOwnedAnnexSubclauses()) {
if (tmpSubclause == annexSubclause) {
return index;
} else if (annexName.equalsIgnoreCase(tmpSubclause.getName())) {
index++;
}
}
}
return -1;
}
use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.
the class ClassifierCreationHelper method buildName.
public String buildName(final ClassifierOperationPartType primaryType, final Supplier<AadlPackage> primaryPkgSupplier, final String identifier, final ClassifierOperationPart basePart) {
final String newName;
if (primaryType == ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION) {
if (basePart == null) {
throw new RuntimeException("Base operation in invalid");
}
final AadlPackage primaryPkg = primaryPkgSupplier.get();
final PackageSection section = primaryPkg.getPublicSection();
// Determine details about the type specified by the base operation part.
final String baseTypeName;
final AadlPackage typePackage;
// Get the name of the type and the package in which it is contained.
if (ClassifierOperationPartType.isCreate(basePart.getType())) {
typePackage = getResolvedPackage(basePart.getSelectedPackage());
baseTypeName = basePart.getIdentifier();
} else if (basePart.getType() == ClassifierOperationPartType.EXISTING) {
final Classifier classifier = getResolvedClassifier(basePart.getSelectedClassifier());
final ComponentType ct = getResolvedComponentType(classifier);
if (ct == null) {
return null;
}
typePackage = getPackage(ct);
baseTypeName = ct.getName();
} else {
throw new RuntimeException("Invalid base operation part: " + basePart.getType());
}
// Handle type not being in same package as implementation
final boolean samePackage = AadlNameUtil.namesAreEqual(primaryPkg, typePackage);
final String localBaseTypeName = samePackage ? baseTypeName : getRenamedType(section, typePackage, baseTypeName).aliasName;
newName = localBaseTypeName + "." + identifier;
} else {
newName = identifier;
}
return newName;
}
use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.
the class AadlPropertyResolver method processContainedPropertyAssociationsInChildren.
private void processContainedPropertyAssociationsInChildren(final BusinessObjectContext q) {
// Process contained property associations contained in children
for (final BusinessObjectContext childQueryable : q.getChildren()) {
final Object childBo = childQueryable.getBusinessObject();
if (childBo instanceof InstanceObject) {
processPropertyAssociationsForInstanceObjectsNotInTree(childQueryable, (InstanceObject) childBo);
} else {
if (childBo instanceof Subcomponent || childBo instanceof FeatureGroup) {
final NamedElement childNamedElement = (NamedElement) childBo;
// Handle refinements
RefinableElement tmpRefinable = (RefinableElement) childNamedElement;
do {
processDeclarativeContainedPropertyAssociations(childQueryable, tmpRefinable.getOwnedPropertyAssociations());
tmpRefinable = tmpRefinable.getRefinedElement();
} while (tmpRefinable != null);
// Process contained property associations contained in the element's classifier
if (childBo instanceof FeatureGroup) {
final FeatureGroupType featureGroupType = AadlPrototypeUtil.getFeatureGroupType(AadlPrototypeUtil.getPrototypeBindingContext(childQueryable), (FeatureGroup) childBo);
if (featureGroupType != null) {
processDeclarativeContainedPropertyAssociations(childQueryable, featureGroupType);
}
} else if (childBo instanceof Subcomponent) {
final Classifier subcomponentClassifier = AadlPrototypeUtil.getComponentClassifier(AadlPrototypeUtil.getPrototypeBindingContext(childQueryable), (Subcomponent) childBo);
if (subcomponentClassifier != null) {
processDeclarativeContainedPropertyAssociations(childQueryable, subcomponentClassifier);
}
}
} else if (childBo instanceof Classifier) {
processDeclarativeContainedPropertyAssociations(childQueryable, ((Classifier) childBo));
} else if (childBo instanceof AadlPackage) {
processContainedPropertyAssociationsInChildren(childQueryable);
}
}
}
}
use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.
the class AadlClassifierUtil method getComponentImplementation.
/**
* Returns a component implementation for a specified business object. Only component implementations and subcomponents are supported.
* @param bo
* @return
*/
public static Optional<ComponentImplementation> getComponentImplementation(final Object bo) {
final ComponentImplementation ci;
if (bo instanceof BusinessObjectContext) {
return getComponentImplementation(((BusinessObjectContext) bo).getBusinessObject());
} else if (bo instanceof ComponentImplementation) {
ci = (ComponentImplementation) bo;
} else if (bo instanceof Subcomponent) {
final Classifier scClassifier = ((Subcomponent) bo).getAllClassifier();
ci = scClassifier instanceof ComponentImplementation ? (ComponentImplementation) scClassifier : null;
} else {
ci = null;
}
return Optional.ofNullable(ci);
}
Aggregations