You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/03/11 18:19:50 UTC

svn commit: r921950 - in /james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr: ./ mail/ mail/model/ user/ user/model/

Author: norman
Date: Thu Mar 11 17:19:49 2010
New Revision: 921950

URL: http://svn.apache.org/viewvc?rev=921950&view=rev
Log:
More work on JCR (IMAP-93)

Added:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/IsPersistent.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserSubscriptionManager.java
Removed:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailboxMembership.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java
Modified:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRHeader.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailbox.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRProperty.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java

Added: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/IsPersistent.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/IsPersistent.java?rev=921950&view=auto
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/IsPersistent.java (added)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/IsPersistent.java Thu Mar 11 17:19:49 2010
@@ -0,0 +1,48 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+public interface IsPersistent {
+
+
+    /**
+     * Merge the object with the node
+     * 
+     * @param node
+     */
+    public void merge(Node node) throws RepositoryException;
+    
+	/**
+	 * Return underlying Node
+	 * 
+	 * @return node
+	 */
+	public Node getNode();
+	
+	/**
+	 * Return if the object is persistent
+	 * 
+	 * @return
+	 */
+	public boolean isPersistent();
+	
+}

Added: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java?rev=921950&view=auto
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java (added)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java Thu Mar 11 17:19:49 2010
@@ -0,0 +1,66 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr;
+
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.store.Authenticator;
+import org.apache.james.imap.store.Subscriber;
+
+/**
+ * JCR based MailboxManager which use the same username and password to obtain a
+ * JCR Session for every MailboxSession
+ * 
+ * 
+ */
+public class JCRGlobalUserMailboxManager extends JCRMailboxManager {
+
+    private final String username;
+    private final String password;
+
+    public JCRGlobalUserMailboxManager(final Authenticator authenticator, final Subscriber subscriber, final Repository repository, final String workspace, final String username, final String password) {
+        super(authenticator, subscriber, repository, workspace);
+
+        this.username = username;
+        this.password = password;
+    }
+
+    @Override
+    protected Session getSession(MailboxSession s) throws MailboxException {
+        try {
+            return getRepository().login(new SimpleCredentials(username, password.toCharArray()), getWorkspace());
+        } catch (LoginException e) {
+            throw new MailboxException(HumanReadableText.INVALID_LOGIN, e);
+        } catch (NoSuchWorkspaceException e) {
+            throw new MailboxException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
+        } catch (RepositoryException e) {
+            throw new MailboxException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
+
+        }
+    }
+
+}

