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

    CND Syntax Errors

    bwallis42

      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

       

      {code}

              JcrEngine engine = null;

       

              try

              {

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

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

                  engine = config.build();

                  engine.start();

       

                  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();

       

                  while(it.hasNext())

                  {

                      Object   o  = it.next();

                      NodeType nt = (NodeType) o;

                      printNodeDetails(nt, false);

                  }

              }

              catch(Throwable e)

              {

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

                  e.printStackTrace();

              }

      {code}

       

      If I run this with the following cnd file

       

      {code}

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

      [local:A] mixin

      - local:title (STRING) xx

      {code}

       

      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

       

      {code}

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

      [local:A] mixin

      - local:title (STRING)

       

      [local:B] mixin

      - local:title (STRING)

       

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

      {code}

       

      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)

      {code}

       

      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"

        xmlns:jcr="http://www.jcp.org/jcr/1.0">

       

        <!-- Define the JCR repositories -->

        <mode:repositories>

       

        <!-- a CPF repository -->

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

        mode:source="IMR Store">

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

        </mode:options>

        </mode:repository>

       

        </mode:repositories>

       

        <!-- 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:classname="org.modeshape.graph.connector.inmemory.InMemoryRepositorySource"

        mode:description="The repository for our content"

        mode:defaultWorkspaceName="default">

        </mode:source>

        </mode:sources>

       

        <mode:sequencers>

        </mode:sequencers>

      </configuration>

      {code}

        • 1. Re: CND Syntax Errors
          rhauch

          After looking at the code, the "registerNodeTypes(...)" methods that read the node types from a CND file use a reader that only throws an exception if the file could not be read. Otherwise, any problems are captured as errors or warnings, but these aren't currently being checked so the NodeTypeManager tries to register an empty set of node types.

           

          This is obviously incorrect. Would you mind logging a defect? We'll get this fixed for 2.8 and 3.0. We should be logging warnings, and errors should result in an exception.

          • 2. Re: CND Syntax Errors
            bwallis42

            Created ticket MODE-1400