001/*
002 * Copyright 2012-2016 UnboundID Corp.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License (GPLv2 only)
006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007 * as published by the Free Software Foundation.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, see <http://www.gnu.org/licenses>.
016 */
017
018package com.unboundid.scim.data;
019
020import com.unboundid.scim.schema.AttributeDescriptor;
021import com.unboundid.scim.sdk.InvalidResourceException;
022import com.unboundid.scim.sdk.SCIMAttribute;
023import com.unboundid.scim.sdk.SCIMAttributeValue;
024
025import java.util.ArrayList;
026import java.util.List;
027
028
029
030/**
031 * A complex type that specifies XML data format configuration options.
032 */
033public class XmlDataFormatConfig
034{
035  private final boolean supported;
036
037
038
039  /**
040   * The <code>AttributeValueResolver</code> that resolves SCIM attribute values
041   * to/from <code>XmlDataFormatConfig</code> instances.
042   */
043  public static final AttributeValueResolver<XmlDataFormatConfig>
044      XML_DATA_FORMAT_CONFIG_RESOLVER =
045      new AttributeValueResolver<XmlDataFormatConfig>()
046      {
047        /**
048         * {@inheritDoc}
049         */
050        @Override
051        public XmlDataFormatConfig toInstance(final SCIMAttributeValue value)
052        {
053          return new XmlDataFormatConfig(
054              value.getSubAttributeValue("supported",
055                  BOOLEAN_RESOLVER));
056        }
057
058        /**
059         * {@inheritDoc}
060         */
061        @Override
062        public SCIMAttributeValue fromInstance(
063            final AttributeDescriptor attributeDescriptor,
064            final XmlDataFormatConfig value)
065            throws InvalidResourceException
066        {
067          final List<SCIMAttribute> subAttributes =
068              new ArrayList<SCIMAttribute>(1);
069
070          final AttributeDescriptor supportedDescriptor =
071              attributeDescriptor.getSubAttribute("supported");
072          subAttributes.add(
073              SCIMAttribute.create(
074                  supportedDescriptor,
075                  BOOLEAN_RESOLVER.fromInstance(supportedDescriptor,
076                      value.supported)));
077
078          return SCIMAttributeValue.createComplexValue(subAttributes);
079        }
080      };
081
082
083
084  /**
085   * Create a <code>XmlDataFormatConfig</code> instance.
086   *
087   * @param supported  Specifies whether the XML data format is supported.
088   */
089  public XmlDataFormatConfig(final boolean supported)
090  {
091    this.supported = supported;
092  }
093
094
095
096  /**
097   * Indicates whether the XML data format is supported.
098   * @return  {@code true} if the XML data format is supported.
099   */
100  public boolean isSupported()
101  {
102    return supported;
103  }
104
105
106
107  @Override
108  public boolean equals(final Object o)
109  {
110    if (this == o)
111    {
112      return true;
113    }
114    if (o == null || getClass() != o.getClass())
115    {
116      return false;
117    }
118
119    final XmlDataFormatConfig that = (XmlDataFormatConfig) o;
120
121    if (supported != that.supported)
122    {
123      return false;
124    }
125
126    return true;
127  }
128
129
130
131  @Override
132  public int hashCode()
133  {
134    return (supported ? 1 : 0);
135  }
136
137
138
139  @Override
140  public String toString()
141  {
142    final StringBuilder sb = new StringBuilder();
143    sb.append("XmlDataFormatConfig");
144    sb.append("{supported=").append(supported);
145    sb.append('}');
146    return sb.toString();
147  }
148}