Added: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserSubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserSubscriptionManager.java?rev=921950&view=auto
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserSubscriptionManager.java (added)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserSubscriptionManager.java Thu Mar 11 17:19:49 2010
@@ -0,0 +1,63 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr;
+
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.mailbox.SubscriptionException;
+import org.apache.james.imap.store.PasswordAwareUser;
+
+/**
+ * JCR based SubscriptionManager which use the same username and password to
+ * obtain a JCR Session for every MailboxSession
+ * 
+ * 
+ */
+public class JCRGlobalUserSubscriptionManager extends JCRSubscriptionManager {
+
+    private String username;
+    private String password;
+
+    public JCRGlobalUserSubscriptionManager(final Repository repository, final String workspace, final String username, final String password) {
+        super(repository, workspace);
+        this.username = username;
+        this.password = password;
+    }
+
+    @Override
+    protected Session getSession(PasswordAwareUser user) throws SubscriptionException {
+        try {
+            return getRepository().login(new SimpleCredentials(username, password.toCharArray()), getWorkspace());
+        } catch (LoginException e) {
+            throw new SubscriptionException(HumanReadableText.INVALID_LOGIN, e);
+        } catch (NoSuchWorkspaceException e) {
+            throw new SubscriptionException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
+        } catch (RepositoryException e) {
+            throw new SubscriptionException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
+
+        }
+    }
+
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java Thu Mar 11 17:19:49 2010
@@ -1,64 +1,66 @@
-package org.apache.james.imap.jcr;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.jcr.Repository;
-import javax.jcr.Session;
-import javax.mail.Flags;
-import javax.swing.RepaintManager;
-
-import org.apache.james.imap.jcr.mail.model.JCRHeader;
-import org.apache.james.imap.mailbox.MailboxException;
-import org.apache.james.imap.mailbox.MailboxSession;
-import org.apache.james.imap.store.StoreMailbox;
-import org.apache.james.imap.store.mail.MessageMapper;
-import org.apache.james.imap.store.mail.model.Header;
-import org.apache.james.imap.store.mail.model.Mailbox;
-import org.apache.james.imap.store.mail.model.MailboxMembership;
-import org.apache.james.imap.store.mail.model.PropertyBuilder;
-
-public class JCRMailbox extends StoreMailbox{
-
-    private final Repository repos;
-
-    public JCRMailbox(final Mailbox mailbox, final MailboxSession session, final Repository repos) {
-        super(mailbox, session );
-        this.repos = repos;
-    }
-
-    @Override
-    protected MailboxMembership copyMessage(MailboxMembership originalMessage, long uid) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    protected Header createHeader(int lineNumber, String name, String value) {
-        return new JCRHeader(name, value, lineNumber);
-    }
-
-    @Override
-    protected MailboxMembership createMessage(Date internalDate, long uid, int size, int bodyStartOctet, byte[] document, Flags flags, List<Header> headers, PropertyBuilder propertyBuilder) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    protected MessageMapper createMessageMapper(MailboxSession session) {
-        
-        return null;
-    }
-
-    @Override
-    protected Mailbox getMailboxRow() throws MailboxException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    protected Mailbox reserveNextUid() throws MailboxException {
-        return null;
-    }
-
-}
+package org.apache.james.imap.jcr;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.jcr.Repository;
+import javax.mail.Flags;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.jcr.mail.model.JCRHeader;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.store.StoreMailbox;
+import org.apache.james.imap.store.mail.MessageMapper;
+import org.apache.james.imap.store.mail.model.Header;
+import org.apache.james.imap.store.mail.model.Mailbox;
+import org.apache.james.imap.store.mail.model.MailboxMembership;
+import org.apache.james.imap.store.mail.model.PropertyBuilder;
+
+public class JCRMailbox extends StoreMailbox{
+
+    private final Repository repos;
+    private final String workspace;
+    private final Log log;
+    public JCRMailbox(final Mailbox mailbox, final MailboxSession session, final Repository repos, final String workspace, final Log log) {
+        super(mailbox, session );
+        this.repos = repos;
+        this.workspace = workspace;
+        this.log = log;
+    }
+
+    @Override
+    protected MailboxMembership copyMessage(MailboxMembership originalMessage, long uid) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    protected Header createHeader(int lineNumber, String name, String value) {
+        return new JCRHeader(name, value, lineNumber, log);
+    }
+
+    @Override
+    protected MailboxMembership createMessage(Date internalDate, long uid, int size, int bodyStartOctet, byte[] document, Flags flags, List<Header> headers, PropertyBuilder propertyBuilder) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    protected MessageMapper createMessageMapper(MailboxSession session) {
+        
+        return null;
+    }
+
+    @Override
+    protected Mailbox getMailboxRow() throws MailboxException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    protected Mailbox reserveNextUid() throws MailboxException {
+        return null;
+    }
+
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java Thu Mar 11 17:19:49 2010
@@ -1,103 +1,138 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.imap.jcr;
-
-import java.util.ArrayList;
-import java.util.Locale;
-
-import javax.jcr.LoginException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.SimpleCredentials;
-
-import org.apache.commons.logging.Log;
-import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.jcr.mail.JCRMailboxMapper;
-import org.apache.james.imap.mailbox.BadCredentialsException;
-import org.apache.james.imap.mailbox.MailboxException;
-import org.apache.james.imap.mailbox.MailboxSession;
-import org.apache.james.imap.store.Authenticator;
-import org.apache.james.imap.store.PasswordAwareMailboxSession;
-import org.apache.james.imap.store.PasswordAwareUser;
-import org.apache.james.imap.store.StoreMailbox;
-import org.apache.james.imap.store.StoreMailboxManager;
-import org.apache.james.imap.store.Subscriber;
-import org.apache.james.imap.store.mail.MailboxMapper;
-import org.apache.james.imap.store.mail.model.Mailbox;
-import org.apache.james.imap.store.transaction.TransactionalMapper;
-
-/**
- * JCR implementation of a MailboxManager
- * 
- *
- */
-public class JCRMailboxManager extends StoreMailboxManager{
-
-	private final Repository repository;
-
-    public JCRMailboxManager(final Authenticator authenticator, final Subscriber subscriber, final Repository repository) {
-        super(authenticator, subscriber);
-        this.repository = repository;
-    }
-
-    @Override
-    protected StoreMailbox createMailbox(Mailbox mailboxRow, MailboxSession session) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    protected MailboxMapper createMailboxMapper(MailboxSession session) throws MailboxException{
-    	PasswordAwareUser s = (PasswordAwareUser) session.getUser();
-        try {
-			return new JCRMailboxMapper(repository.login(new SimpleCredentials(s.getUserName(), s.getPassword().toCharArray())));
-		} catch (LoginException e) {
-			throw new MailboxException(HumanReadableText.INVALID_LOGIN, e);
-		} catch (RepositoryException e) {
-			throw new MailboxException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
-		}
-    }
-
-    @Override
-    protected void doCreate(String namespaceName, MailboxSession session) throws MailboxException {
-        final Mailbox mailbox = new org.apache.james.imap.jcr.mail.model.JCRMailbox(namespaceName, randomUidValidity());
-        final MailboxMapper mapper = createMailboxMapper(session);
-        mapper.execute(new TransactionalMapper.Transaction(){
-
-            public void run() throws MailboxException {
-                mapper.save(mailbox);
-            }
-            
-        });
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.MailboxManager#login(java.lang.String, java.lang.String, org.apache.commons.logging.Log)
-     */
-    public MailboxSession login(String userid, String passwd, Log log) throws BadCredentialsException, MailboxException {
-        if (login(userid, passwd)) {
-        	
-            return new PasswordAwareMailboxSession(randomId(), userid, passwd, log, getDelimiter(), new ArrayList<Locale>());
-        } else {
-            throw new BadCredentialsException();
-        }
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.jcr.mail.JCRMailboxMapper;
+import org.apache.james.imap.mailbox.BadCredentialsException;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.store.Authenticator;
+import org.apache.james.imap.store.PasswordAwareMailboxSession;
+import org.apache.james.imap.store.PasswordAwareUser;
+import org.apache.james.imap.store.StoreMailbox;
+import org.apache.james.imap.store.StoreMailboxManager;
+import org.apache.james.imap.store.Subscriber;
+import org.apache.james.imap.store.mail.MailboxMapper;
+import org.apache.james.imap.store.mail.model.Mailbox;
+import org.apache.james.imap.store.transaction.TransactionalMapper;
+
+/**
+ * JCR implementation of a MailboxManager
+ * 
+ * 
+ */
+public class JCRMailboxManager extends StoreMailboxManager {
+
+    private final Repository repository;
+    private final String workspace;
+    private final Log logger = LogFactory.getLog(JCRMailboxManager.class);
+
+    public JCRMailboxManager(final Authenticator authenticator, final Subscriber subscriber, final Repository repository, final String workspace) {
+        super(authenticator, subscriber);
+        this.repository = repository;
+        this.workspace = workspace;
+    }
+
+    @Override
+    protected StoreMailbox createMailbox(Mailbox mailboxRow, MailboxSession session) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    protected MailboxMapper createMailboxMapper(MailboxSession session) throws MailboxException {
+        return new JCRMailboxMapper(getSession(session), logger);
+
+    }
+
+    /**
+     * Return a new JCR Session for the given MailboxSession
+     * 
+     * @param s
+     * @return session
+     * @throws MailboxException
+     */
+    protected Session getSession(MailboxSession s) throws MailboxException {
+        PasswordAwareUser user = (PasswordAwareUser) s.getUser();
+        try {
+            return repository.login(new SimpleCredentials(user.getUserName(), user.getPassword().toCharArray()), getWorkspace());
+        } catch (LoginException e) {
+            throw new MailboxException(HumanReadableText.INVALID_LOGIN, e);
+        } catch (NoSuchWorkspaceException e) {
+            throw new MailboxException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
+        } catch (RepositoryException e) {
+            throw new MailboxException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
+
+        }
+    }
+
+    @Override
+    protected void doCreate(String namespaceName, MailboxSession session) throws MailboxException {
+        final Mailbox mailbox = new org.apache.james.imap.jcr.mail.model.JCRMailbox(namespaceName, randomUidValidity());
+        final MailboxMapper mapper = createMailboxMapper(session);
+        mapper.execute(new TransactionalMapper.Transaction() {
+
+            public void run() throws MailboxException {
+                mapper.save(mailbox);
+            }
+
+        });
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.mailbox.MailboxManager#login(java.lang.String,
+     * java.lang.String, org.apache.commons.logging.Log)
+     */
+    public MailboxSession login(String userid, String passwd, Log log) throws BadCredentialsException, MailboxException {
+        if (login(userid, passwd)) {
+
+            return new PasswordAwareMailboxSession(randomId(), userid, passwd, log, getDelimiter(), new ArrayList<Locale>());
+        } else {
+            throw new BadCredentialsException();
+        }
+    }
+
+    /**
+     * Return the JCR workspace
+     * 
+     * @return workspace
+     */
+    protected String getWorkspace() {
+        return workspace;
+    }
+
+    protected Repository getRepository() {
+        return repository;
+    }
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java Thu Mar 11 17:19:49 2010
@@ -1,72 +1,103 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.imap.jcr;
-
-import javax.jcr.LoginException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.SimpleCredentials;
-
-import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.jcr.user.JCRSubscriptionMapper;
-import org.apache.james.imap.jcr.user.model.JCRSubscription;
-import org.apache.james.imap.mailbox.SubscriptionException;
-import org.apache.james.imap.mailbox.MailboxSession.User;
-import org.apache.james.imap.store.PasswordAwareUser;
-import org.apache.james.imap.store.StoreSubscriptionManager;
-import org.apache.james.imap.store.user.SubscriptionMapper;
-import org.apache.james.imap.store.user.model.Subscription;
-
-/**
- * JCR implementation of a SubscriptionManager
- * 
- *
- */
-public class JCRSubscriptionManager extends StoreSubscriptionManager{
-
-    private final Repository repos;
-
-    public JCRSubscriptionManager(final Repository repos) {
-        super();
-
-        this.repos = repos;
-    }
-    
-    @Override
-    protected SubscriptionMapper createMapper(User user) throws SubscriptionException{
-    	PasswordAwareUser pUser = (PasswordAwareUser) user;
-    	
-		try {
-			JCRSubscriptionMapper mapper = new JCRSubscriptionMapper(repos.login(new SimpleCredentials(pUser.getUserName(), pUser.getPassword().toCharArray())));
-	        return mapper;
-
-		} catch (LoginException e) {
-			throw new SubscriptionException(HumanReadableText.INVALID_LOGIN, e);
-		} catch (RepositoryException e) {
-			throw new SubscriptionException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
-
-		}
-    }
-
-    @Override
-    protected Subscription createSubscription(User user, String mailbox) {
-        return new JCRSubscription(user.getUserName(), mailbox);
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr;
+
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.jcr.user.JCRSubscriptionMapper;
+import org.apache.james.imap.jcr.user.model.JCRSubscription;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.SubscriptionException;
+import org.apache.james.imap.mailbox.MailboxSession.User;
+import org.apache.james.imap.store.PasswordAwareUser;
+import org.apache.james.imap.store.StoreSubscriptionManager;
+import org.apache.james.imap.store.user.SubscriptionMapper;
+import org.apache.james.imap.store.user.model.Subscription;
+
+/**
+ * JCR implementation of a SubscriptionManager
+ * 
+ * 
+ */
+public class JCRSubscriptionManager extends StoreSubscriptionManager {
+    private Log logger = LogFactory.getLog(JCRSubscriptionManager.class);
+
+    private final Repository repository;
+    private String workspace;
+
+    public JCRSubscriptionManager(final Repository repository, final String workspace) {
+        super();
+        this.workspace = workspace;
+        this.repository = repository;
+    }
+
+    @Override
+    protected SubscriptionMapper createMapper(User user) throws SubscriptionException {
+        PasswordAwareUser pUser = (PasswordAwareUser) user;
+
+        JCRSubscriptionMapper mapper = new JCRSubscriptionMapper(getSession(pUser), logger);
+        return mapper;
+    }
+
+    @Override
+    protected Subscription createSubscription(User user, String mailbox) {
+        return new JCRSubscription(user.getUserName(), mailbox, logger);
+    }
+
+    /**
+     * Return a new JCR Session for the given MailboxSession
+     * 
+     * @param s
+     * @return session
+     * @throws MailboxException
+     */
+    protected Session getSession(PasswordAwareUser user) throws SubscriptionException {
+        try {
+            return repository.login(new SimpleCredentials(user.getUserName(), user.getPassword().toCharArray()), getWorkspace());
+        } catch (LoginException e) {
+            throw new SubscriptionException(HumanReadableText.INVALID_LOGIN, e);
+        } catch (NoSuchWorkspaceException e) {
+            throw new SubscriptionException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
+        } catch (RepositoryException e) {
+            throw new SubscriptionException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
+
+        }
+    }
+
+    /**
+     * Return the JCR workspace
+     * 
+     * @return workspace
+     */
+    protected String getWorkspace() {
+        return workspace;
+    }
+
+    protected Repository getRepository() {
+        return repository;
+    }
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java Thu Mar 11 17:19:49 2010
@@ -29,6 +29,7 @@ import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 
+import org.apache.commons.logging.Log;
 import org.apache.jackrabbit.util.Text;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.jcr.JCRImapConstants;
@@ -49,9 +50,11 @@ public class JCRMailboxMapper extends No
     private final static String WILDCARD = "*";
     private final Session session;
     private final String PATH = "mailboxes";
+    private Log logger;
 
-    public JCRMailboxMapper(Session session) {
+    public JCRMailboxMapper(final Session session, final Log logger) {
         this.session = session;
+        this.logger = logger;
     }
 
     /*

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java Thu Mar 11 17:19:49 2010
@@ -1,67 +1,124 @@
-package org.apache.james.imap.jcr.mail;
-
-import java.util.List;
-
-import org.apache.james.imap.mailbox.MessageRange;
-import org.apache.james.imap.mailbox.SearchQuery;
-import org.apache.james.imap.mailbox.StorageException;
-import org.apache.james.imap.store.mail.MessageMapper;
-import org.apache.james.imap.store.mail.model.MailboxMembership;
-import org.apache.james.imap.store.transaction.NonTransactionalMapper;
-
-public class JCRMessageMapper extends NonTransactionalMapper implements MessageMapper{
-
-    @Override
-    public long countMessagesInMailbox() throws StorageException {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    @Override
-    public long countUnseenMessagesInMailbox() throws StorageException {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    @Override
-    public void delete(MailboxMembership message) throws StorageException {
-        // TODO Auto-generated method stub
-        
-    }
-
-    @Override
-    public List<MailboxMembership> findInMailbox(MessageRange set) throws StorageException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public List<MailboxMembership> findMarkedForDeletionInMailbox(MessageRange set) throws StorageException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public List<MailboxMembership> findRecentMessagesInMailbox() throws StorageException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public List<MailboxMembership> findUnseenMessagesInMailboxOrderByUid() throws StorageException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public void save(MailboxMembership message) throws StorageException {
-        // TODO Auto-generated method stub
-        
-    }
-
-    @Override
-    public List<MailboxMembership> searchMailbox(SearchQuery query) throws StorageException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr.mail;
+
+import java.util.List;
+
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.mailbox.MessageRange;
+import org.apache.james.imap.mailbox.SearchQuery;
+import org.apache.james.imap.mailbox.StorageException;
+import org.apache.james.imap.store.mail.MessageMapper;
+import org.apache.james.imap.store.mail.model.MailboxMembership;
+import org.apache.james.imap.store.transaction.NonTransactionalMapper;
+
+public class JCRMessageMapper extends NonTransactionalMapper implements MessageMapper{
+
+
+    private final Session session;
+    private final Log logger;
+
+    public JCRMessageMapper(final Session session, final Log logger) {
+        this.session = session;
+        this.logger = logger;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#countMessagesInMailbox()
+     */
+    public long countMessagesInMailbox() throws StorageException {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#countUnseenMessagesInMailbox()
+     */
+    public long countUnseenMessagesInMailbox() throws StorageException {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#delete(org.apache.james.imap.store.mail.model.MailboxMembership)
+     */
+    public void delete(MailboxMembership message) throws StorageException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#findInMailbox(org.apache.james.imap.mailbox.MessageRange)
+     */
+    public List<MailboxMembership> findInMailbox(MessageRange set) throws StorageException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#findMarkedForDeletionInMailbox(org.apache.james.imap.mailbox.MessageRange)
+     */
+    public List<MailboxMembership> findMarkedForDeletionInMailbox(MessageRange set) throws StorageException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#findRecentMessagesInMailbox()
+     */
+    public List<MailboxMembership> findRecentMessagesInMailbox() throws StorageException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailboxOrderByUid()
+     */
+    public List<MailboxMembership> findUnseenMessagesInMailboxOrderByUid() throws StorageException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#save(org.apache.james.imap.store.mail.model.MailboxMembership)
+     */
+    public void save(MailboxMembership message) throws StorageException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#searchMailbox(org.apache.james.imap.mailbox.SearchQuery)
+     */
+    public List<MailboxMembership> searchMailbox(SearchQuery query) throws StorageException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRHeader.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRHeader.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRHeader.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRHeader.java Thu Mar 11 17:19:49 2010
@@ -1,112 +1,132 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.imap.jcr.mail.model;
-
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
-import javax.jcr.ValueFormatException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
-
-import org.apache.james.imap.jcr.JCRImapConstants;
-import org.apache.james.imap.store.mail.model.AbstractComparableHeader;
-import org.apache.james.imap.store.mail.model.Header;
-
-/**
- * JCR implementation of a Header
- * 
- *
- */
-public class JCRHeader extends AbstractComparableHeader{
-
-    public final static String FIELDNAME_PROPERTY = JCRImapConstants.PROPERTY_PREFIX + "fieldName";
-    public final static String VALUE_PROPERTY = JCRImapConstants.PROPERTY_PREFIX + "value";
-    public final static String LINENUMBER_PROPERTY = JCRImapConstants.PROPERTY_PREFIX + "lineNumber";
-
-    private final String fieldName;
-    private final String value;
-    private final int lineNumber;
-    
-    public JCRHeader(final String fieldName, final String value, final int lineNumber) {
-        this.fieldName = fieldName;
-        this.value = value;
-        this.lineNumber = lineNumber;
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.model.Header#getFieldName()
-     */
-    public String getFieldName() {
-        return fieldName;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.model.Header#getLineNumber()
-     */
-    public int getLineNumber() {
-        return lineNumber;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.model.Header#getValue()
-     */
-    public String getValue() {
-        return value;
-    }
-
-
-    /**
-     * Create a JCRHeader from the given Node
-     * 
-     * @param node
-     * @return jcrHeader
-     * @throws PathNotFoundException
-     * @throws RepositoryException
-     */
-    public static JCRHeader from(Node node) throws PathNotFoundException, RepositoryException {
-        String name = node.getProperty(FIELDNAME_PROPERTY).getString();
-        String value = node.getProperty(VALUE_PROPERTY).getString();
-        int number = new Long(node.getProperty(LINENUMBER_PROPERTY).getLong()).intValue();
-        return new JCRHeader(name, value, number);
-    }
-    
-    /**
-     * Copy all value of the given Header to the node
-     * 
-     * @param node
-     * @param header
-     * @return node
-     * @throws ValueFormatException
-     * @throws VersionException
-     * @throws LockException
-     * @throws ConstraintViolationException
-     * @throws RepositoryException
-     */
-    public static Node copy(Node node, Header header) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
-        node.setProperty(FIELDNAME_PROPERTY, header.getFieldName());
-        node.setProperty(VALUE_PROPERTY, header.getValue());
-        node.setProperty(LINENUMBER_PROPERTY, header.getLineNumber());
-        return node;
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr.mail.model;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.jcr.IsPersistent;
+import org.apache.james.imap.jcr.JCRImapConstants;
+import org.apache.james.imap.store.mail.model.AbstractComparableHeader;
+
+/**
+ * JCR implementation of a Header
+ * 
+ *
+ */
+public class JCRHeader extends AbstractComparableHeader implements JCRImapConstants, IsPersistent{
+
+    public final static String FIELDNAME_PROPERTY = PROPERTY_PREFIX + "fieldName";
+    public final static String VALUE_PROPERTY = PROPERTY_PREFIX + "value";
+    public final static String LINENUMBER_PROPERTY = PROPERTY_PREFIX + "lineNumber";
+
+    private String fieldName;
+    private String value;
+    private int lineNumber;
+    private Log logger;
+    private Node node;
+    
+    public JCRHeader(Node node, Log logger) {
+        this.node = node;
+        this.logger = logger;
+    }
+    
+    
+    
+    public JCRHeader(final String fieldName, final String value, final int lineNumber, Log logger) {
+        this.fieldName = fieldName;
+        this.value = value;
+        this.lineNumber = lineNumber;
+        this.logger = logger;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.model.Header#getFieldName()
+     */
+    public String getFieldName() {
+        if (isPersistent()) {
+            try {
+                return  node.getProperty(FIELDNAME_PROPERTY).getString();
+            } catch (RepositoryException e) {
+                logger.error("Unable to access property " + FIELDNAME_PROPERTY, e);
+            }
+        }
+        return fieldName;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.model.Header#getLineNumber()
+     */
+    public int getLineNumber() {
+        if (isPersistent()) {
+            try {
+                return  new Long(node.getProperty(LINENUMBER_PROPERTY).getLong()).intValue();
+            } catch (RepositoryException e) {
+                logger.error("Unable to access property " + FIELDNAME_PROPERTY, e);
+            }
+        }
+        return lineNumber;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.model.Header#getValue()
+     */
+    public String getValue() {
+        if (isPersistent()) {
+            try {
+                return node.getProperty(VALUE_PROPERTY).getString();
+            } catch (RepositoryException e) {
+                logger.error("Unable to access property " + FIELDNAME_PROPERTY, e);
+            }
+        }
+        return value;
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.jcr.IsPersistent#getNode()
+     */
+    public Node getNode() {
+        return node;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.jcr.IsPersistent#isPersistent()
+     */
+    public boolean isPersistent() {
+        return node != null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.jcr.IsPersistent#merge(javax.jcr.Node)
+     */
+    public void merge(Node node) throws RepositoryException {
+        this.node = node;
+        this.fieldName = null;
+        this.lineNumber = 0;
+        this.value = null;
+    }
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailbox.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailbox.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailbox.java Thu Mar 11 17:19:49 2010
@@ -81,7 +81,11 @@ public class JCRMailbox implements Mailb
         return id;
     }
 
-    @Override
+   
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.model.Mailbox#getName()
+     */
     public String getName() {
         return name;
     }

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRProperty.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRProperty.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRProperty.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRProperty.java Thu Mar 11 17:19:49 2010
@@ -1,125 +1,161 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.imap.jcr.mail.model;
-
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
-import javax.jcr.ValueFormatException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
-
-import org.apache.james.imap.jcr.JCRImapConstants;
-import org.apache.james.imap.store.mail.model.AbstractComparableProperty;
-
-/**
- * JCR implementation of a Property
- *
- */
-public class JCRProperty extends AbstractComparableProperty<JCRProperty>{
-
-    public final static String NAMESPACE_PROPERTY = JCRImapConstants.PROPERTY_PREFIX + "namespace";
-    public final static String LOCALNAME_PROPERTY = JCRImapConstants.PROPERTY_PREFIX + "localName";
-    public final static String VALUE_PROPERTY = JCRImapConstants.PROPERTY_PREFIX + "value";
-    public final static String ORDER_PROPERTY = JCRImapConstants.PROPERTY_PREFIX + "order";
-    
-    private final String namespace;
-    private final String localName;
-    private final String value;
-    private final int order;
-
-    public JCRProperty(final String namespace, final String localName, final String value, final int order) {
-        this.namespace = namespace;
-        this.localName = localName;
-        this.value = value;
-        this.order = order;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.model.AbstractComparableProperty#getOrder()
-     */
-    public int getOrder() {
-        return order;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.model.Property#getLocalName()
-     */
-    public String getLocalName() {
-        return localName;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.model.Property#getNamespace()
-     */
-    public String getNamespace() {
-        return namespace;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.model.Property#getValue()
-     */
-    public String getValue() {
-        return value;
-    }
-    
-    /**
-     * Create a JCRProperty from the given node
-     * 
-     * @param node
-     * @return property
-     * @throws ValueFormatException
-     * @throws PathNotFoundException
-     * @throws RepositoryException
-     */
-    public static JCRProperty from(Node node) throws ValueFormatException, PathNotFoundException, RepositoryException {
-        String namespace = node.getProperty(NAMESPACE_PROPERTY).getString();
-        int order = new Long(node.getProperty(ORDER_PROPERTY).getLong()).intValue();
-        String localname = node.getProperty(LOCALNAME_PROPERTY).getString();
-        String value = node.getProperty(VALUE_PROPERTY).getString();
-
-        return new JCRProperty(namespace, localname, value, order);
-    }
-    
-    /**
-     * Copy all value of the given Property to the node
-     * 
-     * @param node
-     * @param property
-     * @return node
-     * @throws ValueFormatException
-     * @throws VersionException
-     * @throws LockException
-     * @throws ConstraintViolationException
-     * @throws RepositoryException
-     */
-    public static Node copy(Node node, AbstractComparableProperty<?> property) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
-        node.setProperty(NAMESPACE_PROPERTY, property.getNamespace());
-        node.setProperty(ORDER_PROPERTY, property.getOrder());
-        node.setProperty(LOCALNAME_PROPERTY, property.getLocalName());
-        node.setProperty(VALUE_PROPERTY, property.getValue());
-        return node;
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr.mail.model;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.jcr.IsPersistent;
+import org.apache.james.imap.jcr.JCRImapConstants;
+
+import org.apache.james.imap.store.mail.model.AbstractComparableProperty;
+
+public class JCRProperty extends AbstractComparableProperty<JCRProperty> implements JCRImapConstants, IsPersistent {
+
+    private Node node;
+    private final Log logger;
+    private String namespace;
+    private String localName;
+    private String value;
+    private int order;
+
+    public final static String NAMESPACE_PROPERTY = PROPERTY_PREFIX + "namespace";
+    public final static String LOCALNAME_PROPERTY = PROPERTY_PREFIX + "localName";
+    public final static String VALUE_PROPERTY = PROPERTY_PREFIX + "value";
+    public final static String ORDER_PROPERTY = PROPERTY_PREFIX + "order";
+
+    public JCRProperty(final Node node, final Log logger) {
+        this.node = node;
+        this.logger = logger;
+    }
+
+    public JCRProperty(final String namespace, final String localName, final String value, final int order, Log logger) {
+        this.namespace = namespace;
+        this.localName = localName;
+        this.value = value;
+        this.order = order;
+        this.logger = logger;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.james.imap.store.mail.model.AbstractComparableProperty#getOrder
+     * ()
+     */
+    public int getOrder() {
+        if (isPersistent()) {
+            try {
+                return new Long(node.getProperty(ORDER_PROPERTY).getLong()).intValue();
+            } catch (RepositoryException e) {
+                logger.error("Unable to access Property " + ORDER_PROPERTY, e);
+            }
+            return 0;
+        }
+        return order;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.jcr.IsPersistent#getNode()
+     */
+    public Node getNode() {
+        return node;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.store.mail.model.Property#getLocalName()
+     */
+    public String getLocalName() {
+        if (isPersistent()) {
+            try {
+                return node.getProperty(LOCALNAME_PROPERTY).getString();
+            } catch (RepositoryException e) {
+                logger.error("Unable to access Property " + LOCALNAME_PROPERTY, e);
+            }
+            return null;
+        }
+        return localName;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.store.mail.model.Property#getNamespace()
+     */
+    public String getNamespace() {
+        if (isPersistent()) {
+            try {
+                return node.getProperty(NAMESPACE_PROPERTY).getString();
+            } catch (RepositoryException e) {
+                logger.error("Unable to access Property " + NAMESPACE_PROPERTY, e);
+            }
+            return null;
+        }
+        return namespace;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.store.mail.model.Property#getValue()
+     */
+    public String getValue() {
+        if (isPersistent()) {
+            try {
+                return node.getProperty(VALUE_PROPERTY).getString();
+            } catch (RepositoryException e) {
+                logger.error("Unable to access Property " + VALUE_PROPERTY, e);
+            }
+            return null;
+        }
+        return value;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.jcr.IsPersistent#isPersistent()
+     */
+    public boolean isPersistent() {
+        return node != null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.jcr.IsPersistent#merge(javax.jcr.Node)
+     */
+    public void merge(Node node) throws RepositoryException {
+        node.setProperty(NAMESPACE_PROPERTY, namespace);
+        node.setProperty(ORDER_PROPERTY, order);
+        node.setProperty(LOCALNAME_PROPERTY, localName);
+        node.setProperty(VALUE_PROPERTY, value);
+
+        namespace = null;
+        order = 0;
+        localName = null;
+        value = null;
+    }
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java Thu Mar 11 17:19:49 2010
@@ -27,8 +27,10 @@ import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.commons.logging.Log;
 import org.apache.jackrabbit.util.Text;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.jcr.IsPersistent;
 import org.apache.james.imap.jcr.JCRImapConstants;
 import org.apache.james.imap.jcr.user.model.JCRSubscription;
 import org.apache.james.imap.mailbox.SubscriptionException;
@@ -37,101 +39,119 @@ import org.apache.james.imap.store.user.
 import org.apache.james.imap.store.user.model.Subscription;
 
 /**
- * JCR implementation of a SubscriptionManager. Just be aware, this SubscriptionManager doesn't
- * support transactions. So very call on a method ends in a "real" action
-  *
+ * JCR implementation of a SubscriptionManager. Just be aware, this
+ * SubscriptionManager doesn't support transactions. So very call on a method
+ * ends in a "real" action
+ * 
  */
-public class JCRSubscriptionMapper extends NonTransactionalMapper implements SubscriptionMapper{
+public class JCRSubscriptionMapper extends NonTransactionalMapper implements SubscriptionMapper {
 
-	private final Session session;
-	private final static String PATH = "subscriptions";
-	
-	public JCRSubscriptionMapper(Session session) {
-		this.session = session;
-	}
-	
-
-	/*
-	 * (non-Javadoc)
-	 * @see org.apache.james.imap.store.user.SubscriptionMapper#delete(org.apache.james.imap.store.user.model.Subscription)
-	 */
-	public void delete(Subscription subscription) throws SubscriptionException {
-		try {
-			Node node = session.getRootNode().getNode(PATH + JCRImapConstants.NODE_DELIMITER + getPath(subscription.getUser(), subscription.getMailbox()));
-			node.remove();
-			session.save();
-		} catch (PathNotFoundException e) {
-			// do nothing
-		} catch (RepositoryException e) {
-			throw new SubscriptionException(HumanReadableText.DELETED_FAILED,e);
-		}
-
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * @see org.apache.james.imap.store.user.SubscriptionMapper#findFindMailboxSubscriptionForUser(java.lang.String, java.lang.String)
-	 */
-	public Subscription findFindMailboxSubscriptionForUser(String user,
-			String mailbox) throws SubscriptionException {
-		try {
-			Node node = session.getRootNode().getNode(PATH + JCRImapConstants.NODE_DELIMITER + getPath(user, mailbox));
-			return JCRSubscription.from(node);
-		} catch (PathNotFoundException e) {
-			return null;
-		} catch (RepositoryException e) {
+    private final Session session;
+    private final Log log;
+    private final static String PATH = "subscriptions";
+
+    public JCRSubscriptionMapper(final Session session, final Log log) {
+        this.session = session;
+        this.log = log;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.james.imap.store.user.SubscriptionMapper#delete(org.apache
+     * .james.imap.store.user.model.Subscription)
+     */
+    public void delete(Subscription subscription) throws SubscriptionException {
+        // Check if the subscription was persistent in JCR if not don't do
+        // anything
+        if (subscription instanceof IsPersistent) {
+            try {
+
+                Node node = ((IsPersistent) subscription).getNode();
+                node.remove();
+                session.save();
+            } catch (PathNotFoundException e) {
+                // do nothing
+            } catch (RepositoryException e) {
+                throw new SubscriptionException(HumanReadableText.DELETED_FAILED, e);
+            }
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @seeorg.apache.james.imap.store.user.SubscriptionMapper#
+     * findFindMailboxSubscriptionForUser(java.lang.String, java.lang.String)
+     */
+    public Subscription findFindMailboxSubscriptionForUser(String user, String mailbox) throws SubscriptionException {
+        try {
+            Node node = session.getRootNode().getNode(PATH + JCRImapConstants.NODE_DELIMITER + getPath(user, mailbox));
+            return new JCRSubscription(node, log);
+        } catch (PathNotFoundException e) {
+            return null;
+        } catch (RepositoryException e) {
             throw new SubscriptionException(HumanReadableText.SEARCH_FAILED, e);
-		}
-	}
+        }
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.apache.james.imap.store.user.SubscriptionMapper#findSubscriptionsForUser(java.lang.String)
-	 */
-	public List<Subscription> findSubscriptionsForUser(String user)
-			throws SubscriptionException {
-		List<Subscription> subList = new ArrayList<Subscription>();
-		try {
-			Node node = session.getRootNode().getNode(PATH + JCRImapConstants.NODE_DELIMITER + Text.escapeIllegalJcrChars(user));
-			NodeIterator nodeIt = node.getNodes("*");
-			while(nodeIt.hasNext()) {
-				subList.add(JCRSubscription.from(nodeIt.nextNode()));
-			}
-		} catch (PathNotFoundException e) {
-			// Do nothing just return the empty list later
-		} catch (RepositoryException e) {
-			throw new SubscriptionException(HumanReadableText.SEARCH_FAILED,e);
-		}
-		return subList;
-
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * @see org.apache.james.imap.store.user.SubscriptionMapper#save(org.apache.james.imap.store.user.model.Subscription)
-	 */
-	public void save(Subscription subscription) throws SubscriptionException {
-		String username = subscription.getUser();
-		String mailbox = subscription.getMailbox();
-		String nodename = getPath(username,mailbox);
-		try {
-			Node node = session.getRootNode().getNode(PATH);
-			Node subNode;
-			if (node.hasNode(nodename )) {
-				subNode = node.getNode(nodename);
-			} else {
-				subNode = node.addNode(nodename);
-			}
-			JCRSubscription.copy(subscription, subNode);
-			session.save();
-		} catch (RepositoryException e) {
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.james.imap.store.user.SubscriptionMapper#findSubscriptionsForUser
+     * (java.lang.String)
+     */
+    public List<Subscription> findSubscriptionsForUser(String user) throws SubscriptionException {
+        List<Subscription> subList = new ArrayList<Subscription>();
+        try {
+            Node node = session.getRootNode().getNode(PATH + JCRImapConstants.NODE_DELIMITER + Text.escapeIllegalJcrChars(user));
+            NodeIterator nodeIt = node.getNodes("*");
+            while (nodeIt.hasNext()) {
+                subList.add(new JCRSubscription(nodeIt.nextNode(), log));
+            }
+        } catch (PathNotFoundException e) {
+            // Do nothing just return the empty list later
+        } catch (RepositoryException e) {
+            throw new SubscriptionException(HumanReadableText.SEARCH_FAILED, e);
+        }
+        return subList;
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.james.imap.store.user.SubscriptionMapper#save(org.apache.james
+     * .imap.store.user.model.Subscription)
+     */
+    public void save(Subscription subscription) throws SubscriptionException {
+        String username = subscription.getUser();
+        String mailbox = subscription.getMailbox();
+        String nodename = getPath(username, mailbox);
+        try {
+            Node node = session.getRootNode().getNode(PATH);
+            Node subNode;
+            if (node.hasNode(nodename)) {
+                subNode = node.getNode(nodename);
+            } else {
+                subNode = node.addNode(nodename);
+            }
+
+            // Copy new properties to the node
+            ((JCRSubscription)subscription).merge(subNode);
+
+            session.save();
+        } catch (RepositoryException e) {
             throw new SubscriptionException(HumanReadableText.SAVE_FAILED, e);
-		}		
-	}
-	
-	private String getPath(String username, String mailbox) {
-		return Text.escapeIllegalJcrChars(username) + JCRImapConstants.NODE_DELIMITER + Text.escapeIllegalJcrChars(mailbox);
-	}
+        }
+    }
 
+    private String getPath(String username, String mailbox) {
+        return Text.escapeIllegalJcrChars(username) + JCRImapConstants.NODE_DELIMITER + Text.escapeIllegalJcrChars(mailbox);
+    }
 
 }

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java?rev=921950&r1=921949&r2=921950&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java Thu Mar 11 17:19:49 2010
@@ -20,84 +20,101 @@
 package org.apache.james.imap.jcr.user.model;
 
 import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
-import javax.jcr.ValueFormatException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
 
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.jcr.IsPersistent;
 import org.apache.james.imap.jcr.JCRImapConstants;
 import org.apache.james.imap.store.user.model.Subscription;
 
-
 /**
  * JCR implementation of a Subscription
- *
+ * 
  */
-public class JCRSubscription implements Subscription{
-
-	private final String mailbox;
-
-	private final String username;
-
-	public final static String USERNAME_PROPERTY = JCRImapConstants.PROPERTY_PREFIX + "username";
-	public final static String MAILBOX_PROPERTY = JCRImapConstants.PROPERTY_PREFIX  + "mailbox";
+public class JCRSubscription implements Subscription, IsPersistent, JCRImapConstants {
+    public final static String USERNAME_PROPERTY = PROPERTY_PREFIX + "username";
+    public final static String MAILBOX_PROPERTY = PROPERTY_PREFIX  + "mailbox";
+    
+    private Node node;
+    private final Log log;
+    private String mailbox;
+    private String username;
+
+    
+    public JCRSubscription(Node node, Log log) {
+        this.node = node;
+        this.log = log;
+    }
+
+    public JCRSubscription(String username, String mailbox, Log log) {
+        this.username = username;
+        this.mailbox = mailbox;
+        this.log = log;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.store.user.model.Subscription#getMailbox()
+     */
+    public String getMailbox() {
+        if (isPersistent()) {
+            try {
+                return node.getProperty(MAILBOX_PROPERTY).getString();
+            } catch (RepositoryException e) {
+                log.error("Unable to access Property " + MAILBOX_PROPERTY, e);
+            }
+            return null;
+        }
+        return mailbox;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.store.user.model.Subscription#getUser()
+     */
+    public String getUser() {
+        if (isPersistent()) {
+            try {
+                return node.getProperty(USERNAME_PROPERTY).getString();
+            } catch (RepositoryException e) {
+                log.error("Unable to access Property " + USERNAME_PROPERTY, e);
+            }
+            return null;
+        }
+        return username;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.imap.jcr.NodeAware#getNode()
+     */
+    public Node getNode() {
+        return node;
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.jcr.IsPersistent#isPersistent()
+     */
+    public boolean isPersistent() {
+        return node != null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.jcr.IsPersistent#merge(javax.jcr.Node)
+     */
+    public void merge(Node node) throws RepositoryException{
+        this.node = node;
+        node.setProperty(USERNAME_PROPERTY, username);
+        node.setProperty(MAILBOX_PROPERTY, mailbox);
+
+        mailbox = null;
+        username = null;
+    }
 
-	public JCRSubscription(String username, String mailbox) {
-		this.username = username;
-		this.mailbox = mailbox;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * @see org.apache.james.imap.store.user.model.Subscription#getMailbox()
-	 */
-	public String getMailbox() {
-		return mailbox;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * @see org.apache.james.imap.store.user.model.Subscription#getUser()
-	 */
-	public String getUser() {
-		return username;
-	}
-	
-	/**
-	 * Return the JCRSubscription for the given node
-	 * 
-	 * @param node 
-	 * @return subscription
-	 * @throws ValueFormatException
-	 * @throws PathNotFoundException
-	 * @throws RepositoryException
-	 */
-	public static JCRSubscription from(Node node) throws ValueFormatException, PathNotFoundException, RepositoryException {
-		String username = node.getProperty(USERNAME_PROPERTY).getString();;
-		String mailbox = node.getProperty(MAILBOX_PROPERTY).getString();
-		
-		return new JCRSubscription(username, mailbox);
-	}
-	
-	
-	/**
-	 * Copy all needed properties to the given node for the given subscription
-	 * 
-	 * @param subscription
-	 * @param node
-	 * @return node
-	 * @throws ValueFormatException
-	 * @throws VersionException
-	 * @throws LockException
-	 * @throws ConstraintViolationException
-	 * @throws RepositoryException
-	 */
-	public static Node copy(Subscription subscription, Node node) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
-		node.setProperty(USERNAME_PROPERTY, subscription.getUser());
-		node.setProperty(MAILBOX_PROPERTY, subscription.getMailbox());
-		return node;
-		
-	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org