CND Syntax Errors
bwallis42 Feb 11, 2012 5:52 PMSyntax 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}