Ejemplo n.º 1
0
  @Test
  public void testMore() throws InterruptedException {
    final Element e1 = TestUtils.getElement("test1", Regexp.<AbstractStructuralNode>getMutable());
    final Element e2 = TestUtils.getElement("test2", Regexp.<AbstractStructuralNode>getMutable());
    final Element e3 = TestUtils.getElement("test3", Regexp.<AbstractStructuralNode>getMutable());
    final Element e4 = TestUtils.getElement("test4", Regexp.<AbstractStructuralNode>getMutable());

    e1.getSubnodes().setType(RegexpType.CONCATENATION);
    e1.getSubnodes().setInterval(RegexpInterval.getOnce());
    e2.getSubnodes().setType(RegexpType.CONCATENATION);
    e2.getSubnodes().setInterval(RegexpInterval.getOnce());
    e3.getSubnodes().setType(RegexpType.CONCATENATION);
    e3.getSubnodes().setInterval(RegexpInterval.getOnce());
    e4.getSubnodes().setType(RegexpType.CONCATENATION);
    e4.getSubnodes().setInterval(RegexpInterval.getOnce());

    e1.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e2));
    e1.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e3));
    e3.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e4));

    final List<Element> elements = Arrays.asList(e1, e2);

    Collections.shuffle(elements);

    final TopologicalSort s = new TopologicalSort(elements);
    final List<Element> toposorted = s.sort();

    assertEquals(2, toposorted.size());
    assertTrue(toposorted.indexOf(e1) > toposorted.indexOf(e2));
    assertTrue(toposorted.indexOf(e1) > toposorted.indexOf(e3));
    assertTrue(toposorted.indexOf(e2) > toposorted.indexOf(e4));
  }
  /** Test of cleanRegularExpression method, of class CleanerEmptyChildren. */
  @Test
  public void testCleanRegularExpression2() {
    System.out.println("cleanRegularExpression2");

    final Regexp<String> r3 = Regexp.<String>getMutable();
    r3.setInterval(RegexpInterval.getOnce());
    r3.setType(RegexpType.TOKEN);
    r3.setContent("a");
    r3.setImmutable();

    final Regexp<String> r2 = Regexp.<String>getMutable();
    r2.setInterval(RegexpInterval.getOnce());
    r2.setType(RegexpType.CONCATENATION);
    r2.addChild(r3);
    r2.setImmutable();

    final Regexp<String> r1 = Regexp.<String>getMutable();
    r1.setInterval(RegexpInterval.getOnce());
    r1.setType(RegexpType.CONCATENATION);
    r1.addChild(r2);
    r1.setImmutable();

    final Regexp<String> regexp = r1;
    final EmptyChildren<String> instance = new EmptyChildren<String>();
    final Regexp<String> result = instance.cleanRegularExpression(regexp);
    assertEquals("a", result.toString());
  }
Ejemplo n.º 3
0
  /**
   * Check if <code>Element</code> is properly defined; redefine it to lambda when it was empty, or
   * redefine it to token if it only contained a simple data type. This method should be used only
   * when the tag of a node was ELEMENT!
   *
   * @param ret Element to be finalized.
   */
  public static void finalizeElement(final Element ret, final List<String> newContext) {

    if (ret.getSubnodes().getInterval() == null) {
      ret.getSubnodes().setInterval(RegexpInterval.getOnce());
    }
    if (ret.getSubnodes().getChildren().isEmpty()
        && ret.getMetadata().containsKey(XSDAttribute.TYPE.getMetadataName())) {
      // [SIMPLE DATA SECTION]
      // element has empty children, but its specified type is one of the built-in types
      // create SimpleData with the defined type of the element
      ret.getSubnodes().setType(RegexpType.TOKEN);
      ret.getSubnodes()
          .setContent(
              new SimpleData(
                  newContext,
                  XSDUtility.SIMPLE_DATA_NAME,
                  Collections.<String, Object>emptyMap(),
                  (String) ret.getMetadata().get(XSDAttribute.TYPE.getMetadataName()),
                  Collections.<String>emptyList()));
    } else if (ret.getSubnodes().getChildren().isEmpty() && ret.getSubnodes().getType() == null) {
      // element with empty children and no specified type has currently only one option
      // since we don't support restrictions, extensions, complexcontent -> it has to be LAMBDA
      XSDUtility.setLambda(ret);
    } else if (ret.getSubnodes().getType() == null) {
      // type of element must be non-null, but apparently it has some children
      // this should not happen
      LOG.warn(NbBundle.getMessage(DOMHelper.class, "Warn.SetDefaultType", ret.getName()));
      ret.getSubnodes().setType(RegexpType.CONCATENATION);
      ret.getSubnodes().setContent(null);
    }
    if (ret.isMutable()) {
      ret.setImmutable();
    }
  }
Ejemplo n.º 4
0
 @Test
 public void testOne() throws InterruptedException {
   final Element e = TestUtils.getElement("test", Regexp.<AbstractStructuralNode>getMutable());
   e.getSubnodes().setType(RegexpType.CONCATENATION);
   e.getSubnodes().setInterval(RegexpInterval.getOnce());
   final TopologicalSort s = new TopologicalSort(Arrays.asList(e));
   final List<Element> elements = s.sort();
   assertEquals(1, elements.size());
   assertEquals(e, elements.get(0));
 }
  /** Test of start method, of class SchemaGeneratorImpl. */
  @Test
  public void testStart1() throws Exception {
    System.out.println("start alt 2,5");

    Element c = Element.getMutable();
    c.setName("c");
    c.getSubnodes().setType(RegexpType.LAMBDA);
    c.getSubnodes().setImmutable();

    Element b = Element.getMutable();
    b.setName("b");
    b.getSubnodes().setType(RegexpType.LAMBDA);
    b.getSubnodes().setImmutable();

    Regexp<AbstractStructuralNode> rb = Regexp.<AbstractStructuralNode>getToken(b);
    Regexp<AbstractStructuralNode> rc = Regexp.<AbstractStructuralNode>getToken(c);

    Element treeBase = Element.getMutable();
    treeBase.setName("a");
    treeBase.getSubnodes().setType(RegexpType.ALTERNATION);
    treeBase.getSubnodes().getChildren().add(rb);
    treeBase.getSubnodes().getChildren().add(rc);
    treeBase.getSubnodes().setInterval(RegexpInterval.getBounded(2, 5));

    List<Element> grammar = new ArrayList<Element>();
    grammar.add(treeBase);

    SchemaGeneratorCallback callback =
        new SchemaGeneratorCallback() {

          @Override
          public void finished(String schema, String extension) {
            assertEquals(
                "<!-- %generated% -->\n<!ELEMENT a ((b|c),(b|c),(b|c)?,(b|c)?,(b|c)?)>\n", schema);
          }
        };
    SchemaGeneratorImpl instance = new SchemaGeneratorImpl();
    instance.start(grammar, callback);
  }