source: contrib/MailArchiver/sources/vendor/mime4j/apache-mime4j-0.7-SNAPSHOT-20110327.010440-17/dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java @ 6785

Revision 6785, 3.7 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
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 ****************************************************************/
19package org.apache.james.mime4j.message;
20
21import org.apache.james.mime4j.dom.MessageBuilder;
22import org.apache.james.mime4j.dom.MessageServiceFactory;
23import org.apache.james.mime4j.dom.MessageFormatter;
24import org.apache.james.mime4j.stream.MimeEntityConfig;
25import 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 */
33public 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}
Note: See TracBrowser for help on using the repository browser.