Ejemplo n.º 1
0
 public Element toXml() {
   Element root = new Element(ROOT_ELEMENT);
   root.setAttribute(ATTR_VERSION, Integer.toString(DEPENDENCIES_VERSION));
   if (myModelHash != null) {
     root.setAttribute(ATTR_MODEL_HASH, myModelHash);
   }
   if (myParametersHash != null) {
     root.setAttribute(ATTR_PARAMS_HASH, myParametersHash);
   }
   String[] models = myUsedModelsHashes.keySet().toArray(new String[myUsedModelsHashes.size()]);
   Arrays.sort(models);
   for (String model : models) {
     Element e = new Element(NODE_MODEL);
     e.setAttribute(ATTR_MODEL_ID, model);
     String hash = myUsedModelsHashes.get(model);
     if (hash != null) {
       e.setAttribute(ATTR_HASH, hash);
     }
     root.addContent(e);
   }
   if (myRootDependencies != null) {
     for (GenerationRootDependencies data : myRootDependencies) {
       Element e = new Element(data.getRootId() != null ? NODE_ROOT : NODE_COMMON);
       data.saveTo(e);
       root.addContent(e);
     }
   }
   return root;
 }
Ejemplo n.º 2
0
  private static <C> void assertListsEqual(
      List<C> expectedList, List<C> actualList, Comparator<C> comparator, String name) {
    List<C> notFoundExpected = new ArrayList<C>();
    List<C> notFoundActual = new ArrayList<C>();
    for (C expected : expectedList) {
      boolean found = false;
      for (C actual : actualList) {
        if (comparator.compare(actual, expected) == 0) {
          found = true;
          break;
        }
      }
      if (!found) {
        notFoundExpected.add(expected);
      }
    }

    for (C actual : actualList) {
      boolean found = false;
      for (C expected : expectedList) {
        if (comparator.compare(actual, expected) == 0) {
          found = true;
          break;
        }
      }
      if (!found) {
        notFoundActual.add(actual);
      }
    }

    if (!notFoundExpected.isEmpty()) {
      fail("Not found expected " + name + " " + Arrays.toString(notFoundExpected.toArray()));
    }

    if (!notFoundActual.isEmpty()) {
      fail("Not expected " + name + " " + Arrays.toString(notFoundActual.toArray()));
    }
  }
  public static List<INodeSubstituteAction> createDefaultActions(
      @NotNull SNode applicableConcept,
      SNode parentNode,
      SNode currentChild,
      IChildNodeSetter setter,
      IOperationContext operationContext) {

    String conceptFqName = NameUtil.nodeFQName(applicableConcept);
    SNode link = null;
    if (setter instanceof DefaultChildNodeSetter) {
      DefaultChildNodeSetter defaultSetter = (DefaultChildNodeSetter) setter;
      link = defaultSetter.getLinkDeclaration();
    }

    IScope scope = operationContext.getScope();

    if (!ModelConstraintsManager.canBeChild(conceptFqName, operationContext, parentNode, link)) {
      return new ArrayList<INodeSubstituteAction>();
    }

    SNode smartRef = ReferenceConceptUtil.getCharacteristicReference(applicableConcept);
    if (smartRef != null) {
      List<INodeSubstituteAction> smartActions =
          createSmartReferenceActions(
              applicableConcept, smartRef, parentNode, currentChild, setter, operationContext);
      if (smartActions != null) {
        return smartActions;
      } else {
        return Collections.emptyList();
      }
    } else {
      return Arrays.asList(
          (INodeSubstituteAction)
              new DefaultChildNodeSubstituteAction(
                  applicableConcept, parentNode, currentChild, setter, scope));
    }
  }