Map<String, Object> sessionAttributes,
boolean readOnly ) {
this.repository = repository;
// Get the node key of the workspace we're going to use ...
final RepositoryCache repositoryCache = repository.repositoryCache();
WorkspaceCache workspace = repositoryCache.getWorkspaceCache(workspaceName);
NodeKey rootKey = workspace.getRootKey();
// Now create a specific reference factories that know about the root node key ...
TextDecoder decoder = context.getDecoder();
ValueFactories factories = context.getValueFactories();
ReferenceFactory rootKeyAwareStrongRefFactory = NodeIdentifierReferenceFactory.newInstance(rootKey, decoder, factories,
false, false);
ReferenceFactory rootKeyAwareWeakRefFactory = NodeIdentifierReferenceFactory.newInstance(rootKey, decoder, factories,
true, false);
ReferenceFactory rootKeyAwareSimpleRefFactory = NodeIdentifierReferenceFactory.newInstance(rootKey, decoder, factories,
true, true);
context = context.with(rootKeyAwareStrongRefFactory).with(rootKeyAwareWeakRefFactory).with(rootKeyAwareSimpleRefFactory);
// Create an execution context for this session that uses a local namespace registry ...
final NamespaceRegistry globalNamespaceRegistry = context.getNamespaceRegistry(); // thread-safe!
final LocalNamespaceRegistry localRegistry = new LocalNamespaceRegistry(globalNamespaceRegistry); // not-thread-safe!
this.context = context.with(localRegistry);
this.sessionRegistry = new JcrNamespaceRegistry(Behavior.SESSION, localRegistry, globalNamespaceRegistry, this);
this.workspace = new JcrWorkspace(this, workspaceName);
// Create the session cache ...
this.cache = repositoryCache.createSession(this.context, workspaceName, readOnly);
this.rootNode = new JcrRootNode(this, this.cache.getRootKey());
this.jcrNodes.put(this.rootNode.key(), this.rootNode);
this.sessionAttributes = sessionAttributes != null ? sessionAttributes : Collections.<String, Object>emptyMap();
// Pre-cache all of the namespaces to be a snapshot of what's in the global registry at this time.