One question people have when starting out with ModeShape and JCR is this:
Should I create one CND file with all of my node types, or should I create multiple CND files?
Naturally, the answer is “It depends”, since there really is no one way that works for everyone. So to help you figure out your own answer, here are several guidelines that we consider. (If you know of others, please let us know in the comments.)
(BTW, do you know about our CND Editor for Eclipse? If not, check it out because it really makes it easy to edit CND files. It doesn’t even require you to have or use ModeShape.)
A single CND file is easy, and can have node type names that use different namespaces. Just look at a CND file with the standard built-in types. Where possible, keep things simple and use just a single CND file.
Perhaps you have enough node types that it’s becomes harder to keep them all in one CND file. In that case, consider putting semantically-related node type definitions in separate files.
Some node types might be more reusable than others. In this case, consider putting common or more reusable node types in separate files. For example, you might reuse a subset of your node type definitions in multiple repositories. Or multiple applications might need a common set of node type definitions, while also having their own application-specific types.
When you have reusable node types, then you might also want to consider how those common node types are governed. Are they defined by a central group of people? Are they put into their own Maven artifacts that can be easily shared, and if so are they released separately from the applications? These may all affect how you break up those common node types into one or more files.
You may also want to create separate CND files when they’re used/registered at different times. Deployment mechanisms will often dictate the ability or desire to do this.
A ModeShape repository configuration can specify a set of CND files that are to be registered immediately upon startup of the repository. But applications using that repository can also use the JCR API to register new (or updated) node types, too. So you might want some node types to be installed upon initialization, while others might be registered only when the application needs them. You’ll likely want different CND files for each purpose.
Here’s an example. Consider that you have ModeShape installed into an AS7 instance, so the ModeShape repositories are configured as part of the AS7 configuration and started when they’re needed/used. Then web application (or web service) can simply get a hold of the (running) repository via the JNDI, @Resource injection, or RepositoryFactory techniques. In fact, multiple applications can use the same repository. Perhaps some basic node types should installed as part of the repository configuration, while each application (if deployed) can register their own application-specific (or even common) node types.