Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/util/LDIFRecord.java

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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
8 * the 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 mozilla.org code.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38 package org.ietf.ldap.util;
39
40 import java.io.Serializable;
41
42 import org.ietf.ldap.LDAPControl;
43
44 /**
45 * An object of this class represents an LDIF record in an LDIF
46 * file (or in LDIF data). A record can contain a list of attributes
47 * (which describes an entry) or a list of modifications (which
48 * decribes the changes that need to be made to an entry).
49 * Each record also has a distinguished name.
50 * <P>
51 *
52 * You can get an <CODE>LDIFRecord</CODE> object from LDIF data
53 * by calling the <CODE>nextRecord</CODE> method of the
54 * <CODE>LDIF</CODE> object holding the data.
55 * <P>
56 *
57 * If you are constructing a new <CODE>LDIFRecord</CODE> object,
58 * you can specify the content of the record in one of the
59 * following ways:
60 * <P>
61 *
62 * <UL>
63 * <LI>To create a record that specifies an entry, use an object of
64 * the <CODE>LDIFAttributeContent</CODE> class.
65 * <LI>To create a record that specifies a modification to be made,
66 * use an object of one of the following classes:
67 * <UL>
68 * <LI>Use <CODE>LDIFAddContent</CODE> to add a new entry.
69 * <LI>Use <CODE>LDIFModifyContent</CODE> to modify an entry.
70 * <LI>Use <CODE>LDIFDeleteContent</CODE> to delete an entry.
71 * </UL>
72 * </UL>
73 * <P>
74 *
75 * @version 1.0
76 * @see org.ietf.ldap.util.LDIF
77 * @see org.ietf.ldap.util.LDIFAddContent
78 * @see org.ietf.ldap.util.LDIFModifyContent
79 * @see org.ietf.ldap.util.LDIFDeleteContent
80 * @see org.ietf.ldap.util.LDIFAttributeContent
81 */
82 public class LDIFRecord implements Serializable {
83
84 /**
85 * Internal variables
86 */
87 private String m_dn = null;
88 private LDIFBaseContent m_content = null;
89 static final long serialVersionUID = -6537481934870076178L;
90
91 /**
92 * Constructs a new <CODE>LDIFRecord</CODE> object with the
93 * specified content.
94 * @param dn distinguished name of the entry associated with
95 * the record
96 * @param content content of the LDIF record. You can specify
97 * an object of the <CODE>LDIFAttributeContent</CODE>,
98 * <CODE>LDIFAddContent</CODE>, <CODE>LDIFModifyContent</CODE>,
99 * or <CODE>LDIFDeleteContent</CODE> classes.
100 * @see org.ietf.ldap.util.LDIFAddContent
101 * @see org.ietf.ldap.util.LDIFModifyContent
102 * @see org.ietf.ldap.util.LDIFDeleteContent
103 * @see org.ietf.ldap.util.LDIFAttributeContent
104 */
105 public LDIFRecord(String dn, LDIFContent content) {
106 m_dn = dn;
107 m_content = (LDIFBaseContent)content;
108 }
109
110 /**
111 * Retrieves the distinguished name of the LDIF record.
112 * @return the distinguished name of the LDIF record.
113 */
114 public String getDN() {
115 return m_dn;
116 }
117
118 /**
119 * Retrieves the content of the LDIF record. The content is
120 * an object of the <CODE>LDIFAttributeContent</CODE>,
121 * <CODE>LDIFAddContent</CODE>, <CODE>LDIFModifyContent</CODE>,
122 * or <CODE>LDIFDeleteContent</CODE> classes.
123 * <P>
124 *
125 * To determine the class of the object, use the <CODE>getType</CODE>
126 * method of that object. <CODE>getType</CODE> returns one of
127 * the following values:
128 * <UL>
129 * <LI><CODE>LDIFContent.ATTRIBUTE_CONTENT</CODE> (the object is an
130 * <CODE>LDIFAttributeContent</CODE> object)
131 * <LI><CODE>LDIFContent.ADD_CONTENT</CODE> (the object is an
132 * <CODE>LDIFAddContent</CODE> object)
133 * <LI><CODE>LDIFContent.MODIFICATION_CONTENT</CODE> (the object is an
134 * <CODE>LDIFModifyContent</CODE> object)
135 * <LI><CODE>LDIFContent.DELETE_CONTENT</CODE> (the object is an
136 * <CODE>LDIFDeleteContent</CODE> object)
137 * </UL>
138 * <P>
139 *
140 * For example:
141 * <PRE>
142 * ...
143 * import org.ietf.ldap.*;
144 * import org.ietf.ldap.util.*;
145 * import java.io.*;
146 * import java.util.*;
147 * ...
148 * try {
149 * // Parse the LDIF file test.ldif.
150 * LDIF parser = new LDIF( "test.ldif" );
151 * // Iterate through each LDIF record in the file.
152 * LDIFRecord nextRec = parser.nextRecord();
153 * while ( nextRec != null ) {
154 * // Based on the type of content in the record,
155 * // get the content and cast it as the appropriate
156 * // type.
157 * switch( nextRec.getContent().getType() ) {
158 * case LDIFContent.ATTRIBUTE_CONTENT:
159 * LDIFAttributeContent attrContent =
160 * (LDIFAttributeContent)nextRec.getContent();
161 * break;
162 * case LDIFContent.ADD_CONTENT:
163 * LDIFAddContent addContent =
164 * (LDIFAddContent)nextRec.getContent();
165 * break;
166 * case LDIFContent.MODIFICATION_CONTENT:
167 * LDIFModifyContent modifyContent =
168 * (LDIFModifyContent)nextRec.getContent();
169 * break;
170 * case LDIFContent.DELETE_CONTENT:
171 * LDIFDeleteContent deleteContent =
172 * (LDIFDeleteContent)nextRec.getContent();
173 * break;
174 * }
175 * ...
176 * // Iterate through each record.
177 * nextRec = parser.nextRecord();
178 * }
179 * } catch ( IOException e ) {
180 * System.out.println( "Error: " + e.toString() );
181 * System.exit(1);
182 * }
183 * ...
184 * </PRE>
185 *
186 * @return the content of the LDIF record.
187 * @see org.ietf.ldap.util.LDIFAddContent
188 * @see org.ietf.ldap.util.LDIFModifyContent
189 * @see org.ietf.ldap.util.LDIFDeleteContent
190 * @see org.ietf.ldap.util.LDIFAttributeContent
191 */
192 public LDIFContent getContent() {
193 return m_content;
194 }
195
196 /**
197 * Retrieves the list of controls specified in the content
198 * of the LDIF record, if any.
199 * @return an array of <CODE>LDAPControl</CODE> objects that
200 * represent any controls specified in the LDIF record,
201 * or <CODE>null</CODE> if none were specified.
202 */
203 public LDAPControl[] getControls() {
204 return (m_content == null) ? null : m_content.getControls();
205 }
206
207 /**
208 * Gets the string representation of the <CODE>LDIFRecord</CODE>
209 * object.
210 * @return the string representation of the LDIF record.
211 */
212 public String toString() {
213 return "LDIFRecord {dn=" + m_dn + ", content=" + m_content + "}";
214 }
215 }