1 | /**************************************************************** |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one * |
---|
3 | * or more contributor license agreements. See the NOTICE file * |
---|
4 | * distributed with this work for additional information * |
---|
5 | * regarding copyright ownership. The ASF licenses this file * |
---|
6 | * to you under the Apache License, Version 2.0 (the * |
---|
7 | * "License"); you may not use this file except in compliance * |
---|
8 | * with the License. You may obtain a copy of the License at * |
---|
9 | * * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 * |
---|
11 | * * |
---|
12 | * Unless required by applicable law or agreed to in writing, * |
---|
13 | * software distributed under the License is distributed on an * |
---|
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * |
---|
15 | * KIND, either express or implied. See the License for the * |
---|
16 | * specific language governing permissions and limitations * |
---|
17 | * under the License. * |
---|
18 | ****************************************************************/ |
---|
19 | package org.apache.james.mime4j.message; |
---|
20 | |
---|
21 | import org.apache.james.mime4j.dom.MessageBuilder; |
---|
22 | import org.apache.james.mime4j.dom.MessageServiceFactory; |
---|
23 | import org.apache.james.mime4j.dom.MessageFormatter; |
---|
24 | import org.apache.james.mime4j.stream.MimeEntityConfig; |
---|
25 | import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory; |
---|
26 | |
---|
27 | /** |
---|
28 | * The default MessageBuilderFactory bundled with Mime4j. |
---|
29 | * |
---|
30 | * Supports the "StorageProvider", "MimeEntityConfig" and "MutableBodyDescriptorFactory" |
---|
31 | * attributes. |
---|
32 | */ |
---|
33 | public class MessageServiceFactoryImpl extends MessageServiceFactory { |
---|
34 | |
---|
35 | private BodyFactory bodyFactory = null; |
---|
36 | private MimeEntityConfig mimeEntityConfig = null; |
---|
37 | private MutableBodyDescriptorFactory mutableBodyDescriptorFactory = null; |
---|
38 | |
---|
39 | @Override |
---|
40 | public MessageBuilder newMessageBuilder() { |
---|
41 | MessageBuilderImpl m = new MessageBuilderImpl(); |
---|
42 | if (bodyFactory != null) m.setBodyFactory(bodyFactory); |
---|
43 | if (mimeEntityConfig != null) m.setMimeEntityConfig(mimeEntityConfig); |
---|
44 | if (mutableBodyDescriptorFactory != null) m.setMutableBodyDescriptorFactory(mutableBodyDescriptorFactory); |
---|
45 | return m; |
---|
46 | } |
---|
47 | |
---|
48 | @Override |
---|
49 | public MessageFormatter newMessageFormatter() { |
---|
50 | MessageFormatterImpl m = new MessageFormatterImpl(); |
---|
51 | return m; |
---|
52 | } |
---|
53 | |
---|
54 | @Override |
---|
55 | public void setAttribute(String name, Object value) |
---|
56 | throws IllegalArgumentException { |
---|
57 | if ("BodyFactory".equals(name)) { |
---|
58 | if (value instanceof BodyFactory) { |
---|
59 | this.bodyFactory = (BodyFactory) value; |
---|
60 | return; |
---|
61 | } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a BodyFactory"); |
---|
62 | } else if ("MimeEntityConfig".equals(name)) { |
---|
63 | if (value instanceof MimeEntityConfig) { |
---|
64 | this.mimeEntityConfig = (MimeEntityConfig) value; |
---|
65 | return; |
---|
66 | } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a MimeEntityConfig"); |
---|
67 | } else if ("MutableBodyDescriptorFactory".equals(name)) { |
---|
68 | if (value instanceof MutableBodyDescriptorFactory) { |
---|
69 | this.mutableBodyDescriptorFactory = (MutableBodyDescriptorFactory) value; |
---|
70 | return; |
---|
71 | } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a MutableBodyDescriptorFactory"); |
---|
72 | } |
---|
73 | |
---|
74 | throw new IllegalArgumentException("Unsupported attribute: "+name); |
---|
75 | |
---|
76 | } |
---|
77 | |
---|
78 | } |
---|