| 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; |
| 39 | |
| 40 | /** |
| 41 | * Helper class supporting schema elements that include syntax |
| 42 | * definitions - attributes and matching rules |
| 43 | * |
| 44 | * @version 1.0 |
| 45 | * @see org.ietf.ldap.LDAPAttributeSchema |
| 46 | * @see org.ietf.ldap.LDAPMatchingRuleSchema |
| 47 | **/ |
| 48 | |
| 49 | class LDAPSyntaxSchemaElement extends LDAPSchemaElement { |
| 50 | |
| 51 | static final long serialVersionUID = 6086340702503710702L; |
| 52 | |
| 53 | /** |
| 54 | * Construct a blank element. |
| 55 | */ |
| 56 | LDAPSyntaxSchemaElement() { |
| 57 | super(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Gets the syntax of the schema element |
| 62 | * @return One of the following values: |
| 63 | * <UL> |
| 64 | * <LI><CODE>cis</CODE> (case-insensitive string) |
| 65 | * <LI><CODE>ces</CODE> (case-exact string) |
| 66 | * <LI><CODE>binary</CODE> (binary data) |
| 67 | * <LI><CODE>int</CODE> (integer) |
| 68 | * <LI><CODE>telephone</CODE> (telephone number -- identical to cis, |
| 69 | * but blanks and dashes are ignored during comparisons) |
| 70 | * <LI><CODE>dn</CODE> (distinguished name) |
| 71 | * <LI><CODE>unknown</CODE> (not a known syntax) |
| 72 | * </UL> |
| 73 | */ |
| 74 | int getSyntax() { |
| 75 | return syntax; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Gets the syntax of the attribute type in dotted-decimal format, |
| 80 | * for example "1.2.3.4.5" |
| 81 | * @return The attribute syntax in dotted-decimal format. |
| 82 | */ |
| 83 | String getSyntaxString() { |
| 84 | return syntaxString; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Convert from enumerated syntax types to an OID |
| 89 | * @param syntax One of the enumerated syntax types |
| 90 | * @return The OID corresponding to the internal type |
| 91 | */ |
| 92 | static String internalSyntaxToString( int syntax ) { |
| 93 | String s; |
| 94 | if ( syntax == cis ) { |
| 95 | s = cisString; |
| 96 | } else if ( syntax == binary ) { |
| 97 | s = binaryString; |
| 98 | } else if ( syntax == ces ) { |
| 99 | s = cesString; |
| 100 | } else if ( syntax == telephone ) { |
| 101 | s = telephoneString; |
| 102 | } else if ( syntax == dn ) { |
| 103 | s = dnString; |
| 104 | } else if ( syntax == integer ) { |
| 105 | s = intString; |
| 106 | } else { |
| 107 | s = null; |
| 108 | } |
| 109 | return s; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Convert from enumerated syntax type to a user-friendly |
| 114 | * string |
| 115 | * @param syntax One of the enumerated syntax types |
| 116 | * @return A user-friendly syntax description |
| 117 | */ |
| 118 | String syntaxToString() { |
| 119 | String s; |
| 120 | if ( syntax == cis ) { |
| 121 | s = "case-insensitive string"; |
| 122 | } else if ( syntax == binary ) { |
| 123 | s = "binary"; |
| 124 | } else if ( syntax == integer ) { |
| 125 | s = "integer"; |
| 126 | } else if ( syntax == ces ) { |
| 127 | s = "case-exact string"; |
| 128 | } else if ( syntax == telephone ) { |
| 129 | s = "telephone"; |
| 130 | } else if ( syntax == dn ) { |
| 131 | s = "distinguished name"; |
| 132 | } else { |
| 133 | s = syntaxString; |
| 134 | } |
| 135 | return s; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Convert from an OID to one of the enumerated syntax types |
| 140 | * @param syntax A dotted-decimal OID |
| 141 | * @return The internal enumerated type corresponding to the |
| 142 | * OID; <CODE>unknown</CODE> if it is not one of the known |
| 143 | * types |
| 144 | */ |
| 145 | int syntaxCheck( String syntax ) { |
| 146 | int i = unknown; |
| 147 | if ( syntax == null ) { |
| 148 | } else if ( syntax.equals( cisString ) ) { |
| 149 | i = cis; |
| 150 | } else if ( syntax.equals( binaryString ) ) { |
| 151 | i = binary; |
| 152 | } else if ( syntax.equals( cesString ) ) { |
| 153 | i = ces; |
| 154 | } else if ( syntax.equals( intString ) ) { |
| 155 | i = integer; |
| 156 | } else if ( syntax.equals( telephoneString ) ) { |
| 157 | i = telephone; |
| 158 | } else if ( syntax.equals( dnString ) ) { |
| 159 | i = dn; |
| 160 | } |
| 161 | return i; |
| 162 | } |
| 163 | |
| 164 | public String toString() { |
| 165 | return "LDAPSyntaxSchemaElement: " + getSyntaxString(); |
| 166 | } |
| 167 | |
| 168 | int syntax = unknown; |
| 169 | String syntaxString = null; |
| 170 | } |