KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > AttributeHierarchy


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.core.model;
22
23
24 import java.util.Arrays JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27
28 /**
29  * An AttributeHierarchy is a container for an attribute including all its subtypes.
30  * <p>
31  * Example:
32  * <ul>
33  * <li>attributeDescription is <code>name</code>
34  * <li>attributes contains <code>cn:test1</code>, <code>sn:test2</code> and <code>givenName:test3</code>
35  * </ul>
36  *
37  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
38  * @version $Rev$, $Date$
39  */

40 public class AttributeHierarchy
41 {
42
43     /** The entry */
44     private IEntry entry;
45
46     /** The attribute description */
47     private String JavaDoc attributeDescription;
48
49     /** The attributes */
50     private IAttribute[] attributes;
51
52
53     /**
54      * Creates a new instance of AttributeHierarchy.
55      *
56      * @param entry the entry
57      * @param attributeDescription the attribute description
58      * @param attributes the attributes
59      */

60     public AttributeHierarchy( IEntry entry, String JavaDoc attributeDescription, IAttribute[] attributes )
61     {
62         if ( entry == null || attributeDescription == null || attributes == null || attributes.length < 1
63             || attributes[0] == null )
64         {
65             throw new IllegalArgumentException JavaDoc( "Empty AttributeHierachie" );
66         }
67         this.entry = entry;
68         this.attributeDescription = attributeDescription;
69         this.attributes = attributes;
70     }
71
72
73     /**
74      * Gets the attributes.
75      *
76      * @return the attributes
77      */

78     public IAttribute[] getAttributes()
79     {
80         return attributes;
81     }
82
83
84     /**
85      * Checks whether the given attribute is contained
86      * in this attribute hierarchy.
87      *
88      * @param attribute the attribute to check
89      * @return true if the attribute is contained in this attribute hierarchy
90      */

91     public boolean contains( IAttribute attribute )
92     {
93         return Arrays.asList( attributes ).contains( attribute );
94     }
95
96
97     /**
98      * Returns an iterator over the elements of this attribute hierarchy.
99      *
100      * @return an iterator over the elements of this attribute hierarchy
101      */

102     public Iterator JavaDoc<IAttribute> iterator()
103     {
104         return Arrays.asList( attributes ).iterator();
105     }
106
107
108     /**
109      * Gets the first attribute.
110      *
111      * @return the first attribute
112      */

113     public IAttribute getAttribute()
114     {
115         return attributes[0];
116     }
117
118
119     /**
120      * Gets the number of attributes.
121      *
122      * @return the number of attributes
123      */

124     public int size()
125     {
126         return attributes.length;
127     }
128
129
130     /**
131      * Gets the attribute description.
132      *
133      * @return the attribute description
134      */

135     public String JavaDoc getAttributeDescription()
136     {
137         return attributeDescription;
138     }
139
140
141     /**
142      * Gets the entry.
143      *
144      * @return the entry
145      */

146     public IEntry getEntry()
147     {
148         return entry;
149     }
150
151 }
152
Popular Tags