1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.api.ldap.aci;
22
23
24 import java.io.StringReader;
25 import java.text.ParseException;
26
27 import org.apache.directory.api.i18n.I18n;
28 import org.apache.directory.api.ldap.model.schema.SchemaManager;
29 import org.apache.directory.api.ldap.model.schema.normalizers.NameComponentNormalizer;
30 import org.apache.directory.api.util.StringConstants;
31
32 import antlr.RecognitionException;
33 import antlr.TokenStreamException;
34
35
36
37
38
39
40
41
42
43 public class ACIItemParser
44 {
45
46 private ReusableAntlrACIItemParser parser;
47
48
49 private ReusableAntlrACIItemLexer lexer;
50
51
52 private final boolean isNormalizing;
53
54
55
56
57
58
59
60 public ACIItemParser( SchemaManager schemaManager )
61 {
62 this.lexer = new ReusableAntlrACIItemLexer( new StringReader( "" ) );
63 this.parser = new ReusableAntlrACIItemParser( lexer );
64
65
66
67 this.parser.init( schemaManager );
68
69 this.isNormalizing = false;
70 }
71
72
73
74
75
76
77
78
79 public ACIItemParser( NameComponentNormalizer normalizer, SchemaManager schemaManager )
80 {
81 this.lexer = new ReusableAntlrACIItemLexer( new StringReader( "" ) );
82 this.parser = new ReusableAntlrACIItemParser( lexer );
83
84 this.parser.setNormalizer( normalizer );
85 this.isNormalizing = true;
86
87
88
89 this.parser.init( schemaManager );
90 }
91
92
93
94
95
96
97
98
99 private synchronized void reset( String spec )
100 {
101 StringReader in = new StringReader( spec );
102 this.lexer.prepareNextInput( in );
103 this.parser.resetState();
104 }
105
106
107
108
109
110
111
112
113
114
115
116 public synchronized ACIItem parse( String spec ) throws ParseException
117 {
118 ACIItem aCIItem;
119
120 if ( ( spec == null ) || StringConstants.EMPTY.equals( spec.trim() ) )
121 {
122 return null;
123 }
124
125
126 reset( spec );
127
128 try
129 {
130 aCIItem = this.parser.wrapperEntryPoint();
131 }
132 catch ( TokenStreamException e )
133 {
134 throw new ParseException( I18n
135 .err( I18n.ERR_07004_PARSER_FAILURE_ACI_ITEM, spec, e.getLocalizedMessage() ), 0 );
136 }
137 catch ( RecognitionException e )
138 {
139 throw new ParseException(
140 I18n
141 .err( I18n.ERR_07004_PARSER_FAILURE_ACI_ITEM, spec, e.getLocalizedMessage(), e.getLine(),
142 e.getColumn() ), e.getColumn() );
143 }
144
145 return aCIItem;
146 }
147
148
149
150
151
152
153
154 public boolean isNormizing()
155 {
156 return this.isNormalizing;
157 }
158 }