001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.api.ldap.aci.protectedItem;
021
022
023import org.apache.directory.api.ldap.model.schema.AttributeType;
024
025
026/**
027 * An element of {@link RestrictedByItem}.
028 * 
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 */
031public class RestrictedByElem
032{
033    /** The AttributeType on which the restriction is applied */
034    private AttributeType attributeType;
035
036    /** The list of allowed AttributeType values */
037    private AttributeType valuesIn;
038
039
040    /**
041     * Creates a new instance.
042     * 
043     * @param attributeType the attribute type to restrict
044     * @param valuesIn the attribute type only whose values are allowed in <tt>attributeType</tt>.
045     */
046    public RestrictedByElem( AttributeType attributeType, AttributeType valuesIn )
047    {
048        this.attributeType = attributeType;
049        this.valuesIn = valuesIn;
050    }
051
052
053    /**
054     * Gets the attribute type to restrict.
055     *
056     * @return the attribute type
057     */
058    public AttributeType getAttributeType()
059    {
060        return attributeType;
061    }
062
063
064    /**
065     * Gets the attribute type only whose values are allowed in
066     * <tt>attributeType</tt>.
067     *
068     * @return the list of allowed AttributeType values
069     */
070    public AttributeType getValuesIn()
071    {
072        return valuesIn;
073    }
074
075
076    /**
077     * {@inheritDoc}
078     */
079    @Override
080    public int hashCode()
081    {
082        int hash = 37;
083        hash = hash * 17 + attributeType.hashCode();
084        hash = hash * 17 + valuesIn.hashCode();
085        return hash;
086    }
087
088
089    /**
090     * {@inheritDoc}
091     */
092    @Override
093    public boolean equals( Object o )
094    {
095        if ( o == null )
096        {
097            return false;
098        }
099
100        if ( this == o )
101        {
102            return true;
103        }
104
105        if ( o instanceof RestrictedByElem )
106        {
107            RestrictedByElem that = ( RestrictedByElem ) o;
108            if ( this.attributeType == null )
109            {
110                if ( that.attributeType == null )
111                {
112                    if ( this.valuesIn == null )
113                    {
114                        return that.valuesIn == null;
115                    }
116                    else
117                    {
118                        return this.valuesIn.equals( that.valuesIn );
119                    }
120                }
121                return false;
122            }
123            else
124            {
125                if ( this.attributeType.equals( that.attributeType ) )
126                {
127                    if ( this.valuesIn == null )
128                    {
129                        return that.valuesIn == null;
130                    }
131                    else
132                    {
133                        return this.valuesIn.equals( that.valuesIn );
134                    }
135                }
136                return false;
137            }
138        }
139        return false;
140    }
141
142
143    /**
144     * {@inheritDoc}
145     */
146    @Override
147    public String toString()
148    {
149        return "{ type " + attributeType.getName() + ", valuesIn " + valuesIn.getName() + " }";
150    }
151}