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 org.eclipse.gmf.runtime.notation.View;
027:
028: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BaseElement;
029: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BindingComponent;
030: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.CBR;
031: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DecorativeModelElement;
032: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DefaultMepType;
033: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.FTP;
034: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.File;
035: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HTTP;
036: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.JMS;
037: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.MessageExchange;
038: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RegularType;
039: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Script;
040: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Sequencer;
041: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
042: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.MessageExchangeEditPart;
043: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.BindingComponentImpl;
044: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.CBRImpl;
045: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.FTPImpl;
046: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.FileImpl;
047: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.HTTPImpl;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.JMSImpl;
049: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.ScriptImpl;
050: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.SequencerImpl;
051: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.TCPIPImpl;
052:
053: public class RuleStrategy {
054:
055: public MessageExchangeEditPart editPart;
056: public RuleFactory ruleFactory = null;
057: MessageExchange object;
058: BaseElement target_component;
059: BaseElement source_component;
060:
061: public RuleStrategy(MessageExchangeEditPart editPart) {
062: this .editPart = editPart;
063: object = (MessageExchange) ((View) editPart.getModel())
064: .getElement();
065: target_component = object.getTargetElement();
066: source_component = object.getSourceElement();
067: ruleFactory = new RuleFactory(this .editPart, source_component,
068: target_component);
069: }
070:
071: public DefaultMepType getDefault_MEP() {
072:
073: if (ruleFactory != null)
074: return ruleFactory.getDefault_MEP();
075: else {
076:
077: return DefaultMepType.INOUT_LITERAL;
078: }
079:
080: }
081:
082: public void modifyExpression() {
083: if (source_component instanceof CBR) {
084: if (object.getType().equals(RegularType.EXACT_LITERAL))
085: object.setLabel(object.getExpression());
086: }
087: }
088:
089: public void refreshTargetDel(MessageExchangeEditPart editPart) {
090: if (ruleFactory != null)
091: ruleFactory.refreshTargetDel(editPart);
092: }
093:
094: public void refreshSourceDel() {
095: if (ruleFactory != null)
096: ruleFactory.refreshSourceDel();
097: }
098:
099: public RuleFactory getRuleFactory() {
100: return ruleFactory;
101: }
102:
103: public void refreshTarget() {
104: if (ruleFactory != null)
105: ruleFactory.refreshTarget();
106: }
107:
108: public void refreshSource() {
109: if (ruleFactory != null)
110: ruleFactory.refreshSource();
111:
112: }
113:
114: public boolean sourceTargetIsConnection() {
115: /*object = (MessageExchange) ((View) editPart.getModel()).getElement();
116: target_component = object.getTargetElement();
117: source_component = object.getSourceElement();
118: ruleFactory = new RuleFactory(this.editPart, source_component,
119: target_component);*/
120:
121: return ruleFactory.isConnected();
122:
123: }
124:
125: public void addAdapters() {
126: editPart.getDiagramEdge().getElement().eAdapters().add(
127: editPart.getDomainModelRefresher());
128:
129: // fetch the default mep for each type of the component, put them in the
130: // adapter
131: if (source_component instanceof BindingComponent) {
132: if (!(target_component instanceof DecorativeModelElement))
133: ((BindingComponentImpl) source_component).getConsumer()
134: .eAdapters().add(
135: editPart.getDomainModelRefresher());
136: else
137: ((BindingComponentImpl) source_component).getProvider()
138: .eAdapters().add(
139: editPart.getDomainModelRefresher());
140: }
141:
142: else if (source_component instanceof DecorativeModelElement) {
143: if (target_component instanceof BindingComponent) {
144: ((BindingComponentImpl) target_component).getConsumer()
145: .eAdapters().add(
146: editPart.getDomainModelRefresher());
147:
148: }
149: }
150: }
151:
152: public void removeAdapters() {
153:
154: editPart.getDiagramEdge().getElement().eAdapters().remove(
155: editPart.getDomainModelRefresher());
156: // first get the connection itself
157:
158: // fetch the default mep for each type of the component, put them in the
159: // adapter
160: if (source_component instanceof BindingComponent) {
161: if (!(target_component instanceof DecorativeModelElement))
162: ((BindingComponentImpl) source_component).getConsumer()
163: .eAdapters().remove(
164: editPart.getDomainModelRefresher());
165: else
166: ((BindingComponentImpl) source_component).getProvider()
167: .eAdapters().remove(
168: editPart.getDomainModelRefresher());
169: }
170:
171: else if (source_component instanceof DecorativeModelElement) {
172: if (target_component instanceof BindingComponent) {
173: ((BindingComponentImpl) target_component).getConsumer()
174: .eAdapters().remove(
175: editPart.getDomainModelRefresher());
176:
177: }
178: }
179:
180: }
181: }
|