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.asn1.actions;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.ber.Asn1Container;
25 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
26 import org.apache.directory.api.asn1.ber.tlv.BerValue;
27 import org.apache.directory.api.asn1.ber.tlv.TLV;
28 import org.apache.directory.api.i18n.I18n;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38
39
40 public abstract class AbstractReadOctetString<C extends Asn1Container> extends GrammarAction<C>
41 {
42
43 private static final Logger LOG = LoggerFactory.getLogger( AbstractReadOctetString.class );
44
45
46 private boolean canBeNull = Boolean.FALSE;
47
48
49
50
51
52
53
54 public AbstractReadOctetString( String name )
55 {
56 super( name );
57 }
58
59
60
61
62
63
64
65
66 public AbstractReadOctetString( String name, boolean canBeNull )
67 {
68 super( name );
69
70 this.canBeNull = canBeNull;
71 }
72
73
74
75
76
77
78
79
80 protected abstract void setOctetString( byte[] value, C container );
81
82
83
84
85
86 @Override
87 public final void action( C container ) throws DecoderException
88 {
89 TLV tlv = container.getCurrentTLV();
90
91
92 if ( ( tlv.getLength() == 0 ) && ( !canBeNull ) )
93 {
94 LOG.error( I18n.err( I18n.ERR_04066 ) );
95
96
97 throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
98 }
99
100 BerValue value = tlv.getValue();
101
102
103 if ( ( value.getData() == null ) && ( !canBeNull ) )
104 {
105 LOG.error( I18n.err( I18n.ERR_04066 ) );
106
107
108 throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
109 }
110
111 setOctetString( value.getData(), container );
112 }
113 }