Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 24590 invoked from network); 7 Jan 2005 14:48:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Jan 2005 14:48:51 -0000 Received: (qmail 19948 invoked by uid 500); 7 Jan 2005 14:48:51 -0000 Mailing-List: contact jackrabbit-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-commits@incubator.apache.org Received: (qmail 19929 invoked by uid 500); 7 Jan 2005 14:48:50 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 19926 invoked by uid 99); 7 Jan 2005 14:48:50 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 07 Jan 2005 06:48:50 -0800 Received: (qmail 24529 invoked by uid 65534); 7 Jan 2005 14:48:49 -0000 Date: 7 Jan 2005 14:48:49 -0000 Message-ID: <20050107144849.24526.qmail@minotaur.apache.org> From: stefan@apache.org To: jackrabbit-cvs@incubator.apache.org Subject: svn commit: r124504 - /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: stefan Date: Fri Jan 7 06:48:46 2005 New Revision: 124504 URL: http://svn.apache.org/viewcvs?view=rev&rev=124504 Log: fixed creation of workspaces through api Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&rev=124504&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java&r1=124503&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java&r2=124504 ============================================================================== --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java Fri Jan 7 06:48:46 2005 @@ -263,25 +263,11 @@ ntReg = NodeTypeRegistry.create(nsReg, new BasedFileSystem(repStore, "/nodetypes")); - /** - * todo implement 'System' workspace - * - the system workspace should have the /jcr:system node - * - versions, version history and node types should be reflected in - * this system workspace as content under /jcr:system - * - all other workspaces should be dynamic workspaces based on - * this 'read-only' system workspace - */ - - // check system root node of system workspace - // (for now, we just create a system root node in all workspaces) - Iterator wspNames = wspInfos.keySet().iterator(); - while (wspNames.hasNext()) { - String wspName = (String) wspNames.next(); - NodeImpl rootNode = (NodeImpl) getSystemSession(wspName).getRootNode(); - if (!rootNode.hasNode(SYSTEM_ROOT_NAME)) { - rootNode.addNode(SYSTEM_ROOT_NAME, NodeTypeRegistry.REP_SYSTEM); - rootNode.save(); - } + // initialize workspaces + iter = wspInfos.keySet().iterator(); + while (iter.hasNext()) { + String wspName = (String) iter.next(); + initWorkspace(wspName); } // init version manager @@ -296,29 +282,6 @@ nodesCount = Long.parseLong(repProps.getProperty(STATS_NODE_COUNT_PROPERTY, "0")); propsCount = Long.parseLong(repProps.getProperty(STATS_PROP_COUNT_PROPERTY, "0")); - // get the system session for every defined workspace and - // register as an event listener - iter = wspInfos.values().iterator(); - while (iter.hasNext()) { - String wspName = ((WorkspaceInfo) iter.next()).getName(); - Session s = getSystemSession(wspName); - s.getWorkspace().getObservationManager().addEventListener(this, - Event.NODE_ADDED | Event.NODE_REMOVED - | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED, - "/", true, null, null, false); - - // register SearchManager as EventListener - SearchManager searchMgr = getSearchManager(wspName); - - if (searchMgr != null) { - s.getWorkspace().getObservationManager().addEventListener(searchMgr, - Event.NODE_ADDED | Event.NODE_REMOVED | - Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED | - Event.PROPERTY_CHANGED, - "/", true, null, null, false); - } - } - // finally register shutdown hook Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { @@ -341,6 +304,46 @@ return new RepositoryImpl(config); } + private void initWorkspace(String wspName) throws RepositoryException { + // get system session and Workspace instance + SessionImpl sysSession = getSystemSession(wspName); + WorkspaceImpl wsp = (WorkspaceImpl) sysSession.getWorkspace(); + + /** + * todo implement 'System' workspace + * FIXME + * - the should be one 'System' workspace per repositoy + * - the 'System' workspace should have the /jcr:system node + * - versions, version history and node types should be reflected in + * this system workspace as content under /jcr:system + * - all other workspaces should be dynamic workspaces based on + * this 'read-only' system workspace + * + * for now, we just create a /jcr:system node in every workspace + */ + NodeImpl rootNode = (NodeImpl) sysSession.getRootNode(); + if (!rootNode.hasNode(SYSTEM_ROOT_NAME)) { + rootNode.addNode(SYSTEM_ROOT_NAME, NodeTypeRegistry.REP_SYSTEM); + rootNode.save(); + } + + // register the repository as event listener for keeping repository statistics + wsp.getObservationManager().addEventListener(this, + Event.NODE_ADDED | Event.NODE_REMOVED + | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED, + "/", true, null, null, false); + + // register SearchManager as event listener + SearchManager searchMgr = getSearchManager(wspName); + if (searchMgr != null) { + wsp.getObservationManager().addEventListener(searchMgr, + Event.NODE_ADDED | Event.NODE_REMOVED | + Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED | + Event.PROPERTY_CHANGED, + "/", true, null, null, false); + } + } + RepositoryConfig getConfig() { // check state if (disposed) { @@ -390,8 +393,9 @@ * Returns the names of all workspaces of this repository. * * @return the names of all workspaces of this repository. + * @see SessionImpl#getWorkspaceNames */ - protected String[] getWorkspaceNames() { + String[] getWorkspaceNames() { return (String[]) wspInfos.keySet().toArray(new String[wspInfos.keySet().size()]); } @@ -401,8 +405,9 @@ * @param workspaceName name of the new workspace * @throws RepositoryException if a workspace with the given name * already exists or if another error occurs + * @see SessionImpl#createWorkspace(String) */ - public void createWorkspace(String workspaceName) throws RepositoryException { + synchronized void createWorkspace(String workspaceName) throws RepositoryException { if (wspInfos.containsKey(workspaceName)) { throw new RepositoryException("workspace '" + workspaceName + "' already exists."); } @@ -411,6 +416,9 @@ WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName); WorkspaceInfo info = new WorkspaceInfo(config); wspInfos.put(workspaceName, info); + + // setup/initialize new workspace + initWorkspace(workspaceName); } PersistentItemStateProvider getWorkspaceStateManager(String workspaceName) Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java?view=diff&rev=124504&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java&r1=124503&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java&r2=124504 ============================================================================== --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Fri Jan 7 06:48:46 2005 @@ -23,7 +23,6 @@ import org.apache.jackrabbit.core.state.NodeState; import org.apache.jackrabbit.core.state.PersistentItemStateProvider; import org.apache.jackrabbit.core.state.SessionItemStateManager; -import org.apache.jackrabbit.core.version.VersionManagerImpl; import org.apache.jackrabbit.core.version.VersionManager; import org.apache.jackrabbit.core.xml.ImportHandler; import org.apache.log4j.Logger; @@ -329,10 +328,23 @@ * Returns the names of all workspaces of this repository with respect of the * access rights of this session. * - * @return the names of all workspaces of this repository. + * @return the names of all accessible workspaces */ public String[] getWorkspaceNames() { + // @todo filter workspace names based on credentials of this session return rep.getWorkspaceNames(); + } + + /** + * Creates a workspace with the given name. + * + * @param workspaceName name of the new workspace + * @throws RepositoryException if a workspace with the given name + * already exists or if another error occurs + */ + public void createWorkspace(String workspaceName) throws RepositoryException { + // @todo verify that this session has the right privileges for this operation + rep.createWorkspace(workspaceName); } /**