KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > kernel > security > impl > ldap > LDAPDN


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Shirley Sasson.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46
47 package org.mr.kernel.security.impl.ldap;
48
49 import java.util.Vector JavaDoc;
50 import java.util.StringTokenizer JavaDoc;
51 import java.util.List JavaDoc;
52
53 /**
54  * This class represents an LDAP distinguished name (DN) of an entry.
55  * It holds its full path, for example:
56  * "dc=Groups,dc=Principals,dc=MyDomain,dc=Domains,dc=manta,dc=com".
57  * It holds a list of LDAPEntry objects, each one represents an entry, without
58  * its preceding path, for example "dc=Principals".
59  *
60  * @version 1.0
61  * @since apr 17, 2006
62  * @author Shirley Sasson
63  *
64  */

65 public class LDAPDN {
66     private String JavaDoc _path;
67     private List JavaDoc _entries;
68     private LDAPDN _parent;
69     private String JavaDoc _strParent;
70
71     /**
72      * Constructs a new instance of LDAPDN with the full entry path given.
73      *
74      * @param path full entry path
75      */

76     public LDAPDN(String JavaDoc path){
77         _path = path;
78         _entries = new Vector JavaDoc();
79         StringTokenizer JavaDoc token = new StringTokenizer JavaDoc(path, ",");
80         while (token.hasMoreTokens()){
81             String JavaDoc current = token.nextToken();
82             LDAPEntry entry = new LDAPEntry(current);
83             _entries.add(entry);
84         }
85
86         buildParentDN();
87     }
88
89     /**
90      * Retunrs the full path of the entry.
91      *
92      * @return the string representation of the full path of the entry
93      *
94      */

95     public String JavaDoc getPath(){
96         return _path;
97     }
98
99     /**
100      * Retunrns a list of LDAPEntry objects, that represent the entry.
101      *
102      * @return a list of LDAPEntry objects, that represent the entry
103      *
104      */

105     public List JavaDoc getEntries(){
106         return _entries;
107     }
108
109     /**
110      * Returns the string representation of the full path of the parent of the entry.
111      *
112      * @return the string representation of the full path of the parent of the entry
113      *
114      */

115     public String JavaDoc getStringParentDN(){
116         return _strParent;
117     }
118
119     /**
120      * Retunrs an LDAPDN object representing the parent of the entry.
121      *
122      * @return an LDAPDN object representing the parent of the entry
123      *
124      */

125     public LDAPDN getParentDN(){
126         return _parent;
127     }
128
129     /**
130      * Retunrs the LDAPEntry object indicating the entry name, without the full
131      * path of its parent.
132      *
133      * @return the LDAPEntry object indicating the entry name, without the full
134      * path of its parent
135      *
136      */

137     public LDAPEntry getFirstEntry(){
138         return (LDAPEntry) _entries.get(0);
139     }
140
141     /**
142      * Returns the string representation of the entry name, without the full
143      * path of its parent.
144      *
145      * @return string representation of the entry name, without the full
146      * path of its parent
147      *
148      */

149     public String JavaDoc getStrFirstEntry(){
150         LDAPEntry entry = (LDAPEntry) _entries.get(0);
151         return entry.getName() + "=" + entry.getValue();
152     }
153
154     /**
155      * Returns a string representation of this LDAPDN.
156      *
157      * @return a string representation of this LDAPDN.
158      */

159     public String JavaDoc toString(){
160         return _path;
161     }
162
163     private void buildParentDN(){
164         String JavaDoc temp = "";
165         for (int i=1 ; i<_entries.size() ; i++){
166             LDAPEntry entry = (LDAPEntry) _entries.get(i);
167             temp += entry.getName() + "=" + entry.getValue() + ",";
168         }
169         // remove last comma
170
if (temp.indexOf(',') != -1)
171             temp = temp.substring(0, temp.length()-1);
172         _strParent = temp;
173         if (_strParent != null && !"".equals(_strParent))
174             _parent = new LDAPDN(_strParent);
175     }
176 }
177
Popular Tags