Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:08:45+00:00 2026-05-31T19:08:45+00:00

Section 7.1.6 of the Modeshape docs say ‘Your application can now create and remove

  • 0

Section 7.1.6 of the Modeshape docs say ‘Your application can now create and remove workspaces using the standard JCR 2.0 API.’

The JCR 2.0 doc says to use Workspace.createWorkspace(String name)

How do I make this part of my repository obtained using the code at the bottom of this post?

Also, how to I get a list of the workspaces already in the repository?

Thanks

for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {

    if (factory instanceof org.modeshape.jcr.api.RepositoryFactory) {
        org.modeshape.jcr.api.RepositoryFactory modeshapeRepositoryFactory = (org.modeshape.jcr.api.RepositoryFactory) factory;

        final Repositories repositories = modeshapeRepositoryFactory.getRepositories(JCR_CONFIG_FILE_URL);

        if (repositories != null) {

            Set<String> repositoryNames = repositories.getRepositoryNames();
            if (repositoryNames != null) {
                for (String repoName : repositoryNames) {
                    log.info(repoName);
                }
            }
        }
        else {
            System.out.println("repositories reference was null");
        }
    }

    try {

        repository = factory.getRepository(parameters);
        if (repository != null) {
            printRepoDetails(repository, parameters, factory);
            repositoryFactory = factory; // Keep reference to allow clean shutdown.  Not part of JCR 2.0
            break;
        }
    }
    catch (RepositoryException e) {
        log.error("Error getting repository: \n" + e.toString());
        e.printStackTrace();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:08:46+00:00Added an answer on May 31, 2026 at 7:08 pm

    The javax.jcr.Repository interface allows you to get the descriptors of the repository and to log in to establish a session to a workspace in the repository. But all other operations require authentication and authorization, which means they can be performed with a javax.jcr.Session or via the other session-specific interfaces (such as javax.jcr.Workspace).

    All examples shown below use on the standard JCR API.

    To obtain a Session, simply log into the Repository:

    javax.jcr.Repository repository = ...
    javax.jcr.Session session = repository.login();
    

    Note that this call doesn’t supply any credentials and results in an “anonymous” session that uses the default workspace. An anonymous session may not have privilege to do much, so you may need to use one of the other overloaded forms of the login method that allow you to supply various combinations of credentials and/or workspace names. (The ModeShape configuration allows you to dictate the name of the default workspace, to control whether anonymous sessions are allowed, and to specify the roles allowed by anonymous sessions.) If you specify a workspace name and that workspace doesn’t exist, the method will throw a javax.jcr.NoSuchWorkspaceException exception (that is a subclass of the javax.jcr.RepositoryException).

    To get the list of workspaces, get the session’s Workspace object and call the getAccessibleWorkspaceNames() method:

    javax.jcr.Workspace workspace = session.getWorkspace();
    String[] workspaceNames = workspace.getAccessibleWorkspaceNames();
    

    You can then do something with the workspace names, such as check whether the workspace you need already exists.

    To create a new empty workspace, simply use the Workspace object:

    String newWorkspaceName = ...
    workspace.createWorkspace(newWorkspaceName);
    

    Alternatively, you can create a new workspace that is a copy of an existing workspace.

    String newWorkspaceName = ...
    String originalWorkspaceName = ...
    workspace.createWorkspace(newWorkspaceName,originalWorkspaceName);
    

    Note that the mix:referenceable nodes will have the same identifiers in both the original and new workspaces. This is an important characteristic of JCR workspaces and often a big reason for using separate workspaces (rather than separate areas of a single workspace). See the JSR-283 specification for more detail.

    And finally, you can destroy existing workspaces, too:

    String existingWorkspaceName
    workspace.deleteWorkspace(existingWorkspaceName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of my site where users can add addresses to their
Section 2.2 of RFC 2822 defined e-mail message header fields. However it doesn't say
Section  TextFrame   Table    Row 1 - N, Dynamically generated using a datatable.  TextFrame   Table
In section 3.6.1.2 of both C++ Standard 1998 and 2003 editions, An implementation shall
i have a private section where specific users can login on my system (restricted
I have a Section model, where a Section can be a parent of another
A section of a Flash animation I'm creating involves an area where people can
I refactored a slow section of an application we inherited from another company to
The section §3.9.1/6 from the C++ Standard says, Values of type bool are either
The section $7.3.1.1/2 from the C++ Standard reads: The use of the static keyword

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.