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.extended.ads_impl.cancel;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
25 import org.apache.directory.api.asn1.ber.grammar.Grammar;
26 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
27 import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
28 import org.apache.directory.api.asn1.ber.tlv.BerValue;
29 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoder;
30 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException;
31 import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
32 import org.apache.directory.api.i18n.I18n;
33 import org.apache.directory.api.util.Strings;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public final class CancelRequestGrammar extends AbstractGrammar<CancelRequestContainer>
53 {
54
55 static final Logger LOG = LoggerFactory.getLogger( CancelRequestGrammar.class );
56
57
58 private static Grammar<CancelRequestContainer> instance = new CancelRequestGrammar();
59
60
61
62
63
64 @SuppressWarnings("unchecked")
65 private CancelRequestGrammar()
66 {
67 setName( CancelRequestGrammar.class.getName() );
68
69
70 super.transitions = new GrammarTransition[CancelStatesEnum.LAST_CANCEL_STATE.ordinal()][256];
71
72
73
74
75
76
77
78
79 super.transitions[CancelStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
80 new GrammarTransition<CancelRequestContainer>( CancelStatesEnum.START_STATE,
81 CancelStatesEnum.CANCEL_SEQUENCE_STATE,
82 UniversalTag.SEQUENCE.getValue(),
83 null );
84
85
86
87
88
89
90
91
92
93
94 super.transitions[CancelStatesEnum.CANCEL_SEQUENCE_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
95 new GrammarTransition<CancelRequestContainer>( CancelStatesEnum.CANCEL_SEQUENCE_STATE,
96 CancelStatesEnum.CANCEL_ID_STATE,
97 UniversalTag.INTEGER.getValue(),
98 new GrammarAction<CancelRequestContainer>( "Stores CancelId" )
99 {
100 public void action( CancelRequestContainer cancelContainer ) throws DecoderException
101 {
102 BerValue value = cancelContainer.getCurrentTLV().getValue();
103
104 try
105 {
106 int cancelId = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
107
108 if ( LOG.isDebugEnabled() )
109 {
110 LOG.debug( I18n.msg( I18n.MSG_08200_CANCEL_ID, cancelId ) );
111 }
112
113 cancelContainer.getCancelRequest().setCancelId( cancelId );
114
115 cancelContainer.setGrammarEndAllowed( true );
116 }
117 catch ( IntegerDecoderException ide )
118 {
119 String msg = I18n.err( I18n.ERR_08200_CANCELID_DECODING_FAILED, Strings.dumpBytes( value.getData() ) );
120 LOG.error( msg );
121 throw new DecoderException( msg, ide );
122 }
123 }
124 } );
125 }
126
127
128
129
130
131
132
133 public static Grammar<CancelRequestContainer> getInstance()
134 {
135 return instance;
136 }
137 }