コード例 #1
0
  public static IPersistenceKit calculateInheritedPersistence(
      IEntity model, IPersistenceKit defaultPersistenceKit) {
    IEntityIterator<IEntity> iterator =
        IteratorFactory.scannerIterator(IteratorFactory.ancestorOrSelfIterator())
            .withPattern(
                GenericTraversalFactory.instance.one(
                    GenericMatcherFactory.instance.isFragmentMatcher(),
                    GenericMatcherFactory.instance.hasKindMatcher(EntityKinds.COMPOSITE)));

    iterator.reset(model);
    while (iterator.hasNext()) {
      String persistenceKitId = getPersistenceKitId(iterator.next());
      if (persistenceKitId != null) return ReflectionFactory.getPersistenceKit(persistenceKitId);
    }

    return defaultPersistenceKit;
  }
コード例 #2
0
  public static void moveArtifactsIntoWorkspace(IEntity artifacts, IBindingManager bm) {
    switch (artifacts.wGetEntityDescriptor().getOrdinal()) {
      case ArtifactsEntityDescriptorEnum.Workspace_ord:
        Projects projectsPoint = (Projects) bm.wGet("projectsPoint");
        if (projectsPoint == null) throw new IllegalArgumentException("projectsPoint is undefined");

        IEntityIterator<Project> projectIterator = IteratorFactory.childIterator();
        projectIterator.reset(((Workspace) artifacts).getProjects());
        for (Project project : projectIterator) {
          projectIterator.remove();
          projectsPoint.add(project);
        }
        break;
      case ArtifactsEntityDescriptorEnum.Artifacts_ord:
        Artifacts packagesPoint = (Artifacts) bm.wGet("packagesPoint");
        if (packagesPoint == null) throw new IllegalArgumentException("packagesPoint is undefined");

        IEntityIterator<Artifact> artifactIterator = IteratorFactory.childIterator();
        artifactIterator.reset(artifacts);
        for (Artifact artifact : artifactIterator) {
          artifactIterator.remove();
          packagesPoint.add(artifact);
        }
        break;
      case ArtifactsEntityDescriptorEnum.PackageArtifact_ord:
      case ArtifactsEntityDescriptorEnum.FolderArtifact_ord:
        packagesPoint = (Artifacts) bm.wGet("packagesPoint");
        if (packagesPoint == null) throw new IllegalArgumentException("packagesPoint is undefined");

        packagesPoint.add((Artifact) artifacts);
        break;
      case ArtifactsEntityDescriptorEnum.FileArtifact_ord:
        Artifacts packageArtifactsPoint = (Artifacts) bm.wGet("packageArtifactsPoint");
        if (packageArtifactsPoint == null)
          throw new IllegalArgumentException("packageArtifactsPoint is undefined");

        packageArtifactsPoint.add((FileArtifact) artifacts);
        break;
    }
  }
コード例 #3
0
  @Override
  public void run(IOperationProgressMonitor pm)
      throws InvocationTargetException, InterruptedException {
    IEntity selfEntity =
        EntityUtils.mapEntity(selfModel, EntityUtils.clone(EntityUtils.getCompoundRoot(selfModel)));

    Set<String> initialNames = bm.wNames();

    pm.beginTask("Executing sample...", IOperationProgressMonitor.TOTAL_WORK);

    behaviorModel =
        BehaviorUtils.apply(
            "whole:org.whole.lang.ui.views:SamplePerspectiveSemantics#SampleViewBehavior",
            behaviorModel,
            bm);

    IEntity derivedModel = null;
    try {
      IEntityIterator<?> iterator = BehaviorUtils.lazyEvaluate(behaviorModel, 0, bm);
      iterator.setBindings(selfBindings);
      iterator.reset(selfEntity);

      if (iterator.getClass().equals(ConstantIterator.class)) {
        IEntity result = iterator.next();
        if (result == null || !EntityUtils.isData(result)) derivedModel = result;
        else {
          Object resultValue = result.wGetValue();
          derivedModel =
              IVisitor.class.isInstance(resultValue)
                  ? BindingManagerFactory.instance.createValue(
                      Matcher.match((IVisitor) resultValue, selfEntity))
                  : result;
        }
      } else if (iterator.hasNext()) {
        derivedModel = MiscEntityFactory.instance.createMisc(0);

        ITransactionScope transactionScope =
            BindingManagerFactory.instance.createTransactionScope();
        bm.wEnterScope(transactionScope);
        try {
          for (IEntity result : iterator) {
            transactionScope.commit();
            derivedModel.wAdd(
                GenericEntityFactory.instance.create(
                    CommonsEntityDescriptorEnum.SameStageFragment,
                    // CommonsEntityFactory.instance.createSameStageFragment(
                    EntityUtils.clone(result))); // TODO substitute with a no containment fragment
          }
        } finally {
          transactionScope.rollback();
          bm.wExitScope();
        }
      }
    } catch (MissingVariableException e) {
      addMissingVariables(contextModel, e);
    } catch (OperationCanceledException e) {
      // gracefully terminate execution
    } catch (Exception e) {
      if (e.getCause() instanceof MissingVariableException)
        addMissingVariables(contextModel, (MissingVariableException) e.getCause());
    } finally {
      pm.endTask();
    }

    IEntity variablesModel = null;
    if (derivedModel != null) {
      EnvironmentEntityFactory ef = EnvironmentEntityFactory.instance;
      variablesModel = ef.createBindings(0);
      for (String name : new TreeSet<String>(bm.wLocalNames()))
        if (!initialNames.contains(name))
          variablesModel.wAdd(
              ef.createBinding(ef.createName(name), ef.createValue(BindingUtils.wGet(bm, name))));

      final IEntity contents = derivedModel;
      final IEntity variables = variablesModel;
      context
          .get(UISynchronize.class)
          .asyncExec(
              new Runnable() {
                public void run() {
                  context.get(IEntityPartViewer.class).setContents(null, contents);
                  context
                      .get(IEventBroker.class)
                      .post(IUIConstants.TOPIC_UPDATE_VARIABLES, variables);
                }
              });
    }
  }
コード例 #4
0
 public static IEntity getChild(IEntity entity, IEntity child) {
   IEntityIterator<IEntity> iterator =
       IteratorFactory.childMatcherIterator().withPattern(createPattern(child));
   iterator.reset(entity);
   return iterator.hasNext() ? iterator.next() : null;
 }