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    
023    import java.io.Serializable;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    
029    /**
030     * Objectclass specification bean used to store the schema information for an
031     * objectclass definition.
032     * 
033     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034     * @version $Rev: 664290 $
035     */
036    public class DefaultObjectClass extends AbstractSchemaObject implements ObjectClass, Serializable
037    {
038        private static final long serialVersionUID = -4744807759763092241L;
039    
040        /** empty array of ObjectClasses so we do not have to recreate objects */
041        private static final ObjectClass[] EMPTY_OCLASS_ARR = new ObjectClass[0];
042    
043        /** empty array of AttributeTypes so we do not have to recreate objects */
044        private static final AttributeType[] EMPTY_ATYPE_ARR = new AttributeType[0];
045    
046        // ------------------------------------------------------------------------
047        // Specification Variables
048        // ------------------------------------------------------------------------
049    
050        /** */
051        private ObjectClassTypeEnum type = ObjectClassTypeEnum.ABSTRACT;
052    
053        /** */
054        private ArrayList<AttributeType> mayList;
055    
056        /** */
057        private ArrayList<AttributeType> mustList;
058    
059        /** */
060        private ArrayList<ObjectClass> superClasses;
061    
062    
063        // ------------------------------------------------------------------------
064        // C O N S T R U C T O R S
065        // ------------------------------------------------------------------------
066    
067        /**
068         * Creates an ObjectClassImpl instance with an OID.
069         * 
070         * @param oid the unique object identifier for this objectClass
071         */
072        DefaultObjectClass(String oid)
073        {
074            super( oid );
075        }
076    
077    
078        // ------------------------------------------------------------------------
079        // ObjectClass Methods
080        // ------------------------------------------------------------------------
081    
082        public ObjectClass[] getSuperClasses()
083        {
084            if ( superClasses == null )
085            {
086                return EMPTY_OCLASS_ARR;
087            }
088    
089            return superClasses.toArray( EMPTY_OCLASS_ARR );
090        }
091    
092    
093        public ObjectClassTypeEnum getType()
094        {
095            return type;
096        }
097    
098    
099        public AttributeType[] getMustList()
100        {
101            if ( mustList == null )
102            {
103                return EMPTY_ATYPE_ARR;
104            }
105    
106            return mustList.toArray( EMPTY_ATYPE_ARR );
107        }
108    
109    
110        public boolean isStructural()
111        {
112            return type == ObjectClassTypeEnum.STRUCTURAL;
113        }
114    
115    
116        public boolean isAbstract()
117        {
118            return type == ObjectClassTypeEnum.ABSTRACT;
119        }
120    
121        
122        public boolean isAuxiliary()
123        {
124            return type == ObjectClassTypeEnum.AUXILIARY;
125        }
126    
127        
128        public AttributeType[] getMayList()
129        {
130            if ( mayList == null )
131            {
132                return EMPTY_ATYPE_ARR;
133            }
134    
135            return mayList.toArray( EMPTY_ATYPE_ARR );
136        }
137    
138    
139        // ------------------------------------------------------------------------
140        // Package Friendly Mutators
141        // ------------------------------------------------------------------------
142    
143        /**
144         * Adds a list of AttributeTypes that may be present within this
145         * ObjectClass.
146         * 
147         * @param mayList
148         *            more AttributeTypes to add to the optional attribute list
149         */
150        void addToMayList( List<AttributeType> mayList )
151        {
152            if ( this.mayList == null )
153            {
154                this.mayList = new ArrayList<AttributeType>();
155            }
156    
157            this.mayList.addAll( mayList );
158        }
159    
160    
161        /**
162         * Adds a list of AttributeTypes that must be present within this
163         * ObjectClass.
164         * 
165         * @param mustList
166         *            more AttributeTypes to add to the mandatory list
167         */
168        void addToMustList( List<AttributeType> mustList )
169        {
170            if ( this.mustList == null )
171            {
172                this.mustList = new ArrayList<AttributeType>();
173            }
174    
175            this.mustList.addAll( mustList );
176        }
177    
178    
179        /**
180         * Adds ObjectClass to the list of super classes for this ObjectClass.
181         * 
182         * @param superClasses
183         *            the list of super classes to add to this ObjectClass
184         */
185        void addSuperClasses( List<ObjectClass> superClasses )
186        {
187            if ( this.superClasses == null )
188            {
189                this.superClasses = new ArrayList<ObjectClass>();
190            }
191    
192            this.superClasses.addAll( superClasses );
193        }
194    
195    
196        /**
197         * Sets the classType for this ObjectClass.
198         * 
199         * @param type
200         *            the new class type enumeration for this ObjectClass
201         */
202        void setType( ObjectClassTypeEnum type )
203        {
204            this.type = type;
205        }
206    }