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.Connection;
23: import org.drools.ruleflow.core.MilestoneNode;
24:
25: /**
26: * Default implementation of a milestone node.
27: *
28: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
29: */
30: public class MilestoneNodeImpl extends NodeImpl implements
31: MilestoneNode {
32:
33: private static final long serialVersionUID = 8552568488755348247L;
34:
35: private String constraint;
36:
37: public void setConstraint(final String constraint) {
38: this .constraint = constraint;
39: }
40:
41: public String getConstraint() {
42: return this .constraint;
43: }
44:
45: public Connection getFrom() {
46: final List list = getIncomingConnections();
47: if (list.size() > 0) {
48: return (Connection) list.get(0);
49: }
50: return null;
51: }
52:
53: public Connection getTo() {
54: final List list = getOutgoingConnections();
55: if (list.size() > 0) {
56: return (Connection) list.get(0);
57: }
58: return null;
59: }
60:
61: protected void validateAddIncomingConnection(
62: final Connection connection) {
63: super .validateAddIncomingConnection(connection);
64: if (getIncomingConnections().size() > 0) {
65: throw new IllegalArgumentException(
66: "A MilestoneNode cannot have more than one incoming node");
67: }
68: }
69:
70: protected void validateAddOutgoingConnection(
71: final Connection connection) {
72: super .validateAddOutgoingConnection(connection);
73: for (final Iterator it = getOutgoingConnections().iterator(); it
74: .hasNext();) {
75: final Connection conn = (Connection) it.next();
76: if (conn.getType() == connection.getType()) {
77: throw new IllegalArgumentException(
78: "A MilestoneNode can have at most one outgoing node");
79: }
80: }
81: }
82:
83: }
|