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