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 rd...@apache.org on 2008/12/17 23:46:50 UTC

svn commit: r727563 - /james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/VirtualUserTable.java

Author: rdonkin
Date: Wed Dec 17 14:46:49 2008
New Revision: 727563

URL: http://svn.apache.org/viewvc?rev=727563&view=rev
Log:
Switch to JSR250 since this seems to work better than Phoenix.

Modified:
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/VirtualUserTable.java

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/VirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/VirtualUserTable.java?rev=727563&r1=727562&r2=727563&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/VirtualUserTable.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/VirtualUserTable.java Wed Dec 17 14:46:49 2008
@@ -22,15 +22,14 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import javax.annotation.Resource;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.james.Constants;
 import org.apache.james.api.vut.ErrorMappingException;
 import org.apache.james.api.vut.VirtualUserTableStore;
 import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetException;
 
 /**
  * Mailet which should get used when using VirtualUserTable-Store to implementations
@@ -45,33 +44,69 @@
 public class VirtualUserTable extends AbstractVirtualUserTableMailet {
     private org.apache.james.api.vut.VirtualUserTable vut;
 
-    /*
-     * (non-Javadoc)
+    private VirtualUserTableStore vutStore;
+    
+       
+    /**
+     * Gets the virtual user table.
+     * @return the vut
+     */
+    public final org.apache.james.api.vut.VirtualUserTable getVut() {
+        return vut;
+    }
+
+    /**
+     * Sets the virtual user table.
+     * @param vut the vut to set
+     */
+    @Resource(name=org.apache.james.api.vut.VirtualUserTable.ROLE)
+    public final void setVut(org.apache.james.api.vut.VirtualUserTable vut) {
+        this.vut = vut;
+    }
+
+    /**
+     * Gets the virtual user table store.
+     * @return the vutStore, possibly null
+     */
+    public final VirtualUserTableStore getVutStore() {
+        return vutStore;
+    }
+
+    /**
+     * Sets the virtual table store.
+     * @param vutStore the vutStore to set, possibly null
+     */
+    @Resource(name=VirtualUserTableStore.ROLE)
+    public final void setVutStore(VirtualUserTableStore vutStore) {
+        this.vutStore = vutStore;
+    }
+
+    /**
      * @see org.apache.mailet.base.GenericMailet#init()
      */
     public void init() throws MessagingException {
         super.init();
-        ServiceManager compMgr = (ServiceManager) getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
-
-        try {
-            String vutName = getInitParameter("virtualusertable");
-            if (vutName == null || vutName.length() == 0) {
-                try {
-                    vut = (org.apache.james.api.vut.VirtualUserTable) compMgr.lookup(org.apache.james.api.vut.VirtualUserTable.ROLE); 
-                } catch (ServiceException e) {
-                    log("Failed to retrieve VirtualUserTable component:" + e.getMessage());
-                }
-            } else {
-                vut = ((VirtualUserTableStore) compMgr.lookup(VirtualUserTableStore.ROLE)).getTable(vutName);
+        
+        if (vut == null && vutStore == null) {
+            throw new MailetException("Not initialised. Please ensure that the mailet container supports either" +
+            " setter or constructor injection. ");
+        }
+        
+        String vutName = getInitParameter("virtualusertable");
+        if (vutName == null || vutName.length() == 0) {
+            if (vut == null) {
+                throw new MailetException("When 'virtualusertable' is unset, a virtual user table must be " +
+                "provided by the container.");
             }
-
-        } catch (ServiceException cnfe) {
-            log("Failed to retrieve VirtualUserTableStore component:" + cnfe.getMessage());
+        } else if (vutStore == null) {
+            throw new MailetException("When 'virtualusertable' is set, a virtual user table store must be " +
+                    "provided by the container.");
+        } else {
+            vut = vutStore.getTable(vutName);
         }
     }
 
-    /*
-     * (non-Javadoc)
+    /**
      * @see org.apache.james.transport.mailets.AbstractVirtualUserTable#processMail(org.apache.mailet.MailAddress, org.apache.mailet.MailAddress, javax.mail.internet.MimeMessage)
      */
     public Collection processMail(MailAddress sender, MailAddress recipient, MimeMessage message) throws MessagingException {
@@ -95,8 +130,7 @@
         return rcpts;
     }
 
-    /*
-     * (non-Javadoc)
+    /**
      * @see org.apache.mailet.base.GenericMailet#getMailetInfo()
      */
     public String getMailetInfo() {



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