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.ldap.codec.api.LdapApiServiceFactory;
34 import org.apache.directory.api.ldap.extras.extended.cancel.CancelRequestImpl;
35 import org.apache.directory.api.util.Strings;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public final class CancelGrammar extends AbstractGrammar<CancelContainer>
55 {
56
57 static final Logger LOG = LoggerFactory.getLogger( CancelGrammar.class );
58
59
60 static final boolean IS_DEBUG = LOG.isDebugEnabled();
61
62
63 private static Grammar<CancelContainer> instance = new CancelGrammar();
64
65
66
67
68
69 @SuppressWarnings("unchecked")
70 private CancelGrammar()
71 {
72 setName( CancelGrammar.class.getName() );
73
74
75 super.transitions = new GrammarTransition[CancelStatesEnum.LAST_CANCEL_STATE.ordinal()][256];
76
77
78
79
80
81
82
83
84 super.transitions[CancelStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
85 new GrammarTransition<CancelContainer>( CancelStatesEnum.START_STATE,
86 CancelStatesEnum.CANCEL_SEQUENCE_STATE,
87 UniversalTag.SEQUENCE.getValue(),
88 new GrammarAction<CancelContainer>( "Init Cancel" )
89 {
90 public void action( CancelContainer cancelContainer )
91 {
92 CancelRequestDecorator cancel = new CancelRequestDecorator(
93 LdapApiServiceFactory.getSingleton(),
94 new CancelRequestImpl() );
95
96 cancelContainer.setCancel( cancel );
97 }
98 } );
99
100
101
102
103
104
105
106
107
108
109 super.transitions[CancelStatesEnum.CANCEL_SEQUENCE_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
110 new GrammarTransition<CancelContainer>( CancelStatesEnum.CANCEL_SEQUENCE_STATE,
111 CancelStatesEnum.CANCEL_ID_STATE,
112 UniversalTag.INTEGER.getValue(),
113 new GrammarAction<CancelContainer>( "Stores CancelId" )
114 {
115 public void action( CancelContainer cancelContainer ) throws DecoderException
116 {
117 BerValue value = cancelContainer.getCurrentTLV().getValue();
118
119 try
120 {
121 int cancelId = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
122
123 if ( IS_DEBUG )
124 {
125 LOG.debug( "CancelId = " + cancelId );
126 }
127
128 cancelContainer.getCancel().setCancelId( cancelId );
129 cancelContainer.setGrammarEndAllowed( true );
130 }
131 catch ( IntegerDecoderException e )
132 {
133 String msg = I18n.err( I18n.ERR_04031, Strings.dumpBytes( value.getData() ) );
134 LOG.error( msg );
135 throw new DecoderException( msg );
136 }
137 }
138 } );
139 }
140
141
142
143
144
145
146
147 public static Grammar<CancelContainer> getInstance()
148 {
149 return instance;
150 }
151 }