Package org.jboss.dna.sequencer.ddl.node

Examples of org.jboss.dna.sequencer.ddl.node.AstNode


        assertThat(parent.getChildCount(), is(2));
    }

    @Test
    public void shouldExtractChildByReplacingWithFirstGrandchild() {
        parent = new AstNode(name("parent"));
        AstNode child1 = new AstNode(parent, name("childA"));
        AstNode child2 = new AstNode(parent, name("childB"));
        AstNode child3 = new AstNode(parent, name("childC"));
        AstNode grandChild1 = new AstNode(child2, name("grandchildA"));
        AstNode grandChild2 = new AstNode(child2, name("grandchildB"));
        assertThat(parent.getChild(0), is(sameInstance(child1)));
        assertThat(parent.getChild(1), is(sameInstance(child2)));
        assertThat(parent.getChild(2), is(sameInstance(child3)));
        // Perform the extraction ...
        parent.extractChild(child2);
View Full Code Here


        assertThat(child2.getParent(), is(nullValue()));
    }

    @Test
    public void shouldReplaceChild() {
        AstNode parentOfReplacement = new AstNode(name("parentOfReplacement"));
        AstNode replacement = new AstNode(parentOfReplacement, name("replacement"));
        parent = new AstNode(name("parent"));
        AstNode child1 = new AstNode(parent, name("childA"));
        AstNode child2 = new AstNode(parent, name("childB"));
        AstNode child3 = new AstNode(parent, name("childC"));
        assertThat(parent.getChild(0), is(sameInstance(child1)));
        assertThat(parent.getChild(1), is(sameInstance(child2)));
        assertThat(parent.getChild(2), is(sameInstance(child3)));
        // Perform the replacement ...
        assertThat(parent.replaceChild(child2, replacement), is(true));
        assertThat(parent.getChild(0), is(sameInstance(child1)));
        assertThat(parent.getChild(1), is(sameInstance(replacement)));
        assertThat(parent.getChild(2), is(sameInstance(child3)));
        assertThat(replacement.getParent(), is(sameInstance(parent)));
        assertThat(child1.getParent(), is(sameInstance(parent)));
        assertThat(child2.getParent(), is(nullValue()));
        assertThat(child3.getParent(), is(sameInstance(parent)));
        // The replacement should no longer be a child of its former parent ...
        assertThat(parentOfReplacement.getChildCount(), is(0));
    }
View Full Code Here

        assertThat(parentOfReplacement.getChildCount(), is(0));
    }

    @Test
    public void shouldReplaceChildWithAnotherChildToSwapPositions() {
        parent = new AstNode(name("parent"));
        AstNode child1 = new AstNode(parent, name("childA"));
        AstNode child2 = new AstNode(parent, name("childB"));
        AstNode child3 = new AstNode(parent, name("childC"));
        assertThat(parent.getChild(0), is(sameInstance(child1)));
        assertThat(parent.getChild(1), is(sameInstance(child2)));
        assertThat(parent.getChild(2), is(sameInstance(child3)));
        // Perform the replacement ...
        assertThat(parent.replaceChild(child2, child3), is(true));
        assertThat(parent.getChild(0), is(sameInstance(child1)));
        assertThat(parent.getChild(1), is(sameInstance(child3)));
        assertThat(parent.getChild(2), is(sameInstance(child2)));
        assertThat(child1.getParent(), is(sameInstance(parent)));
        assertThat(child2.getParent(), is(sameInstance(parent)));
        assertThat(child3.getParent(), is(sameInstance(parent)));
    }
View Full Code Here

        assertThat(child3.getParent(), is(sameInstance(parent)));
    }

    @Test
    public void shouldNotReplaceChildIfChildNodeIsNotReallyAChild() {
        AstNode nonChild = new AstNode(name("nonChild"));
        AstNode replacement = new AstNode(name("replacement"));
        parent = new AstNode(name("parent"));
        AstNode child1 = new AstNode(parent, name("childA"));
        AstNode child2 = new AstNode(parent, name("childB"));
        AstNode child3 = new AstNode(parent, name("childC"));
        assertThat(parent.getChild(0), is(sameInstance(child1)));
        assertThat(parent.getChild(1), is(sameInstance(child2)));
        assertThat(parent.getChild(2), is(sameInstance(child3)));
        assertThat(parent.replaceChild(nonChild, replacement), is(false));
    }
