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: DataLinkDeclaration.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: class DataLinkDeclaration {
011: private String mSrcOutput = null;
012: private String mSrcOutbean = null;
013: private String mDestId = null;
014: private boolean mSnapback = false;
015: private String mDestInput = null;
016: private String mDestInbean = null;
017: private FlowLinkBuilder mFlowLinkBuilder = null;
018:
019: DataLinkDeclaration(String srcOutput, String srcOutbean,
020: String destId, boolean snapback, String destInput,
021: String destInbean, FlowLinkBuilder flowlink) {
022: if (srcOutput != null && 0 == srcOutput.length())
023: srcOutput = null;
024: if (srcOutbean != null && 0 == srcOutbean.length())
025: srcOutbean = null;
026: if (destId != null && 0 == destId.length())
027: destId = null;
028: if (destInput != null && 0 == destInput.length())
029: destInput = null;
030: if (destInbean != null && 0 == destInbean.length())
031: destInbean = null;
032:
033: assert srcOutput != null || srcOutbean != null;
034: assert (srcOutput != null && srcOutput.length() > 0)
035: || (srcOutbean != null && srcOutbean.length() > 0);
036: assert destId != null || snapback;
037: assert null == destId || !snapback;
038: assert destInput != null || destInbean != null;
039: assert (destInput != null && destInput.length() > 0)
040: || (destInbean != null && destInbean.length() > 0);
041:
042: mSrcOutput = srcOutput;
043: mSrcOutbean = srcOutbean;
044: mDestId = destId;
045: mSnapback = snapback;
046: mDestInput = destInput;
047: mDestInbean = destInbean;
048: mFlowLinkBuilder = flowlink;
049: }
050:
051: String getSrcOutput() {
052: return mSrcOutput;
053: }
054:
055: String getSrcOutbean() {
056: return mSrcOutbean;
057: }
058:
059: String getDestId() {
060: return mDestId;
061: }
062:
063: void makeAbsoluteDestId(SiteBuilder builder) {
064: if (mDestId != null) {
065: mDestId = builder.makeAbsoluteElementId(mDestId);
066: mDestId = Site.getCanonicalId(mDestId);
067: }
068: }
069:
070: String getDestInput() {
071: return mDestInput;
072: }
073:
074: String getDestInbean() {
075: return mDestInbean;
076: }
077:
078: boolean transfersBean() {
079: return !(mSrcOutput != null && mDestInput != null);
080:
081: }
082:
083: boolean isSnapback() {
084: return mSnapback;
085: }
086:
087: FlowLink getFlowLink() {
088: if (null == mFlowLinkBuilder) {
089: return null;
090: }
091: return mFlowLinkBuilder.getFlowLinkDeclaration().getFlowLink();
092: }
093:
094: FlowLinkDeclaration getFlowLinkDeclaration() {
095: if (null == mFlowLinkBuilder) {
096: return null;
097: }
098: return mFlowLinkBuilder.getFlowLinkDeclaration();
099: }
100:
101: public int hashCode() {
102: int srcoutput = 1;
103: int srcoutbean = 1;
104: int destid = 1;
105: int snapback = 1;
106: int destinput = 1;
107: int destinbean = 1;
108: int flowlink = 1;
109:
110: if (mSrcOutput != null) {
111: srcoutput = mSrcOutput.hashCode();
112: }
113: if (mSrcOutbean != null) {
114: srcoutbean = mSrcOutbean.hashCode();
115: }
116: if (mDestId != null) {
117: destid = mDestId.hashCode();
118: }
119: if (mSnapback) {
120: snapback = 2;
121: }
122: if (mDestInput != null) {
123: destinput = mDestInput.hashCode();
124: }
125: if (mDestInbean != null) {
126: destinbean = mDestInbean.hashCode();
127: }
128: if (mFlowLinkBuilder != null) {
129: flowlink = mFlowLinkBuilder.hashCode();
130: }
131:
132: return srcoutput * srcoutbean * destid * snapback * destinput
133: * destinbean * flowlink;
134: }
135:
136: public boolean equals(Object other) {
137: if (this == other) {
138: return true;
139: }
140:
141: if (null == other) {
142: return false;
143: }
144:
145: if (!(other instanceof DataLinkDeclaration)) {
146: return false;
147: }
148:
149: DataLinkDeclaration other_datalink = (DataLinkDeclaration) other;
150: if (other_datalink.getSrcOutput() != null
151: || getSrcOutput() != null) {
152: if (null == other_datalink.getSrcOutput()
153: || null == getSrcOutput()) {
154: return false;
155: } else if (!other_datalink.getSrcOutput().equals(
156: getSrcOutput())) {
157: return false;
158: }
159: }
160: if (other_datalink.getSrcOutbean() != null
161: || getSrcOutbean() != null) {
162: if (null == other_datalink.getSrcOutbean()
163: || null == getSrcOutbean()) {
164: return false;
165: } else if (!other_datalink.getSrcOutbean().equals(
166: getSrcOutbean())) {
167: return false;
168: }
169: }
170: if (!other_datalink.getDestId().equals(getDestId())) {
171: return false;
172: }
173: if (other_datalink.isSnapback() != isSnapback()) {
174: return false;
175: }
176: if (other_datalink.getDestInput() != null
177: || getDestInput() != null) {
178: if (null == other_datalink.getDestInput()
179: || null == getDestInput()) {
180: return false;
181: } else if (!other_datalink.getDestInput().equals(
182: getDestInput())) {
183: return false;
184: }
185: }
186: if (other_datalink.getDestInbean() != null
187: || getDestInbean() != null) {
188: if (null == other_datalink.getDestInbean()
189: || null == getDestInbean()) {
190: return false;
191: } else if (!other_datalink.getDestInbean().equals(
192: getDestInbean())) {
193: return false;
194: }
195: }
196: if (other_datalink.getFlowLink() != null
197: || getFlowLink() != null) {
198: if (null == other_datalink.getFlowLink()
199: && getFlowLink() != null) {
200: return false;
201: }
202: if (other_datalink.getFlowLink() != null
203: && null == getFlowLink()) {
204: return false;
205: }
206: if (!other_datalink.getFlowLink().equals(getFlowLink())) {
207: return false;
208: }
209: }
210:
211: return true;
212: }
213: }
|