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;
026import org.apache.directory.api.ldap.model.schema.AttributeType;
027
028
029/**
030 * A parser for RFC 4512 attribute type descriptions.
031 * 
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class AttributeTypeDescriptionSchemaParser extends AbstractSchemaParser<AttributeType>
035{
036    /**
037     * Creates a schema parser instance.
038     */
039    public AttributeTypeDescriptionSchemaParser()
040    {
041        super( AttributeType.class, I18n.ERR_13830_CANNOT_PARSE_NULL_ATTR_TYPE, I18n.ERR_13831_ATTRIBUTE_TYPE_PARSING_FAILURE, 
042            I18n.ERR_13832_ATTRIBUTE_TYPE_DESC_PARSE_FAILURE );
043    }
044
045
046    /**
047     * Parses a attribute type description according to RFC 4512:
048     * 
049     * <pre>
050     * AttributeTypeDescription = LPAREN WSP
051     *     numericoid                    ; object identifier
052     *     [ SP "NAME" SP qdescrs ]      ; short names (descriptors)
053     *     [ SP "DESC" SP qdstring ]     ; description
054     *     [ SP "OBSOLETE" ]             ; not active
055     *     [ SP "SUP" SP oid ]           ; supertype
056     *     [ SP "EQUALITY" SP oid ]      ; equality matching rule
057     *     [ SP "ORDERING" SP oid ]      ; ordering matching rule
058     *     [ SP "SUBSTR" SP oid ]        ; substrings matching rule
059     *     [ SP "SYNTAX" SP noidlen ]    ; value syntax
060     *     [ SP "SINGLE-VALUE" ]         ; single-value
061     *     [ SP "COLLECTIVE" ]           ; collective
062     *     [ SP "NO-USER-MODIFICATION" ] ; not user modifiable
063     *     [ SP "USAGE" SP usage ]       ; usage
064     *     extensions WSP RPAREN         ; extensions
065     * 
066     * usage = "userApplications"     /  ; user
067     *         "directoryOperation"   /  ; directory operational
068     *         "distributedOperation" /  ; DSA-shared operational
069     *         "dSAOperation"            ; DSA-specific operational     
070     * 
071     * extensions = *( SP xstring SP qdstrings )
072     * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 
073     * </pre>
074     * 
075     * @param attributeTypeDescription the attribute type description to be parsed
076     * @return the parsed AttributeTypeDescription bean
077     * @throws ParseException if there are any recognition errors (bad syntax)
078     */
079    public AttributeType parse( String attributeTypeDescription ) throws ParseException
080    {
081        AttributeType attributeType = fastParser.parseAttributeType( attributeTypeDescription );
082        attributeType.setSpecification( attributeTypeDescription );
083
084        // Update the schemaName
085        updateSchemaName( attributeType );
086
087        return attributeType;
088    }
089}