View Javadoc
1   package org.argeo.slc.client.ui.dist.model;
2   
3   import javax.jcr.RepositoryException;
4   import javax.jcr.Session;
5   
6   import org.argeo.jcr.JcrUtils;
7   import org.argeo.slc.SlcException;
8   
9   /**
10   * Abstract set of similar workspaces, that is a bunch of workspaces with same
11   * prefix.
12   */
13  public class WkspGroupElem extends DistParentElem {
14  
15  	private Session defaultSession;
16  
17  	public WkspGroupElem(RepoElem repoElem, String prefix) {
18  		super(prefix, repoElem.inHome(), repoElem.isReadOnly());
19  		setParent(repoElem);
20  		// Directly adds children upon creation
21  		try {
22  			defaultSession = repoElem.repositoryLogin(null);
23  			String[] wkpNames = defaultSession.getWorkspace()
24  					.getAccessibleWorkspaceNames();
25  			for (String wkpName : wkpNames) {
26  				if (prefix.equals(getPrefix(wkpName))
27  				// if (wkpName.startsWith(prefix)
28  						&& repoElem.isWorkspaceVisible(wkpName))
29  					addChild(new WorkspaceElem(WkspGroupElem.this, repoElem,
30  							wkpName));
31  			}
32  		} catch (RepositoryException e) {
33  			throw new SlcException("Cannot retrieve workspace names", e);
34  		}
35  	}
36  
37  	// FIXME - we rely on a "hard coded" convention : Workspace name must have
38  	// this format: name-major.minor
39  	// We might expose this method as static public, to be used among others by
40  	// the RepoElem parent objects when building its children
41  	private String getPrefix(String workspaceName) {
42  		if (workspaceName.lastIndexOf(VERSION_SEP) > 0)
43  			return workspaceName.substring(0,
44  					workspaceName.lastIndexOf(VERSION_SEP));
45  		else
46  			return workspaceName;
47  	}
48  
49  	public void dispose() {
50  		JcrUtils.logoutQuietly(defaultSession);
51  		super.dispose();
52  	}
53  }