View Full Code Here

        assertThat(parent.replaceChild(nonChild, replacement), is(false));
    }

    @Test
    public void shouldReturnPath() {
        AstNode root = new AstNode(name("root"));
        AstNode node1 = new AstNode(root, name("node1"));
        AstNode node2 = new AstNode(node1, name("node2"));
        AstNode node3 = new AstNode(node2, name("node3"));
        AstNode node4 = new AstNode(node3, name("node4"));
        AstNode node5 = new AstNode(node4, name("node5"));
        node4.setProperty(name("prop1"), "value1");
        assertThat(root.getPath(context), is(path("/root")));
        assertThat(node1.getPath(context), is(path("/root/node1")));
        assertThat(node2.getPath(context), is(path("/root/node1/node2")));
        assertThat(node3.getPath(context), is(path("/root/node1/node2/node3")));
        assertThat(node4.getPath(context), is(path("/root/node1/node2/node3/node4")));
        assertThat(node5.getPath(context), is(path("/root/node1/node2/node3/node4/node5")));
    }
View Full Code Here

     * @return the root tree {@link AstNode}
     * @throws ParsingException
     */
    public AstNode parse( String ddl ) throws ParsingException {
        assert ddl != null;
        AstNode rootNode = new AstNode(StandardDdlLexicon.STATEMENTS_CONTAINER);
        rootNode.setProperty(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.UNSTRUCTURED);

        parse(ddl, rootNode);

        return rootNode;
    }
View Full Code Here

        while (moveToNextStatementStart(tokens)) {

            // It is assumed that if a statement is registered, the registering dialect will handle the parsing of that object
            // and successfully create a statement {@link AstNode}
            AstNode stmtNode = parseNextStatement(tokens, rootNode);

            if (stmtNode == null) {
                markStartOfStatement(tokens);

                String stmtName = tokens.consume();
View Full Code Here

    protected AstNode parseNextStatement( DdlTokenStream tokens,
                                          AstNode node ) {
        assert tokens != null;
        assert node != null;

        AstNode stmtNode = null;

        if (tokens.matches(CREATE)) {
            stmtNode = parseCreateStatement(tokens, node);
        } else if (tokens.matches(ALTER)) {
            stmtNode = parseAlterStatement(tokens, node);
View Full Code Here

                    // For known, parsed statements, the terminator is consumed in the markEndOfStatement() method. So if we get
                    // here, we then we know we've got an unknown statement.
                    if (tokens.matches(getTerminator()) && sb.length() > 0) {
                        nextTokenValue = getTerminator();
                        // Let's call this a statement up until now
                        AstNode unknownNode = unknownTerminatedNode(getRootNode());
                        markEndOfStatement(tokens, unknownNode);
                        // We've determined that it's just an unknown node, which we determine is not a problem node.
                        problem = null;
                    } else {
                        // Just keep consuming, but check each token value and allow sub-classes to handle the token if they wish.
                        // ORACLE, for instance can terminator a complex statement with a backslash, '/'. Calling
                        // handleUnknownToken() allows that dialect to create it's own statement node that can be assessed and
                        // used during the rewrite() call at the end of parsing.
                        nextTokenValue = tokens.consume();
                        AstNode unknownNode = handleUnknownToken(tokens, nextTokenValue);
                        if (unknownNode != null) {
                            markEndOfStatement(tokens, unknownNode);
                            // We've determined that it's just an unknown node, which we determine is not a problem node.
                            problem = null;
                        }
View Full Code Here

    public final void attachNewProblem( DdlParserProblem problem,
                                        AstNode parentNode ) {
        assert problem != null;
        assert parentNode != null;

        AstNode problemNode = nodeFactory().node("DDL PROBLEM", parentNode, TYPE_PROBLEM);
        problemNode.setProperty(PROBLEM_LEVEL, problem.getLevel());
        problemNode.setProperty(MESSAGE, problem.toString() + "[" + problem.getUnusedSource() + "]");

        testPrint(problem.toString());
    }
View Full Code Here

TOP

Related Classes of org.jboss.dna.sequencer.ddl.node.AstNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.