001    /*
002     * Copyright 2011-2012 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    
018    package com.unboundid.scim.data;
019    
020    import com.unboundid.scim.schema.AttributeDescriptor;
021    import com.unboundid.scim.sdk.InvalidResourceException;
022    import com.unboundid.scim.sdk.SCIMAttribute;
023    import com.unboundid.scim.sdk.SCIMAttributeValue;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    
029    
030    /**
031     * A complex type that specifies Change Password configuration options.
032     */
033    public class ChangePasswordConfig
034    {
035      private final boolean supported;
036    
037    
038    
039      /**
040       * The <code>AttributeValueResolver</code> that resolves SCIM attribute values
041       * to/from <code>ChangePasswordConfig</code> instances.
042       */
043      public static final AttributeValueResolver<ChangePasswordConfig>
044          CHANGE_PASSWORD_CONFIG_RESOLVER =
045          new AttributeValueResolver<ChangePasswordConfig>()
046          {
047            /**
048             * {@inheritDoc}
049             */
050            @Override
051            public ChangePasswordConfig toInstance(final SCIMAttributeValue value) {
052              return new ChangePasswordConfig(
053                  value.getSubAttributeValue("supported",
054                      BOOLEAN_RESOLVER));
055            }
056    
057            /**
058             * {@inheritDoc}
059             */
060            @Override
061            public SCIMAttributeValue fromInstance(
062                final AttributeDescriptor attributeDescriptor,
063                final ChangePasswordConfig value)
064                throws InvalidResourceException
065            {
066              final List<SCIMAttribute> subAttributes =
067                  new ArrayList<SCIMAttribute>(1);
068    
069              final AttributeDescriptor supportedDescriptor =
070                  attributeDescriptor.getSubAttribute("supported");
071              subAttributes.add(
072                  SCIMAttribute.create(
073                      supportedDescriptor,
074                      BOOLEAN_RESOLVER.fromInstance(supportedDescriptor,
075                          value.supported)));
076    
077              return SCIMAttributeValue.createComplexValue(subAttributes);
078            }
079          };
080    
081    
082    
083      /**
084       * Create a <code>ChangePasswordConfig</code> instance.
085       *
086       * @param supported  Specifies whether the Change Password operation is
087       *                   supported.
088       */
089      public ChangePasswordConfig(final boolean supported)
090      {
091        this.supported = supported;
092      }
093    
094    
095    
096      /**
097       * Indicates whether the Change Password operation is supported.
098       * @return  {@code true} if the Change Password operation 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 ChangePasswordConfig that = (ChangePasswordConfig) 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("ChangePasswordConfig");
144        sb.append("{supported=").append(supported);
145        sb.append('}');
146        return sb.toString();
147      }
148    }