001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.rules;
025:
026: import java.util.List;
027:
028: import org.eclipse.gmf.runtime.notation.View;
029: import org.eclipse.swt.SWT;
030: import org.eclipse.swt.widgets.MessageBox;
031: import org.eclipse.ui.PlatformUI;
032:
033: import com.bostechcorp.cbesb.common.i18n.I18N;
034: import com.bostechcorp.cbesb.common.i18n.Messages;
035: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BaseElement;
036: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BindingComponent;
037: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.CBR;
038: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Comment;
039: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DecorativeModelElement;
040: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DefaultMepType;
041: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.ExternalSystem;
042: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.FTP;
043: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.File;
044: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HTTP;
045: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.JMS;
046: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.MessageExchange;
047: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Parser;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Script;
049: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Sequencer;
050: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.ServiceEngine;
051: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
052: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Transformer;
053: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.XSLT;
054: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.MessageExchangeEditPart;
055:
056: public class RuleFactory {
057:
058: public BaseElement source;
059: public BaseElement target;
060: static MessageExchangeEditPart editPart;
061: Source source_com;
062: Target target_com;
063:
064: public RuleFactory(MessageExchangeEditPart editPart,
065: BaseElement source, BaseElement target) {
066: this .source = source;
067: this .target = target;
068: this .editPart = editPart;
069: }
070:
071: public boolean isConnected() {
072: if (sourceFine()) {
073: return targetFine();
074: }
075:
076: else
077: return false;
078: }
079:
080: public BaseElement getSourceCom() {
081: return source;
082: }
083:
084: public BaseElement getTargetCom() {
085: return target;
086: }
087:
088: public Target getTarget() {
089: return target_com;
090: }
091:
092: public Source getSource() {
093: return source_com;
094: }
095:
096: public void refreshTargetDel(MessageExchangeEditPart editPart) {
097: if (getTargetCom() instanceof Sequencer) {
098: SequencerTarget tar = ((SequencerTarget) this .getTarget());
099: tar.refreshSequncerSourceConnectionDel(editPart);
100: }
101: if (getTargetCom() instanceof CBR) {
102: CbrTarget tar = ((CbrTarget) this .getTarget());
103: tar.refreshCbrSourceConnectionDel(editPart);
104: }
105:
106: }
107:
108: public void refreshSourceDel() {
109: if (getSourceCom() instanceof Sequencer) {
110: SequencerSource tar = ((SequencerSource) this .getSource());
111: tar.refreshSequncerSourceConnectionDel();
112: }
113: }
114:
115: public boolean sourceFine() {
116: if (source == null) {
117: return false;
118: }
119: if (equalComponent(source, target))
120: return false;
121: if (source instanceof BindingComponent) {
122: BCSource bcsource = new BCSource((BindingComponent) source,
123: target);
124: return bcsource.asSource();
125: }
126:
127: else if (source instanceof Sequencer) {
128: SequencerSource sequencerSource = new SequencerSource(
129: this .editPart, (Sequencer) source, target);
130: source_com = sequencerSource;
131: if (sequencerSource.asSource()) {
132: try {
133: sequencerSource.refreshSequncerSourceConnection();
134: } catch (Exception e) {
135: e.printStackTrace();
136: }
137: return true;
138: } else
139: return false;
140: } else if (source instanceof CBR) {
141: CbrSource cbrSource = new CbrSource(this .editPart,
142: (CBR) source, target);
143: source_com = cbrSource;
144: if (cbrSource.asSource()) {
145: try {
146: cbrSource.refreshCbrSourceConnection();
147: } catch (Exception e) {
148: e.printStackTrace();
149: }
150: return true;
151: } else
152: return false;
153: } else if ((source instanceof ServiceEngine)
154: || (source instanceof Comment)) {
155: Source source2 = new Source(source, target);
156: source_com = source2;
157: return source2.asSource();
158: }
159:
160: else if (source instanceof ExternalSystem) {
161: ExternSysSource externSysSource = new ExternSysSource(
162: (ExternalSystem) source, target);
163: source_com = externSysSource;
164: return externSysSource.asSource();
165: }
166:
167: return true;
168: }
169:
170: public boolean targetFine() {
171: if (target == null) {
172: return false;
173: }
174:
175: if (target instanceof BindingComponent) {
176: BCTarget bctarget = new BCTarget(source,
177: (BindingComponent) target);
178: return bctarget.asTarget();
179: }
180:
181: else if (target instanceof Sequencer) {
182: SequencerTarget sequencerTarget = new SequencerTarget(
183: this .editPart, source, (Sequencer) target);
184: target_com = (SequencerTarget) sequencerTarget;
185: return sequencerTarget.asTarget();
186: } else if (target instanceof CBR) {
187: CbrTarget cbrTarget = new CbrTarget(this .editPart, source,
188: (CBR) target);
189: target_com = (CbrTarget) cbrTarget;
190: return cbrTarget.asTarget();
191: }
192:
193: else if (target instanceof ServiceEngine) {
194: Target target2 = new Target(source, target);
195: return target2.asTarget();
196: }
197:
198: else if (target instanceof ExternalSystem) {
199: ExternSysTarget externSysTarget = new ExternSysTarget(
200: source, (ExternalSystem) target);
201: return externSysTarget.asTarget();
202: } else if (target instanceof Comment) {
203: CommentTarget commentTarget = new CommentTarget(source,
204: (Comment) target);
205: return commentTarget.asTarget();
206: }
207: return true;
208: }
209:
210: public DefaultMepType getDefault_MEP() {
211: DefaultMepType default_mep = null;
212:
213: if (source instanceof BindingComponent) {
214:
215: BindingComponent component = (BindingComponent) source;
216: if (target instanceof DecorativeModelElement)
217: default_mep = DefaultMepType.INOUT_LITERAL;
218: else
219: default_mep = component.getConsumer().getDefaultMep();
220:
221: }
222:
223: else if (source instanceof Sequencer) {
224:
225: default_mep = ((SequencerSource) source_com)
226: .getDefaultMepTypeForNewConn();
227:
228: }
229:
230: else if (source instanceof CBR) {
231: default_mep = ((CbrSource) source_com)
232: .getDefaultMepTypeForNewConn();
233: }
234:
235: else if (source instanceof DecorativeModelElement) {
236: if (target instanceof BindingComponent) {
237:
238: BindingComponent component = (BindingComponent) target;
239: default_mep = component.getConsumer().getDefaultMep();
240: }
241:
242: }
243: return default_mep;
244: }
245:
246: public static MessageBox getMessageBox(String text, String message) {
247: MessageBox messageBox = new MessageBox(PlatformUI
248: .getWorkbench().getActiveWorkbenchWindow().getShell(),
249: SWT.ICON_INFORMATION | SWT.OK);
250: messageBox.setText(text);
251: messageBox.setMessage(message);
252: return messageBox;
253:
254: }
255:
256: public void refreshTarget() {
257:
258: // if the target is a sequencer or a CBR, we will refresh the connections coming out of it.
259: if (getTargetCom() instanceof Sequencer) {
260: SequencerTarget tar = ((SequencerTarget) this .getTarget());
261: tar.refreshSequncerSourceConnection();
262: } else if (getTargetCom() instanceof CBR) {
263: CbrTarget tar = ((CbrTarget) this .getTarget());
264: tar.refreshCbrSourceConnection();
265: }
266:
267: }
268:
269: public void refreshSource() {
270: // if the source is a sequencer or a CBR, we will refresh the connections coming out of it.
271: if (getSourceCom() instanceof Sequencer) {
272: SequencerSource tar = ((SequencerSource) this .getSource());
273: tar.refreshSequncerSourceConnectionPostCr();
274: }
275:
276: }
277:
278: public static int maximum(List list) {
279: int max = 0;
280: int label_num = 0;
281: if (list.size() == 1)
282: return max;
283: for (int i = 0; i < list.size(); i++) {
284: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
285: .get(i);
286:
287: View model = (View) connectionEditPart.getModel();
288: MessageExchange object = (MessageExchange) model
289: .getElement();
290: try {
291: label_num = Integer.parseInt(object.getLabel());
292: } catch (Exception e) {
293: e.printStackTrace();
294: }
295:
296: if (max <= label_num)
297: max = label_num;
298: }
299: return max;
300: }
301:
302: public static int postdel_maximum(List list,
303: MessageExchangeEditPart editPart) {
304: int max = 0;
305: int label_num = 0;
306:
307: if (list.size() == 1)
308: return max;
309: for (int i = 0; i < list.size(); i++) {
310:
311: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
312: .get(i);
313: if (!connectionEditPart.equals(editPart)) {
314: View model = (View) connectionEditPart.getModel();
315: MessageExchange object = (MessageExchange) model
316: .getElement();
317: try {
318: label_num = Integer.parseInt(object.getLabel());
319: } catch (Exception e) {
320: e.printStackTrace();
321: }
322:
323: if (max <= label_num)
324: max = label_num;
325: }
326: }
327: return max;
328: }
329:
330: private boolean equalComponent(BaseElement source,
331: BaseElement target) {
332:
333: if (source.equals(target)) {
334: String text = I18N.getString(Messages.COMP_SUG);
335: String message = I18N.getString(Messages.COMP_CON_SELF);
336: MessageBox messageBox = RuleFactory.getMessageBox(text,
337: message);
338: int buttonID = messageBox.open();
339: switch (buttonID) {
340: case SWT.YES:
341: break;
342: }
343: return true;
344: } else
345: return false;
346: }
347:
348: }
|