use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.
the class InstanceUtil method resolveComponentPrototype.
/**
* Find the binding for a given component prototype.
*
* @param proto the prototype to resolve
* @param context the context in which the prototype is used, e.g., a
* subcomponent instance
* @param classifierCache an optional cache of known instantiated
* classifiers, may be null
* @return The component prototype actual that the prototype resolves to.
*/
public static ComponentPrototypeActual resolveComponentPrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
ComponentPrototypeActual cpa = null;
ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) resolvePrototype(proto, context, classifierCache);
if (cpb == null) {
// cannot resolve
return null;
}
EList<ComponentPrototypeActual> actuals = cpb.getActuals();
if (actuals != null && actuals.size() > 0) {
ComponentPrototypeActual actual = actuals.get(0);
if (actual.getSubcomponentType() instanceof ComponentClassifier) {
cpa = actual;
} else {
// resolve recursively
cpa = resolveComponentPrototype((ComponentPrototype) actual.getSubcomponentType(), context.getContainingComponentInstance(), classifierCache);
}
}
return cpa;
}
use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.
the class InstanceUtil method resolveFeatureGroupPrototype.
/**
* Find the binding for a given feature group prototype.
*
* @param proto the prototype to resolve
* @param context the context in which the prototype is used, e.g., a
* subcomponent instance
* @param classifierCache an optional cache of known instantiated
* classifiers, may be null
* @return The feature group prototype actual the prototype is bound to.
*/
public static FeatureGroupPrototypeActual resolveFeatureGroupPrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
FeatureGroupPrototypeActual result = null;
FeatureGroupPrototypeBinding fgpb = (FeatureGroupPrototypeBinding) resolvePrototype(proto, context, classifierCache);
if (fgpb == null) {
// cannot resolve
return null;
}
FeatureGroupPrototypeActual actual = fgpb.getActual();
if (actual.getFeatureType() instanceof FeatureGroupType) {
result = actual;
} else {
// resolve recursively
result = resolveFeatureGroupPrototype((FeatureGroupPrototype) actual.getFeatureType(), context.getContainingComponentInstance(), classifierCache);
}
return result;
}
use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.
the class PropertyImpl method getPropertyValueFromDeclarativeModel.
protected void getPropertyValueFromDeclarativeModel(EvaluationContext ctx, PropertyAcc pas) throws InvalidModelException {
InstanceObject io = ctx.getInstanceObject();
List<? extends NamedElement> compDecls = io.getInstantiatedObjects();
if (compDecls == null) {
}
// Here we assume compDecls is empty or has only one element
if (!compDecls.isEmpty()) {
NamedElement compDecl = compDecls.get(0);
if (compDecl == null) {
return;
}
InstantiatedClassifier ic = ctx.getClassifierCache().get(io);
Classifier cl = (ic == null) ? null : ic.getClassifier();
if (compDecl instanceof Subcomponent) {
((SubcomponentImpl) compDecl).getPropertyValue(this, pas, cl, false);
} else if (compDecl instanceof FeatureGroup) {
((FeatureGroupImpl) compDecl).getPropertyValue(this, pas, cl, false);
} else if (compDecl instanceof Feature) {
((FeatureImpl) compDecl).getPropertyValue(this, pas, cl, false);
} else if (compDecl instanceof PortConnection) {
((PortConnectionImpl) compDecl).getPropertyValue(this, pas);
} else {
compDecl.getPropertyValueInternal(this, pas, true);
}
}
}
use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.
the class InstanceUtil method resolveFeaturePrototype.
/**
* Find the binding for a given feature prototype.
*
* @param proto the prototype to resolve
* @param context the context in which the prototype is used, e.g., a
* subcomponent instance
* @param classifierCache an optional cache of known instantiated
* classifiers, may be null
* @return The actual feature this prototype resolves to.
*/
public static FeaturePrototypeActual resolveFeaturePrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
FeaturePrototypeActual result = null;
FeaturePrototypeBinding fpb = (FeaturePrototypeBinding) resolvePrototype(proto, context, classifierCache);
if (fpb == null) {
return null;
}
result = fpb.getActual();
if (result instanceof FeaturePrototypeReference) {
// resolve recursively
result = resolveFeaturePrototype(((FeaturePrototypeReference) fpb.getActual()).getPrototype(), context.getContainingComponentInstance(), classifierCache);
}
return result;
}
use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.
the class InstanceUtil method getInstantiatedClassifier.
/**
* Get the component or feature group classifier that is instantiated by an
* instance object. Resolve prototypes if needed.
*
* @param iobj the instance object
* @param index the index of the instance object in an array
* @param classifierCache an optional cache of known instantiated
* classifiers, may be null
* @return the instantiated classifier together with bindings for anonymous
* classifiers
*/
public static InstantiatedClassifier getInstantiatedClassifier(InstanceObject iobj, int index, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
InstantiatedClassifier ic = null;
if (classifierCache != null) {
final InstantiatedClassifier temp = classifierCache.get(iobj);
if (temp != null) {
return temp == InstantiatedClassifier.NULL ? null : temp;
}
}
if (iobj instanceof SystemInstance) {
ic = new InstantiatedClassifier(((SystemInstance) iobj).getComponentImplementation(), null);
}
if (ic == null) {
Classifier classifier = null;
EList<PrototypeBinding> prototypeBindings = null;
Prototype prototype = null;
if (iobj instanceof ComponentInstance) {
Subcomponent sub = ((ComponentInstance) iobj).getSubcomponent();
classifier = sub.getClassifier();
prototypeBindings = sub.getOwnedPrototypeBindings();
prototype = sub.getPrototype();
} else if (iobj instanceof FeatureInstance) {
FeatureType ft = ((FeatureGroup) ((FeatureInstance) iobj).getFeature()).getFeatureType();
classifier = (ft instanceof Classifier) ? (Classifier) ft : null;
prototype = (ft instanceof Prototype) ? (Prototype) ft : null;
} else {
return null;
}
if (classifier != null) {
ic = new InstantiatedClassifier(classifier, prototypeBindings);
}
// no classifier => try prototype
if (ic == null) {
if (prototype != null) {
// resolve prototype
if (prototype instanceof ComponentPrototype) {
ComponentPrototypeActual cpa = resolveComponentPrototype(prototype, iobj, classifierCache);
if (cpa != null) {
ic = new InstantiatedClassifier((ComponentClassifier) cpa.getSubcomponentType(), cpa.getBindings());
} else {
// ISSUE 986: If the constraining classifier is missing (null), then don't create an InstantiatedClassifier object
final ComponentClassifier cc = ((ComponentPrototype) prototype).getConstrainingClassifier();
if (cc != null) {
ic = new InstantiatedClassifier(cc, noBindings);
}
}
} else if (prototype instanceof FeatureGroupPrototype) {
FeatureGroupPrototypeActual fpa = resolveFeatureGroupPrototype(prototype, iobj, classifierCache);
if (fpa != null) {
ic = new InstantiatedClassifier((FeatureGroupType) fpa.getFeatureType(), fpa.getBindings());
} else {
ic = new InstantiatedClassifier(((FeatureGroupPrototype) prototype).getConstrainingFeatureGroupType(), noBindings);
}
}
}
}
}
if (classifierCache != null) {
classifierCache.put(iobj, ic == null ? InstantiatedClassifier.NULL : ic);
}
return ic;
}
Aggregations