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
31 import antlr.RecognitionException;
32 import antlr.TokenStreamException;
33
34
35
36
37
38
39
40
41
42 public class ACIItemParser
43 {
44
45 private ReusableAntlrACIItemParser parser;
46
47
48 private ReusableAntlrACIItemLexer lexer;
49
50
51 private final boolean isNormalizing;
52
53
54
55
56
57
58
59 public ACIItemParser( SchemaManager schemaManager )
60 {
61 this.lexer = new ReusableAntlrACIItemLexer( new StringReader( "" ) );
62 this.parser = new ReusableAntlrACIItemParser( lexer );
63
64
65
66 this.parser.init( schemaManager );
67
68 this.isNormalizing = false;
69 }
70
71
72
73
74
75
76
77
78 public ACIItemParser( NameComponentNormalizer normalizer, SchemaManager schemaManager )
79 {
80 this.lexer = new ReusableAntlrACIItemLexer( new StringReader( "" ) );
81 this.parser = new ReusableAntlrACIItemParser( lexer );
82
83 this.parser.setNormalizer( normalizer );
84 this.isNormalizing = true;
85
86
87
88 this.parser.init( schemaManager );
89 }
90
91
92
93
94
95
96 private synchronized void reset( String spec )
97 {
98 StringReader in = new StringReader( spec );
99 this.lexer.prepareNextInput( in );
100 this.parser.resetState();
101 }
102
103
104
105
106
107
108
109
110
111
112
113 public synchronized ACIItem parse( String spec ) throws ParseException
114 {
115 ACIItem aCIItem = null;
116
117 if ( spec == null || spec.trim().equals( "" ) )
118 {
119 return null;
120 }
121
122 reset( spec );
123
124 try
125 {
126 aCIItem = this.parser.wrapperEntryPoint();
127 }
128 catch ( TokenStreamException e )
129 {
130 throw new ParseException( I18n
131 .err( I18n.ERR_04004_PARSER_FAILURE_ACI_ITEM, spec, e.getLocalizedMessage() ), 0 );
132 }
133 catch ( RecognitionException e )
134 {
135 throw new ParseException(
136 I18n
137 .err( I18n.ERR_04004_PARSER_FAILURE_ACI_ITEM, spec, e.getLocalizedMessage(), e.getLine(),
138 e.getColumn() ), e.getColumn() );
139 }
140
141 return aCIItem;
142 }
143
144
145
146
147
148
149
150 public boolean isNormizing()
151 {
152 return this.isNormalizing;
153 }
154 }