View Javadoc

1   /*
2    * Copyright (c) 2004 UNINETT FAS
3    *
4    * This program is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the Free
6    * Software Foundation; either version 2 of the License, or (at your option)
7    * any later version.
8    *
9    * This program is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12   * more details.
13   *
14   * You should have received a copy of the GNU General Public License along with
15   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16   * Place - Suite 330, Boston, MA 02111-1307, USA.
17   *
18   */
19  
20  package no.feide.moria.directory.index;
21  
22  /***
23   * Represents an indexed reference to an external element. Used to distinguish
24   * between explicitly and implicitly indexed references.
25   */
26  public class IndexedReference {
27  
28      /*** External references. */
29      private final String[] myReferences;
30  
31      /***
32       * Usernames, where each element matches the same index in
33       * <code>myReferences</code>.
34       */
35      private final String[] myUsernames;
36  
37      /***
38       * Passwords, where each element matches the same index in
39       * <code>myReferences</code>.
40       */
41      private final String[] myPasswords;
42  
43      /*** true if this is a fully qualified reference to an external element. */
44      private final boolean explicit;
45  
46  
47      /***
48       * Constructor. Creates a new indexed reference.
49       * @param references
50       *            One or more external references. Cannot be <code>null</code>.
51       * @param usernames
52       *            Usernames for each external reference. Cannot be
53       *            <code>null</code>, and must have the same number of
54       *            elements as <code>references</code>.
55       * @param passwords
56       *            Passwords for each external reference. Cannot be
57       *            <code>null</code>, and must have the same number of
58       *            elements as <code>references</code>.
59       * @param explicitReference
60       *            <code>true</code> if this is a fully qualified reference to
61       *            an external element, otherwise <code>false</code>.
62       * @throws NullPointerException
63       * @throws IllegalArgumentException
64       *             If <code>references</code> is <code>null</code> or an
65       *             empty array, or if <code>usernames</code> or
66       *             <code>passwords</code> are <code>null</code> or contain a
67       *             different number of elements than <code>references</code>.
68       */
69      public IndexedReference(final String[] references,
70                              final String[] usernames, final String[] passwords,
71                              final boolean explicitReference)
72      throws IllegalArgumentException {
73  
74          super();
75  
76          // Sanity checks.
77          if ((references == null) || (references.length == 0))
78              throw new NullPointerException("References cannot be NULL or an empty array");
79          if (usernames == null)
80              throw new IllegalArgumentException("Usernames cannot be NULL");
81          if (passwords == null)
82              throw new IllegalArgumentException("Passwords cannot be NULL");
83          if ((usernames.length != references.length) || (passwords.length != references.length))
84              throw new IllegalArgumentException("References, usernames and passwords must have the same number of elements");
85  
86          // Assignments.
87          myReferences = (String[]) references.clone();
88          explicit = explicitReference;
89          myUsernames = (String[]) usernames.clone();
90          myPasswords = (String[]) passwords.clone();
91  
92      }
93  
94  
95      /***
96       * Gets the external references.
97       * @return One or more external references.
98       */
99      public final String[] getReferences() {
100 
101         return (String[]) myReferences.clone();
102 
103     }
104 
105 
106     /***
107      * Gets the usernames.
108      * @return One or more usernames.
109      */
110     public final String[] getUsernames() {
111 
112         return (String[]) myUsernames.clone();
113 
114     }
115 
116 
117     /***
118      * Gets the external passwords.
119      * @return One or more passwords.
120      */
121     public final String[] getPasswords() {
122 
123         return (String[]) myPasswords.clone();
124 
125     }
126 
127 
128     /***
129      * Checks whether this reference is an explicit reference to an external
130      * element, or an implicit reference to a search base of some sort.
131      * @return <code>true</code> if this is a fully qualified external
132      *         reference to an element, otherwise <code>false</code>.
133      */
134     public final boolean isExplicitlyIndexed() {
135 
136         return explicit;
137 
138     }
139 
140 }