1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.name; 21 22 23 import java.io.StringReader; 24 import java.util.List; 25 26 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; 27 import org.apache.directory.api.ldap.model.message.ResultCodeEnum; 28 29 30 /** 31 * A Dn parser that is able to parse complex DNs. This is an Antlr based parser. 32 * 33 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 34 */ 35 /* No protection*/class ComplexDnParser 36 { 37 38 /** 39 * Parses an Dn. 40 * 41 * @param name the string representation of the distinguished name 42 * @param rdns the (empty) list where parsed RDNs are put to 43 * 44 * @throws LdapInvalidDnException the invalid name exception 45 */ 46 /* No protection*/void parseDn( String name, List<Rdn> rdns ) throws LdapInvalidDnException 47 { 48 AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) ); 49 50 try 51 { 52 dnParser.relativeDistinguishedNames( rdns ); 53 } 54 catch ( Exception e ) 55 { 56 throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, e.getMessage(), e ); 57 } 58 } 59 60 61 /** 62 * Parses an Rdn. 63 * 64 * @param name the string representationof the relative distinguished name 65 * @param rdn the (empty) Rdn where parsed ATAVs are put to 66 * 67 * @throws LdapInvalidDnException the invalid name exception 68 */ 69 /* No protection*/void parseRdn( String name, Rdn rdn ) throws LdapInvalidDnException 70 { 71 AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) ); 72 73 try 74 { 75 dnParser.relativeDistinguishedName( rdn ); 76 } 77 catch ( Exception e ) 78 { 79 throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, e.getMessage(), e ); 80 } 81 } 82 }