Model Utility Classes

AutosarUtil

The class AutosarUtil is a static utility class. Its methods are not directly related to the MDF model but are useful when client code deals with AUTOSAR paths and shortnames on string basis. Some of these methods are
  • isValidShortname(String): Checks if this shortname is valid according the rules, the AUTOSAR standard defines (character set for example)
  • getLastShortname(String): Returns the last shortname of the specified AUTOSAR path
  • getFirstShortname(String): Returns the first shortname of the specified AUTOSAR path
  • getAllShortnames(String): Returns all shortnames of the specified AUTOSAR path

AsrPath

The AsrPath class represents an AUTOSAR path without a connection to any model. AsrPaths are constant; their values cannot be changed after they are created. This class is immutable!
AsrPath methods
// String based APIs
final AsrPath genericPath = AsrPath.create("/a/b");
final AsrPath relativeChildPathWithParent = AsrPath.create(genericPath, "e");
final AsrPath absoluteChildPathWithParent = AsrPath.create(genericPath, "/a/b/e");

// Error tolerant APIs
final String pathMayBeInvalid = "??/invalid/??";
final AsrPath mayBeInvalidPath = AsrPath.tryCreate(pathMayBeInvalid);
if (mayBeInvalidPath != null) {
    // work on valid path
}

// retrieve the model element: connect to loaded model via project context
final MIReferrable referrableAutosarObject = genericPath.getAutosarObject(getProjectContext());
if (referrableAutosarObject != null) {
    // work with autosar object
}

TypedAsrPath

Typed version of an AsrPath to represent an AUTOSAR path and its expected metamodel class.

TypedAsrPath methods
// String based APIs
final TypedAsrPath<MIContainer> containerAsrPath = AsrPath.create("/ActiveEcuC/PduR/PduRRoutingTables/PduRRoutingPathGroup", MIContainer.class);
final TypedAsrPath<MIModuleConfiguration> moduleAsrPath = AsrPath.create("/ActiveEcuC/PduR", MIModuleConfiguration.class);
final TypedAsrPath<MIContainer> pduRRoutingTables = AsrPath.create(moduleAsrPath, "PduRRoutingTables", MIContainer.class);

// Error tolerant APIs
final String pathMayBeInvalid = "??/invalid/??";
final TypedAsrPath<MIContainer> mayBeInvalidPath = AsrPath.tryCreate(pathMayBeInvalid, MIContainer.class);
if (mayBeInvalidPath != null) {
    // work on valid path
}

// check model elements: connect to loaded model via project context
final MIReferrable referrable = getReferrable();
if (containerAsrPath.isPathOf(referrable)) {
    // referrable has correct path and type
    final MIContainer container = (MIContainer) referrable;
}
This class implements an immutable identifier for AUTOSAR objects.

An AsrObjectLink can be created for each object in the MDF AUTOSAR model tree. The main use case of object links is to identify an object unambiguously at a specific point in time for logging reasons. Additionally and under specific conditions it is also possible to find the related MDF object using its AsrObjectLink instance. But this search-by-link cannot be guaranteed after model changes (details and restrictions below).

  • They are immutable and will therefore become invalid when the model changes
  • So they don't guarantee that the related MDF object can be retrieved after the model has been changed. Search-by-link may even find another object or throw an exception in this case

DefRefs

The DefRef class represents an AUTOSAR definition reference (e.g. /MICROSAR/CanIf) without a connection to any model. A DefRef replaces the String which represents a definition reference. You shall always use a DefRef instance, when you want to reference something by it's definition.

The class abstracts the behavior of definition references in the AUTOSAR model (e.g. AUTOSAR 3 and AUTOSAR 4 handling).

DefRefs are constant; their values can not be changed after they are created. All DefRef classes are immutable.

A DefRef represents the definition reference as two parts:

  • Package part - e.g. /MICROSAR
  • Definition without the package part - e.g. CanIf/CanIfGeneral
This is used to navigate through the AUTOSAR model with refinements and wildcards. So you have to create a DefRef with the two parts separated.

The figure DefRefClasses shows the structure of the DefRef class and its sub classes.

DefRef class structure
Figure 1. DefRef class structure

Creation

You can create a DefRef object with following public static methods (partial):
  • DefRef.create(DefRef, String) - Parent DefRef, Child name
  • DefRef.create(IDefRefWildcard, String) - Wildcard, Definition without package
  • DefRef.create(MIHasDefinition) - Model object
  • DefRef.create(MIHasDefinition, String) - Parent object, Child name
  • DefRef.create(MIParamConfMultiplicity) - Definition object
  • DefRef.create(String, String) - Package part, Definition without package

