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;
021    
022    import org.apache.directory.shared.i18n.I18n;
023    
024    
025    /**
026     * Type safe enumerations for an objectClass' type. An ObjectClass type can be
027     * one of the following types:
028     * <ul>
029     * <li>ABSTRACT</li>
030     * <li>AUXILIARY</li>
031     * <li>STRUCTURAL</li>
032     * </ul>
033     * 
034     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035     */
036    public enum ObjectClassTypeEnum
037    {
038        /** The enumeration constant value for the abstract objectClasses */
039        ABSTRACT( 0 ),
040    
041        /** The enumeration constant value for the auxillary objectClasses */
042        AUXILIARY( 1 ),
043    
044        /** The enumeration constant value for the structural objectClasses */
045        STRUCTURAL( 2 );
046    
047        /** The int constant value for the abstract objectClasses */
048        public static final int ABSTRACT_VAL = 0;
049    
050        /** The int constant value for the auxillary objectClasses */
051        public static final int AUXILIARY_VAL = 1;
052    
053        /** The int constant value for the structural objectClasses */
054        public static final int STRUCTURAL_VAL=2;
055        
056        /** Stores the integer value of each element of the enumeration */
057        private int value;
058        
059        /**
060         * Private constructor so no other instances can be created other than the
061         * public static constants in this class.
062         * 
063         * @param name
064         *            a string name for the enumeration value.
065         * @param value
066         *            the integer value of the enumeration.
067         */
068        private ObjectClassTypeEnum( int value )
069        {
070            this.value = value;
071        }
072    
073        
074        /**
075         * @return The value associated with the current element.
076         */
077        public int getValue()
078        {
079            return value;
080        }
081    
082        /**
083         * Gets the objectClass type enumeration of AUXILIARY, STRUCTURAL, or,
084         * ABSTRACT.
085         * 
086         * @param name options are AUXILIARY, STRUCTURAL, or, ABSTRACT
087         * 
088         * @return the type safe enumeration for the objectClass type
089         */
090        public static ObjectClassTypeEnum getClassType( String name )
091        {
092            String upperCase = name.trim().toUpperCase();
093    
094            if ( upperCase.equals( "STRUCTURAL" ) )
095            {
096                return STRUCTURAL;
097            }
098            else if ( upperCase.equals( "AUXILIARY" ) )
099            {
100                return AUXILIARY;
101            }
102            else if ( upperCase.equals( "ABSTRACT" ) )
103            {
104                return ABSTRACT;
105            }
106    
107            throw new IllegalArgumentException( I18n.err( I18n.ERR_04327, name) );
108        }
109    }