1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.extras.controls.ad_impl;
21
22 import org.apache.directory.api.asn1.DecoderException;
23 import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
24 import org.apache.directory.api.asn1.ber.grammar.Grammar;
25 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
26 import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
27 import org.apache.directory.api.asn1.ber.tlv.BerValue;
28 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoder;
29 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException;
30 import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
31 import org.apache.directory.api.i18n.I18n;
32 import org.apache.directory.api.util.Strings;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public final class AdDirSyncRequestGrammar extends AbstractGrammar<AdDirSyncRequestContainer>
55 {
56
57
58 private static final Logger LOG = LoggerFactory.getLogger( AdDirSyncRequestGrammar.class );
59
60
61 private static final AdDirSyncRequestGrammar INSTANCE = new AdDirSyncRequestGrammar();
62
63
64
65
66
67
68
69 @SuppressWarnings("unchecked")
70 private AdDirSyncRequestGrammar()
71 {
72 setName( AdDirSyncRequestGrammar.class.getName() );
73
74 super.transitions = new GrammarTransition[AdDirSyncRequestStatesEnum.LAST_AD_DIR_SYNC_REQUEST_STATE.ordinal()][256];
75
76
77
78
79
80
81
82
83 super.transitions[AdDirSyncRequestStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
84 new GrammarTransition<AdDirSyncRequestContainer>(
85 AdDirSyncRequestStatesEnum.START_STATE, AdDirSyncRequestStatesEnum.AD_DIR_SYNC_REQUEST_SEQUENCE_STATE,
86 UniversalTag.SEQUENCE.getValue(),
87 new GrammarAction<AdDirSyncRequestContainer>( "Initialization" )
88 {
89 @Override
90 public void action( AdDirSyncRequestContainer container ) throws DecoderException
91 {
92 }
93 } );
94
95
96
97
98
99
100
101
102
103 super.transitions[AdDirSyncRequestStatesEnum.AD_DIR_SYNC_REQUEST_SEQUENCE_STATE.ordinal()][UniversalTag.INTEGER
104 .getValue()] =
105 new GrammarTransition<AdDirSyncRequestContainer>( AdDirSyncRequestStatesEnum.AD_DIR_SYNC_REQUEST_SEQUENCE_STATE,
106 AdDirSyncRequestStatesEnum.PARENTS_FIRST_STATE, UniversalTag.INTEGER.getValue(),
107 new GrammarAction<AdDirSyncRequestContainer>( "Set AdDirSyncRequestControl parentsFirst" )
108 {
109 @Override
110 public void action( AdDirSyncRequestContainer container ) throws DecoderException
111 {
112 BerValue value = container.getCurrentTLV().getValue();
113
114 try
115 {
116 int parentsFirst = IntegerDecoder.parse( value );
117
118 if ( LOG.isDebugEnabled() )
119 {
120 LOG.debug( I18n.msg( I18n.MSG_08108_PARENTS_FIRST, parentsFirst ) );
121 }
122
123 container.getAdDirSyncRequest().setParentsFirst( parentsFirst );
124 }
125 catch ( IntegerDecoderException ide )
126 {
127 String msg = I18n.err( I18n.ERR_08107_AD_DIR_SYNC_PARENTS_FIRST_DECODING_ERROR, ide.getMessage() );
128 LOG.error( msg, ide );
129 throw new DecoderException( msg, ide );
130 }
131 }
132 } );
133
134
135
136
137
138
139
140
141
142
143 super.transitions[AdDirSyncRequestStatesEnum.PARENTS_FIRST_STATE.ordinal()][UniversalTag.INTEGER
144 .getValue()] =
145 new GrammarTransition<AdDirSyncRequestContainer>( AdDirSyncRequestStatesEnum.PARENTS_FIRST_STATE,
146 AdDirSyncRequestStatesEnum.MAX_ATTRIBUTE_COUNT_STATE, UniversalTag.INTEGER.getValue(),
147 new GrammarAction<AdDirSyncRequestContainer>( "Set AdDirSyncRequestControl maxAttributeCount" )
148 {
149 @Override
150 public void action( AdDirSyncRequestContainer container ) throws DecoderException
151 {
152 BerValue value = container.getCurrentTLV().getValue();
153
154 try
155 {
156 int maxAttributeCount = IntegerDecoder.parse( value );
157
158 if ( LOG.isDebugEnabled() )
159 {
160 LOG.debug( I18n.msg( I18n.MSG_08109_MAX_ATTRIBUTE_COUNT, maxAttributeCount ) );
161 }
162
163 container.getAdDirSyncRequest().setMaxAttributeCount( maxAttributeCount );
164 }
165 catch ( IntegerDecoderException ide )
166 {
167 String msg = I18n.err( I18n.ERR_08108_AD_DIR_SYNC_MAX_ATTRIBUTE_COUNT_DECODING_ERROR, ide.getMessage() );
168 LOG.error( msg, ide );
169 throw new DecoderException( msg, ide );
170 }
171 }
172 } );
173
174
175
176
177
178
179
180
181
182 super.transitions[AdDirSyncRequestStatesEnum.MAX_ATTRIBUTE_COUNT_STATE.ordinal()][UniversalTag.OCTET_STRING
183 .getValue()] =
184 new GrammarTransition<AdDirSyncRequestContainer>( AdDirSyncRequestStatesEnum.MAX_ATTRIBUTE_COUNT_STATE,
185 AdDirSyncRequestStatesEnum.COOKIE_STATE, UniversalTag.OCTET_STRING.getValue(),
186 new GrammarAction<AdDirSyncRequestContainer>( "Set AdDirSyncRequestControl cookie" )
187 {
188 @Override
189 public void action( AdDirSyncRequestContainer container )
190 {
191 BerValue value = container.getCurrentTLV().getValue();
192
193 byte[] cookie = value.getData();
194
195 if ( LOG.isDebugEnabled() )
196 {
197 LOG.debug( I18n.msg( I18n.MSG_08000_COOKIE, Strings.dumpBytes( cookie ) ) );
198 }
199
200 container.getAdDirSyncRequest().setCookie( cookie );
201
202 container.setGrammarEndAllowed( true );
203 }
204 } );
205 }
206
207
208
209
210
211 public static Grammar<AdDirSyncRequestContainer> getInstance()
212 {
213 return INSTANCE;
214 }
215 }