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.model.schema.syntaxCheckers;
21
22
23 import org.apache.directory.api.asn1.util.Oid;
24 import org.apache.directory.api.i18n.I18n;
25 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
26 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
27 import org.apache.directory.api.util.Strings;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 @SuppressWarnings("serial")
46 public final class NumericOidSyntaxChecker extends SyntaxChecker
47 {
48
49
50
51 public static final NumericOidSyntaxChecker INSTANCE =
52 new NumericOidSyntaxChecker( SchemaConstants.NUMERIC_OID_SYNTAX );
53
54
55
56
57 public static final class Builder extends SCBuilder<NumericOidSyntaxChecker>
58 {
59
60
61
62 private Builder()
63 {
64 super( SchemaConstants.NUMERIC_OID_SYNTAX );
65 }
66
67
68
69
70
71
72 @Override
73 public NumericOidSyntaxChecker build()
74 {
75 return new NumericOidSyntaxChecker( oid );
76 }
77 }
78
79
80
81
82
83
84
85 private NumericOidSyntaxChecker( String oid )
86 {
87 super( oid );
88 }
89
90
91
92
93
94 public static Builder builder()
95 {
96 return new Builder();
97 }
98
99
100
101
102
103 @Override
104 public boolean isValidSyntax( Object value )
105 {
106 String strValue;
107
108 if ( value == null )
109 {
110 if ( LOG.isDebugEnabled() )
111 {
112 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
113 }
114
115 return false;
116 }
117
118 if ( value instanceof String )
119 {
120 strValue = ( String ) value;
121 }
122 else if ( value instanceof byte[] )
123 {
124 strValue = Strings.utf8ToString( ( byte[] ) value );
125 }
126 else
127 {
128 strValue = value.toString();
129 }
130
131 if ( strValue.length() == 0 )
132 {
133 if ( LOG.isDebugEnabled() )
134 {
135 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
136 }
137
138 return false;
139 }
140
141
142 boolean result = Oid.isOid( strValue );
143
144 if ( LOG.isDebugEnabled() )
145 {
146 if ( result )
147 {
148 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
149 }
150 else
151 {
152 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
153 }
154 }
155
156 return result;
157 }
158 }