001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /* $Id: TransitionImpl.java 473861 2006-11-12 03:51:14Z gregor $ */
020:
021: package org.apache.lenya.workflow.impl;
022:
023: import org.apache.avalon.framework.logger.AbstractLogEnabled;
024: import org.apache.lenya.workflow.Action;
025: import org.apache.lenya.workflow.Condition;
026: import org.apache.lenya.workflow.Transition;
027:
028: import java.util.ArrayList;
029: import java.util.List;
030:
031: /**
032: * Implementation of a transition.
033: */
034: public class TransitionImpl extends AbstractLogEnabled implements
035: Transition {
036:
037: /**
038: * Ctor.
039: * @param sourceState The source state.
040: * @param destinationState The destination state.
041: */
042: protected TransitionImpl(String sourceState, String destinationState) {
043: this .source = sourceState;
044: this .destination = destinationState;
045: }
046:
047: private List actions = new ArrayList();
048: private boolean isSynchronized = false;
049:
050: /**
051: * Returns the actions which are assigned tothis transition.
052: * @return An array of actions.
053: */
054: public Action[] getActions() {
055: return (Action[]) this .actions.toArray(new Action[this .actions
056: .size()]);
057: }
058:
059: /**
060: * Assigns an action to this transition.
061: * @param action The action.
062: */
063: public void addAction(Action action) {
064: this .actions.add(action);
065: }
066:
067: private List conditions = new ArrayList();
068:
069: /**
070: * @see org.apache.lenya.workflow.Transition#getConditions()
071: */
072: public Condition[] getConditions() {
073: return (Condition[]) this .conditions
074: .toArray(new Condition[this .conditions.size()]);
075: }
076:
077: /**
078: * Assigns a condition to this transition.
079: * @param condition The condition.
080: */
081: public void addCondition(Condition condition) {
082: this .conditions.add(condition);
083: }
084:
085: private String event;
086:
087: /**
088: * Returns the event which invokes this transition.
089: * @return An event.
090: */
091: public String getEvent() {
092: return this .event;
093: }
094:
095: /**
096: * Sets the event to invoke this transition.
097: * @param anEvent An event.
098: */
099: public void setEvent(String anEvent) {
100: this .event = anEvent;
101: }
102:
103: private String source;
104:
105: /**
106: * @see org.apache.lenya.workflow.Transition#getSource()
107: */
108: public String getSource() {
109: return this .source;
110: }
111:
112: private String destination;
113:
114: /**
115: * @see org.apache.lenya.workflow.Transition#getDestination()
116: */
117: public String getDestination() {
118: return this .destination;
119: }
120:
121: /**
122: * @see java.lang.Object#toString()
123: */
124: public String toString() {
125: StringBuffer buf = new StringBuffer();
126: buf.append(getEvent() + " [");
127: Condition[] _conditions = getConditions();
128:
129: for (int i = 0; i < _conditions.length; i++) {
130: if (i > 0) {
131: buf.append(", ");
132: }
133:
134: buf.append(_conditions[i].toString());
135: }
136:
137: buf.append("]");
138:
139: Action[] _actions = getActions();
140:
141: if (_actions.length > 0) {
142: buf.append(" / ");
143:
144: for (int i = 0; i < _actions.length; i++) {
145: if (i > 0) {
146: buf.append(", ");
147: }
148:
149: buf.append(_actions[i].toString());
150: }
151: }
152:
153: return buf.toString();
154: }
155:
156: /**
157: * Returns if this transition is synchronized.
158: * @return A boolean value.
159: */
160: public boolean isSynchronized() {
161: return this .isSynchronized;
162: }
163:
164: /**
165: * Sets if this transition is synchronized.
166: * @param _isSynchronized A boolean value.
167: */
168: protected void setSynchronized(boolean _isSynchronized) {
169: this.isSynchronized = _isSynchronized;
170: }
171:
172: }
|