View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2007, Ontotext Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2007</p>
22   * <p>Company: Ontotext Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.bpmo.model;
26  
27  import java.util.*;
28  
29  import org.wsmostudio.bpmo.model.blockpatterns.BlockPatternNode;
30  import org.wsmostudio.bpmo.model.connectors.*;
31  
32  public abstract class WorkflowEntitiesContainer extends WorkflowEntityNode {
33  
34      protected List<WorkflowEntityNode> workflows = new ArrayList<WorkflowEntityNode>();
35      
36      public void addWorkflow(WorkflowEntityNode value) {
37          if (value == null) {
38              throw new IllegalArgumentException();
39          }
40          this.workflows.add(value);
41          value.setOwner(this);
42          firePropertyChange("content", null, value);
43      }
44  
45      public Collection<WorkflowEntityNode> listWorkflows() {
46          return Collections.unmodifiableList(this.workflows);
47      }
48  
49      public void removeWorkflow(WorkflowEntityNode value) {
50          this.workflows.remove(value);
51          value.setOwner(null);
52          firePropertyChange("content", value, null);
53      }
54      
55      protected void cloneProperties(WorkflowEntitiesContainer clone) {
56          super.cloneProperties(clone);
57          Map<WorkflowEntityNode, WorkflowEntityNode> clonesMap = 
58              new HashMap<WorkflowEntityNode, WorkflowEntityNode>();
59          Set<GraphConnector> conns = new HashSet<GraphConnector>();
60          for(WorkflowEntityNode wf : workflows) {
61              WorkflowEntityNode clonedChild = wf.cloneNode(); 
62              clone.addWorkflow(clonedChild);
63              clonesMap.put(wf, clonedChild);
64              conns.addAll(wf.listInArcs());
65              conns.addAll(wf.listOutArcs());
66              
67              if (wf instanceof BlockPatternNode) {
68                  clonesMap.put(((BlockPatternNode)wf).getStartNode(), 
69                          ((BlockPatternNode)clonedChild).getStartNode());
70                  clonesMap.put(((BlockPatternNode)wf).getEndNode(), 
71                          ((BlockPatternNode)clonedChild).getEndNode());
72              }
73              
74          }
75          if (clone instanceof BlockPatternNode) {
76              clonesMap.put(((BlockPatternNode)this).getStartNode(), 
77                      ((BlockPatternNode)clone).getStartNode());
78              clonesMap.put(((BlockPatternNode)this).getEndNode(), 
79                      ((BlockPatternNode)clone).getEndNode());
80  
81              conns.addAll(((BlockPatternNode)this).getStartNode().listOutArcs());
82              conns.addAll(((BlockPatternNode)this).getEndNode().listInArcs());
83          }
84          clonesMap.put(this, clone);
85          
86          for(GraphConnector conn : conns) {
87              WorkflowEntityNode newSource = clonesMap.get(conn.getSource());
88              WorkflowEntityNode newTarget = clonesMap.get(conn.getTarget());
89              
90              if (newSource == null 
91                      || newTarget == null) {
92                  System.out.println("Invalid!!!!");
93                  continue;
94              }
95              if (newTarget instanceof BlockPatternNode) {
96                  newTarget = ((BlockPatternNode)newTarget).getStartNode();
97              }
98              if (newSource instanceof BlockPatternNode) {
99                  newSource = ((BlockPatternNode)newSource).getEndNode();
100             }
101             
102             GraphConnector newConn = null;
103             if (conn instanceof DataflowConnector) {
104                 newConn = new DataflowConnector(newSource, 
105                         conn.getSourceTerminal(), 
106                         newTarget, 
107                         conn.getTargetTerminal());
108             }
109             else if (conn instanceof ControlflowArc) {
110                 newConn = new ControlflowArc(newSource, 
111                         conn.getSourceTerminal(), 
112                         newTarget, 
113                         conn.getTargetTerminal());
114             }
115             else {
116                 newConn = new MessageConnector(newSource, 
117                         conn.getSourceTerminal(), 
118                         newTarget, 
119                         conn.getTargetTerminal());
120             }
121             conn.cloneProperties(newConn);
122         }
123     }
124 
125 }