001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: FlowLinkBuilder.java 3701 2007-03-18 12:24:23Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import com.uwyn.rife.engine.exceptions.EngineException;
011: import com.uwyn.rife.engine.exceptions.FlowLinkAmbiguousTargetException;
012: import com.uwyn.rife.engine.exceptions.FlowLinkTargetRequiredException;
013:
014: public class FlowLinkBuilder {
015: private ElementInfoBuilder mElementInfoBuilder = null;
016:
017: private String mSrcExit = null;
018: private String mDestId = null;
019: private boolean mSnapback = false;
020: private boolean mCancelInheritance = false;
021: private boolean mCancelEmbedding = false;
022: private boolean mRedirect = false;
023: private boolean mCancelContinuations = false;
024:
025: private FlowLinkDeclaration mDeclaration = null;
026:
027: public FlowLinkBuilder(ElementInfoBuilder elementInfoBuilder,
028: String srcExit) {
029: mElementInfoBuilder = elementInfoBuilder;
030: mSrcExit = srcExit;
031: }
032:
033: public FlowLinkBuilder destId(String destId) {
034: if (destId != null && 0 == destId.length())
035: destId = null;
036:
037: mDestId = destId;
038: return this ;
039: }
040:
041: public FlowLinkBuilder snapback(boolean snapback) {
042: mSnapback = snapback;
043: return this ;
044: }
045:
046: public FlowLinkBuilder cancelInheritance(boolean cancelInheritance) {
047: mCancelInheritance = cancelInheritance;
048: return this ;
049: }
050:
051: public FlowLinkBuilder cancelEmbedding(boolean cancelEmbedding) {
052: mCancelEmbedding = cancelEmbedding;
053: return this ;
054: }
055:
056: public FlowLinkBuilder redirect(boolean redirect) {
057: mRedirect = redirect;
058: return this ;
059: }
060:
061: public FlowLinkBuilder cancelContinuations(
062: boolean cancelContinuations) {
063: mCancelContinuations = cancelContinuations;
064: return this ;
065: }
066:
067: public FlowLinkBuilder addDataLink(String srcOutput,
068: String destInput) throws EngineException {
069: addDataLink(srcOutput, null, false, destInput, null);
070:
071: return this ;
072: }
073:
074: public FlowLinkBuilder addSnapbackDataLink(String srcOutput,
075: String destInput) throws EngineException {
076: addDataLink(srcOutput, null, true, destInput, null);
077:
078: return this ;
079: }
080:
081: public FlowLinkBuilder addDataLinkBean(String srcOutbean,
082: String destInbean) throws EngineException {
083: addDataLink(null, srcOutbean, false, null, destInbean);
084:
085: return this ;
086: }
087:
088: public FlowLinkBuilder addSnapbackDataLinkBean(String srcOutbean,
089: String destInbean) throws EngineException {
090: addDataLink(null, srcOutbean, true, null, destInbean);
091:
092: return this ;
093: }
094:
095: public FlowLinkBuilder addDataLink(String srcOutput,
096: String srcOutbean, boolean snapback, String destInput,
097: String destInbean) throws EngineException {
098: String dest_id = null;
099: if (!snapback) {
100: dest_id = mDestId;
101: }
102: mElementInfoBuilder.addDataLink(srcOutput, srcOutbean, dest_id,
103: snapback, destInput, destInbean, this );
104:
105: return this ;
106: }
107:
108: public ElementInfoBuilder leaveFlowLink() {
109: mElementInfoBuilder
110: .addFlowLinkDeclaration(getFlowLinkDeclaration());
111: return mElementInfoBuilder;
112: }
113:
114: String getSrcExit() {
115: return mSrcExit;
116: }
117:
118: FlowLinkDeclaration getFlowLinkDeclaration() throws EngineException {
119: if (mDeclaration != null) {
120: return mDeclaration;
121: }
122:
123: if (null == mDestId && !mSnapback) {
124: throw new FlowLinkTargetRequiredException(
125: mElementInfoBuilder.getSiteBuilder()
126: .getDeclarationName(), mElementInfoBuilder
127: .getElementDeclaration().getId(), mSrcExit);
128: }
129: if (mDestId != null && mSnapback) {
130: throw new FlowLinkAmbiguousTargetException(
131: mElementInfoBuilder.getSiteBuilder()
132: .getDeclarationName(), mElementInfoBuilder
133: .getElementDeclaration().getId(), mSrcExit);
134: }
135:
136: mDeclaration = new FlowLinkDeclaration(mElementInfoBuilder
137: .getSiteBuilder(), mSrcExit, mDestId, mSnapback,
138: mCancelInheritance, mCancelEmbedding, mRedirect,
139: mCancelContinuations);
140:
141: return mDeclaration;
142: }
143:
144: ElementInfoBuilder getElementInfoBuilder() {
145: return mElementInfoBuilder;
146: }
147: }
|