Author: keith
Date: Sun Jul 13 06:41:46 2008
New Revision: 19188
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19188

Log:
Throwing Mashup faults instead of MessagingException


Modified:
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/email/Email.java

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/email/Email.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/email/Email.java?rev=19188&r1=19187&r2=19188&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/email/Email.java
      (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/email/Email.java
      Sun Jul 13 06:41:46 2008
@@ -135,7 +135,7 @@
      * </p>
      */
     public static Scriptable jsConstructor(Context cx, Object[] args, Function 
ctorObj,
-                                           boolean inNewExpr) throws 
IOException {
+                                           boolean inNewExpr) throws 
MashupFault {
 
         Email email = new Email();
         Properties props = new Properties();
@@ -201,8 +201,12 @@
      * email.from = "[EMAIL PROTECTED]";
      * </pre>
      */
-    public void jsSet_from(String from) throws MessagingException {
-        message.setFrom(new InternetAddress(from));
+    public void jsSet_from(String from) throws MashupFault {
+        try {
+            message.setFrom(new InternetAddress(from));
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
     }
 
     public String jsGet_from() throws MessagingException {
@@ -214,8 +218,13 @@
         return from;
     }
 
-    public String[] jsGet_to() throws MessagingException {
-        Address[] addresses = message.getRecipients(Message.RecipientType.TO);
+    public String[] jsGet_to() throws MashupFault {
+        Address[] addresses;
+        try {
+            addresses = message.getRecipients(Message.RecipientType.TO);
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
         String[] to = new String[addresses.length];
         for (int i = 0; i < to.length; i++) {
             to[i] = addresses[i].toString();
@@ -236,12 +245,17 @@
      * email.to = to;
      * </pre>
      */
-    public void jsSet_to(Object toObject) throws MessagingException, 
MashupFault {
+    public void jsSet_to(Object toObject) throws MashupFault {
         addRecipients(Message.RecipientType.TO, toObject);
     }
 
-    public String[] jsGet_cc() throws MessagingException {
-        Address[] addresses = message.getRecipients(Message.RecipientType.CC);
+    public String[] jsGet_cc() throws MashupFault {
+        Address[] addresses;
+        try {
+            addresses = message.getRecipients(Message.RecipientType.CC);
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
         String[] cc = new String[addresses.length];
         for (int i = 0; i < cc.length; i++) {
             cc[i] = addresses[i].toString();
@@ -262,12 +276,17 @@
      * email.cc = cc;
      * </pre>
      */
-    public void jsSet_cc(Object ccObject) throws MessagingException, 
MashupFault {
+    public void jsSet_cc(Object ccObject) throws MashupFault {
         addRecipients(Message.RecipientType.CC, ccObject);
     }
 
-    public String[] jsGet_bcc() throws MessagingException {
-        Address[] addresses = message.getRecipients(Message.RecipientType.BCC);
+    public String[] jsGet_bcc() throws MashupFault {
+        Address[] addresses;
+        try {
+            addresses = message.getRecipients(Message.RecipientType.BCC);
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
         String[] bcc = new String[addresses.length];
         for (int i = 0; i < bcc.length; i++) {
             bcc[i] = addresses[i].toString();
@@ -288,8 +307,9 @@
      * email.bcc = bcc;
      * </pre>
      */
-    public void jsSet_bcc(Object bccObject) throws MessagingException, 
MashupFault {
+    public void jsSet_bcc(Object bccObject) throws MashupFault {
         addRecipients(Message.RecipientType.BCC, bccObject);
+
     }
 
     /**
@@ -298,12 +318,20 @@
      * email.subject = "WSO2 Mashup server 1.0 Released";
      * </pre>
      */
-    public void jsSet_subject(String subject) throws MessagingException {
-        message.setSubject(subject);
+    public void jsSet_subject(String subject) throws MashupFault {
+        try {
+            message.setSubject(subject);
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
     }
 
-    public String jsGet_subject() throws MessagingException {
-        return message.getSubject();
+    public String jsGet_subject() throws MashupFault {
+        try {
+            return message.getSubject();
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
     }
 
     /**
@@ -312,14 +340,18 @@
      * email.text = "WSO2 Mashup server 1.0 was Released on 28th January 2008";
      * </pre>
      */
-    public void jsSet_text(String text) throws MessagingException {
+    public void jsSet_text(String text) throws MashupFault {
         this.text = text;
         BodyPart messageBodyPart = new MimeBodyPart();
-        messageBodyPart.setText(text);
-        multipart.addBodyPart(messageBodyPart);
+        try {
+            messageBodyPart.setText(text);
+            multipart.addBodyPart(messageBodyPart);
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
     }
 
-    public String jsGet_text() throws MessagingException {
+    public String jsGet_text() {
         return text;
     }
 
@@ -331,7 +363,7 @@
      * email.html = <h1>WSO2 Mashup server 1.0 was Released on 28th January 
2008</h1>;     // Setting the HTML content as an XML object
      * </pre>
      */
-    public void jsSet_html(Object html) throws MessagingException, IOException 
{
+    public void jsSet_html(Object html) throws MashupFault {
         if (html instanceof String) {
             this.html = (String) html;
         } else if (html instanceof XML) {
@@ -348,13 +380,21 @@
                             "either a String or an XML element.");
         }
         BodyPart messageBodyPart = new MimeBodyPart();
-        DataHandler dataHandler = new DataHandler(
-                new ByteArrayDataSource(this.html, "text/html"));
-        messageBodyPart.setDataHandler(dataHandler);
-        multipart.addBodyPart(messageBodyPart);
+        DataHandler dataHandler = null;
+        try {
+            dataHandler = new DataHandler(
+                    new ByteArrayDataSource(this.html, "text/html"));
+            messageBodyPart.setDataHandler(dataHandler);
+            multipart.addBodyPart(messageBodyPart);
+        } catch (IOException e) {
+            throw new MashupFault(e);
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
+
     }
 
-    public String jsGet_html() throws MessagingException {
+    public String jsGet_html() {
         return html;
     }
 
@@ -364,15 +404,18 @@
      * email.send()
      * </pre>
      */
-    public void jsFunction_send() throws MessagingException {
-        message.setContent(multipart);
-        Transport.send(message);
+    public void jsFunction_send() throws MashupFault {
+        try {
+            Transport.send(message);
+            message.setContent(multipart);
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
+        }
     }
 
     public static void jsFunction_addAttachement(Context cx, Scriptable 
thisObj, Object[] arguments,
-                                                Function funObj)
-            throws MashupFault, MessagingException {
-        Email.jsFunction_addAttachment(cx, thisObj, arguments,funObj);
+                                                Function funObj) throws 
MashupFault {
+            Email.jsFunction_addAttachment(cx, thisObj, arguments,funObj);
     }
 
     /**
@@ -384,8 +427,7 @@
      * </pre>
      */
     public static void jsFunction_addAttachment(Context cx, Scriptable 
thisObj, Object[] arguments,
-                                                Function funObj)
-            throws MashupFault, MessagingException {
+                                                Function funObj) throws 
MashupFault {
         Email email = (Email) thisObj;
         for (int i = 0; i < arguments.length; i++) {
             JavaScriptFileObject fileObject;
@@ -401,9 +443,13 @@
             BodyPart messageBodyPart = new MimeBodyPart();
             File file = fileObject.getFile();
             DataSource source = new FileDataSource(file);
-            messageBodyPart.setDataHandler(new DataHandler(source));
-            messageBodyPart.setFileName(file.getName());
-            email.multipart.addBodyPart(messageBodyPart);
+            try {
+                messageBodyPart.setDataHandler(new DataHandler(source));
+                messageBodyPart.setFileName(file.getName());
+                email.multipart.addBodyPart(messageBodyPart);
+            } catch (MessagingException e) {
+                throw new MashupFault(e);
+            }
         }
     }
 
@@ -421,7 +467,9 @@
         }
     }
 
-    private void addRecipients(Message.RecipientType recipientType, Object 
recipientObject) throws MessagingException, MashupFault {
+    private void addRecipients(Message.RecipientType recipientType, Object 
recipientObject)
+            throws MashupFault {
+        try {
             if (recipientObject instanceof String[]) {
                 String[] to = (String[]) recipientObject;
                 InternetAddress[] recipientAddresses = new 
InternetAddress[to.length];
@@ -432,21 +480,21 @@
             } else if (recipientObject instanceof NativeArray) {
                 NativeArray nativeArray = (NativeArray) recipientObject;
                 Object[] objects = nativeArray.getAllIds();
-                    for (int i = 0; i < objects.length; i++) {
-                        Object object = objects[i];
-                        Object o;
-                        if (object instanceof String) {
-                            String property = (String) object;
-                            if ("length".equals(property)) {
-                                continue;
-                            }
-                            o = nativeArray.get(property, nativeArray);
-                        } else {
-                            Integer property = (Integer) object;
-                            o = nativeArray.get(property.intValue(), 
nativeArray);
+                for (int i = 0; i < objects.length; i++) {
+                    Object object = objects[i];
+                    Object o;
+                    if (object instanceof String) {
+                        String property = (String) object;
+                        if ("length".equals(property)) {
+                            continue;
                         }
-                        message.addRecipient(recipientType, new 
InternetAddress((String) o));
+                        o = nativeArray.get(property, nativeArray);
+                    } else {
+                        Integer property = (Integer) object;
+                        o = nativeArray.get(property.intValue(), nativeArray);
                     }
+                    message.addRecipient(recipientType, new 
InternetAddress((String) o));
+                }
             } else if (recipientObject instanceof String) {
                 message.addRecipient(recipientType, new 
InternetAddress((String) recipientObject));
             } else {
@@ -454,5 +502,8 @@
                         "The argument to this function should be an array of 
email addresses or a " +
                                 "single email address");
             }
+        } catch (MessagingException e) {
+            throw new MashupFault(e);
         }
+    }
 }

_______________________________________________
Mashup-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to