Class AspectModelLoader

java.lang.Object
org.eclipse.esmf.metamodel.loader.AspectModelLoader

public class AspectModelLoader extends Object
Provides functionality to load an Aspect Model from a VersionedModel and use the correct SAMM resources to instantiate it. To load a regular Aspect Model, use getElements(VersionedModel) or getElementsUnchecked(VersionedModel). To load elements from an RDF model that might contain elements from multiple namespaces, use getNamespaces(VersionedModel).

Instances of VersionedModel are gained through an AspectModelResolver.

  • Method Details

    • getNamespaces

      public static io.vavr.control.Try<List<ModelNamespace>> getNamespaces(VersionedModel versionedModel)
      Loads elements from an RDF model that possibly contains multiple namespaces, and organize the result into a collection of ModelNamespace. Use this method only when you expect the RDF model to contain more than one namespace (which is not the case when aspect models contain the usual element definitions with one namespace per file), otherwise use getElements(VersionedModel).
      Parameters:
      versionedModel - The RDF model representation of the Aspect model
      Returns:
      the list of namespaces
    • getElements

      public static io.vavr.control.Try<List<ModelElement>> getElements(VersionedModel versionedModel)
      Creates Java instances for model element classes from the RDF input model
      Parameters:
      versionedModel - The RDF model representation of the Aspect model
      Returns:
      the list of loaded model elements on success
    • getElementsUnchecked

      public static List<ModelElement> getElementsUnchecked(VersionedModel versionedModel)
      Does the same as getElements(VersionedModel) but throws an exception in case of failures.
      Parameters:
      versionedModel - The RDF model representation of the Aspect model
      Returns:
      the list of model elements
      Throws:
      AspectLoadingException - when elements can not be loaded
    • getAspects

      public static io.vavr.control.Try<List<Aspect>> getAspects(VersionedModel versionedModel)
      Convenience method that does the same as getElements(VersionedModel) except it will return only the aspects contained in the model.
      Parameters:
      versionedModel - The RDF model representation of the Aspect model
      Returns:
      the list of model aspects
    • getAspectsUnchecked

      public static List<Aspect> getAspectsUnchecked(VersionedModel versionedModel)
      Does the same as getAspects(VersionedModel) but throws an exception in case of failures.
      Parameters:
      versionedModel - The RDF model representation of the Aspect model
      Returns:
      the list of model aspects
      Throws:
      AspectLoadingException - when elements can not be loaded
    • getSingleAspect

      public static io.vavr.control.Try<Aspect> getSingleAspect(VersionedModel versionedModel)
      Convenience method to load the single Aspect from a model, when the model contains exactly one Aspect. Caution: The method handles this special case. Aspect Models are allowed to contain any number of Aspects (including zero), so for the general case you should use getElements(VersionedModel) instead.
      Parameters:
      versionedModel - The RDF model representation of the Aspect model
      Returns:
      the single Aspect contained in the model
    • getSingleAspectUnchecked

      public static Aspect getSingleAspectUnchecked(VersionedModel versionedModel)
      Convenience method to load the single Aspect from a model, when the model contains exactly one Aspect. Does the same as getSingleAspect(VersionedModel) but throws an exception on failure. Caution: The method handles this special case. Aspect Models are allowed to contain any number of Aspects (including zero), so for the general case you should use getElementsUnchecked(VersionedModel) instead.
      Parameters:
      versionedModel - The RDF model representation of the Aspect model
      Returns:
      the single Aspect contained in the model
    • getSingleAspect

      public static io.vavr.control.Try<Aspect> getSingleAspect(VersionedModel versionedModel, Predicate<Aspect> selector)
      Similar to getSingleAspect(VersionedModel), except that a predicate can be provided to select which of potentially multiple aspects should be selected
      Parameters:
      versionedModel - the RDF model reprensentation of the Aspect model
      selector - the predicate to select an Aspect
      Returns:
      the selected Aspect, or a failure if 0 or more than 1 matching Aspects were found
    • getAspectContext

      public static io.vavr.control.Try<AspectContext> getAspectContext(File input)
      Convenience method to create an AspectContext directly from a model file. This method makes the following assumptions:
      • The model file is located in a directory structure as required by the FileSystemStrategy
      • The closure of the loaded model contains exactly one Aspect
      • The Aspect has the same name as the file's basename
      The method is intended for use in tests and comparable use cases, not as a general replacement for loading Aspect Models, since it does not handle model files with less or more than one Aspect.
      Parameters:
      input - the model file
      Returns:
      the loaded Aspect Context