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    import org.apache.directory.shared.ldap.constants.SchemaConstants;
023    import org.apache.directory.shared.ldap.schema.AbstractSyntaxChecker;
024    import org.apache.directory.shared.ldap.schema.SyntaxChecker;
025    
026    
027    /**
028     * An UUID syntax checker.
029     * 
030     * UUID ::= OCTET STRING (SIZE(16)) -- constrained to an UUID [RFC4122]
031     * 
032     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033     * @version $Rev: 736240 $
034     */
035    public class UuidSyntaxChecker extends AbstractSyntaxChecker
036    {
037        /** the Apache assigned internal OID for this syntax checker */
038        public static final SyntaxChecker INSTANCE = new UuidSyntaxChecker();
039    
040    
041        /**
042         * Creates a new instance of UUIDSyntaxChecker.
043         */
044        public UuidSyntaxChecker()
045        {
046            super( SchemaConstants.UUID_SYNTAX );
047        }
048    
049    
050        /**
051         * 
052         * Creates a new instance of UUIDSyntaxChecker.
053         * 
054         * @param oid the oid to associate with this new SyntaxChecker
055         *
056         */
057        protected UuidSyntaxChecker( String oid )
058        {
059            super( oid );
060        }
061    
062        
063        /**
064         * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(Object)
065         * 
066         * @param value the value of some attribute with the syntax
067         * @return true if the value is in the valid syntax, false otherwise
068         */
069        public boolean isValidSyntax( Object value )
070        {
071            if ( value == null )
072            {
073                return false;
074            }
075            
076            if ( ! ( value instanceof byte[] ) )
077            {
078                return false;
079            }
080            
081            byte[] uuid = (byte[])value;
082            
083            // The UUID must have a length of 16 bytes
084            if ( uuid.length != 16 )
085            {
086                return false;
087            }
088            
089            // There is not that much we can check.
090            return true;
091        }
092    }