001    /*
002     * The MIT License
003     * Copyright (c) 2012 Microsoft Corporation
004     *
005     * Permission is hereby granted, free of charge, to any person obtaining a copy
006     * of this software and associated documentation files (the "Software"), to deal
007     * in the Software without restriction, including without limitation the rights
008     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009     * copies of the Software, and to permit persons to whom the Software is
010     * furnished to do so, subject to the following conditions:
011     *
012     * The above copyright notice and this permission notice shall be included in
013     * all copies or substantial portions of the Software.
014     *
015     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021     * THE SOFTWARE.
022     */
023    
024    package microsoft.exchange.webservices.data.autodiscover;
025    
026    import microsoft.exchange.webservices.data.core.EwsXmlReader;
027    import microsoft.exchange.webservices.data.core.XmlElementNames;
028    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
029    import microsoft.exchange.webservices.data.security.XmlNodeType;
030    
031    /**
032     * Represents the email Protocol connection settings for pop/imap/smtp
033     * protocols.
034     */
035    public final class ProtocolConnection {
036    
037      /**
038       * The encryption method.
039       */
040      private String encryptionMethod;
041    
042      /**
043       * The hostname.
044       */
045      private String hostname;
046    
047      /**
048       * The port.
049       */
050      private int port;
051    
052      /**
053       * Initializes a new instance of the {@link ProtocolConnection} class.
054       */
055    
056      protected ProtocolConnection() {
057      }
058    
059      /**
060       * Read user setting with ProtocolConnection value.
061       *
062       * @param reader EwsServiceXmlReader
063       * @return the protocol connection
064       * @throws Exception the exception
065       */
066      protected static ProtocolConnection loadFromXml(EwsXmlReader reader)
067          throws Exception {
068        ProtocolConnection connection = new ProtocolConnection();
069    
070        do {
071          reader.read();
072    
073          if (reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) {
074            if (reader.getLocalName().equals(
075                XmlElementNames.EncryptionMethod)) {
076              connection.setEncryptionMethod(reader
077                  .readElementValue(String.class));
078            } else if (reader.getLocalName().equals(
079                XmlElementNames.Hostname)) {
080              connection.setHostname(reader
081                  .readElementValue(String.class));
082            } else if (reader.getLocalName().equals(XmlElementNames.Port)) {
083              connection.setPort(reader.readElementValue(int.class));
084            }
085          }
086        } while (!reader.isEndElement(XmlNamespace.Autodiscover,
087            XmlElementNames.ProtocolConnection));
088    
089        return connection;
090      }
091    
092      /**
093       * Initializes a new instance of the ProtocolConnection class.
094       *
095       * @param encryptionMethod The encryption method.
096       * @param hostname         The hostname.
097       * @param port             The port number to use for the portocol.
098       */
099      protected ProtocolConnection(String encryptionMethod, String hostname,
100          int port) {
101        this.encryptionMethod = encryptionMethod;
102        this.hostname = hostname;
103        this.port = port;
104      }
105    
106      /**
107       * Gets the encryption method.
108       *
109       * @return The encryption method.
110       */
111      public String getEncryptionMethod() {
112        return this.encryptionMethod;
113      }
114    
115      /**
116       * Sets the encryption method.
117       *
118       * @param value the new encryption method
119       */
120      public void setEncryptionMethod(String value) {
121        this.encryptionMethod = value;
122      }
123    
124      /**
125       * Gets the hostname.
126       *
127       * @return The hostname.
128       */
129      public String getHostname() {
130        return this.hostname;
131    
132      }
133    
134      /**
135       * Sets the hostname.
136       *
137       * @param value the new hostname
138       */
139      public void setHostname(String value) {
140        this.hostname = value;
141      }
142    
143      /**
144       * Gets the port number.
145       *
146       * @return The port number.
147       */
148      public int getPort() {
149        return this.port;
150      }
151    
152      /**
153       * Sets the port.
154       *
155       * @param value the new port
156       */
157      public void setPort(int value) {
158        this.port = value;
159      }
160    }