+ Session session;
+ try {
+ session = repository.login(workspaceName);
+ } catch (NoSuchWorkspaceException e) {
+ if (autocreateWorkspaces)
+ session = createWorkspaceAndLogsIn(null, workspaceName);
+ else
+ throw e;
+ }
+ processNewSession(session);
+ return session;
+ }
+
+ protected synchronized void processNewSession(Session session) {
+ try {
+ NamespaceHelper namespaceHelper = new NamespaceHelper(session);
+ namespaceHelper.registerNamespaces(namespaces);
+
+ for (byte[] arr : cnds)
+ CndImporter.registerNodeTypes(new InputStreamReader(
+ new ByteArrayInputStream(arr)), session, true);
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot process new session", e);
+ }
+ }
+
+ /**
+ * Logs in to the default workspace, creates the required workspace, logs
+ * out, logs in to the required workspace.
+ */
+ protected Session createWorkspaceAndLogsIn(Credentials credentials,
+ String workspaceName) throws RepositoryException {
+ if (workspaceName == null)
+ throw new ArgeoException("No workspace specified.");
+ Session session = repository.login(credentials);
+ session.getWorkspace().createWorkspace(workspaceName);
+ session.logout();
+ return repository.login(credentials, workspaceName);
+ }
+
+ public void setResourceLoader(ResourceLoader resourceLoader) {
+ this.resourceLoader = resourceLoader;