001    /*
002     * Copyright 1999-2001,2004 The Apache Software Foundation.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */ 
016    
017    package org.apache.commons.workflow.base;
018    
019    
020    import java.util.ArrayList;
021    import org.apache.commons.workflow.Activity;
022    import org.apache.commons.workflow.Context;
023    import org.apache.commons.workflow.Descriptor;
024    import org.apache.commons.workflow.Descriptors;
025    import org.apache.commons.workflow.Step;
026    import org.apache.commons.workflow.StepException;
027    
028    
029    /**
030     * <p><strong>DescriptorStep</strong> is a convenient base class for more
031     * sophisticated <code>Step</code> implementations that already support
032     * the APIs provided by <code>BaseStep</code>, and also implement the
033     * <code>Descriptors</code> interafce.
034     *
035     * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
036     * @author Craig R. McClanahan
037     */
038    
039    public abstract class DescriptorStep extends BaseStep implements Descriptors {
040    
041    
042        // ----------------------------------------------------- Instance Variables
043    
044    
045        /**
046         * The list of <code>Descriptor</code> objects associated with this
047         * <code>Step</code>.
048         */
049        protected ArrayList descriptors = new ArrayList();
050    
051    
052        // --------------------------------------------------------- Public Methods
053    
054    
055        /**
056         * Add a new <code>Descriptor</code> to the set associated with
057         * this object.
058         *
059         * @param descriptor The Descriptor to be added
060         */
061        public void addDescriptor(Descriptor descriptor) {
062    
063            descriptors.add(descriptor);
064    
065        }
066    
067    
068        /**
069         * Return the set of <code>Descriptor</code> objects associated with
070         * this object, in the order that they were originally added.
071         */
072        public Descriptor[] findDescriptors() {
073    
074            Descriptor results[] = new Descriptor[descriptors.size()];
075            return ((Descriptor[]) descriptors.toArray(results));
076    
077        }
078    
079    
080        /**
081         * Remove an existing <code>Descriptor</code> from the set associated
082         * with this object.
083         *
084         * @param descriptor The Descriptor to be removed
085         */
086        public void removeDescriptor(Descriptor descriptor) {
087    
088            descriptors.remove(descriptor);
089    
090        }
091    
092    
093    }