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.property.complex;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
027    import microsoft.exchange.webservices.data.core.XmlElementNames;
028    import microsoft.exchange.webservices.data.core.enumeration.property.error.RuleErrorCode;
029    import microsoft.exchange.webservices.data.core.enumeration.property.RuleProperty;
030    
031    /**
032     * Defines the RuleError class.
033     */
034    public final class RuleError extends ComplexProperty {
035    
036      /**
037       * The Rule property.
038       */
039      private RuleProperty ruleProperty;
040    
041      /**
042       * The Rule validation error code.
043       */
044      private RuleErrorCode errorCode;
045    
046      /**
047       * The Error message.
048       */
049      private String errorMessage;
050    
051      /**
052       * The Field value.
053       */
054      private String value;
055    
056      /**
057       * The Initializes a new instance of the RuleError class.
058       */
059      protected RuleError() {
060        super();
061      }
062    
063      /**
064       * Gets the property which failed validation.
065       *
066       * @return ruleProperty
067       */
068      public RuleProperty getRuleProperty() {
069        return this.ruleProperty;
070      }
071    
072      /**
073       * Gets the validation error code.
074       *
075       * @return ruleProperty
076       */
077      public RuleErrorCode getErrorCode() {
078        return this.errorCode;
079      }
080    
081      /**
082       * Gets the error message.
083       *
084       * @return ruleProperty
085       */
086      public String getErrorMessage() {
087        return this.errorMessage;
088      }
089    
090      /**
091       * Gets the value that failed validation.
092       */
093      public String getValue() {
094        return this.value;
095      }
096    
097      /**
098       * Tries to read element from XML.
099       *
100       * @param reader The reader
101       * @return True if element was read
102       * @throws Exception
103       */
104      @Override
105      public boolean tryReadElementFromXml(EwsServiceXmlReader reader)
106          throws Exception {
107        if (reader.getLocalName().equals(XmlElementNames.FieldURI)) {
108          this.ruleProperty = reader.readElementValue(RuleProperty.class);
109          return true;
110        } else if (reader.getLocalName().equals(XmlElementNames.ErrorCode)) {
111          this.errorCode = reader.readElementValue(RuleErrorCode.class);
112          return true;
113        } else if (reader.getLocalName().equals(XmlElementNames.ErrorMessage)) {
114          this.errorMessage = reader.readElementValue();
115          return true;
116        } else if (reader.getLocalName().equals(XmlElementNames.FieldValue)) {
117          this.value = reader.readElementValue();
118          return true;
119        } else {
120          return false;
121        }
122      }
123    }