View Javadoc
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  import org.apache.directory.api.ldap.model.name.AntlrDnLexer;
29  import org.apache.directory.api.ldap.model.name.AntlrDnParser;
30  
31  
32  /**
33   * A Dn parser that is able to parse complex DNs. This is an Antlr based parser.
34   * 
35   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36   */
37  /* No protection*/class ComplexDnParser
38  {
39  
40      /**
41       * Parses an Dn.
42       * 
43       * @param name the string representation of the distinguished name
44       * @param rdns the (empty) list where parsed RDNs are put to
45       * 
46       * @throws LdapInvalidDnException the invalid name exception
47       */
48      /* No protection*/void parseDn( String name, List<Rdn> rdns ) throws LdapInvalidDnException
49      {
50          AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) );
51  
52          try
53          {
54              dnParser.relativeDistinguishedNames( rdns );
55          }
56          catch ( Exception e )
57          {
58              throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, e.getMessage(), e );
59          }
60      }
61  
62  
63      /**
64       * Parses an Rdn.
65       * 
66       * @param name the string representationof the relative distinguished name
67       * @param rdn the (empty) Rdn where parsed ATAVs are put to
68       * 
69       * @throws LdapInvalidDnException the invalid name exception
70       */
71      /* No protection*/void parseRdn( String name, Rdn rdn ) throws LdapInvalidDnException
72      {
73          AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) );
74  
75          try
76          {
77              dnParser.relativeDistinguishedName( rdn );
78          }
79          catch ( Exception e )
80          {
81              throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, e.getMessage(), e );
82          }
83      }
84  }