X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=plugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fproviders%2FDistSessionFactory.java;fp=plugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fproviders%2FDistSessionFactory.java;h=0000000000000000000000000000000000000000;hb=0d236262a853a1286b317c30d64d4692bc21c7a4;hp=b8f2c7541c3d5748c9208643d897f8c14119c1e6;hpb=dc95cc0fdc36c88e778cdfd52d443d0a0b8d926c;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/providers/DistSessionFactory.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/providers/DistSessionFactory.java deleted file mode 100644 index b8f2c7541..000000000 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/providers/DistSessionFactory.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.argeo.slc.client.ui.dist.providers; - -import javax.jcr.Credentials; -import javax.jcr.NoSuchWorkspaceException; -import javax.jcr.Node; -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.RepositoryFactory; -import javax.jcr.Session; - -import org.argeo.jcr.JcrUtils; -import org.argeo.slc.SlcException; -import org.argeo.slc.repo.RepoUtils; -import org.argeo.util.security.Keyring; - -/** - * Provides shortcut to retrieve sessions, repositories and workspaces that are - * persisted in the current user node using path only. - */ -public class DistSessionFactory { - - /* DEPENDENCY INJECTION */ - private RepositoryFactory repositoryFactory; - private Keyring keyring; - private Repository nodeRepository; - - /** - * Returns a new session on the given workspace. This session *must* be - * disposed by the caller. If the workspace does not exist and - * createIfNeeded==true, tries to create it - * - * */ - public Session getSessionFromWorkspacePath(String path, - boolean createIfNeeded) { - Session nodeSession = null; - try { - nodeSession = nodeRepository.login(); - Node localWksp = nodeSession.getNode(path); - Repository repository = RepoUtils.getRepository(repositoryFactory, - keyring, localWksp.getParent()); - Credentials credentials = RepoUtils.getRepositoryCredentials( - keyring, localWksp.getParent()); - - String wkspName = JcrUtils.lastPathElement(path); - Session session = null; - try { - session = repository.login(credentials, wkspName); - } catch (NoSuchWorkspaceException e) { - if (createIfNeeded) { - Session defaultSession = repository.login(credentials); - try { - defaultSession.getWorkspace().createWorkspace(wkspName); - } catch (Exception e1) { - throw new SlcException("Cannot create new workspace " - + wkspName, e); - } finally { - JcrUtils.logoutQuietly(defaultSession); - } - session = repository.login(credentials, wkspName); - } else - throw new SlcException("Workspace" + wkspName - + "does not exists and should not be created", e); - } - return session; - } catch (RepositoryException e) { - throw new SlcException("cannot create session" + " for workspace " - + path, e); - } finally { - JcrUtils.logoutQuietly(nodeSession); - } - } - - /* - * DEPENDENCY INJECTION - */ - public void setRepositoryFactory(RepositoryFactory repositoryFactory) { - this.repositoryFactory = repositoryFactory; - } - - public void setKeyring(Keyring keyring) { - this.keyring = keyring; - } - - public void setRepository(Repository nodeRepository) { - this.nodeRepository = nodeRepository; - } -} \ No newline at end of file