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, eCopyOfUuidSyntaxCheckerither 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    import org.apache.directory.shared.ldap.constants.SchemaConstants;
023    import org.apache.directory.shared.ldap.csn.Csn;
024    import org.apache.directory.shared.ldap.csn.InvalidCSNException;
025    import org.apache.directory.shared.ldap.schema.AbstractSyntaxChecker;
026    import org.apache.directory.shared.ldap.schema.SyntaxChecker;
027    
028    
029    /**
030     * An CSN syntax checker.
031     * 
032     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033     * @version $Rev: 736240 $
034     */
035    public class CsnSyntaxChecker extends AbstractSyntaxChecker
036    {
037        /** the Apache assigned internal OID for this syntax checker */
038        public static final SyntaxChecker INSTANCE = new CsnSyntaxChecker();
039    
040    
041        /**
042         * Creates a new instance of CsnSyntaxChecker.
043         */
044        public CsnSyntaxChecker()
045        {
046            super( SchemaConstants.CSN_SYNTAX );
047        }
048    
049    
050        /**
051         * 
052         * Creates a new instance of CsnSyntaxChecker.
053         * 
054         * @param oid the oid to associate with this new SyntaxChecker
055         *
056         */
057        protected CsnSyntaxChecker( String oid )
058        {
059            super( oid );
060        }
061    
062        
063        /**
064         * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(Object)
065         * 
066         * The value is stored as a String internally.
067         * 
068         * @param value the value of some attribute with the syntax
069         * @return true if the value is in the valid syntax, false otherwise
070         */
071        public boolean isValidSyntax( Object value )
072        {
073            if ( value == null )
074            {
075                return false;
076            }
077            
078            if ( ! ( value instanceof String ) )
079            {
080                return false;
081            }
082            
083            String csnStr = (String)value;
084            
085            // It must be a valid CSN : try to create a new one.
086            try
087            {
088                return Csn.isValid( csnStr );
089            }
090            catch ( InvalidCSNException icsne )
091            {
092                return false;
093            }
094        }
095    }