Search in sources :

Example 11 with SubprogramType

use of org.osate.aadl2.SubprogramType in project AGREE by loonwerks.

the class EphemeralImplementationUtil method createComponentImplementationInternal.

/**
 * Internal method to actually create the ephemeral component implementation and containing resource.
 * <p>
 * This method is intended to by invoked only from the command stack so that editing permissions are managed
 * through the transactional editing domain.
 *
 * @param ct The {@link ComponentType} for which to create an ephemeral implementation.
 * @param aadlResource The {@link Resource} in which to place the ephemeral implementation and it containing
 *     {@link AadlPackage}.
 * @return A {@link ComponentImplementation} matching the given component type.
 * @throws InterruptedException
 */
private ComponentImplementation createComponentImplementationInternal(ComponentType ct, Resource aadlResource) throws InterruptedException {
    // Create a package and public section to contain the created
    // component implementation
    AadlPackage aadlPackage = Aadl2Factory.eINSTANCE.createAadlPackage();
    aadlPackage.setName(aadlResource.getURI().trimFragment().trimFileExtension().lastSegment().toString());
    PublicPackageSection publicSection = aadlPackage.createOwnedPublicSection();
    // Add import for package containing ct
    AadlPackage ctPackage = (AadlPackage) AgreeUtils.getClosestContainerOfType(ct, AadlPackage.class);
    publicSection.getImportedUnits().add(ctPackage);
    // Add renames clause to make linking to ct easy
    PackageRename ctRename = publicSection.createOwnedPackageRename();
    ctRename.setName("");
    ctRename.setRenamedPackage(ctPackage);
    ctRename.setRenameAll(true);
    // Create the component implementation in the public section
    ComponentImplementation compImpl;
    if (ct instanceof ThreadType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getThreadImplementation());
    } else if (ct instanceof ThreadGroupType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getThreadGroupImplementation());
    } else if (ct instanceof ProcessType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getProcessImplementation());
    } else if (ct instanceof SubprogramType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getSubprogramImplementation());
    } else if (ct instanceof ProcessorType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getProcessorImplementation());
    } else if (ct instanceof BusType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getBusImplementation());
    } else if (ct instanceof DeviceType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getDeviceImplementation());
    } else if (ct instanceof SystemType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getSystemImplementation());
    } else {
        throw new AgreeException("Unhandled component type: " + ct.getClass().toString());
    }
    compImpl.setType(ct);
    compImpl.setName(ct.getName() + ".wrapper");
    // Add the package and its contents to the resource
    aadlResource.getContents().add(aadlPackage);
    // IResource as we build it.
    try {
        aadlResource.save(null);
    } catch (IOException e) {
        e.printStackTrace();
        setErrorMessage(e.getMessage());
        return null;
    } catch (NullPointerException npe) {
        npe.printStackTrace();
        setErrorMessage(npe.getMessage());
        npe.getMessage();
        return null;
    // } catch (InterruptedException e) {
    // throw e;
    } catch (Exception e) {
        e.printStackTrace();
        errorMessage = e.getMessage();
        e.getMessage();
        return null;
    }
    return compImpl;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ThreadGroupType(org.osate.aadl2.ThreadGroupType) AadlPackage(org.osate.aadl2.AadlPackage) BusType(org.osate.aadl2.BusType) ProcessorType(org.osate.aadl2.ProcessorType) SystemType(org.osate.aadl2.SystemType) IOException(java.io.IOException) RollbackException(org.eclipse.emf.transaction.RollbackException) IOException(java.io.IOException) DeviceType(org.osate.aadl2.DeviceType) ProcessType(org.osate.aadl2.ProcessType) PublicPackageSection(org.osate.aadl2.PublicPackageSection) ThreadType(org.osate.aadl2.ThreadType) PackageRename(org.osate.aadl2.PackageRename) SubprogramType(org.osate.aadl2.SubprogramType)

Aggregations

SubprogramType (org.osate.aadl2.SubprogramType)10 BusType (org.osate.aadl2.BusType)5 DeviceType (org.osate.aadl2.DeviceType)5 EObject (org.eclipse.emf.ecore.EObject)4 AbstractImplementation (org.osate.aadl2.AbstractImplementation)4 AbstractType (org.osate.aadl2.AbstractType)4 BusImplementation (org.osate.aadl2.BusImplementation)4 ComponentImplementation (org.osate.aadl2.ComponentImplementation)4 DeviceImplementation (org.osate.aadl2.DeviceImplementation)4 MemoryImplementation (org.osate.aadl2.MemoryImplementation)4 MemoryType (org.osate.aadl2.MemoryType)4 ProcessImplementation (org.osate.aadl2.ProcessImplementation)4 ProcessType (org.osate.aadl2.ProcessType)4 ProcessorImplementation (org.osate.aadl2.ProcessorImplementation)4 ProcessorType (org.osate.aadl2.ProcessorType)4 Property (org.osate.aadl2.Property)4 SubprogramImplementation (org.osate.aadl2.SubprogramImplementation)4 SystemImplementation (org.osate.aadl2.SystemImplementation)4 SystemType (org.osate.aadl2.SystemType)4 ThreadGroupImplementation (org.osate.aadl2.ThreadGroupImplementation)4