Example #1
0
  /**
   * Performs the step of a single weave. The lower-level aspect from the instantiation is woven
   * into the given aspect.
   *
   * @param base the higher-level aspect the lower-level aspect is woven into
   * @param instantiation the lower-level aspect to weave into the base aspect
   */
  public void doWeaveSingle(Aspect base, Instantiation instantiation) {
    System.out.println(
        "Weaving " + instantiation.getSource().getName() + " into " + base.getName());
    StructuralViewWeaver structuralViewWeaver = StructuralViewWeaver.getInstance();
    for (COREModelReuse modelReuse : instantiation.getSource().getModelReuses()) {
      COREModelReuse copy = EcoreUtil.copy(modelReuse);
      base.getModelReuses().add(copy);
    }

    // CHECKSTYLE:IGNORE ParameterAssignment FOR 2 LINES: Needed, because the operation returns the
    // result,
    // however it returns base.
    base = structuralViewWeaver.weave(base, instantiation);

    WeavingInformation currentWeavingInformation = structuralViewWeaver.getWeavingInformation();

    // Update the model reuses.
    ReferenceUpdater.getInstance().update(base.getModelReuses(), currentWeavingInformation);

    createTrace(base, instantiation.getSource(), currentWeavingInformation);

    // Merge weaving information, to be able to look at woven elements later.
    this.weavingInformation.merge(currentWeavingInformation);

    messageViewWeaver.copyMessageViews(base, instantiation.getSource(), currentWeavingInformation);
    StateViewWeaverUtils.copyStateViews(base, instantiation.getSource(), currentWeavingInformation);

    base.getInstantiations().remove(instantiation);
  }
Example #2
0
 /**
  * Create a trace of each traceable element in woven aspect.
  *
  * @param base the aspect we are adding tracing information to
  * @param wovenAspect the aspect woven into the base
  * @param currentWeavingInformation contains all the weaving information of the current weaving
  */
 private void createTrace(
     Aspect base, Aspect wovenAspect, WeavingInformation currentWeavingInformation) {
   WovenAspect wovenAspectTracing = RamFactory.eINSTANCE.createWovenAspect();
   // TODO: Might have to be the textual represention of the aspect name...
   wovenAspectTracing.setName(wovenAspect.getName());
   wovenAspectTracing.setComesFrom(wovenAspect);
   // Create tracing hierarchy
   createTracingHierarchy(wovenAspect, wovenAspectTracing);
   base.getWovenAspects().add(wovenAspectTracing);
   // associate the wovenAspects to the Traceable elements
   createTrace(currentWeavingInformation, wovenAspectTracing);
 }
Example #3
0
  /**
   * Weaves two directly dependent aspects together (single weave). Weaves the structural view and
   * copies the message and states view of the lower-level to the higher-level aspect.
   *
   * @param base the aspect to weave into (higher-level aspect)
   * @param instantiation the instantiation for the lower-level aspect
   * @return the woven aspect which resulted from weaving the lower-level into the higher-level
   *     aspect
   */
  public Aspect weaveSingle(Aspect base, Instantiation instantiation) {
    weavingInformation.clear();

    Aspect result = loadNewInstance(base);

    // Get the instantiation from the new instance, because the parameter
    // refers to the instantiation of base.
    int index = base.getInstantiations().indexOf(instantiation);
    Instantiation actualInstantiation = result.getInstantiations().get(index);

    doWeaveSingle(result, actualInstantiation);

    return result;
  }
Example #4
0
  /**
   * Weaves the complete hierarchy in a top-down manner with the exception that no state and message
   * views are woven. This means, state and message views are only copied.
   *
   * @param aspect the aspect of which all dependent aspects should be woven into
   * @return a woven aspect (copy) with no dependencies (all dependent aspects are woven into it)
   * @see #weaveAllTopDown(Aspect)
   * @see #weaveSingle(Aspect, Instantiation)
   */
  public Aspect weaveAllSingle(Aspect aspect) {
    weavingInformation.clear();

    Aspect result = loadNewInstance(aspect);

    while (!result.getInstantiations().isEmpty()) {
      // Get the first level of instantiations for this aspect ...
      List<Instantiation> currentLevel = new ArrayList<Instantiation>(result.getInstantiations());

      // Weave only the first level ...
      for (Instantiation instantiation : currentLevel) {
        doWeaveSingle(result, instantiation);
      }
    }

    return result;
  }
Example #5
0
  /**
   * Resolves dependencies of the given aspect from the bottom (of the dependency hierarchy) up. For
   * each two aspects, a single weave is performed (only structure is woven, rest is copied over).
   *
   * @param aspect the aspect to resolve dependencies for
   * @see #weaveAllBottomUp(Aspect)
   */
  private void resolveDependenciesBottomUp(Aspect aspect) {
    // Create a copy of the instantiations to evade a concurrent modification,
    // when instantiations are removed in doWeaveSingle.
    List<Instantiation> instantiations = new ArrayList<Instantiation>(aspect.getInstantiations());

    for (Instantiation instantiation : instantiations) {
      // Find the lowest aspect recursively ...
      if (!instantiation.getSource().getInstantiations().isEmpty()) {
        resolveDependenciesBottomUp(instantiation.getSource());
      }

      doWeaveSingle(aspect, instantiation);
    }
  }
Example #6
0
 /**
  * Creates the hierarchy of {@link WovenAspect} associated for wovenAspect. This hierarchy will
  * contain the tracing information. Realizes a copy of the WovenAspects so that they don't
  * directly own references to the tracing elements
  *
  * @param wovenAspect the {@link Aspect} associated to the tracing hierarchy
  * @param wovenAspectTracing the {@link WovenAspect} to add the hierarchy to
  */
 private void createTracingHierarchy(Aspect wovenAspect, WovenAspect wovenAspectTracing) {
   for (WovenAspect child : wovenAspect.getWovenAspects()) {
     WovenAspect childCopy = EcoreUtil.copy(child);
     wovenAspectTracing.getChildren().add(childCopy);
   }
 }