001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.schema;
028
029 import org.opends.server.types.DebugLogLevel;
030 import static org.opends.server.loggers.ErrorLogger.logError;
031 import static org.opends.server.loggers.debug.DebugLogger.*;
032 import org.opends.server.loggers.debug.DebugTracer;
033 import static org.opends.messages.SchemaMessages.*;
034 import org.opends.messages.MessageBuilder;
035 import static org.opends.server.schema.SchemaConstants.*;
036
037 import org.opends.server.admin.std.server.AttributeSyntaxCfg;
038 import org.opends.server.api.ApproximateMatchingRule;
039 import org.opends.server.api.AttributeSyntax;
040 import org.opends.server.api.AttributeValueDecoder;
041 import org.opends.server.api.EqualityMatchingRule;
042 import org.opends.server.api.OrderingMatchingRule;
043 import org.opends.server.api.SubstringMatchingRule;
044 import org.opends.server.config.ConfigException;
045 import org.opends.server.core.AbsoluteSubtreeSpecification;
046 import org.opends.server.core.DirectoryServer;
047 import org.opends.server.types.AttributeValue;
048 import org.opends.server.types.ByteString;
049 import org.opends.server.types.DirectoryException;
050
051
052
053 /**
054 * This class defines the absolute subtree specification attribute
055 * syntax, which is used to select sets of entries in dynamic groups and
056 * access control rules.
057 */
058 public final class AbsoluteSubtreeSpecificationSyntax
059 extends AttributeSyntax<AttributeSyntaxCfg>
060 {
061 /**
062 * The tracer object for the debug logger.
063 */
064 private static final DebugTracer TRACER = getTracer();
065
066 // The default equality matching rule for this syntax.
067 private EqualityMatchingRule defaultEqualityMatchingRule;
068
069 // The default ordering matching rule for this syntax.
070 private OrderingMatchingRule defaultOrderingMatchingRule;
071
072 // The default substring matching rule for this syntax.
073 private SubstringMatchingRule defaultSubstringMatchingRule;
074
075 /**
076 * An {@link AbsoluteSubtreeSpecification} attribute value decoder for
077 * this syntax.
078 */
079 public static final AttributeValueDecoder<AbsoluteSubtreeSpecification>
080 DECODER = new AttributeValueDecoder<AbsoluteSubtreeSpecification>() {
081 /**
082 * {@inheritDoc}
083 */
084 public AbsoluteSubtreeSpecification decode(AttributeValue value)
085 throws DirectoryException {
086 return AbsoluteSubtreeSpecification.valueOf(value.getStringValue());
087 }
088 };
089
090 /**
091 * Creates a new instance of this syntax. Note that the only thing
092 * that should be done here is to invoke the default constructor for
093 * the superclass. All initialization should be performed in the
094 * <CODE>initializeSyntax</CODE> method.
095 */
096 public AbsoluteSubtreeSpecificationSyntax() {
097 // No implementation required.
098 }
099
100 /**
101 * {@inheritDoc}
102 */
103 public void initializeSyntax(AttributeSyntaxCfg configuration)
104 throws ConfigException {
105
106 defaultEqualityMatchingRule = DirectoryServer
107 .getEqualityMatchingRule(EMR_OCTET_STRING_OID);
108 if (defaultEqualityMatchingRule == null) {
109 logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get(
110 EMR_OCTET_STRING_OID, SYNTAX_ABSOLUTE_SUBTREE_SPECIFICATION_NAME));
111 }
112
113 defaultOrderingMatchingRule = DirectoryServer
114 .getOrderingMatchingRule(OMR_OCTET_STRING_OID);
115 if (defaultOrderingMatchingRule == null) {
116 logError(ERR_ATTR_SYNTAX_UNKNOWN_ORDERING_MATCHING_RULE.get(
117 OMR_OCTET_STRING_OID, SYNTAX_ABSOLUTE_SUBTREE_SPECIFICATION_NAME));
118 }
119
120 defaultSubstringMatchingRule = DirectoryServer
121 .getSubstringMatchingRule(SMR_OCTET_STRING_OID);
122 if (defaultSubstringMatchingRule == null) {
123 logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get(
124 SMR_OCTET_STRING_OID, SYNTAX_ABSOLUTE_SUBTREE_SPECIFICATION_NAME));
125 }
126 }
127
128 /**
129 * Retrieves the common name for this attribute syntax.
130 *
131 * @return The common name for this attribute syntax.
132 */
133 public String getSyntaxName() {
134
135 return SYNTAX_ABSOLUTE_SUBTREE_SPECIFICATION_NAME;
136 }
137
138 /**
139 * Retrieves the OID for this attribute syntax.
140 *
141 * @return The OID for this attribute syntax.
142 */
143 public String getOID() {
144
145 return SYNTAX_ABSOLUTE_SUBTREE_SPECIFICATION_OID;
146 }
147
148 /**
149 * Retrieves a description for this attribute syntax.
150 *
151 * @return A description for this attribute syntax.
152 */
153 public String getDescription() {
154
155 return SYNTAX_ABSOLUTE_SUBTREE_SPECIFICATION_DESCRIPTION;
156 }
157
158 /**
159 * Retrieves the default equality matching rule that will be used for
160 * attributes with this syntax.
161 *
162 * @return The default equality matching rule that will be used for
163 * attributes with this syntax, or <CODE>null</CODE> if
164 * equality matches will not be allowed for this type by
165 * default.
166 */
167 public EqualityMatchingRule getEqualityMatchingRule() {
168
169 return defaultEqualityMatchingRule;
170 }
171
172 /**
173 * Retrieves the default ordering matching rule that will be used for
174 * attributes with this syntax.
175 *
176 * @return The default ordering matching rule that will be used for
177 * attributes with this syntax, or <CODE>null</CODE> if
178 * ordering matches will not be allowed for this type by
179 * default.
180 */
181 public OrderingMatchingRule getOrderingMatchingRule() {
182
183 return defaultOrderingMatchingRule;
184 }
185
186 /**
187 * Retrieves the default substring matching rule that will be used for
188 * attributes with this syntax.
189 *
190 * @return The default substring matching rule that will be used for
191 * attributes with this syntax, or <CODE>null</CODE> if
192 * substring matches will not be allowed for this type by
193 * default.
194 */
195 public SubstringMatchingRule getSubstringMatchingRule() {
196
197 return defaultSubstringMatchingRule;
198 }
199
200 /**
201 * Retrieves the default approximate matching rule that will be used
202 * for attributes with this syntax.
203 *
204 * @return The default approximate matching rule that will be used for
205 * attributes with this syntax, or <CODE>null</CODE> if
206 * approximate matches will not be allowed for this type by
207 * default.
208 */
209 public ApproximateMatchingRule getApproximateMatchingRule() {
210
211 // There is no approximate matching rule by default.
212 return null;
213 }
214
215 /**
216 * Indicates whether the provided value is acceptable for use in an
217 * attribute with this syntax. If it is not, then the reason may be
218 * appended to the provided buffer.
219 *
220 * @param value
221 * The value for which to make the determination.
222 * @param invalidReason
223 * The buffer to which the invalid reason should be appended.
224 * @return <CODE>true</CODE> if the provided value is acceptable for
225 * use with this syntax, or <CODE>false</CODE> if not.
226 */
227 public boolean valueIsAcceptable(ByteString value,
228 MessageBuilder invalidReason)
229 {
230 // Use the subtree specification code to make this determination.
231 try {
232 AbsoluteSubtreeSpecification.valueOf(value.stringValue());
233
234 return true;
235 } catch (DirectoryException e) {
236 if (debugEnabled())
237 {
238 TRACER.debugCaught(DebugLogLevel.ERROR, e);
239 }
240
241 invalidReason.append(e.getMessageObject());
242 return false;
243 }
244 }
245 }