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.core.request;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
027    import microsoft.exchange.webservices.data.core.ExchangeService;
028    import microsoft.exchange.webservices.data.core.XmlElementNames;
029    import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling;
030    import microsoft.exchange.webservices.data.core.response.ExecuteDiagnosticMethodResponse;
031    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
032    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
033    import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
034    import org.w3c.dom.Node;
035    
036    import javax.xml.stream.XMLStreamException;
037    
038    /**
039     * Defines the ExecuteDiagnosticMethodRequest class.
040     */
041    public final class ExecuteDiagnosticMethodRequest extends
042        MultiResponseServiceRequest<ExecuteDiagnosticMethodResponse> {
043    
044      private Node xmlNode;
045      private String verb;
046    
047      /**
048       * Initializes a new instance of the ExecuteDiagnosticMethodRequest class.
049       *
050       * @throws Exception
051       */
052      public ExecuteDiagnosticMethodRequest(ExchangeService service)
053          throws Exception {
054        super(service, ServiceErrorHandling.ThrowOnError);
055      }
056    
057      /**
058       * Gets the name of the XML element.
059       *
060       * @return XmlElementNames
061       */
062      @Override public String getXmlElementName() {
063        return XmlElementNames.ExecuteDiagnosticMethod;
064      }
065    
066      /**
067       * Writes XML elements.
068       *
069       * @param writer The writer
070       * @throws XMLStreamException the XML stream exception
071       * @throws ServiceXmlSerializationException
072       */
073      @Override
074      protected void writeElementsToXml(EwsServiceXmlWriter writer)
075          throws ServiceXmlSerializationException, XMLStreamException {
076        writer.writeElementValue(XmlNamespace.Messages,
077            XmlElementNames.Verb, this.getVerb());
078    
079        writer.writeStartElement(XmlNamespace.Messages,
080            XmlElementNames.Parameter);
081        writer.writeNode(this.getParameter());
082        writer.writeEndElement();
083      }
084    
085      /**
086       * Gets the name of the response XML element.
087       *
088       * @return XML element name
089       */
090      @Override
091      protected String getResponseXmlElementName() {
092        return XmlElementNames.ExecuteDiagnosticMethodResponse;
093      }
094    
095      /**
096       * Gets the request version.
097       *
098       * @return Earliest Exchange version in which this request is supported.
099       */
100      @Override
101      protected ExchangeVersion getMinimumRequiredServerVersion() {
102        /** Set to 2007_SP1 because only test code
103         * will be using this method (it's marked internal.
104         * If it were marked for 2010_SP1, test cases
105         * would have to create new ExchangeService instances
106         * when using this method for tests running under older versions.
107         */
108        return ExchangeVersion.Exchange2007_SP1;
109      }
110    
111      /**
112       * Gets the verb of the method to execute.
113       */
114      protected String getVerb() {
115        return verb;
116      }
117    
118      /**
119       * Sets the verb of the method to execute.
120       */
121      public void setVerb(String value) {
122        this.verb = value;
123      }
124    
125      /**
126       * Gets the parameter to the executing method.
127       */
128      protected Node getParameter() {
129        return xmlNode;
130      }
131    
132      /**
133       * Sets the parameter to the executing method.
134       */
135      public void setParameter(Node value) {
136        this.xmlNode = value;
137      }
138    
139      /**
140       * Creates the service response.
141       *
142       * @param service       The service
143       * @param responseIndex Index of the response
144       * @return Service response
145       */
146      @Override
147      protected ExecuteDiagnosticMethodResponse createServiceResponse(ExchangeService service,
148          int responseIndex) {
149        return new ExecuteDiagnosticMethodResponse(service);
150      }
151    
152      /**
153       * Gets the name of the response message XML element.
154       *
155       * @return XmlElementNames
156       */
157      @Override
158      protected String getResponseMessageXmlElementName() {
159        return XmlElementNames.ExecuteDiagnosticMethodResponseMEssage;
160      }
161    
162      /**
163       * Gets the expected response message count.
164       *
165       * @return Number of expected response messages.
166       */
167      @Override
168      protected int getExpectedResponseMessageCount() {
169        return 1;
170      }
171    }