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 private synchronized void reset( String spec )
98 {
99 StringReader in = new StringReader( spec );
100 this.lexer.prepareNextInput( in );
101 this.parser.resetState();
102 }
103
104
105
106
107
108
109
110
111
112
113
114 public synchronized ACIItem parse( String spec ) throws ParseException
115 {
116 ACIItem aCIItem;
117
118 if ( spec == null || StringConstants.EMPTY .equals( spec.trim() ) )
119 {
120 return null;
121 }
122
123
124 reset( spec );
125
126 try
127 {
128 aCIItem = this.parser.wrapperEntryPoint();
129 }
130 catch ( TokenStreamException e )
131 {
132 throw new ParseException( I18n
133 .err( I18n.ERR_04004_PARSER_FAILURE_ACI_ITEM, spec, e.getLocalizedMessage() ), 0 );
134 }
135 catch ( RecognitionException e )
136 {
137 throw new ParseException(
138 I18n
139 .err( I18n.ERR_04004_PARSER_FAILURE_ACI_ITEM, spec, e.getLocalizedMessage(), e.getLine(),
140 e.getColumn() ), e.getColumn() );
141 }
142
143 return aCIItem;
144 }
145
146
147
148
149
150
151
152 public boolean isNormizing()
153 {
154 return this.isNormalizing;
155 }
156 }