001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    https://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.api.ldap.model.schema.parsers;
021
022
023import java.text.ParseException;
024
025import org.apache.directory.api.i18n.I18n;
026
027
028/**
029 * A parser for ApacheDS normalizer descriptions.
030 * 
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 */
033public class NormalizerDescriptionSchemaParser extends AbstractSchemaParser<NormalizerDescription>
034{
035
036    /**
037     * Creates a schema parser instance.
038     */
039    public NormalizerDescriptionSchemaParser()
040    {
041        super( NormalizerDescription.class, I18n.ERR_13854_CANNOT_PARSE_NULL_NORM, I18n.ERR_13855_NORM_PARSING_FAILURE,
042            I18n.ERR_13856_NORM_DESC_PARSING_FAILURE );
043    }
044
045
046    /**
047     * Parses a normalizer description:
048     * 
049     * <pre>
050     * NormalizerDescription = LPAREN WSP
051     *     numericoid                           ; object identifier
052     *     [ SP "DESC" SP qdstring ]            ; description
053     *     SP "FQCN" SP fqcn                    ; fully qualified class name
054     *     [ SP "BYTECODE" SP base64 ]          ; optional base64 encoded bytecode
055     *     extensions WSP RPAREN                ; extensions
056     * 
057     * base64          = *(4base64-char)
058     * base64-char     = ALPHA / DIGIT / "+" / "/"
059     * fqcn = fqcnComponent 1*( DOT fqcnComponent )
060     * fqcnComponent = ???
061     * 
062     * extensions = *( SP xstring SP qdstrings )
063     * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 
064     * </pre>
065     * 
066     * @param normalizerDescription the normalizer description to be parsed
067     * @return the parsed NormalizerDescription bean
068     * @throws ParseException if there are any recognition errors (bad syntax)
069     */
070    public NormalizerDescription parse( String normalizerDescription ) throws ParseException
071    {
072        NormalizerDescription normalizer = fastParser.parseNormalizer( normalizerDescription );
073        normalizer.setSpecification( normalizerDescription );
074
075        // Update the schemaName
076        updateSchemaName( normalizer );
077
078        return normalizer;
079    }
080}