Skip to main content
summaryrefslogtreecommitdiffstats
blob: 87c72f38b7c4f16ee75b8c5c1c93c66137f26819 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*******************************************************************************
 * Copyright (c) 2005, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20060726   151614 pmoogk@ca.ibm.com - Peter Moogk
 * 20061011   159283 makandre@ca.ibm.com - Andrew Mak, project not associated to EAR when using ant on command-line
 *******************************************************************************/

package org.eclipse.wst.command.internal.env.ant;

import java.util.Hashtable;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.command.internal.env.EnvironmentMessages;
import org.eclipse.wst.command.internal.env.context.PersistentResourceContext;
import org.eclipse.wst.command.internal.env.core.CommandManager;
import org.eclipse.wst.command.internal.env.core.context.TransientResourceContext;
import org.eclipse.wst.command.internal.env.core.data.DataFlowManager;
import org.eclipse.wst.command.internal.env.core.data.DataMappingRegistryImpl;
import org.eclipse.wst.command.internal.env.core.fragment.CommandFragment;
import org.eclipse.wst.command.internal.env.core.fragment.FragmentListener;

/**
 * 
 * Central point of control for web service Ant tasks.
 * Constructs Ant environment, root fragment and command manager.  Starts execution of the command stack.
 * 
 * @author joan
 *
 */

public class AntController {
	
	
   private AntOperationManager operationManager_;
	
   public AntController(Hashtable properties)
   {
	   // construct the environment - passing in the property table	   
	   // --maintains link to property table plus any other environment properties
	   // --code to access extension point mappings for operations to retrieve data from property table
	   TransientResourceContext  resourceContext = (TransientResourceContext)PersistentResourceContext.getInstance().copy();
	   AntStatusHandler          handler         = new AntStatusHandler();
	   AntEnvironment            environment     = new AntEnvironment(this, resourceContext, handler, properties);
       
	   // construct data manager for maintaining state across operations
	   DataFlowManager dataManager = new DataFlowManager( new DataMappingRegistryImpl(), environment);
       
	   //  set up operation fragments - conditional on options by user... service or client
	   //  also need to initialize the "selection" or input file (WSDL, Java) here
	   
	   CommandFragment rootFragment =  environment.getRootCommandFragment();
	   
	   if (rootFragment != null)
	   {		   
	       //construct the engine - manages execution of operations
		   createOperationManager(rootFragment, dataManager, environment);
		   
		   DataMappingRegistryImpl    dataRegistry_   = new DataMappingRegistryImpl();
		   rootFragment.registerDataMappings(dataRegistry_);		   
	   }
	   else  //problem getting the root fragment - scenario type is likely missing
	   {
		   handler.reportError(new Status(IStatus.ERROR, "ws_ant", 9999, EnvironmentMessages.MSG_ERROR_ANT_SCENARIO_TYPE, null));
		   return;
	   }
	      
	   //ready to start running operations
 	   ((AntOperationManager)getOperationManager()).moveForwardToNextStop(new NullProgressMonitor());

 	   if (!operationManager_.getLastStatus().isOK()) 		   
 		   operationManager_.undoToLastStop();
   }
   
   private void createOperationManager(CommandFragment frag, DataFlowManager mgr, AntEnvironment env)
   {		   
		   operationManager_ = new AntOperationManager(frag, mgr, env);			
	
		   operationManager_.setPeekFragmentListener( 
				      new FragmentListener()
				      {
				        public  boolean notify( CommandFragment fragment )
				        {
				          return peekFragment( fragment );
				        }
				      } );  
				                  
		   operationManager_.setNextFragmentListener( 
				      new FragmentListener()
				      {
				        public  boolean notify( CommandFragment fragment )
				        {
				          return nextFragment( fragment );
				        }
				      } );  
				                                                             
		   operationManager_.setUndoFragmentListener(
				      new FragmentListener()
				      {
				        public boolean notify( CommandFragment fragment )
				        {
				          return undoFragment( fragment );
				        }
				      } );
   }
	
	protected CommandManager getOperationManager()
	{
		return operationManager_;
	}
	
	/**
	   * The CommandFragmentEngine calls this method when it is peeking forward
	   * in the fragments.  When peeking forward the command stack state in the
	   * engine is not changes.
	   * 
	   * 
	   * @param fragment the fragment that it is peeking at.
	   * @return Indicates whether peeking should stop or not.
	   */
	  protected boolean peekFragment( CommandFragment fragment )
	  {     
	    return true;
	  }
	  
	  /**
	   * The CommandFragmentEngine calls this method when it is moving forward
	   * in the fragments.   When moving forward the command stack state is saved
	   * at each fragment is traversed.
	   * 
	   * @param fragment the fragment that is being traversed.
	   * @return indicates if the forward traversal should continue.  
	   */
	  protected boolean nextFragment( CommandFragment fragment )
	  {     
	    return true;
	  }
	  
	  /**
	   * This method is called for each fragment when the command engine is unwinding
	   * its stack during an undo operation.
	   * 
	   * @param fragment  the fragment being undone.
	   * @return returns true if the undo process should continue.
	   */
	  protected boolean undoFragment( CommandFragment fragment )
	  {  	  	
	    return true;
	  }
	   

	
	
   
   }

Back to the top