Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/LDAPMatchingRuleUseSchema.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 import java.util.Vector;
41
42 /**
43 * The definition of a matching rule use in the schema.
44 * <A HREF="http://ds.internic.net/rfc/rfc2252.txt"
45 * TARGET="_blank">RFC 2252, Lightweight Directory Access Protocol (v3):
46 * Attribute Syntax Definitions</A> covers the types of information
47 * that need to be specified in the definition of a matching rule use.
48 * According to the RFC, the description of a matching rule use can
49 * include the following information:
50 * <P>
51 *
52 * <UL>
53 * <LI>an OID identifying the matching rule
54 * <LI>a name identifying the matching rule use
55 * <LI>a description of the matching rule use
56 * <LI>a list of attributes the matching rule applies to
57 * </UL>
58 * <P>
59 *
60 * When you construct an <CODE>LDAPMatchingRuleUseSchema</CODE> object, you can
61 * specify these types of information as arguments to the constructor or
62 * in the MatchingRuleUseDescription format specified in RFC 2252.
63 * When an LDAP client searches an LDAP server for the schema, the server
64 * returns schema information as an object with values in this
65 * format.
66 * <P>
67 *
68 * You can get the name, OID, and description of this matching rule use
69 * definition by using the <CODE>getName</CODE>, <CODE>getOID</CODE>, and
70 * <CODE>getDescription</CODE> methods inherited from the abstract class
71 * <CODE>LDAPSchemaElement</CODE>. Custom qualifiers are
72 * accessed with <CODE>getQualifier</CODE> and <CODE>getQualifierNames</CODE>
73 * from <CODE>LDAPSchemaElement</CODE>.
74 * <P>
75 *
76 * To add or remove this matching rule definition from the
77 * schema, use the <CODE>add</CODE> and <CODE>remove</CODE>
78 * methods, which this class inherits from the <CODE>LDAPSchemaElement</CODE>
79 * abstract class.
80 * <P>
81 * RFC 2252 defines MatchingRuleUseDescription follows:
82 * <P>
83 * <PRE>
84 * Values of the matchingRuleUse list the attributes which are suitable
85 * for use with an extensible matching rule.
86 *
87 * MatchingRuleUseDescription = "(" whsp
88 * numericoid whsp ; MatchingRule identifier
89 * [ "NAME" qdescrs ]
90 * [ "DESC" qdstring ]
91 * [ "OBSOLETE" ]
92 * "APPLIES" oids ; AttributeType identifiers
93 * whsp ")"
94 * </PRE>
95 * <P>
96 *
97 * @version 1.0
98 * @see org.ietf.ldap.LDAPSchemaElement
99 * @see org.ietf.ldap.LDAPMatchingRuleSchema
100 **/
101
102 public class LDAPMatchingRuleUseSchema extends LDAPAttributeSchema {
103
104
105
106 /**
107 * Constructs a matching rule use definition, using the specified
108 * information.
109 * @param names names of the matching rule
110 * @param oid object identifier (OID) of the matching rule
111 * in dotted-decimal format (for example, "1.2.3.4")
112 * @param description description of the matching rule
113 * @param obsolete <CODE>true</CODE> if the element is obsolete
114 * @param attributes array of the OIDs of the attributes for which
115 * the matching rule is applicable
116 */
117 public LDAPMatchingRuleUseSchema( String[] names,
118 String oid,
119 String description,
120 boolean obsolete,
121 String[] attributes ) {
122 if ( (oid == null) || (oid.trim().length() < 1) ) {
123 throw new IllegalArgumentException( "OID required" );
124 }
125 this.names = names;
126 this.oid = oid;
127 this.description = description;
128 attrName = "matchingruleuse";
129 _attributes = new String[attributes.length];
130 for( int i = 0; i < attributes.length; i++ ) {
131 _attributes[i] = attributes[i];
132 }
133 if ( obsolete ) {
134 setQualifier( OBSOLETE, "" );
135 }
136 }
137
138 /**
139 * Constructs a matching rule use definition based on descriptions in
140 * the MatchingRuleUseDescription format. For information on this format,
141 * (see <A HREF="http://ds.internic.net/rfc/rfc2252.txt"
142 * TARGET="_blank">RFC 2252, Lightweight Directory Access Protocol (v3):
143 * Attribute Syntax Definitions</A>. This is the format that LDAP servers
144 * and clients use to exchange schema information. For example, when
145 * you search an LDAP server for its schema, the server returns an entry
146 * with attributes that include "matchingrule" and "matchingruleuse".
147 * The values of these attributes are matching rule descriptions
148 * in this format.
149 * <P>
150 *
151 * @param use definition of the use of the matching rule in the
152 * MatchingRuleUseDescription format
153 */
154 public LDAPMatchingRuleUseSchema( String use ) {
155 attrName = "matchingruleuse";
156 parseValue( use );
157 Vector<String> v = (Vector<String>)properties.get( "APPLIES" );
158 if ( v != null ) {
159 _attributes = new String[v.size()];
160 v.copyInto( _attributes );
161 v.removeAllElements();
162 }
163 }
164
165 /**
166 * Gets the list of the OIDs of the attribute types which can be used
167 * with the matching rule.
168 * @return array of the OIDs of the attribute types which can be used
169 * with the matching rule.
170 */
171 public String[] getApplicableAttributes() {
172 return _attributes;
173 }
174
175 /**
176 * Gets the attribute name for a schema element
177 *
178 * @return The attribute name of the element
179 */
180 String getAttributeName() {
181 return "matchingruleuse";
182 }
183
184 /**
185 * Gets the matching rule use definition in the string representation
186 * of the MatchingRuleUseDescription data type defined in X.501 (see
187 * <A HREF="http://ds.internic.net/rfc/rfc2252.txt"
188 * TARGET="_blank">RFC 2252, Lightweight Directory Access Protocol
189 * (v3): Attribute Syntax Definitions</A>
190 * for a description of these formats).
191 * This is the format that LDAP servers and clients use to exchange
192 * schema information. (For example, when
193 * you search an LDAP server for its schema, the server returns an entry
194 * with the attributes "matchingrules" and "matchingruleuse". The
195 * values of these attributes are matching rule description and
196 * matching rule use description in these formats.)
197 * <P>
198 *
199 * @return a string in a format that can be used as the value of
200 * the <CODE>matchingruleuse</CODE> attribute (which describes the use of
201 * a matching rule in the schema) of a <CODE>subschema</CODE> object
202 */
203 public String getValue() {
204 String s = getValuePrefix();
205 if ( (_attributes != null) && (_attributes.length > 0) ) {
206 s += "APPLIES ( ";
207 for( int i = 0; i < _attributes.length; i++ ) {
208 if ( i > 0 )
209 s += " $ ";
210 s += _attributes[i];
211 }
212 s += " ) ";
213 }
214 s += ')';
215 return s;
216 }
217
218 /**
219 * Gets the definition of the matching rule use in Directory format
220 *
221 * @return definition of the matching rule use in Directory format
222 */
223 public String toString() {
224 return getValue();
225 }
226
227 // Qualifiers tracked explicitly
228 static final String[] EXPLICIT = { OBSOLETE };
229
230 private String[] _attributes = null;
231 }