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     *    http://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     */
020    package org.apache.directory.shared.ldap.name;
021    
022    
023    import java.io.StringReader;
024    import java.util.List;
025    
026    import javax.naming.InvalidNameException;
027    
028    
029    /**
030     * A DN parser that is able to parse complex DNs. This is an Antlr based parser.
031     * 
032     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033     * @version $Rev: 664290 $, $Date: 2008-06-07 08:28:06 +0200 (Sa, 07 Jun 2008) $
034     */
035    public class ComplexLdapDnParser
036    {
037    
038        /**
039         * Parses an DN.
040         * 
041         * @param name the string representation of the distinguished name
042         * @param rdns the (empty) list where parsed RDNs are put to
043         * 
044         * @throws InvalidNameException the invalid name exception
045         */
046        public void parseDn( String name, List<Rdn> rdns ) throws InvalidNameException
047        {
048            AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) );
049            try
050            {
051                dnParser.relativeDistinguishedNames( rdns );
052            }
053            catch ( Exception e )
054            {
055                InvalidNameException ine = new InvalidNameException( e.getMessage() );
056                ine.setRootCause( e );
057                throw ine;
058            }
059        }
060    
061    
062        /**
063         * Parses an RDN.
064         * 
065         * @param name the string representationof the relative distinguished name
066         * @param rdn the (empty) RDN where parsed ATAVs are put to
067         * 
068         * @throws InvalidNameException the invalid name exception
069         */
070        public void parseRdn( String name, Rdn rdn ) throws InvalidNameException
071        {
072            AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) );
073            try
074            {
075                dnParser.relativeDistinguishedName( rdn );
076            }
077            catch ( Exception e )
078            {
079                InvalidNameException ine = new InvalidNameException( e.getMessage() );
080                ine.setRootCause( e );
081                throw ine;
082            }
083        }
084    
085    }