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