001: /*
002: * Bossa Workflow System
003: *
004: * $Id: Bossa.java,v 1.14 2004/01/15 22:13:32 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;
026:
027: import java.io.IOException;
028: import java.io.Serializable;
029:
030: import org.prevayler.Prevayler;
031:
032: import com.bigbross.bossa.history.Historian;
033: import com.bigbross.bossa.notify.NotificationBus;
034: import com.bigbross.bossa.resource.ResourceManager;
035: import com.bigbross.bossa.wfnet.CaseTypeManager;
036: import com.bigbross.bossa.work.WorkManager;
037:
038: /**
039: * This class represents a workflow engine in the Bossa workflow library.
040: * Use an instance of this class, created by the factory class
041: * <code>BossaFactory</code>, to access all elements of the Bossa API. <p>
042: *
043: * @author <a href="http://www.bigbross.com">BigBross Team</a>
044: * @see com.bigbross.bossa.BossaFactory
045: */
046: public class Bossa implements Serializable {
047:
048: private CaseTypeManager caseTypeManager;
049:
050: private ResourceManager resourceManager;
051:
052: private WorkManager workManager;
053:
054: private Historian historian;
055:
056: private NotificationBus notificationBus;
057:
058: private TimeSource timeSource;
059:
060: private transient Prevayler prevayler;
061:
062: /**
063: * Creates an empty Bossa workflow engine. <p>
064: */
065: Bossa() {
066: caseTypeManager = new CaseTypeManager(this );
067: resourceManager = new ResourceManager(this );
068: workManager = new WorkManager(this );
069: historian = new Historian(this );
070: notificationBus = null;
071: timeSource = new DeterministicTimeSource();
072: prevayler = null;
073: }
074:
075: /**
076: * Associates a notification bus with this engine instance. <p>
077: *
078: * @param notificationBus the notification bus.
079: */
080: void setNotificationBus(NotificationBus notificationBus) {
081: this .notificationBus = notificationBus;
082: }
083:
084: /**
085: * Associates a time source with this engine instance. <p>
086: *
087: * @param timeSource the time source.
088: */
089: void setTimeSource(TimeSource timeSource) {
090: this .timeSource = timeSource;
091: }
092:
093: /**
094: * Associates a prevayler with this engine instance. <p>
095: *
096: * @param prevayler the prevayler.
097: */
098: void setPrevayler(Prevayler prevayler) {
099: this .prevayler = prevayler;
100: }
101:
102: /**
103: * Executes a transaction using the current prevayler. <p>
104: *
105: * @param transaction the transaction to be executed.
106: * @return the value returned by the transaction.
107: * @exception BossaException if the transaction throws an exception.
108: */
109: public Object execute(BossaTransaction transaction)
110: throws BossaException {
111: try {
112: if (prevayler != null) {
113: return prevayler.execute(transaction);
114: } else {
115: return transaction.execute(this );
116: }
117: } catch (BossaException e) {
118: throw e;
119: } catch (Exception e) {
120: throw new BossaException("Unexpected exception.", e);
121: }
122: }
123:
124: /**
125: * Writes to disk the complete object tree of this engine instance. <p>
126: */
127: public void takeSnapshot() throws IOException {
128: prevayler.takeSnapshot();
129: }
130:
131: /**
132: * Returns the case type manager of this engine. <p>
133: *
134: * @return the case type manager of this engine.
135: */
136: public CaseTypeManager getCaseTypeManager() {
137: return caseTypeManager;
138: }
139:
140: /**
141: * Returns the resource manager of this engine. <p>
142: *
143: * @return the resource manager of this engine.
144: */
145: public ResourceManager getResourceManager() {
146: return resourceManager;
147: }
148:
149: /**
150: * Returns the work manager of this engine. <p>
151: *
152: * @return the work manager of this engine.
153: */
154: public WorkManager getWorkManager() {
155: return workManager;
156: }
157:
158: /**
159: * Returns the historian of this engine. <p>
160: *
161: * @return the historian of this engine.
162: */
163: public Historian getHistorian() {
164: return historian;
165: }
166:
167: /**
168: * Returns the time source of this engine. <p>
169: *
170: * @return the time source of this engine.
171: */
172: public TimeSource getTimeSource() {
173: return timeSource;
174: }
175:
176: /**
177: * Returns the notification bus of this engine. <p>
178: *
179: * @return the notification bus of this engine.
180: */
181: public NotificationBus getNotificationBus() {
182: return notificationBus;
183: }
184: }
|