01: package org.drools.ruleflow.core.impl;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.util.Iterator;
20: import java.util.List;
21:
22: import org.drools.ruleflow.core.ActionNode;
23: import org.drools.ruleflow.core.Connection;
24:
25: /**
26: * Default implementation of an action node.
27: *
28: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
29: */
30: public class ActionNodeImpl extends NodeImpl implements ActionNode {
31:
32: private static final long serialVersionUID = -2899376492708393815L;
33:
34: private Object action;
35:
36: public Object getAction() {
37: return action;
38: }
39:
40: public void setAction(Object action) {
41: this .action = action;
42: }
43:
44: public Connection getFrom() {
45: final List list = getIncomingConnections();
46: if (list.size() > 0) {
47: return (Connection) list.get(0);
48: }
49: return null;
50: }
51:
52: public Connection getTo() {
53: final List list = getOutgoingConnections();
54: if (list.size() > 0) {
55: return (Connection) list.get(0);
56: }
57: return null;
58: }
59:
60: protected void validateAddIncomingConnection(
61: final Connection connection) {
62: super .validateAddIncomingConnection(connection);
63: if (getIncomingConnections().size() > 0) {
64: throw new IllegalArgumentException(
65: "An ActionNode cannot have more than one incoming node");
66: }
67: }
68:
69: protected void validateAddOutgoingConnection(
70: final Connection connection) {
71: super .validateAddOutgoingConnection(connection);
72: for (final Iterator it = getOutgoingConnections().iterator(); it
73: .hasNext();) {
74: final Connection conn = (Connection) it.next();
75: if (conn.getType() == connection.getType()) {
76: throw new IllegalArgumentException(
77: "An ActionNode can have at most one outgoing node");
78: }
79: }
80: }
81:
82: }
|