1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can
10 * obtain a copy of the License at
11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
12 * or LICENSE.txt. See the License for the specific
13 * language governing permissions and limitations under the License.
14 *
15 * When distributing the software, include this License Header Notice in each
16 * file and include the License file at LICENSE.txt.
17 *
18 * GPL Classpath Exception:
19 * Oracle designates this particular file as subject to the "Classpath"
20 * exception as provided by Oracle in the GPL Version 2 section of the License
21 * file that accompanied this code.
22 *
23 * Modifications:
24 * If applicable, add the following below the License Header, with the fields
25 * enclosed by brackets [] replaced by your own identifying information:
26 * "Portions Copyright [year] [name of copyright owner]"
27 *
28 * Contributor(s):
29 * If you wish your version of this file to be governed by only the CDDL or
30 * only the GPL Version 2, indicate your decision by adding "[Contributor]
31 * elects to include this software in this distribution under the [CDDL or GPL
32 * Version 2] license." If you don't indicate a single choice of license, a
33 * recipient has the option to distribute your version of this file under
34 * either the CDDL, the GPL Version 2 or to extend the choice of license to
35 * its licensees as provided above. However, if you add GPL Version 2 code
36 * and therefore, elected the GPL Version 2 license, then the option applies
37 * only if the new code is made subject to such option by the copyright
38 * holder.
39 */
40
41 package javax.mail;
42
43 /**
44 * The Provider is a class that describes a protocol
45 * implementation. The values typically come from the
46 * javamail.providers and javamail.default.providers
47 * resource files. An application may also create and
48 * register a Provider object to dynamically add support
49 * for a new provider.
50 *
51 * @author Max Spivak
52 * @author Bill Shannon
53 */
54 public class Provider {
55
56 /**
57 * This inner class defines the Provider type.
58 * Currently, STORE and TRANSPORT are the only two provider types
59 * supported.
60 */
61
62 public static class Type {
63 public static final Type STORE = new Type("STORE");
64 public static final Type TRANSPORT = new Type("TRANSPORT");
65
66 private String type;
67
68 private Type(String type) {
69 this.type = type;
70 }
71
72 @Override
73 public String toString() {
74 return type;
75 }
76 }
77
78 private Type type;
79 private String protocol, className, vendor, version;
80
81 /**
82 * Create a new provider of the specified type for the specified
83 * protocol. The specified class implements the provider.
84 *
85 * @param type Type.STORE or Type.TRANSPORT
86 * @param protocol valid protocol for the type
87 * @param classname class name that implements this protocol
88 * @param vendor optional string identifying the vendor (may be null)
89 * @param version optional implementation version string (may be null)
90 * @since JavaMail 1.4
91 */
92 public Provider(Type type, String protocol, String classname,
93 String vendor, String version) {
94 this.type = type;
95 this.protocol = protocol;
96 this.className = classname;
97 this.vendor = vendor;
98 this.version = version;
99 }
100
101 /**
102 * Returns the type of this Provider.
103 *
104 * @return the provider type
105 */
106 public Type getType() {
107 return type;
108 }
109
110 /**
111 * Returns the protocol supported by this Provider.
112 *
113 * @return the protocol
114 */
115 public String getProtocol() {
116 return protocol;
117 }
118
119 /**
120 * Returns the name of the class that implements the protocol.
121 *
122 * @return the class name
123 */
124 public String getClassName() {
125 return className;
126 }
127
128 /**
129 * Returns the name of the vendor associated with this implementation
130 * or null.
131 *
132 * @return the vendor
133 */
134 public String getVendor() {
135 return vendor;
136 }
137
138 /**
139 * Returns the version of this implementation or null if no version.
140 *
141 * @return the version
142 */
143 public String getVersion() {
144 return version;
145 }
146
147 /** Overrides Object.toString() */
148 @Override
149 public String toString() {
150 String s = "javax.mail.Provider[" + type + "," +
151 protocol + "," + className;
152
153 if (vendor != null)
154 s += "," + vendor;
155
156 if (version != null)
157 s += "," + version;
158
159 s += "]";
160 return s;
161 }
162 }
163