Search in sources :

Example 6 with Prototype

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);
}
Also used : Prototype(org.luaj.vm2.Prototype) LuaClosure(org.luaj.vm2.LuaClosure) LuaString(org.luaj.vm2.LuaString)

Example 7 with Prototype

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);
}
Also used : Prototype(org.luaj.vm2.Prototype) LuaClosure(org.luaj.vm2.LuaClosure)

Example 8 with Prototype

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;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Prototype(org.luaj.vm2.Prototype) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AerospikeException(com.aerospike.client.AerospikeException)

Example 9 with 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;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Prototype(org.luaj.vm2.Prototype) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) AerospikeException(com.aerospike.client.AerospikeException)

Example 10 with 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);
}
Also used : FeatureGroup(org.osate.aadl2.FeatureGroup) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) Prototype(org.osate.aadl2.Prototype) SubprogramGroupClassifier(org.osate.aadl2.SubprogramGroupClassifier) ArrayList(java.util.ArrayList) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) SubprogramGroupClassifier(org.osate.aadl2.SubprogramGroupClassifier) Feature(org.osate.aadl2.Feature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EClass(org.eclipse.emf.ecore.EClass) SubprogramProxy(org.osate.aadl2.SubprogramProxy) SubprogramAccess(org.osate.aadl2.SubprogramAccess) Aadl2Package(org.osate.aadl2.Aadl2Package) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ProcessorFeature(org.osate.aadl2.ProcessorFeature) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) AccessType(org.osate.aadl2.AccessType)

Aggregations

Prototype (org.luaj.vm2.Prototype)39 Prototype (org.osate.aadl2.Prototype)24 Classifier (org.osate.aadl2.Classifier)20 ComponentPrototype (org.osate.aadl2.ComponentPrototype)20 ComponentClassifier (org.osate.aadl2.ComponentClassifier)19 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)17 ComponentPrototypeBinding (org.osate.aadl2.ComponentPrototypeBinding)16 FeaturePrototype (org.osate.aadl2.FeaturePrototype)14 FeaturePrototypeBinding (org.osate.aadl2.FeaturePrototypeBinding)14 FeatureGroupPrototypeBinding (org.osate.aadl2.FeatureGroupPrototypeBinding)13 PrototypeBinding (org.osate.aadl2.PrototypeBinding)13 Subcomponent (org.osate.aadl2.Subcomponent)13 FeatureGroupType (org.osate.aadl2.FeatureGroupType)11 DataPrototype (org.osate.aadl2.DataPrototype)10 NamedElement (org.osate.aadl2.NamedElement)10 ComponentPrototypeActual (org.osate.aadl2.ComponentPrototypeActual)9 DataClassifier (org.osate.aadl2.DataClassifier)9 Feature (org.osate.aadl2.Feature)9 FeatureGroupPrototypeActual (org.osate.aadl2.FeatureGroupPrototypeActual)9 EClass (org.eclipse.emf.ecore.EClass)7