예제 #1
0
 /**
  * Instantiate a deployment plan, i.e. generate an intermediate model via a sequence of
  * transformations
  *
  * @param umlElement a deployment plan (UML package) or a configuration (UML class)
  * @param monitor a progress monitor.
  * @param project the current project. This information is used to store the intermediate model in
  *     a subfolder (tmpModel) of the current project
  * @param genOptions select whether to produce an intermediate model only, also code, ... @see
  *     GenerationOptions
  */
 private void instantiate(IProgressMonitor monitor, int genOptions) {
   try {
     initialize(monitor, genOptions);
     AcceleoDriver.clearErrors();
     executeTransformation();
   } catch (AcceleoException e) {
     displayError(
         Messages.InstantiateDepPlan_AcceleoErrors,
         Messages.InstantiateDepPlan_AcceleoErrorsCheckLog);
   } catch (final TransformationException e) {
     printAndDisplayErrorMessage(e, Messages.InstantiateDepPlan_TransformationException, false);
   } catch (final Exception e) {
     printAndDisplayErrorMessage(e, Messages.InstantiateDepPlan_ErrorsDuringTransformation, true);
   }
 }
예제 #2
0
  protected void executeTransformation() throws Exception {
    modelIsObjectOriented = true;
    ModelManagement intermediateModelManagement = null;

    InstanceSpecification mainInstance = DepUtils.getMainInstance(srcModelComponentDeploymentPlan);
    EList<InstanceSpecification> nodes = AllocUtils.getAllNodes(mainInstance);

    initiateProgressMonitor(generateCode, nodes);

    // --------------------------------------------------------------------
    checkProgressStatus();
    // --------------------------------------------------------------------

    // 1a: create a new model (and applies same profiles / imports)
    Model existingModel = srcModelComponentDeploymentPlan.getModel();
    TransformationContext.sourceRoot = existingModel;

    intermediateModelManagement = createTargetModel(existingModel, existingModel.getName(), true);

    // Declare that the new model is a derivedElement (kind of hack,
    // since the source element (attribute of derive element) remains
    // undefined). This is used to deactivate automatic transformations
    // that should not be applied to the generated model.

    // --------------------------------------------------------------------
    checkProgressStatus();
    // --------------------------------------------------------------------

    // get the temporary model
    Model intermediateModel = intermediateModelManagement.getModel();

    // create a package for global enumerations that are used by Acceleo code
    EnumService.createEnumPackage(intermediateModel);

    // create a lazy copier towards the intermediate model
    LazyCopier intermediateModelCopier =
        new LazyCopier(existingModel, intermediateModel, false, true);
    // add pre-copy and post-copy listeners to the copier
    intermediateModelCopier.preCopyListeners.add(FilterTemplate.getInstance());

    // 1b: reify the connectors "into" the new model
    monitor.subTask(Messages.InstantiateDepPlan_InfoExpandingConnectors);

    // obtain the component deployment plan in target model
    Package intermediateModelComponentDeploymentPlan =
        (Package) intermediateModelCopier.shallowCopy(srcModelComponentDeploymentPlan);
    intermediateModelCopier.createShallowContainer(srcModelComponentDeploymentPlan);

    AbstractContainerTrafo.init();
    InstanceConfigurator.onNodeModel = false;
    MainModelTrafo mainModelTrafo =
        new MainModelTrafo(intermediateModelCopier, intermediateModelComponentDeploymentPlan);
    InstanceSpecification newMainInstance = mainModelTrafo.transformInstance(mainInstance, null);

    // --------------------------------------------------------------------
    checkProgressStatus();
    // --------------------------------------------------------------------

    TransformationUtil.applyInstanceConfigurators(newMainInstance);

    FlattenInteractionComponents.getInstance().flattenAssembly(newMainInstance, null);

    TransformationUtil.propagateAllocation(newMainInstance);

    intermediateModelManagement.saveModel(project, TEMP_MODEL_FOLDER, TEMP_MODEL_POSTFIX);

    // --------------------------------------------------------------------
    checkProgressStatus();
    // --------------------------------------------------------------------

    if (!generateCACOnly) {
      deployOnNodes(mainInstance, existingModel, intermediateModel, newMainInstance);
    }

    intermediateModelManagement.dispose();

    if (AcceleoDriver.hasErrors()) {
      throw new AcceleoException();
    }
  }