001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.schema.syntaxes;
021
022
023 import org.apache.directory.shared.ldap.schema.AbstractSyntaxChecker;
024 import org.apache.directory.shared.ldap.util.StringTools;
025
026
027 /**
028 * A syntax checker which checks to see if an attributeType's type is either:
029 * userApplications
030 * directoryOperation
031 * distributedOperation
032 * dSAOperation
033 .* The case is NOT ignored.
034 *
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 * @version $Rev$
037 */
038 public class AttributeTypeUsageSyntaxChecker extends AbstractSyntaxChecker
039 {
040 /** The Apache OID for meta syntax checker */
041 private static final String SC_OID = "1.3.6.1.4.1.18060.0.4.0.0.3";
042
043 /**
044 *
045 * Creates a new instance of AttributeTypeUsageSyntaxChecker.
046 *
047 */
048 public AttributeTypeUsageSyntaxChecker()
049 {
050 super( SC_OID );
051 }
052
053 /**
054 *
055 * Creates a new instance of AttributeTypeUsageSyntaxChecker.
056 *
057 * @param oid the oid to associate with this new SyntaxChecker
058 *
059 */
060 protected AttributeTypeUsageSyntaxChecker( String oid )
061 {
062 super( oid );
063 }
064
065 /* (non-Javadoc)
066 * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
067 */
068 public boolean isValidSyntax( Object value )
069 {
070 String strValue = null;
071
072 if ( value == null )
073 {
074 return false;
075 }
076
077 if ( value instanceof String )
078 {
079 strValue = ( String ) value;
080 }
081 else if ( value instanceof byte[] )
082 {
083 strValue = StringTools.utf8ToString( ( byte[] ) value );
084 }
085 else
086 {
087 strValue = value.toString();
088 }
089
090 if ( strValue.length() < "userApplications".length() ||
091 strValue.length() > "userApplications".length() )
092 {
093 return false;
094 }
095
096 char ch = strValue.charAt( 0 );
097
098 switch ( ch )
099 {
100 case( 'd' ):
101 if ( "dSAOperation".equals( strValue ) ||
102 "directoryOperation".equals( strValue ) ||
103 "distributedOperation".equals( strValue ) )
104 {
105 return true;
106 }
107
108 return false;
109
110 case( 'u' ):
111 return "userApplications".equals( strValue );
112
113 default:
114 return false;
115 }
116 }
117 }