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    
030    
031    import org.opends.server.admin.std.server.AttributeSyntaxCfg;
032    import org.opends.server.api.ApproximateMatchingRule;
033    import org.opends.server.api.AttributeSyntax;
034    import org.opends.server.api.EqualityMatchingRule;
035    import org.opends.server.api.OrderingMatchingRule;
036    import org.opends.server.api.SubstringMatchingRule;
037    import org.opends.server.config.ConfigException;
038    import org.opends.server.core.DirectoryServer;
039    import org.opends.server.types.ByteString;
040    
041    
042    
043    import static org.opends.server.loggers.ErrorLogger.*;
044    import static org.opends.messages.SchemaMessages.*;
045    import org.opends.messages.MessageBuilder;
046    import static org.opends.server.schema.SchemaConstants.*;
047    
048    
049    /**
050     * This class implements the protocol information attribute syntax, which is
051     * being deprecated.  As such, this implementation behaves exactly like the
052     * directory string syntax.
053     */
054    public class ProtocolInformationSyntax
055           extends AttributeSyntax<AttributeSyntaxCfg>
056    {
057      // The default approximate matching rule for this syntax.
058      private ApproximateMatchingRule defaultApproximateMatchingRule;
059    
060      // The default equality matching rule for this syntax.
061      private EqualityMatchingRule defaultEqualityMatchingRule;
062    
063      // The default ordering matching rule for this syntax.
064      private OrderingMatchingRule defaultOrderingMatchingRule;
065    
066      // The default substring matching rule for this syntax.
067      private SubstringMatchingRule defaultSubstringMatchingRule;
068    
069    
070    
071      /**
072       * Creates a new instance of this syntax.  Note that the only thing that
073       * should be done here is to invoke the default constructor for the
074       * superclass.  All initialization should be performed in the
075       * <CODE>initializeSyntax</CODE> method.
076       */
077      public ProtocolInformationSyntax()
078      {
079        super();
080      }
081    
082    
083    
084      /**
085       * {@inheritDoc}
086       */
087      public void initializeSyntax(AttributeSyntaxCfg configuration)
088             throws ConfigException
089      {
090        defaultApproximateMatchingRule =
091             DirectoryServer.getApproximateMatchingRule(AMR_DOUBLE_METAPHONE_OID);
092        if (defaultApproximateMatchingRule == null)
093        {
094          logError(ERR_ATTR_SYNTAX_UNKNOWN_APPROXIMATE_MATCHING_RULE.get(
095              AMR_DOUBLE_METAPHONE_OID, SYNTAX_PROTOCOL_INFORMATION_NAME));
096        }
097    
098        defaultEqualityMatchingRule =
099             DirectoryServer.getEqualityMatchingRule(EMR_CASE_IGNORE_OID);
100        if (defaultEqualityMatchingRule == null)
101        {
102          logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get(
103              EMR_CASE_IGNORE_OID, SYNTAX_PROTOCOL_INFORMATION_NAME));
104        }
105    
106        defaultOrderingMatchingRule =
107             DirectoryServer.getOrderingMatchingRule(OMR_CASE_IGNORE_OID);
108        if (defaultOrderingMatchingRule == null)
109        {
110          logError(ERR_ATTR_SYNTAX_UNKNOWN_ORDERING_MATCHING_RULE.get(
111              OMR_CASE_IGNORE_OID, SYNTAX_PROTOCOL_INFORMATION_NAME));
112        }
113    
114        defaultSubstringMatchingRule =
115             DirectoryServer.getSubstringMatchingRule(SMR_CASE_IGNORE_OID);
116        if (defaultSubstringMatchingRule == null)
117        {
118          logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get(
119              SMR_CASE_IGNORE_OID, SYNTAX_PROTOCOL_INFORMATION_NAME));
120        }
121      }
122    
123    
124    
125      /**
126       * Retrieves the common name for this attribute syntax.
127       *
128       * @return  The common name for this attribute syntax.
129       */
130      public String getSyntaxName()
131      {
132        return SYNTAX_PROTOCOL_INFORMATION_NAME;
133      }
134    
135    
136    
137      /**
138       * Retrieves the OID for this attribute syntax.
139       *
140       * @return  The OID for this attribute syntax.
141       */
142      public String getOID()
143      {
144        return SYNTAX_PROTOCOL_INFORMATION_OID;
145      }
146    
147    
148    
149      /**
150       * Retrieves a description for this attribute syntax.
151       *
152       * @return  A description for this attribute syntax.
153       */
154      public String getDescription()
155      {
156        return SYNTAX_PROTOCOL_INFORMATION_DESCRIPTION;
157      }
158    
159    
160    
161      /**
162       * Retrieves the default equality matching rule that will be used for
163       * attributes with this syntax.
164       *
165       * @return  The default equality matching rule that will be used for
166       *          attributes with this syntax, or <CODE>null</CODE> if equality
167       *          matches will not be allowed for this type by default.
168       */
169      public EqualityMatchingRule getEqualityMatchingRule()
170      {
171        return defaultEqualityMatchingRule;
172      }
173    
174    
175    
176      /**
177       * Retrieves the default ordering matching rule that will be used for
178       * attributes with this syntax.
179       *
180       * @return  The default ordering matching rule that will be used for
181       *          attributes with this syntax, or <CODE>null</CODE> if ordering
182       *          matches will not be allowed for this type by default.
183       */
184      public OrderingMatchingRule getOrderingMatchingRule()
185      {
186        return defaultOrderingMatchingRule;
187      }
188    
189    
190    
191      /**
192       * Retrieves the default substring matching rule that will be used for
193       * attributes with this syntax.
194       *
195       * @return  The default substring matching rule that will be used for
196       *          attributes with this syntax, or <CODE>null</CODE> if substring
197       *          matches will not be allowed for this type by default.
198       */
199      public SubstringMatchingRule getSubstringMatchingRule()
200      {
201        return defaultSubstringMatchingRule;
202      }
203    
204    
205    
206      /**
207       * Retrieves the default approximate matching rule that will be used for
208       * attributes with this syntax.
209       *
210       * @return  The default approximate matching rule that will be used for
211       *          attributes with this syntax, or <CODE>null</CODE> if approximate
212       *          matches will not be allowed for this type by default.
213       */
214      public ApproximateMatchingRule getApproximateMatchingRule()
215      {
216        return defaultApproximateMatchingRule;
217      }
218    
219    
220    
221      /**
222       * Indicates whether the provided value is acceptable for use in an attribute
223       * with this syntax.  If it is not, then the reason may be appended to the
224       * provided buffer.
225       *
226       * @param  value          The value for which to make the determination.
227       * @param  invalidReason  The buffer to which the invalid reason should be
228       *                        appended.
229       *
230       * @return  <CODE>true</CODE> if the provided value is acceptable for use with
231       *          this syntax, or <CODE>false</CODE> if not.
232       */
233      public boolean valueIsAcceptable(ByteString value,
234                                       MessageBuilder invalidReason)
235      {
236        // We will accept any value for this syntax.
237        return true;
238      }
239    }
240