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 */ 029public class RestrictedByElem 030{ 031 /** The AttributeType on which the restriction is applied */ 032 private AttributeType attributeType; 033 034 /** The list of allowed AttributeType values */ 035 private AttributeType valuesIn; 036 037 038 /** 039 * Creates a new instance. 040 * 041 * @param attributeType the attribute type to restrict 042 * @param valuesIn the attribute type only whose values are allowed in <tt>attributeType</tt>. 043 */ 044 public RestrictedByElem( AttributeType attributeType, AttributeType valuesIn ) 045 { 046 this.attributeType = attributeType; 047 this.valuesIn = valuesIn; 048 } 049 050 051 /** 052 * Gets the attribute type to restrict. 053 * 054 * @return the attribute type 055 */ 056 public AttributeType getAttributeType() 057 { 058 return attributeType; 059 } 060 061 062 /** 063 * Gets the attribute type only whose values are allowed in 064 * <tt>attributeType</tt>. 065 * 066 * @return the list of allowed AttributeType values 067 */ 068 public AttributeType getValuesIn() 069 { 070 return valuesIn; 071 } 072 073 074 /** 075 * {@inheritDoc} 076 */ 077 @Override 078 public int hashCode() 079 { 080 int hash = 37; 081 hash = hash * 17 + attributeType.hashCode(); 082 hash = hash * 17 + valuesIn.hashCode(); 083 return hash; 084 } 085 086 087 /** 088 * {@inheritDoc} 089 */ 090 @Override 091 public boolean equals( Object o ) 092 { 093 if ( o == null ) 094 { 095 return false; 096 } 097 098 if ( this == o ) 099 { 100 return true; 101 } 102 103 if ( o instanceof RestrictedByElem ) 104 { 105 RestrictedByElem that = ( RestrictedByElem ) o; 106 if ( this.attributeType == null ) 107 { 108 if ( that.attributeType == null ) 109 { 110 if ( this.valuesIn == null ) 111 { 112 return that.valuesIn == null; 113 } 114 else 115 { 116 return this.valuesIn.equals( that.valuesIn ); 117 } 118 } 119 return false; 120 } 121 else 122 { 123 if ( this.attributeType.equals( that.attributeType ) ) 124 { 125 if ( this.valuesIn == null ) 126 { 127 return that.valuesIn == null; 128 } 129 else 130 { 131 return this.valuesIn.equals( that.valuesIn ); 132 } 133 } 134 return false; 135 } 136 } 137 return false; 138 } 139 140 141 /** 142 * {@inheritDoc} 143 */ 144 @Override 145 public String toString() 146 { 147 return "{ type " + attributeType.getName() + ", valuesIn " + valuesIn.getName() + " }"; 148 } 149}