Model Utility Classes
AutosarUtil
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 pathgetFirstShortname(String): Returns the first shortname of the specified AUTOSAR pathgetAllShortnames(String): Returns all shortnames of the specified AUTOSAR path
AsrPath
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!
// 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.
// 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;
}
AsrObjectLink
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).
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
DefRef with the two parts separated.
The figure DefRefClasses shows the structure of the DefRef class and its sub classes.
Creation
You can create a DefRef object with following public static methods (partial):DefRef.create(DefRef, String)- Parent DefRef, Child nameDefRef.create(IDefRefWildcard, String)- Wildcard, Definition without packageDefRef.create(MIHasDefinition)- Model objectDefRef.create(MIHasDefinition, String)- Parent object, Child nameDefRef.create(MIParamConfMultiplicity)- Definition objectDefRef.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()returnsfalse, if the element is removed or invisible.
- Note: The method
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()returnsnull, if the element is removed or invisible.
- Note: The method
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
TheTypedDefRef 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
TheDefRef 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 interfaceIDefRefWildcard. 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 classEDefRefWildcard 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 classEDefRefWildcard 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 fromANYwildcard.EDefRefWildcard.AUTOSAR/[AUTOSAR]: Matches on the AUTOSAR3 and AUTOSAR4 packages (seeDefRefclass). It is equal to the AUTOSAR packages, but not to refined packages e.g. /MICROSAR. Any packages which refined from AUTOSAR also refines fromAUTOSARwildcard.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 fromNOT_AUTOSAR_STMDwildcard, 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 fromMICROSARwildcard.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 fromNOT_MICROSARwildcard. Also the AUTOSAR packages refine fromNOT_MICROSARwildcard.