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 package org.apache.directory.shared.ldap.entry; 020 021 import java.util.Collections; 022 import java.util.HashMap; 023 import java.util.Iterator; 024 import java.util.Map; 025 026 import org.apache.directory.shared.ldap.name.DN; 027 028 029 /** 030 * The Abstract class where all the DefaultClientEntry and DefaultServerEntry 031 * common fields and methods will be found. 032 * 033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 034 * @version $Rev$, $Date$ 035 */ 036 public abstract class AbstractEntry<K> implements Entry 037 { 038 /** The DN for this entry */ 039 protected DN dn; 040 041 /** A map containing all the attributes for this entry */ 042 protected Map<K, EntryAttribute> attributes = new HashMap<K, EntryAttribute>(); 043 044 045 /** 046 * Get this entry's DN. 047 * 048 * @return The entry's DN 049 */ 050 public DN getDn() 051 { 052 return dn; 053 } 054 055 056 /** 057 * Set this entry's DN. 058 * 059 * @param dn The DN associated with this entry 060 */ 061 public void setDn( DN dn ) 062 { 063 this.dn = dn; 064 } 065 066 067 /** 068 * Remove all the attributes for this entry. The DN is not reset 069 */ 070 public void clear() 071 { 072 attributes.clear(); 073 } 074 075 076 /** 077 * Returns an enumeration containing the zero or more attributes in the 078 * collection. The behavior of the enumeration is not specified if the 079 * attribute collection is changed. 080 * 081 * @return an enumeration of all contained attributes 082 */ 083 public Iterator<EntryAttribute> iterator() 084 { 085 return Collections.unmodifiableMap( attributes ).values().iterator(); 086 } 087 088 089 /** 090 * Returns the number of attributes. 091 * 092 * @return the number of attributes 093 */ 094 public int size() 095 { 096 return attributes.size(); 097 } 098 099 100 /** 101 * Clone the current entry 102 */ 103 public Entry clone() 104 { 105 try 106 { 107 return (Entry)super.clone(); 108 } 109 catch ( CloneNotSupportedException cnse ) 110 { 111 return null; 112 } 113 } 114 }