1 /*
2 * Copyright 2003 - 2013 The eFaps Team
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.db;
22
23 import java.util.List;
24
25 import org.efaps.admin.event.EventDefinition;
26 import org.efaps.admin.event.EventType;
27 import org.efaps.admin.event.Parameter;
28 import org.efaps.admin.event.Parameter.ParameterValues;
29 import org.efaps.util.EFapsException;
30
31 /**
32 * Abstract class where all eFaps database actions are derived.
33 *
34 * @author The eFaps Team
35 * @version $Id$
36 */
37 public abstract class AbstractAction
38 {
39 /**
40 * Instance holding the oid of the object which is checked in/out.
41 *
42 * @see #getInstance()
43 * @see #setInstance(Instance)
44 */
45 private Instance instance;
46
47 /**
48 * The method gets all events for the given EventType and executes them in
49 * the given order. If no events are defined, nothing is done. The method
50 * return <i>true</i> if a event was found, otherwise <i>false</i>.
51 *
52 * @param _eventtype trigger events to execute
53 * @return <i>true</i> if a trigger was found and executed, otherwise
54 * <i>false</i>
55 * @throws EFapsException on error
56 */
57 protected boolean executeEvents(final EventType _eventtype)
58 throws EFapsException
59 {
60 final boolean ret;
61 final List<EventDefinition> triggers = this.instance.getType().getEvents(_eventtype);
62 if (triggers != null) {
63 final Parameter parameter = new Parameter();
64 parameter.put(ParameterValues.INSTANCE, getInstance());
65 for (final EventDefinition evenDef : triggers) {
66 evenDef.execute(parameter);
67 }
68 ret = true;
69 } else {
70 ret = false;
71 }
72 return ret;
73 }
74
75 /**
76 * This is the getter method for instance variable {@link #instance}.
77 *
78 * @return the Instance of the check in / check out
79 * @see #setInstance(Instance)
80 */
81 protected Instance getInstance()
82 {
83 return this.instance;
84 }
85
86 /**
87 * This is the setter method for instance variable {@link #instance}.
88 *
89 * @param _instance tnstance to set
90 * @see #getInstance()
91 */
92 protected void setInstance(final Instance _instance)
93 {
94 this.instance = _instance;
95 }
96 }