Wildcards

DefRef instances can also have a wildcard instead of a package String (IDefRefWildcard). The wildcard is used to match on multiple packages. See chapter IDefRefWildcard for details.

Useful Methods

This section describes some useful methods (Please look at the javadoc of the DefRef class for a full documentation):
  • defRef.isDefinitionOf(MIHasDefinition) - Checks the definition of the configuration element and returns true if the element has the definition. The "defRef" object is e.g. from the Constants class.
    • Note: The method isDefinitionOf() returns false, if the element is removed or invisible.
  • defRef.asDefinitionOf(MIHasDefinition, Class) - Checks the definition of the configuration element and returns the element casted to the configuration subtype, or null.
    • Note: The method asDefinitionOf() returns null, if the element is removed or invisible.
MIObject yourObject = ...;
DefRef yourDefRef = ...;

if(yourDefRef.isDefinitionOf(yourObject)){
     //It is the correct instance
     //Do something
}

//Or with an integrated cast in the TypedDefRef case
final MIContainer container = yourDefRef.asDefinitionOf(yourObject, MIContainer.class);
if(container  != null){
     //Do something
}

TypedDefRefs

The TypedDefRef class represents an AUTOSAR definition reference with the type of the AUTOSAR (MDF) model. So every TypedDefRef knows which Definition, Configuration and Value element is correct for the Definition path. The DEF_TYPE, CONFIG_TYPE and VALUE_TYPE are Java generics and are used in many APIs to return the specific type of a request. In addition the most TypedDefRefs also provide additional TypeInfo data, like the Multiplicity of the element. See TypeInfo javadoc for more details.

DefRef Wildcards

The DefRef class supports so called wildcards, which could be used to match on multiple packages at once, like the /[MICROSAR] wildcard matches on any DefRef package starting with /MICROSAR. E.g. /MICROSAR, /MICROSAR/S12x, ....

Every wildcard is of type IDefRefWildcard. An IDefRefWildcard instance could be passed to the DefRef.create(IDefRefWildcard, String) method to create a DefRef with wildcard information.

Custom DefRef Wildcards

You could create your own wildcard by implementing the interface IDefRefWildcard. Please choose a good name for your wildcard, because this could be displayed to the user, e.g. in Validation results. The matches(DefRef) method shall return true, if the passed DefRef matches the wildcard constraints.

Every wildcard string shall have the notation /[NameOfWildcard].<br/>E.g. /[MICROSAR], /[!MICROSAR].

Predefined DefRef Wildcards

The class EDefRefWildcard contains the predefined IDefRefWildcards for the DefRef class. These IDefRefWildcards could be used to create DefRefs, without creating your own wildcard for the standard use cases

The DefRef.create(String, String) method will parse the first String to find a wildcard matching the EDefRefWildcards.

Predefined wildcards:

The class EDefRefWildcard defines the following wildcards, with the specified semantic:
  • EDefRefWildcard.ANY /[ANY]: Matches on any package path. It is equal to any package and any packages refines from ANY wildcard.
  • EDefRefWildcard.AUTOSAR /[AUTOSAR]: Matches on the AUTOSAR3 and AUTOSAR4 packages (see DefRef class). It is equal to the AUTOSAR packages, but not to refined packages e.g. /MICROSAR. Any packages which refined from AUTOSAR also refines from AUTOSAR wildcard.
  • EDefRefWildcard.NOT_AUTOSAR_STMD /[!AUTOSAR_STMD]: Matches on any package except the AUTOSAR packages. It is equal to any package, except AUTOSAR packages. Any package refines from NOT_AUTOSAR_STMD wildcard, except AUTOSAR packages.
  • EDefRefWildcard.MICROSAR /[MICROSAR]: Matches on any package stating with /MICROSAR (also /MICROSAR/S12x). It is equal to any package stating with /MICROSAR. Any package starting with /MICROSAR refines from MICROSAR wildcard.
  • EDefRefWildcard.NOT_MICROSAR /[!MICROSAR]: Matches on any package path not starting with /MICROSAR. It is equal to any package not starting with /MICROSAR. Any package, which does not start with /MICROSAR, refines from NOT_MICROSAR wildcard. Also the AUTOSAR packages refine from NOT_MICROSAR wildcard.

Creation of the DefRef with Wildcard

The elements of EDefRefWildcard could be passed to the DefRef constructor:
	DefRef myDefRef = DefRef.create(EDefRefWildcard.MICROSAR, "CanIf");