use of org.osate.aadl2.Prototype in project aerospike-client-java by aerospike.
the class LuaInstance method loadSystemPackage.
private void loadSystemPackage(ClassLoader resourceLoader, String packageName) {
String resourcePath = "udf/" + packageName + ".lua";
Prototype prototype = LuaCache.loadPackageFromResource(resourceLoader, resourcePath, packageName);
LuaClosure function = new LuaClosure(prototype, globals);
function.invoke();
loadedTable.set(packageName, LuaValue.TRUE);
}
use of org.osate.aadl2.Prototype in project aerospike-client-java by aerospike.
the class LuaInstance method loadPackage.
public void loadPackage(Statement statement) {
if (loadedTable.get(statement.getPackageName()).toboolean()) {
return;
}
Prototype prototype;
if (statement.getResourceLoader() == null || statement.getResourcePath() == null) {
prototype = LuaCache.loadPackageFromFile(statement.getPackageName());
} else {
prototype = LuaCache.loadPackageFromResource(statement.getResourceLoader(), statement.getResourcePath(), statement.getPackageName());
}
LuaClosure function = new LuaClosure(prototype, globals);
function.invoke();
loadedTable.set(statement.getPackageName(), LuaValue.TRUE);
}
use of org.osate.aadl2.Prototype in project aerospike-client-java by aerospike.
the class LuaCache method loadPackageFromResource.
/**
* Load lua package from a resource.
*/
public static final Prototype loadPackageFromResource(ClassLoader resourceLoader, String resourcePath, String packageName) throws AerospikeException {
Prototype prototype = Packages.get(packageName);
if (prototype == null) {
try {
InputStream is = resourceLoader.getResourceAsStream(resourcePath);
if (is == null) {
throw new Exception();
}
prototype = compile(packageName, is);
Packages.put(packageName, prototype);
} catch (Exception e) {
throw new AerospikeException("Failed to read resource: " + resourcePath);
}
}
return prototype;
}
use of org.osate.aadl2.Prototype in project aerospike-client-java by aerospike.
the class LuaCache method loadPackageFromFile.
/**
* Load lua package from a file.
*/
public static final Prototype loadPackageFromFile(String packageName) throws AerospikeException {
Prototype prototype = Packages.get(packageName);
if (prototype == null) {
File source = new File(LuaConfig.SourceDirectory, packageName + ".lua");
try {
InputStream is = new FileInputStream(source);
prototype = compile(packageName, is);
Packages.put(packageName, prototype);
} catch (Exception e) {
throw new AerospikeException("Failed to read file: " + source.getAbsolutePath());
}
}
return prototype;
}
use of org.osate.aadl2.Prototype in project osate2 by osate.
the class DefaultSelectSubprogramDialogModel method getSubprograms.
@Override
public List<Object> getSubprograms(final Object context) {
// Build a list of subprograms
final List<Object> subprograms = new ArrayList<Object>();
// Data/Subprogram Group/Abstract Type
if (context instanceof IEObjectDescription) {
final IEObjectDescription desc = (IEObjectDescription) context;
final Classifier contextClassifier = (Classifier) (desc.getEObjectOrProxy().eIsProxy() ? (Classifier) EcoreUtil.resolve(desc.getEObjectOrProxy(), bi.eResource()) : desc.getEObjectOrProxy());
if (!contextClassifier.eIsProxy()) {
for (final Feature tmpFeature : contextClassifier.getAllFeatures()) {
if (tmpFeature instanceof SubprogramAccess) {
// Provides Subprogram Access
if (((SubprogramAccess) tmpFeature).getKind() == AccessType.PROVIDES) {
subprograms.add(tmpFeature);
}
}
}
}
} else if (context instanceof SubprogramGroupAccess) {
// Requires Subprogram Group Access
// Only subprogram group accesses with kind = Requires and which has a subprogram group classifier should be in the context list
// Provides Subprogram Access
final SubprogramGroupClassifier spgClassifier = (SubprogramGroupClassifier) ((SubprogramGroupAccess) context).getAllClassifier();
addProvidesSubprogramAccessesForComponentClassifier(spgClassifier, subprograms);
} else if (context instanceof FeatureGroup) {
// Feature Group
final FeatureGroup fg = (FeatureGroup) context;
// Requires subprogram Access if not inverse and Provides subprogram access if is inverse
final boolean inverted = fg.isInverse();
for (final Feature tmpFeature : AadlFeatureUtil.getAllFeatures(fg.getAllFeatureGroupType())) {
if (tmpFeature instanceof SubprogramAccess) {
final AccessType accessKind = ((SubprogramAccess) tmpFeature).getKind();
if ((!inverted && accessKind == AccessType.REQUIRES) || (inverted && accessKind == AccessType.PROVIDES)) {
subprograms.add(tmpFeature);
}
}
}
} else if (context instanceof SubprogramGroupSubcomponent) {
// Subprogram Group Subcomponent
// Provides Subprogram
addProvidesSubprogramAccessesForComponentClassifier(((SubprogramGroupSubcomponent) context).getAllClassifier(), subprograms);
} else if (context == processorContext) {
// Subprogram Proxy
for (final ProcessorFeature processorFeature : AgeAadlUtil.getAllProcessorFeatures(bi)) {
if (processorFeature instanceof SubprogramProxy) {
subprograms.add(processorFeature);
}
}
} else if (context == nullContext) {
// Null Context
// Subprogram classifier reference
final Aadl2Package aadl2Package = Aadl2Package.eINSTANCE;
for (final IEObjectDescription desc : AadlModelAccessUtil.getAllEObjectsByType(bi.eResource(), aadl2Package.getComponentClassifier())) {
// Add objects that have care either types or implementations of the same category as the classifier type
final EClass classifierEClass = desc.getEClass();
if (aadl2Package.getSubprogramClassifier().isSuperTypeOf(classifierEClass)) {
subprograms.add(desc);
}
}
// Requires Subprogram Access
for (final Feature tmpFeature : bi.getAllFeatures()) {
if (tmpFeature instanceof SubprogramAccess && ((SubprogramAccess) tmpFeature).getKind() == AccessType.REQUIRES) {
subprograms.add(tmpFeature);
}
}
// Subprogram Subcomponent
for (final Subcomponent tmpSc : bi.getAllSubcomponents()) {
if (tmpSc instanceof SubprogramSubcomponent) {
subprograms.add(tmpSc);
}
}
// Subprogram Prototype
for (final Prototype prototype : bi.getAllPrototypes()) {
if (prototype instanceof SubprogramPrototype) {
subprograms.add(prototype);
}
}
}
return Collections.unmodifiableList(subprograms);
}
Aggregations