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