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 objectClass' type is either: 
029     * AUXILIARY, STRUCTURAL, or ABSTRACT.  The case is NOT ignored.
030     *
031     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032     * @version $Rev$
033     */
034    public class ObjectClassTypeSyntaxChecker extends AbstractSyntaxChecker
035    {
036        /** The Apache OID for meta syntax checker */
037        private static final String SC_OID = "1.3.6.1.4.1.18060.0.4.0.0.1";
038        
039        /**
040         * 
041         * Creates a new instance of ObjectClassTypeSyntaxChecker.
042         *
043         */
044        public ObjectClassTypeSyntaxChecker()
045        {
046            super( SC_OID );
047        }
048    
049        
050        /**
051         * 
052         * Creates a new instance of ObjectClassTypeSyntaxChecker.
053         * 
054         * @param oid the oid to associate with this new SyntaxChecker
055         *
056         */
057        protected ObjectClassTypeSyntaxChecker( String oid )
058        {
059            super( oid );
060        }
061        
062        /* (non-Javadoc)
063         * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
064         */
065        public boolean isValidSyntax( Object value )
066        {
067            String strValue = null;
068    
069            if ( value == null )
070            {
071                return false;
072            }
073            
074            if ( value instanceof String )
075            {
076                strValue = ( String ) value;
077            }
078            else if ( value instanceof byte[] )
079            {
080                strValue = StringTools.utf8ToString( ( byte[] ) value ); 
081            }
082            else
083            {
084                strValue = value.toString();
085            }
086    
087            if ( strValue.length() < 8 || strValue.length() > 10 )
088            {
089                return false;
090            }
091            
092            char ch = strValue.charAt( 0 );
093    
094            switch( ch )
095            {
096                case( 'A' ):
097                    if ( "AUXILIARY".equals( strValue ) || "ABSTRACT".equals( strValue ) )
098                    {
099                        return true;
100                    }
101    
102                    return false;
103                
104                case( 'S' ):
105                    return "STRUCTURAL".equals( strValue );
106                
107                default:
108                    return false;
109            }
110        }
111    }