001: /*
002: * Bossa Workflow System
003: *
004: * $Id: Transition.java,v 1.15 2004/02/05 21:43:24 gdvieira Exp $
005: *
006: * Copyright (C) 2003,2004 OpenBR Sistemas S/C Ltda.
007: *
008: * This file is part of Bossa.
009: *
010: * Bossa is free software; you can redistribute it and/or modify it
011: * under the terms of version 2 of the GNU General Public License as
012: * published by the Free Software Foundation.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public
020: * License along with this program; if not, write to the
021: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
022: * Boston, MA 02111-1307, USA.
023: */
024:
025: package com.bigbross.bossa.wfnet;
026:
027: import java.io.Serializable;
028: import java.util.ArrayList;
029: import java.util.Collections;
030: import java.util.List;
031:
032: import com.bigbross.bossa.resource.Expression;
033:
034: /**
035: * This class represents the definition of a transition.
036: *
037: * @author <a href="http://www.bigbross.com">BigBross Team</a>
038: */
039: public class Transition implements Serializable {
040:
041: private CaseType caseType;
042:
043: private String id;
044:
045: private Expression resource;
046:
047: private long timeout;
048:
049: private ArrayList inputs;
050:
051: private ArrayList outputs;
052:
053: /**
054: * Creates a new transition. <p>
055: *
056: * @param caseType the case type this transition is contained.
057: * @param id the id of this transition.
058: * @param resource the expression to select the resource responsible by
059: * this transition.
060: * @param timeout the number of milliseconds this transition will wait
061: * before it fires automatically.
062: */
063: Transition(CaseType caseType, String id, String resource,
064: long timeout) {
065: this .caseType = caseType;
066: this .id = id;
067: this .resource = resource == null ? null : caseType
068: .getResourceRegistry().compile(resource);
069: this .timeout = timeout;
070: this .inputs = new ArrayList();
071: this .outputs = new ArrayList();
072: }
073:
074: /**
075: * Returns the id of this transition. <p>
076: *
077: * @return the id of this transition.
078: */
079: public String getId() {
080: return id;
081: }
082:
083: /**
084: * Returns the resource of this transition. <p>
085: *
086: * @return the resource of this transition.
087: */
088: Expression getResource() {
089: return resource;
090: }
091:
092: /**
093: * Returns the timeout of this transition. <p>
094: *
095: * @return the timeout of this transition.
096: */
097: long getTimeout() {
098: return timeout;
099: }
100:
101: /**
102: * Returns all the input edges of this transition. <p>
103: *
104: * @return a list of all the input edges of this transition.
105: */
106: List getInputEdges() {
107: return Collections.unmodifiableList(inputs);
108: }
109:
110: /**
111: * Returns all the output edges of this transition. <p>
112: *
113: * @return a list of all the output edges of this transition.
114: */
115: List getOutputEdges() {
116: return Collections.unmodifiableList(outputs);
117: }
118:
119: /**
120: * Creates an input edge connecting a place to this transition.
121: * An input edge ties the firing of this transition to the
122: * availability in the place of a number of tokens given by an integer
123: * weight expression. <p>
124: *
125: * @param p the place.
126: * @param expression the weight expression.
127: */
128: public void input(Place p, String expression) {
129: inputs.add(Edge.newInput(p, expression));
130: }
131:
132: /**
133: * Creates an output edge connecting this transition to a place.
134: * An output edge produces in the place, after the firing of this
135: * transition, a number of tokens given by an integer
136: * weight expression. <p>
137: *
138: * @param p the place.
139: * @param expression the weight expression.
140: */
141: public void output(Place p, String expression) {
142: outputs.add(Edge.newOutput(p, expression));
143: }
144: }
|