1 21 22 27 28 package javax.mail; 29 30 import java.util.Vector ; 31 import java.io.InputStream ; 32 import java.io.OutputStream ; 33 import java.io.IOException ; 34 import javax.activation.DataSource ; 35 36 54 55 public abstract class Multipart { 56 57 60 protected Vector parts = new Vector (); 62 66 protected String contentType = "multipart/mixed" ; 68 73 protected Part parent; 74 75 78 protected Multipart() { } 79 80 95 protected void setMultipartDataSource(MultipartDataSource mp) 96 throws MessagingException { 97 contentType = mp.getContentType(); 98 99 int count = mp.getCount(); 100 for (int i = 0; i < count; i++) 101 addBodyPart(mp.getBodyPart(i)); 102 } 103 104 113 public String getContentType() { 114 return contentType; 115 } 116 117 123 public int getCount() throws MessagingException { 124 if (parts == null) 125 return 0; 126 127 return parts.size(); 128 } 129 130 139 public BodyPart getBodyPart(int index) throws MessagingException { 140 if (parts == null) 141 throw new IndexOutOfBoundsException ("No such BodyPart"); 142 143 return (BodyPart )parts.elementAt(index); 144 } 145 146 157 public boolean removeBodyPart(BodyPart part) throws MessagingException { 158 if (parts == null) 159 throw new MessagingException ("No such body part"); 160 161 boolean ret = parts.removeElement(part); 162 part.setParent(null); 163 return ret; 164 } 165 166 178 public void removeBodyPart(int index) throws MessagingException { 179 if (parts == null) 180 throw new IndexOutOfBoundsException ("No such BodyPart"); 181 182 BodyPart part = (BodyPart )parts.elementAt(index); 183 parts.removeElementAt(index); 184 part.setParent(null); 185 } 186 187 197 public synchronized void addBodyPart(BodyPart part) 198 throws MessagingException { 199 if (parts == null) 200 parts = new Vector (); 201 202 parts.addElement(part); 203 part.setParent(this); 204 } 205 206 220 public synchronized void addBodyPart(BodyPart part, int index) 221 throws MessagingException { 222 if (parts == null) 223 parts = new Vector (); 224 225 parts.insertElementAt(part, index); 226 part.setParent(this); 227 } 228 229 238 public abstract void writeTo(OutputStream os) 239 throws IOException , MessagingException ; 240 241 246 public Part getParent() { 247 return parent; 248 } 249 250 259 public void setParent(Part parent) { 260 this.parent = parent; 261 } 262 } 263 | Popular Tags |