Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/LDAPSyntaxSchema.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) 2001
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 syntax type in the schema.
42 * <A HREF="http://www.ietf.org/rfc/rfc2252.txt"
43 * TARGET="_blank">RFC 2252, Lightweight Directory Access Protocol (v3):
44 * LDAP Subschema Attribute</A> covers the types of information
45 * to specify when defining a syntax.
46 * The description of a syntax can include the following:
47 * <P>
48 *
49 * <UL>
50 * <LI>an OID identifying the syntax
51 * <LI>a description of the attribute type
52 * </UL>
53 * <P>
54 *
55 * When you construct an <CODE>LDAPSyntaxSchema</CODE> object, you can
56 * specify these types of information as arguments to the constructor or
57 * in the ldapSyntaxes format specified in RFC 2252.
58 * When an LDAP client searches an LDAP server for the schema, the server
59 * returns schema information as an object with attribute values in this
60 * format.
61 * <P>
62 * RFC 2252 defines SyntaxDescription as follows:
63 * <P>
64 * <PRE>
65 * SyntaxDescription = "(" whsp
66 * numericoid whsp
67 * [ "DESC" qdstring ]
68 * whsp ")"
69 * </PRE>
70 *<P>
71 * Syntax definitions do not have a name, so the <CODE>getName</CODE>
72 * method inherited from <CODE>LDAPSchemaElement</CODE> returns "".
73 * To get the OID and description of this syntax type
74 * definition, use the <CODE>getOID</CODE> and
75 * <CODE>getDescription</CODE> methods inherited from the abstract class
76 * <CODE>LDAPSchemaElement</CODE>.
77 * <P>
78 *
79 * To add or remove this syntax type definition from the
80 * schema, use the <CODE>add</CODE> and <CODE>remove</CODE>
81 * methods, which this class inherits from the <CODE>LDAPSchemaElement</CODE>
82 * abstract class.
83 *
84 * @version 1.0
85 * @see org.ietf.ldap.LDAPSchemaElement
86 **/
87
88 public class LDAPSyntaxSchema extends LDAPSchemaElement {
89
90 static final long serialVersionUID = 3590667117475688132L;
91
92 /**
93 * Constructs a blank element.
94 */
95 protected LDAPSyntaxSchema() {
96 super();
97 }
98
99 /**
100 * Constructs a syntax type definition, using the specified
101 * information.
102 * @param oid object identifier (OID) of the syntax type
103 * in dotted-string format (for example, "1.2.3.4")
104 * @param description description of syntax type
105 */
106 public LDAPSyntaxSchema( String oid, String description ) {
107 super( new String[] { "" }, oid, description );
108 attrName = "ldapSyntaxes";
109 syntaxElement.syntax = syntaxElement.syntaxCheck( oid );
110 syntaxElement.syntaxString = oid;
111 }
112
113 /**
114 * Constructs a syntax type definition based on a description in
115 * the ldapSyntaxes format. For information on this format,
116 * (see <A HREF="http://www.ietf.org/rfc/rfc2252.txt"
117 * TARGET="_blank">RFC 2252, Lightweight Directory Access Protocol (v3):
118 * LDAP Subschema Attribute</A>. This is the format that LDAP servers
119 * and clients use to exchange schema information. (For example, when
120 * you search an LDAP server for its schema, the server returns an entry
121 * with the syntaxs "objectclasses" and "ldapSyntaxes". The
122 * values of "ldapSyntaxes" are syntax type descriptions
123 * in this format.)
124 * <P>
125 *
126 * @param raw definition of the syntax type in the
127 * ldapSyntaxes format
128 */
129 public LDAPSyntaxSchema( String raw ) {
130 attrName = "ldapSyntaxes";
131 parseValue( raw );
132 }
133
134 /**
135 * Gets the syntax of the schema element
136 * @return one of the following values:
137 * <UL>
138 * <LI><CODE>cis</CODE> (case-insensitive string)
139 * <LI><CODE>ces</CODE> (case-exact string)
140 * <LI><CODE>binary</CODE> (binary data)
141 * <LI><CODE>int</CODE> (integer)
142 * <LI><CODE>telephone</CODE> (telephone number -- identical to cis,
143 * but blanks and dashes are ignored during comparisons)
144 * <LI><CODE>dn</CODE> (distinguished name)
145 * <LI><CODE>unknown</CODE> (not a known syntax)
146 * </UL>
147 */
148 public int getSyntax() {
149 return syntaxElement.syntax;
150 }
151
152 /**
153 * Gets the syntax of the syntax type in dotted-decimal format,
154 * for example "1.2.3.4.5"
155 * @return The syntax syntax in dotted-decimal format.
156 */
157 public String getSyntaxString() {
158 return syntaxElement.syntaxString;
159 }
160
161 /**
162 * Gets the attribute name for a schema element
163 *
164 * @return The attribute name of the element
165 */
166 String getAttributeName() {
167 return "ldapsyntaxes";
168 }
169
170 /**
171 * Prepares a value in RFC 2252 format for submission to a server
172 *
173 * @return a String ready for submission to an LDAP server.
174 */
175 String getValue() {
176 String s = getValuePrefix();
177 String val = getCustomValues();
178 if ( val.length() > 0 ) {
179 s += val + ' ';
180 }
181 s += ')';
182 return s;
183 }
184
185 /**
186 * Gets the definition of the syntax in Directory format
187 *
188 * @return definition of the syntax in Directory format
189 */
190 public String toString() {
191 return getValue();
192 }
193
194 protected LDAPSyntaxSchemaElement syntaxElement =
195 new LDAPSyntaxSchemaElement();
196 }