Constructor. @param session Session object for this service @param urlname URLName object to be used for this service
(Session session, URLName urlname)
| 77 | * @param urlname URLName object to be used for this service |
| 78 | */ |
| 79 | protected Service(Session session, URLName urlname) { |
| 80 | this.session = session; |
| 81 | debug = session.getDebug(); |
| 82 | url = urlname; |
| 83 | |
| 84 | /* |
| 85 | * Initialize the URLName with default values. |
| 86 | * The URLName will be updated when connect is called. |
| 87 | */ |
| 88 | String protocol = null; |
| 89 | String host = null; |
| 90 | int port = -1; |
| 91 | String user = null; |
| 92 | String password = null; |
| 93 | String file = null; |
| 94 | |
| 95 | // get whatever information we can from the URL |
| 96 | // XXX - url should always be non-null here, Session |
| 97 | // passes it into the constructor |
| 98 | if (url != null) { |
| 99 | protocol = url.getProtocol(); |
| 100 | host = url.getHost(); |
| 101 | port = url.getPort(); |
| 102 | user = url.getUsername(); |
| 103 | password = url.getPassword(); |
| 104 | file = url.getFile(); |
| 105 | } |
| 106 | |
| 107 | // try to get protocol-specific default properties |
| 108 | if (protocol != null) { |
| 109 | if (host == null) |
| 110 | host = session.getProperty("mail." + protocol + ".host"); |
| 111 | if (user == null) |
| 112 | user = session.getProperty("mail." + protocol + ".user"); |
| 113 | } |
| 114 | |
| 115 | // try to get mail-wide default properties |
| 116 | if (host == null) |
| 117 | host = session.getProperty("mail.host"); |
| 118 | |
| 119 | if (user == null) |
| 120 | user = session.getProperty("mail.user"); |
| 121 | |
| 122 | // try using the system username |
| 123 | if (user == null) { |
| 124 | try { |
| 125 | user = System.getProperty("user.name"); |
| 126 | } catch (SecurityException sex) { |
| 127 | // XXX - it's not worth creating a MailLogger just for this |
| 128 | //logger.log(Level.CONFIG, "Can't get user.name property", sex); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | url = new URLName(protocol, host, port, file, user, password); |
| 133 | |
| 134 | // create or choose the appropriate event queue |
| 135 | String scope = |
| 136 | session.getProperties().getProperty("mail.event.scope", "folder"); |
nothing calls this directly
no test coverage detected