jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r691321 - in /jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx: JCRServer.java JCRServerMBean.java
Date Tue, 02 Sep 2008 17:03:06 GMT
Author: jukka
Date: Tue Sep  2 10:03:06 2008
New Revision: 691321

URL: http://svn.apache.org/viewvc?rev=691321&view=rev
Log:
JCR-1317: Add a MBean method to programatically create a new Workspace. 

Cleaned up and documented the code.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java?rev=691321&r1=691320&r2=691321&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServer.java
Tue Sep  2 10:03:06 2008
@@ -20,12 +20,11 @@
 import java.io.InputStream;
 import java.util.Properties;
 
-import javax.jcr.Credentials;
-import javax.jcr.LoginException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.Workspace;
 import javax.naming.InitialContext;
 
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
@@ -124,33 +123,24 @@
         remote = null;
     }
 
-    public void createWorkspace( String username, String password, String workspace ) {
+    public void createWorkspace(
+            String username, String password, String name)
+            throws RepositoryException {
+        Session session = localRepository.login(
+                new SimpleCredentials(username, password.toCharArray()));
         try {
-            Credentials cred = new SimpleCredentials( username, password.toCharArray() );
-            Session sesion = this.localRepository.login( cred );
-            JackrabbitWorkspace ws = ( JackrabbitWorkspace ) sesion.getWorkspace();
-            ws.createWorkspace( workspace );
-        } catch ( LoginException ex ) {
-            ex.printStackTrace();
-        } catch ( RepositoryException ex ) {
-            ex.printStackTrace();
+            Workspace workspace = session.getWorkspace();
+            if (workspace instanceof JackrabbitWorkspace) {
+                ((JackrabbitWorkspace) workspace).createWorkspace(name);
+            } else {
+                throw new RepositoryException(
+                        "Not a Jackrabbit workspace: " + workspace);
+            }
+        } finally {
+            session.logout();
         }
     }
 
-    /**
-     * Returns the local repository instance.
-     */
-    Repository getLocalRepository() {
-        return localRepository;
-    }
-
-    /**
-     * Sets the local repository instance.
-     */
-    public void setLocalRepository( Repository localRepository ) {
-        this.localRepository = localRepository;
-    }
-
     public String getLocalAddress() {
         return localAddress;
     }

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java?rev=691321&r1=691320&r2=691321&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/jmx/JCRServerMBean.java
Tue Sep  2 10:03:06 2008
@@ -16,13 +16,24 @@
  */
 package org.apache.jackrabbit.rmi.server.jmx;
 
+import javax.jcr.RepositoryException;
+
 public interface JCRServerMBean {
 
     void start() throws Exception;
 
     void stop() throws Exception;
 
-    void createWorkspace(String username, String password, String workspace);
+    /**
+     * Creates a workspace in the managed repository.
+     *
+     * @param username administrator username
+     * @param password administrator password
+     * @param workspace name of the workspace to create
+     * @throws RepositoryException if the workspace could not be created
+     */
+    void createWorkspace(String username, String password, String workspace)
+        throws RepositoryException;
 
     String getLocalAddress();
 



Mime
View raw message