Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/LDAPDITStructureRuleSchema.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) 2000
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;
39
40 /**
41 * The definition of a DIT structure rule in the schema.
42 * <A HREF="http://www.ietf.org/rfc/rfc2252.txt"
43 * TARGET="_blank">RFC 2252, Lightweight Directory Access Protocol (v3):
44 * DIT Structure Rule Description</A> covers the types of information
45 * to specify when defining a DIT structure rule. According to the RFC,
46 * the description of a DIT structure rule can include the following:
47 * <P>
48 *
49 * <UL>
50 * <LI>an OID identifying the attribute type
51 * <LI>a name identifying the attribute type
52 * <LI>a description of the attribute type
53 * <LI>the name of the parent attribute type
54 * <LI>the syntax used by the attribute (for example,
55 * <CODE>cis</CODE> or <CODE>int</CODE>)
56 * <LI>an indication of whether the attribute type is single-valued
57 * or multi-valued
58 * </UL>
59 * <P>
60 *
61 * When you construct an <CODE>LDAPDITStructureRuleSchema</CODE> object, you can
62 * specify these types of information as arguments to the constructor or
63 * in the AttributeTypeDescription format specified in RFC 2252.
64 * When an LDAP client searches an LDAP server for the schema, the server
65 * returns schema information as an object with attribute values in this
66 * format.
67 * <P>
68 *
69 * There are a number of additional optional description fields which
70 * are not explicitly accessible through LDAPDITStructureRuleSchema, but which
71 * can be managed with setQualifier, getQualifier, and getQualifierNames:
72 * <P>
73 *
74 * <UL>
75 * <LI>OBSOLETE
76 * </UL>
77 * <P>
78 *
79 * To get the name, OID, and description of this DIT structure rule
80 * , use the <CODE>getName</CODE>, <CODE>getOID</CODE>, and
81 * <CODE>getDescription</CODE> methods inherited from the abstract class
82 * <CODE>LDAPSchemaElement</CODE>. Optional and custom qualifiers are
83 * accessed with <CODE>getQualifier</CODE> and <CODE>getQualifierNames</CODE>
84 * from <CODE>LDAPSchemaElement</CODE>.
85 * <P>
86 *
87 * To add or remove this attribute type definition from the
88 * schema, use the <CODE>add</CODE> and <CODE>remove</CODE>
89 * methods, which this class inherits from the <CODE>LDAPSchemaElement</CODE>
90 * abstract class.
91 * <P>
92 * RFC 2252 defines DITStructureRuleDescription as follows:
93 * <P>
94 * <PRE>
95 * DITStructureRuleDescription = "(" whsp
96 * ruleidentifier whsp ; DITStructureRule identifier
97 * [ "NAME" qdescrs ]
98 * [ "DESC" qdstring ]
99 * [ "OBSOLETE" whsp ]
100 * "FORM" woid whsp ; NameForm
101 * [ "SUP" ruleidentifiers whsp ] ; superior DITStructureRules
102 * ")"
103 * </PRE>
104 *
105 * @version 1.0
106 * @see org.ietf.ldap.LDAPSchemaElement
107 **/
108
109 public class LDAPDITStructureRuleSchema extends LDAPSchemaElement {
110
111 static final long serialVersionUID = -2823317246039655811L;
112
113 /**
114 * Constructs a blank element.
115 */
116 protected LDAPDITStructureRuleSchema() {
117 super();
118 }
119
120 /**
121 * Constructs a DIT structure rule definition, using the specified
122 * information.
123 * @param names names of the element
124 * @param ruleID unique identifier of the structure rule.<BR>
125 * NOTE: this is an integer, not a dotted numerical identifier.
126 * Structure rules aren't identified by OID.
127 * @param description description of attribute type
128 * @param obsolete <code>true</code> if the rule is obsolete
129 * @param nameForm either the identifier or name of a name form.
130 * This is used to indirectly refer to the object class that this
131 * structure rule applies to.
132 * @param superiors list of superior structure rules - specified
133 * by their integer ID. The object class specified by this structure
134 * rule (via the nameForm parameter) may only be subordinate in
135 * the DIT to object classes of those represented by the structure
136 * rules here.
137 */
138 public LDAPDITStructureRuleSchema( String[] names,
139 int ruleID,
140 String description,
141 boolean obsolete,
142 String nameForm,
143 String[] superiors ) {
144 super( names, "", description );
145 this.nameForm = nameForm;
146 this.ruleID = ruleID;
147 if ( obsolete ) {
148 setQualifier( OBSOLETE, "" );
149 }
150 if ( (superiors != null) && (superiors.length > 0) ) {
151 setQualifier( SUPERIOR, superiors );
152 }
153 }
154
155 /**
156 * Constructs a DIT structure rule definition based on a description in
157 * the DITStructureRuleDescription format. For information on this format,
158 * (see <A HREF="http://www.ietf.org/rfc/rfc2252.txt"
159 * >RFC 2252, Lightweight Directory Access Protocol (v3):
160 * DIT Structure Rule Description</A>. This is the format that
161 * LDAP servers
162 * and clients use to exchange schema information. (For example, when
163 * you search an LDAP server for its schema, the server returns an entry
164 * with the attributes "objectclasses" and "attributetypes". The
165 * values of "attributetypes" are attribute type descriptions
166 * in this format.)
167 * <P>
168 *
169 * @param raw definition of the DIT structure rule in the
170 * DITStructureRuleDescription format
171 */
172 public LDAPDITStructureRuleSchema( String raw ) {
173 attrName = "ditStructureRules";
174 parseValue( raw );
175 Object o = properties.get( FORM );
176 if ( o != null ) {
177 nameForm = (String)o;
178 }
179 try {
180 ruleID = Integer.parseInt( oid );
181 } catch ( Exception e ) {
182 }
183 }
184
185 /**
186 * Returns the NameForm that this structure rule controls. You can get
187 * the actual object class that this structure rule controls by calling
188 * getNameForm().getObjectClass().
189 *
190 * @return the NameForm that this structure rule controls.
191 */
192 public String getNameForm() {
193 return nameForm;
194 }
195
196 /**
197 * Returns the rule ID for this structure rule. Note that this returns
198 * an integer rather than a dotted decimal OID. Objects of this class do
199 * not have an OID, thus getID will return null.
200 *
201 * @return the rule ID for this structure rule.
202 */
203 public int getRuleID() {
204 return ruleID;
205 }
206
207 /**
208 * Returns a list of all structure rules that are superior to this
209 * structure rule. To resolve to an object class, you need to first
210 * resolve the superior id to another structure rule, then call
211 * getNameForm().getObjectClass() on that structure rule.
212 * @return the structure rules that are superior to this
213 * structure rule.
214 */
215 public String[] getSuperiors() {
216 return getQualifier( SUPERIOR );
217 }
218
219 /**
220 * Prepares a value in RFC 2252 format for submission to a server
221 *
222 * @return a String ready for submission to an LDAP server.
223 */
224 String getValue() {
225 String s = "( " + ruleID + ' ';
226 s += getNameField();
227 if ( description != null ) {
228 s += "DESC \'" + description + "\' ";
229 }
230 if ( isObsolete() ) {
231 s += OBSOLETE + ' ';
232 }
233
234 s += FORM + " " + nameForm + ' ';
235 String val = getValue( SUPERIOR, false );
236 if ( (val != null) && (val.length() > 1) ) {
237 s += val + ' ';
238 }
239 val = getCustomValues();
240 if ( val.length() > 0 ) {
241 s += val + ' ';
242 }
243 s += ')';
244 return s;
245 }
246
247 /**
248 * Gets the definition of the rule in Directory format
249 *
250 * @return definition of the rule in Directory format
251 */
252 public String toString() {
253 return getValue();
254 }
255
256 /**
257 * Gets the attribute name for a schema element
258 *
259 * @return The attribute name of the element
260 */
261 String getAttributeName() {
262 return "ldapditstructurerules";
263 }
264
265 public final static String FORM = "FORM";
266
267 // Qualifiers known to not have values; prepare a Hashtable
268 static final String[] NOVALS = { "OBSOLETE" };
269 static {
270 for( int i = 0; i < NOVALS.length; i++ ) {
271 novalsTable.put( NOVALS[i], NOVALS[i] );
272 }
273 }
274
275 // Qualifiers which we output explicitly in toString()
276 static final String[] IGNOREVALS = { OBSOLETE,
277 FORM,
278 "SUP"
279 };
280
281 private String nameForm = null;
282 private int ruleID = 0;
283 }