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
021package org.apache.directory.api.ldap.trigger;
022
023
024import java.util.List;
025
026import org.apache.commons.lang.NullArgumentException;
027import org.apache.directory.api.i18n.I18n;
028
029
030/**
031 * The Trigger Specification Bean.
032 * 
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class TriggerSpecification
036{
037
038    private LdapOperation ldapOperation;
039
040    private ActionTime actionTime;
041
042    private List<SPSpec> spSpecs;
043
044
045    /**
046     * Instantiates a new trigger specification.
047     *
048     * @param ldapOperation the LDAP operation
049     * @param actionTime the action time
050     * @param spSpecs the stored procedure specs
051     */
052    public TriggerSpecification( LdapOperation ldapOperation, ActionTime actionTime, List<SPSpec> spSpecs )
053    {
054        super();
055        
056        if ( ( ldapOperation == null ) || ( actionTime == null ) || ( spSpecs == null ) )
057        {
058            throw new NullArgumentException( I18n.err( I18n.ERR_04331 ) );
059        }
060        
061        if ( spSpecs.isEmpty() )
062        {
063            throw new IllegalArgumentException( I18n.err( I18n.ERR_04332 ) );
064        }
065        
066        this.ldapOperation = ldapOperation;
067        this.actionTime = actionTime;
068        this.spSpecs = spSpecs;
069    }
070
071
072    /**
073     * Gets the action time.
074     *
075     * @return the action time
076     */
077    public ActionTime getActionTime()
078    {
079        return actionTime;
080    }
081
082
083    /**
084     * Gets the LDAP operation.
085     *
086     * @return the LDAP operation
087     */
088    public LdapOperation getLdapOperation()
089    {
090        return ldapOperation;
091    }
092
093
094    /**
095     * Gets the stored procedure specs.
096     *
097     * @return the stored procedure specs
098     */
099    public List<SPSpec> getSPSpecs()
100    {
101        return spSpecs;
102    }
103
104    /**
105     * The stored procedure spec bean.
106     */
107    public static class SPSpec
108    {
109        private String name;
110
111        private List<StoredProcedureOption> options;
112
113        private List<StoredProcedureParameter> parameters;
114
115
116        /**
117         * Instantiates a new stored procedure spec.
118         *
119         * @param name the name
120         * @param options the options
121         * @param parameters the parameters
122         */
123        public SPSpec( String name, List<StoredProcedureOption> options, List<StoredProcedureParameter> parameters )
124        {
125            super();
126            this.name = name;
127            this.options = options;
128            this.parameters = parameters;
129        }
130
131
132        /**
133         * Gets the name.
134         *
135         * @return the name
136         */
137        public String getName()
138        {
139            return name;
140        }
141
142
143        /**
144         * Gets the options.
145         *
146         * @return the options
147         */
148        public List<StoredProcedureOption> getOptions()
149        {
150            return options;
151        }
152
153
154        /**
155         * Gets the parameters.
156         *
157         * @return the parameters
158         */
159        public List<StoredProcedureParameter> getParameters()
160        {
161            return parameters;
162        }
163
164
165        /**
166         * {@inheritDoc}
167         */
168        @Override
169        public int hashCode()
170        {
171            int h = 37;
172
173            h = h * 17 + ( ( name == null ) ? 0 : name.hashCode() );
174            h = h * 17 + ( ( options == null ) ? 0 : options.hashCode() );
175            h = h * 17 + ( ( parameters == null ) ? 0 : parameters.hashCode() );
176            return h;
177        }
178
179
180        /**
181         * {@inheritDoc}
182         */
183        @Override
184        public boolean equals( Object obj )
185        {
186            if ( this == obj )
187            {
188                return true;
189            }
190            if ( obj == null )
191            {
192                return false;
193            }
194            if ( getClass() != obj.getClass() )
195            {
196                return false;
197            }
198            final SPSpec other = ( SPSpec ) obj;
199            if ( name == null )
200            {
201                if ( other.name != null )
202                {
203                    return false;
204                }
205            }
206            else if ( !name.equals( other.name ) )
207            {
208                return false;
209            }
210            if ( options == null )
211            {
212                if ( other.options != null )
213                {
214                    return false;
215                }
216            }
217            else if ( !options.equals( other.options ) )
218            {
219                return false;
220            }
221            if ( parameters == null )
222            {
223                if ( other.parameters != null )
224                {
225                    return false;
226                }
227            }
228            else if ( !parameters.equals( other.parameters ) )
229            {
230                return false;
231            }
232            return true;
233        }
234
235    }
236
237}