2 Replies Latest reply on Feb 12, 2012 6:05 PM by Brian Wallis

    CND Syntax Errors

    Brian Wallis Master

      Syntax errors don't seem to be caught or reported, they just cause the parsing to halt. I have the following code to load a CND file



              JcrEngine engine = null;




                  InputStream      myConfigStream = TestLoadCND.class.getClassLoader().getResourceAsStream("modeshape-config.xml");

                  JcrConfiguration config         = new JcrConfiguration().loadFrom(myConfigStream);

                  engine = config.build();



                  Repository      repository      = engine.getRepository("CPF repository");

                  Session         session         = repository.login();

                  Workspace       workspace       = session.getWorkspace();

                  NodeTypeManager nodeTypeManager = (NodeTypeManager) workspace.getNodeTypeManager();

                  System.out.println("Parse the cnd file");


                  InputStream myCndStream = TestLoadCND.class.getClassLoader().getResourceAsStream("syntaxError.cnd");

                  nodeTypeManager.registerNodeTypes(myCndStream, false);

                  System.out.println("File parsed");

                  System.out.println("List the new nodes");


                  NodeTypeIterator it = nodeTypeManager.getAllNodeTypes();




                      Object   o  = it.next();

                      NodeType nt = (NodeType) o;

                      printNodeDetails(nt, false);



              catch(Throwable e)


                  System.out.println("Error parsing cnd: " + e.getMessage());





      If I run this with the following cnd file



      <local = 'http://local.domain/local'>

      [local:A] mixin

      - local:title (STRING) xx



      I get no nodes listed from the while loop but I also don't get any indication that there is an error.


      If I remove the "xx" then I get a printout of the details of node local:A.


      If instead I have a semantic error in the CND like so



      <local = 'http://local.domain/local'>

      [local:A] mixin

      - local:title (STRING)


      [local:B] mixin

      - local:title (STRING)


      [local:C] > local:A,local:B



      then I get an error during loading of the CND file as expected:


      {code}Parse the cnd file

      Error parsing cnd: Types 'local:A' and 'local:B' cannot both be supertypes of the same type, as both separately declare property 'local:title'

      org.modeshape.jcr.nodetype.InvalidNodeTypeDefinitionException: Types 'local:A' and 'local:B' cannot both be supertypes of the same type, as both separately declare property 'local:title'

                at org.modeshape.jcr.RepositoryNodeTypeManager.validate(RepositoryNodeTypeManager.java:2160)

                at org.modeshape.jcr.RepositoryNodeTypeManager.validate(RepositoryNodeTypeManager.java:2205)

                at org.modeshape.jcr.RepositoryNodeTypeManager.registerNodeTypes(RepositoryNodeTypeManager.java:1776)

                at org.modeshape.jcr.JcrNodeTypeManager.registerNodeTypes(JcrNodeTypeManager.java:605)

                at org.modeshape.jcr.JcrNodeTypeManager.registerNodeTypes(JcrNodeTypeManager.java:865)

                at au.com.infomedix.documentstore.cnd.TestLoadCND.main(TestLoadCND.java:52)



      Am I missing some setting in my code or not loading the CND correctly?


      Running version 2.7.0 and my modeshape config file is:


      {code:xml}<?xml version="1.0" encoding="UTF-8"?>


      <configuration xmlns:mode="http://www.modeshape.org/1.0"



        <!-- Define the JCR repositories -->



        <!-- a CPF repository -->

        <mode:repository jcr:name="CPF repository"

        mode:source="IMR Store">

        <mode:options jcr:primaryType="mode:options">






        <!-- Define the sources used by the repository (or repositories) to store

                          and access the content -->

        <mode:sources jcr:primaryType="nt:unstructured">

        <!-- The 'IMR Store' repository is an in-memory source with a single default

                                    workspace (though others could be created, too). -->

        <mode:source jcr:name="IMR Store"


        mode:description="The repository for our content"