Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 179329 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (-1 / +13 lines)
Lines 7-13 Link Here
7
            container="Axis2"
7
            container="Axis2"
8
            platform="J2EE"/>
8
            platform="J2EE"/>
9
      <projectizer
9
      <projectizer
10
            class="org.eclipse.tptp.wsdm.tooling.internal.projectizer.EclipseAxis2Projectizer"
10
            class="org.eclipse.tptp.wsdm.tooling.internal.projectizer.EclipseJ2EEAxis2Projectizer"
11
            name="Axis2 J2EE"
11
            name="Axis2 J2EE"
12
            servicePath="/services"
12
            servicePath="/services"
13
            servicePort="8080"/>
13
            servicePort="8080"/>
Lines 16-19 Link Here
16
         point="org.eclipse.ui.startup">
16
         point="org.eclipse.ui.startup">
17
      <startup class="org.eclipse.tptp.wsdm.tooling.internal.codegeneration.Activator"/>
17
      <startup class="org.eclipse.tptp.wsdm.tooling.internal.codegeneration.Activator"/>
18
   </extension>
18
   </extension>
19
   <extension
20
         point="org.eclipse.tptp.wsdm.editor.codeGeneration">
21
      <description
22
            container="Mini"
23
            platform="J2EE">
24
      </description>
25
      <projectizer
26
            class="org.eclipse.tptp.wsdm.tooling.internal.projectizer.EclipseJ2EEMiniProjectizer"
27
            name="J2EE Mini"
28
            servicePort="8080">
29
      </projectizer>
30
   </extension>
19
</plugin>
31
</plugin>
(-)src/org/eclipse/tptp/wsdm/tooling/internal/util/WebProjectHelper.java (-10 / +2 lines)
Lines 14-33 Link Here
14
14
15
15
16
import java.io.File;
16
import java.io.File;
17
import java.net.URI;
18
17
19
import org.eclipse.core.filesystem.URIUtil;
20
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IWorkspaceRoot;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.core.runtime.NullProgressMonitor;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.jst.common.project.facet.IJavaFacetInstallDataModelProperties;
20
import org.eclipse.jst.common.project.facet.IJavaFacetInstallDataModelProperties;
28
import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
21
import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
29
import org.eclipse.jst.j2ee.web.project.facet.IWebFacetInstallDataModelProperties;
22
import org.eclipse.jst.j2ee.web.project.facet.IWebFacetInstallDataModelProperties;
30
import org.eclipse.tptp.wsdm.tooling.provisional.util.ProjectHelper;
31
import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
23
import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
32
import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties;
24
import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties;
33
import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties.FacetDataModelMap;
25
import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties.FacetDataModelMap;
Lines 40-46 Link Here
40
	private IProject _project;
32
	private IProject _project;
41
33
42
	public WebProjectHelper(String name, String location, String binDir, String sourceDir) throws Exception {
34
	public WebProjectHelper(String name, String location, String binDir, String sourceDir) throws Exception {
43
		_project = getProject(location, name);
35
		_project = getProject(location, name, null, false);
44
		
36
		
45
		IDataModel dataModel = DataModelFactory.createDataModel(IWebFacetInstallDataModelProperties.class);   
37
		IDataModel dataModel = DataModelFactory.createDataModel(IWebFacetInstallDataModelProperties.class);   
46
		dataModel.setProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME, name);     
38
		dataModel.setProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME, name);     
Lines 61-67 Link Here
61
		return _project;
53
		return _project;
62
	}
54
	}
63
55
64
	public void setSuspendValidation(boolean shouldSuspend) {		
56
	public void setSuspendValidation(boolean shouldSuspend) {
65
		ValidatorManager.getManager().suspendValidation(getProject(), shouldSuspend);
57
		ValidatorManager.getManager().suspendValidation(getProject(), shouldSuspend);
66
	}
58
	}
67
	
59
	
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseAxis2Projectizer.java (-272 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.internal.projectizer;
14
15
16
import java.io.File;
17
import java.io.FileNotFoundException;
18
import java.net.URL;
19
import java.util.Map;
20
21
import org.apache.muse.tools.generator.projectizer.Axis2ProjectizerConstants;
22
import org.apache.muse.tools.generator.projectizer.J2EEAxis2Projectizer;
23
import org.apache.muse.tools.generator.util.ConfigurationData;
24
import org.apache.muse.tools.generator.util.ServicesDescriptorHelper;
25
import org.apache.muse.util.FileUtils;
26
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
27
import org.apache.muse.ws.wsdl.WsdlUtils;
28
import org.eclipse.core.runtime.FileLocator;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.EclipseConfigurationData;
32
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.TargetedFileList;
33
import org.eclipse.tptp.wsdm.tooling.internal.codegeneration.Activator;
34
import org.eclipse.tptp.wsdm.tooling.internal.util.WebProjectHelper;
35
import org.w3c.dom.Document;
36
import org.w3c.dom.Element;
37
38
/**
39
 * Construct the projectizer for code generation
40
 */
41
public class EclipseAxis2Projectizer extends J2EEAxis2Projectizer {
42
	
43
	private static final String[] LIB_BUNDLE_IDS = { 
44
		"org.apache.muse.api", //$NON-NLS-1$
45
		"org.apache.muse.impl", //$NON-NLS-1$
46
		"org.apache.muse.core", //$NON-NLS-1$
47
		"org.apache.muse.tools", //$NON-NLS-1$
48
		"org.apache.muse.utils" //$NON-NLS-1$
49
		};
50
	
51
	private static final String[] MODULE_BUNDLE_IDS = { 
52
		"org.apache.muse.tools", //$NON-NLS-1$
53
		};
54
	
55
	private File[] _additionalJars;
56
	private Object[][] _instances;
57
	private IProgressMonitor _progressMonitor;
58
	private TargetedFileList[] _filesToCopy;
59
60
	private int _resourceCounter = 0;
61
62
	private String _projectName;
63
64
	private String _projectLocation;
65
	
66
	public void projectize(ConfigurationData configuration) throws Exception {
67
		
68
		ConfigurationData.checkConfiguration(this, configuration);
69
				
70
		try {
71
			
72
		loadParameters(configuration);
73
74
		startProgressMonitor(_progressMonitor, 10);
75
76
		WebProjectHelper helper = createProject();
77
		
78
		_targetDirectory = helper.getProjectDirectory();		
79
		
80
		recordProgress(_progressMonitor, 1);
81
		
82
		helper.setSuspendValidation(true);
83
84
		File webContentDir = copyTemplate(_targetDirectory);
85
		recordProgress(_progressMonitor, 1);
86
						
87
		File descriptorFile = new File(
88
				webContentDir, 
89
				Axis2ProjectizerConstants.DESCRIPTOR_FILE);
90
		
91
		File javaSourceDir = new File(
92
				_targetDirectory, 
93
				Axis2ProjectizerConstants.JAVA_SRC_DIR);
94
		
95
		createJavaSources(javaSourceDir, _filesMaps);
96
		recordProgress(_progressMonitor, 1);
97
		
98
		File wsdldir = new File(
99
				webContentDir, 
100
				Axis2ProjectizerConstants.WSDL_DIR);
101
102
		File routerEntriesDir = new File(webContentDir,Axis2ProjectizerConstants.ROUTER_ENTRIES_DIR);
103
		
104
		ServicesDescriptorHelper servicesHelper = new ServicesDescriptorHelper();
105
				
106
		createBuildFile(_targetDirectory, EclipseAxis2ProjectizerConstants.BUILD_FILE_RESOURCE, EclipseAxis2ProjectizerConstants.BUILD_FILE);
107
		recordProgress(_progressMonitor, 1);
108
		
109
		for(int i=0; i < _capabilitiesList.length; i++) {
110
			Map capabilities = _capabilitiesList[i];
111
			Document wsdl = _wsdls[i];
112
			createDescriptor(_descriptor, wsdl, descriptorFile, capabilities, Axis2ProjectizerConstants.WSDL_RELATIVE_PATH, i);						
113
			MetadataDescriptor rmd = _metadatas[i];
114
			createRMDFile(rmd, wsdl, wsdldir);
115
			createWSDLFile(wsdl, wsdldir);
116
			if(_instances == null) {
117
				createRouterEntries(routerEntriesDir, WsdlUtils.getServiceName(wsdl.getDocumentElement()), _capabilitiesList[i]);
118
			}
119
			updateServicesDescriptor(servicesHelper, wsdl, capabilities);
120
		}		
121
					
122
		if(_instances != null) {
123
			createRouterEntries(routerEntriesDir, _instances);
124
		}
125
		recordProgress(_progressMonitor, 4);
126
		
127
		File servicesFile = new File(webContentDir, Axis2ProjectizerConstants.SERVICES_FILE);
128
		createServicesDescriptor(servicesHelper, servicesFile);
129
		recordProgress(_progressMonitor, 1);
130
		
131
		helper.refreshProject();
132
		recordProgress(_progressMonitor, 1);
133
		
134
		helper.setSuspendValidation(false);
135
		} finally {
136
			finishProgressMonitor(_progressMonitor);
137
		}
138
	}
139
		
140
	private void finishProgressMonitor(IProgressMonitor monitor) {
141
		if(monitor != null) {
142
			monitor.done();
143
		}
144
	}
145
146
	private void recordProgress(IProgressMonitor monitor, int i) {
147
		if(monitor != null) {
148
			monitor.worked(1);
149
		}
150
	}
151
152
	private void startProgressMonitor(IProgressMonitor monitor, int i) {
153
		if(monitor != null) {
154
			monitor.beginTask("Running Projectizer", 9);
155
		}
156
	}
157
158
	protected void loadParameters(ConfigurationData data) {
159
		super.loadParameters(data);
160
		
161
		_additionalJars = (File[])data.getParameter(EclipseConfigurationData.ADDITIONAL_JARS);
162
		_instances = (Object[][])data.getParameter(EclipseConfigurationData.INSTANCES);	
163
		_progressMonitor = (IProgressMonitor)data.getParameter(EclipseConfigurationData.PROGRESS_MONITOR);
164
		_filesToCopy = (TargetedFileList[])data.getParameter(EclipseConfigurationData.AXIS2_FILES);
165
		_projectName = (String)data.getParameter(EclipseConfigurationData.PROJECT_NAME);
166
		_projectLocation = (String)data.getParameter(EclipseConfigurationData.PROJECT_LOCATION);		
167
	}
168
169
	private WebProjectHelper createProject() throws Exception {
170
		WebProjectHelper helper = new WebProjectHelper(_projectName, _projectLocation, EclipseAxis2ProjectizerConstants.JAVA_BIN_DIR, Axis2ProjectizerConstants.JAVA_SRC_DIR);
171
		
172
		return helper;
173
	}
174
	
175
	protected void createRouterEntries(File routerEntriesDir,Object[][] instances) throws Exception {
176
		routerEntriesDir.mkdirs();
177
		
178
		for (int i = 0; i < _instances.length; i++) {
179
			Object[] instancePair = _instances[i];
180
181
			//
182
			// This is really tacky, but it's the only real way to do this
183
			// since there are no pairs. The File use is to get the last element
184
			// of the path in a nice, non-hack way.
185
			//
186
			String path = (String) instancePair[0];
187
			String resourcePathName = new File(path).getName();
188
189
			Element instanceElement = (Element) instancePair[1];
190
191
			File serviceDir = new File(routerEntriesDir, resourcePathName);
192
			File routerEntryFile = new File(serviceDir, getResourceFileName());
193
194
			writeToFileCheck(instanceElement, routerEntryFile);
195
		}
196
	}
197
	
198
	protected String getResourceFileName() {
199
		return Axis2ProjectizerConstants.RESOURCE_FILE.replaceFirst(PLACE_HOLDER, String.valueOf(_resourceCounter++));
200
	}
201
	
202
	protected File copyTemplate(File destination) throws Exception {	
203
		URL url = Platform.getBundle(Activator.PLUGIN_ID).getEntry(EclipseAxis2ProjectizerConstants.WEBCONTENT_DIR_RESOURCE);
204
		url = FileLocator.toFileURL(url);
205
		
206
		File source = toFile(url);
207
		FileUtils.copyDirectory(source, destination);
208
		
209
		File webContentDir = new File(destination, source.getName());
210
		File webContentDestination = new File(webContentDir, "WEB-INF"); //$NON-NLS-1$
211
		
212
		for (int i=0; i < LIB_BUNDLE_IDS.length; i++) {		
213
			url = Platform.getBundle(LIB_BUNDLE_IDS[i]).getEntry(EclipseAxis2ProjectizerConstants.PROJECT_LIB_DIR_RESOURCE);
214
			url = FileLocator.toFileURL(url);
215
	
216
			File libSource = toFile(url);			
217
			FileUtils.copyDirectory(libSource, webContentDestination);
218
		}
219
		
220
		for (int i=0; i < MODULE_BUNDLE_IDS.length; i++) {		
221
			url = Platform.getBundle(MODULE_BUNDLE_IDS[i]).getEntry(EclipseAxis2ProjectizerConstants.PROJECT_MODULE_DIR_RESOURCE);
222
			url = FileLocator.toFileURL(url);
223
	
224
			File libSource = toFile(url);			
225
			FileUtils.copyDirectory(libSource, webContentDestination);
226
		}
227
		
228
		//
229
		//TODO: Hack to copy axis2-platform
230
		//this should be done in some cleaner way
231
		//
232
		
233
		url = Platform.getBundle(MODULE_BUNDLE_IDS[0]).getEntry("/lib/muse-platform-axis2-2.2.0.jar");
234
		url = FileLocator.toFileURL(url);
235
236
		File libSource = toFile(url);			
237
		FileUtils.copyFile(libSource, webContentDestination);
238
		
239
		File libDestination = new File(webContentDestination, "lib");
240
		
241
		if(_additionalJars != null) {
242
			for (int i=0; i < _additionalJars.length; i++) {
243
				if(!_additionalJars[i].exists()) {
244
					throw new FileNotFoundException(_additionalJars[i].getAbsolutePath());
245
				}
246
				
247
				FileUtils.copyFile(_additionalJars[i], libDestination);
248
			}
249
		}
250
		
251
		for (int i=0; i < _filesToCopy.length; i++) {
252
			String dest = _filesToCopy[i].getRelativePath();
253
			File destDir = new File(webContentDir, dest);
254
			String[] files = _filesToCopy[i].getFiles();
255
			
256
			for (int j=0; j < files.length; j++) {
257
				File file = new File(files[j]);
258
				if(!file.exists()) {
259
					throw new FileNotFoundException(file.getAbsolutePath());
260
				}
261
				
262
				FileUtils.copyFile(file, destDir);
263
			}
264
		}
265
266
		return webContentDir;	
267
	}
268
	private File toFile(URL url) throws Exception{
269
270
		return new File(url.getFile());
271
	}
272
}
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseAxis2ProjectizerConstants.java (-34 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.internal.projectizer;
14
15
16
public interface EclipseAxis2ProjectizerConstants {
17
	
18
	String RESOURCES_DIR = "/resources/axis2/"; //$NON-NLS-1$
19
	
20
	String BUILD_FILE_RESOURCE = RESOURCES_DIR + "build.xml"; //$NON-NLS-1$
21
	
22
	String BUILD_FILE = "build.xml"; //$NON-NLS-1$
23
24
	String LAUNCH_FILE_RESOURCE = RESOURCES_DIR + ".externalToolBuilders/jarBuilder.launch"; //$NON-NLS-1$
25
26
	String WEBCONTENT_DIR_RESOURCE = RESOURCES_DIR + "WebContent"; //$NON-NLS-1$
27
28
	String PROJECT_LIB_DIR_RESOURCE = "/lib"; //$NON-NLS-1$
29
	
30
	String PROJECT_MODULE_DIR_RESOURCE = "/modules"; //$NON-NLS-1$
31
32
	String JAVA_BIN_DIR = "bin"; //$NON-NLS-1$
33
34
}
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseJ2EEMiniProjectizer.java (+285 lines)
Lines 1-7 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
1
package org.eclipse.tptp.wsdm.tooling.internal.projectizer;
12
package org.eclipse.tptp.wsdm.tooling.internal.projectizer;
2
13
14
import java.io.File;
15
import java.io.FileNotFoundException;
16
import java.io.InputStream;
17
import java.net.URL;
18
import java.util.Map;
19
3
import org.apache.muse.tools.generator.projectizer.J2EEMiniProjectizer;
20
import org.apache.muse.tools.generator.projectizer.J2EEMiniProjectizer;
21
import org.apache.muse.tools.generator.util.ConfigurationData;
22
import org.apache.muse.util.FileUtils;
23
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
24
import org.apache.muse.ws.wsdl.WsdlUtils;
25
import org.eclipse.core.runtime.FileLocator;
26
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.core.runtime.Platform;
28
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseConfigurationData;
29
import org.eclipse.tptp.wsdm.tooling.internal.util.ProgressMonitorHelper;
30
import org.eclipse.tptp.wsdm.tooling.internal.util.ProjectHelper;
31
import org.eclipse.tptp.wsdm.tooling.internal.util.WebProjectHelper;
32
import org.w3c.dom.Document;
33
import org.w3c.dom.Element;
4
34
5
public class EclipseJ2EEMiniProjectizer extends J2EEMiniProjectizer {
35
public class EclipseJ2EEMiniProjectizer extends J2EEMiniProjectizer {
36
	private static final String[] LIB_BUNDLE_IDS = { 
37
		"org.apache.muse.api", //$NON-NLS-1$
38
		"org.apache.muse.impl", //$NON-NLS-1$
39
		"org.apache.muse.core", //$NON-NLS-1$
40
		"org.apache.muse.tools", //$NON-NLS-1$
41
		"org.apache.muse.utils" //$NON-NLS-1$
42
		};
43
	
44
	private static final String CONTAINER_BUNDLE = "org.apache.muse.tools";//$NON-NLS-1$
45
	private static final String CONTAINER_RESOURCE = "/containers/muse-platform-mini-2.2.0.jar";//$NON-NLS-1$
46
		
47
	private String _projectName;
48
	private String _projectLocation;
49
	private File[] _additionalJars;
50
	private Object[][] _instances;
51
	private ProgressMonitorHelper _progressMonitorHelper;
52
53
	public void projectize(ConfigurationData configuration) throws Exception {
54
		ConfigurationData.checkConfiguration(this, configuration);
55
		loadParameters(configuration);		 
56
		ProgressMonitorHelper progressHelper = getProgressMonitor();
57
		progressHelper.startProgressMonitor(6);
58
		
59
		try {			
60
			WebProjectHelper helper = createProjectHelper();
61
			
62
			helper.setSuspendValidation(true);
63
				
64
			createJavaSources(helper, progressHelper);		
65
			createArtifacts(helper, progressHelper);
66
			createLibraries(helper, progressHelper);
67
						
68
			helper.refreshProject();
69
			helper.setSuspendValidation(false);			
70
		} finally {
71
			progressHelper.finishProgressMonitor();
72
		}
73
	}
74
75
	protected void createLibraries(WebProjectHelper helper, ProgressMonitorHelper progressHelper) throws Exception {		
76
		copyLibrariesFromBundles(helper, LIB_BUNDLE_IDS);
77
		progressHelper.recordProgress();
78
		
79
		copyAdditionalJars(helper);
80
		progressHelper.recordProgress();
81
		
82
		copyContainer(helper);
83
		progressHelper.recordProgress();
84
	}
85
86
	protected void copyContainer(WebProjectHelper helper) throws Exception {
87
		File webInfLibDir = new File(helper.getProjectDirectory(), EclipseJ2EEMiniProjectizerConstants.WEBINFLIB_DIR);
88
		URL url = Platform.getBundle(CONTAINER_BUNDLE).getEntry(CONTAINER_RESOURCE);
89
		url = FileLocator.toFileURL(url);
90
		
91
		File libSource = ProjectHelper.toFile(url);			
92
		FileUtils.copy(libSource, webInfLibDir);
93
	}
94
95
	protected void copyAdditionalJars(WebProjectHelper helper) throws Exception {
96
		File webInfLibDir = new File(helper.getProjectDirectory(), EclipseJ2EEMiniProjectizerConstants.WEBINFLIB_DIR);
97
		
98
		File[] additionalJars = getAdditionalJars();
99
		
100
		if(additionalJars != null) {
101
			for (int i=0; i < additionalJars.length; i++) {
102
				if(!additionalJars[i].exists()) {
103
					throw new FileNotFoundException(additionalJars[i].getAbsolutePath());
104
				}
105
				
106
				FileUtils.copyFile(additionalJars[i], webInfLibDir);
107
			}
108
		}
109
	}
110
111
	protected void copyLibrariesFromBundles(WebProjectHelper helper, String[] libBundleIds) throws Exception {
112
		URL url = null;
113
		File webInfDir = new File(helper.getProjectDirectory(), EclipseJ2EEMiniProjectizerConstants.WEBINF_DIR);
114
		
115
		for (int i=0; i < libBundleIds.length; i++) {		
116
			url = Platform.getBundle(libBundleIds[i]).getEntry(EclipseJ2EEMiniProjectizerConstants.PROJECT_LIB_DIR_RESOURCE);
117
			url = FileLocator.toFileURL(url);
118
	
119
			File libSource = ProjectHelper.toFile(url);			
120
			FileUtils.copyDirectory(libSource, webInfDir);
121
		}
122
	}
123
124
	protected WebProjectHelper createProjectHelper() throws Exception {
125
		return new WebProjectHelper(
126
				getProjectName(), 
127
				getProjectLocation(), 
128
				EclipseJ2EEMiniProjectizerConstants.JAVA_BIN_DIR, 
129
				EclipseJ2EEMiniProjectizerConstants.JAVA_SRC_DIR);
130
	}
131
132
	protected void createJavaSources(WebProjectHelper helper, ProgressMonitorHelper progressHelper) throws Exception {
133
		File javaSourceDir = new File(
134
				helper.getProjectDirectory(), 
135
				EclipseJ2EEMiniProjectizerConstants.JAVA_SRC_DIR);
136
		
137
		createJavaSources(javaSourceDir, getFilesMaps());	
138
		progressHelper.recordProgress();
139
	}
140
141
	protected void createArtifacts(WebProjectHelper helper, ProgressMonitorHelper progressHelper) throws Exception {				
142
		File descriptorFile = new File(
143
				helper.getProjectDirectory(), 
144
				EclipseJ2EEMiniProjectizerConstants.DESCRIPTOR_FILE);
145
		
146
		File wsdldir = new File(
147
				helper.getProjectDirectory(), 
148
				EclipseJ2EEMiniProjectizerConstants.WSDL_DIR);
149
		
150
		File routerEntriesDir = new File(
151
				helper.getProjectDirectory(),
152
				EclipseJ2EEMiniProjectizerConstants.ROUTER_ENTRIES_DIR);
153
		
154
		for(int i=0; i < getNumCapabilityMaps(); i++) {
155
			Map capabilities = getCapabilityMap(i);
156
			MetadataDescriptor rmd = getMetadata(i);
157
			Document wsdl = getWsdl(i);
158
			
159
			createDescriptor(getDescriptor(), 
160
					wsdl, 
161
					descriptorFile, 
162
					capabilities, 
163
					EclipseJ2EEMiniProjectizerConstants.WSDL_RELATIVE_PATH, 
164
					i);					
165
		
166
			createRMDFile(rmd, wsdl, wsdldir);
167
			createWSDLFile(wsdl, wsdldir);
168
			
169
			if(getInstances() == null) {
170
				createRouterEntries(routerEntriesDir, WsdlUtils.getServiceName(wsdl.getDocumentElement()), _capabilitiesList[i]);
171
			}
172
		}		
173
		
174
		progressHelper.recordProgress();
175
					
176
		if(getInstances() != null) {
177
			createRouterEntries(routerEntriesDir, getInstances());
178
		}
179
				
180
		createWebDescriptor(helper);
181
		createBuildFile(helper.getProjectDirectory(), 
182
				EclipseJ2EEMiniProjectizerConstants.BUILD_FILE_RESOURCE, 
183
				EclipseJ2EEMiniProjectizerConstants.BUILD_FILE);
184
		
185
		progressHelper.recordProgress();
186
	}
187
188
	protected void createBuildFile(File baseTargetDir, String buildFileResource, String buildFile) throws Exception {
189
		InputStream buildTemplate = FileUtils.loadFromContext(this.getClass(),buildFileResource);
190
		File build = new File(baseTargetDir, buildFile);
191
		copyStreamCheck(buildTemplate, build);			
192
	}
193
	
194
	protected void createWebDescriptor(WebProjectHelper helper) throws Exception {
195
		File webInfDir =  new File(helper.getProjectDirectory(),EclipseJ2EEMiniProjectizerConstants.WEBINF_DIR);
196
		File descriptorFile = new File(webInfDir, EclipseJ2EEMiniProjectizerConstants.WEBXML_FILE);
197
		if(!descriptorFile.delete()) {
198
			throw new Exception();
199
		}
200
		createFileFromResource(webInfDir, 
201
				EclipseJ2EEMiniProjectizerConstants.WEBXML_RESOURCE, 
202
				EclipseJ2EEMiniProjectizerConstants.WEBXML_FILE);
203
	}
204
205
	protected Map getCapabilityMap(int index) {
206
		return _capabilitiesList[index];
207
	}
208
209
	protected void createRouterEntries(File routerEntriesDir,Object[][] instances) throws Exception {
210
		routerEntriesDir.mkdirs();
211
		
212
		for (int i = 0; i < getInstances().length; i++) {
213
			Object[] instancePair = getInstances()[i];
214
215
			//
216
			// This is really tacky, but it's the only real way to do this
217
			// since there are no pairs. The File use is to get the last element
218
			// of the path in a nice, non-hack way.
219
			//
220
			String path = (String) instancePair[0];
221
			String resourcePathName = new File(path).getName();
222
223
			Element instanceElement = (Element) instancePair[1];
224
225
			File serviceDir = new File(routerEntriesDir, resourcePathName);
226
			File routerEntryFile = new File(serviceDir, getResourceFileName(i));
227
228
			writeToFileCheck(instanceElement, routerEntryFile);
229
		}
230
	}
231
	
232
	/**
233
	 * Get the name of a resource-instance file with the appropriate counter. This is 
234
	 * really just a string-replace of the PLACE_HOLDER value with the given counter
235
	 * 
236
	 * @param counter	The number to use in the string replace
237
	 * @return 			The string with PLACE_HOLDER replaced by the string value of counter
238
	 */
239
	protected String getResourceFileName(int counter) {
240
		return EclipseJ2EEMiniProjectizerConstants.RESOURCE_FILE.replaceFirst(PLACE_HOLDER, String.valueOf(counter));
241
	}
242
243
	protected void loadParameters(ConfigurationData data) {
244
		super.loadParameters(data);
245
246
		_additionalJars = (File[]) data.getParameter(EclipseConfigurationData.ADDITIONAL_JARS);
247
		_instances = (Object[][]) data.getParameter(EclipseConfigurationData.INSTANCES);
248
		_progressMonitorHelper = new ProgressMonitorHelper((IProgressMonitor) data.getParameter(EclipseConfigurationData.PROGRESS_MONITOR));
249
		_projectName = (String) data.getParameter(EclipseConfigurationData.PROJECT_NAME);
250
		_projectLocation = (String) data.getParameter(EclipseConfigurationData.PROJECT_LOCATION);
251
	}
252
253
	protected File[] getAdditionalJars() {
254
		return _additionalJars;
255
	}
256
	
257
	protected Map[] getFilesMaps() {
258
		return _filesMaps;
259
	}
260
	
261
	protected String getProjectLocation() {
262
		return _projectLocation;
263
	}
264
265
	protected String getProjectName() {
266
		return _projectName;
267
	}
268
		
269
	protected ProgressMonitorHelper getProgressMonitor() {
270
		return _progressMonitorHelper;
271
	}
272
	
273
	protected Object[][] getInstances() {
274
		return _instances;
275
	}
276
	
277
	protected Document getDescriptor() {
278
		return _descriptor;
279
	}
280
281
	protected int getNumCapabilityMaps() {
282
		return _capabilitiesList.length;
283
	}
284
285
	protected Document getWsdl(int index) {
286
		return _wsdls[index];
287
	}
6
288
289
	protected MetadataDescriptor getMetadata(int index) {
290
		return _metadatas[index];
291
	}
7
}
292
}
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseJ2EEMiniProjectizerConstants.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.tptp.wsdm.tooling.internal.projectizer;
13
14
public interface EclipseJ2EEMiniProjectizerConstants {
15
16
	String RESOURCE_FILE = "resource-instance-XXX.xml";//$NON-NLS-1$
17
	String WSDL_RELATIVE_PATH = "/wsdl/";//$NON-NLS-1$
18
	
19
	String JAVA_SRC_DIR = "JavaSource/";//$NON-NLS-1$
20
	String WEBCONTENT_DIR = "WebContent/";//$NON-NLS-1$
21
	String WEBINF_DIR = WEBCONTENT_DIR + "WEB-INF/";//$NON-NLS-1$
22
	
23
	String JAVA_BIN_DIR = "/bin";//$NON-NLS-1$
24
	String JAVA_CLASSES_DIR = WEBINF_DIR + "classes/";//$NON-NLS-1$
25
	String DESCRIPTOR_FILE = JAVA_CLASSES_DIR + "muse.xml";//$NON-NLS-1$			
26
	String WSDL_DIR = JAVA_CLASSES_DIR + "wsdl/";//$NON-NLS-1$
27
	String ROUTER_ENTRIES_DIR = JAVA_CLASSES_DIR + "router-entries/";//$NON-NLS-1$
28
	
29
	String RESOURCES_DIR = "/resources/mini/";//$NON-NLS-1$
30
	String WEBXML_RESOURCE = RESOURCES_DIR + "web.xml";//$NON-NLS-1$
31
	String WEBXML_FILE = "web.xml";//$NON-NLS-1$
32
	String PROJECT_LIB_DIR_RESOURCE = "/lib/";//$NON-NLS-1$
33
	String WEBINFLIB_DIR = WEBINF_DIR + "lib/";//$NON-NLS-1$
34
	String BUILD_FILE_RESOURCE = RESOURCES_DIR + "build.xml"; //$NON-NLS-1$;
35
	String BUILD_FILE = "build.xml";
36
}
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseJ2EEAxis2Projectizer.java (+251 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.internal.projectizer;
14
15
16
import java.io.File;
17
import java.io.FileNotFoundException;
18
import java.net.URL;
19
import java.util.Map;
20
21
import org.apache.muse.tools.generator.projectizer.Axis2ProjectizerConstants;
22
import org.apache.muse.tools.generator.projectizer.J2EEAxis2Projectizer;
23
import org.apache.muse.tools.generator.util.ConfigurationData;
24
import org.apache.muse.tools.generator.util.ServicesDescriptorHelper;
25
import org.apache.muse.util.FileUtils;
26
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
27
import org.apache.muse.ws.wsdl.WsdlUtils;
28
import org.eclipse.core.runtime.FileLocator;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseConfigurationData;
32
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.TargetedFileList;
33
import org.eclipse.tptp.wsdm.tooling.internal.codegeneration.Activator;
34
import org.eclipse.tptp.wsdm.tooling.internal.util.ProgressMonitorHelper;
35
import org.eclipse.tptp.wsdm.tooling.internal.util.ProjectHelper;
36
import org.eclipse.tptp.wsdm.tooling.internal.util.WebProjectHelper;
37
import org.w3c.dom.Document;
38
import org.w3c.dom.Element;
39
40
/**
41
 * Construct the projectizer for code generation
42
 */
43
public class EclipseJ2EEAxis2Projectizer extends J2EEAxis2Projectizer {
44
	
45
	
46
	private static final String CONTAINER_BUNDLE = "org.apache.muse.tools";//$NON-NLS-1$
47
	private static final String CONTAINER_RESOURCE = "/containers/muse-platform-axis2-2.2.0.jar";//$NON-NLS-1$
48
		
49
	
50
	private static final String[] LIB_BUNDLE_IDS = { 
51
		"org.apache.muse.api", //$NON-NLS-1$
52
		"org.apache.muse.impl", //$NON-NLS-1$
53
		"org.apache.muse.core", //$NON-NLS-1$
54
		"org.apache.muse.tools", //$NON-NLS-1$
55
		"org.apache.muse.utils" //$NON-NLS-1$
56
		};
57
	
58
	private static final String[] MODULE_BUNDLE_IDS = { 
59
		"org.apache.muse.tools", //$NON-NLS-1$
60
		};
61
	
62
	private File[] _additionalJars;
63
	private Object[][] _instances;
64
	private IProgressMonitor _progressMonitor;
65
	private TargetedFileList[] _filesToCopy;
66
67
	private int _resourceCounter = 0;
68
69
	private String _projectName;
70
71
	private String _projectLocation;
72
	
73
	public void projectize(ConfigurationData configuration) throws Exception {
74
		
75
		ConfigurationData.checkConfiguration(this, configuration);
76
		loadParameters(configuration);
77
		ProgressMonitorHelper progressHelper = new ProgressMonitorHelper(_progressMonitor);	
78
		try {
79
			
80
		progressHelper.startProgressMonitor(10);
81
82
		WebProjectHelper helper = createProject();
83
		
84
		_targetDirectory = helper.getProjectDirectory();		
85
		
86
		progressHelper.recordProgress();
87
		
88
		helper.setSuspendValidation(true);
89
90
		File webContentDir = copyTemplate(_targetDirectory);
91
		progressHelper.recordProgress();
92
						
93
		File descriptorFile = new File(
94
				webContentDir, 
95
				Axis2ProjectizerConstants.DESCRIPTOR_FILE);
96
		
97
		File javaSourceDir = new File(
98
				_targetDirectory, 
99
				Axis2ProjectizerConstants.JAVA_SRC_DIR);
100
		
101
		createJavaSources(javaSourceDir, _filesMaps);
102
		progressHelper.recordProgress();
103
		
104
		File wsdldir = new File(
105
				webContentDir, 
106
				Axis2ProjectizerConstants.WSDL_DIR);
107
108
		File routerEntriesDir = new File(webContentDir,Axis2ProjectizerConstants.ROUTER_ENTRIES_DIR);
109
		
110
		ServicesDescriptorHelper servicesHelper = new ServicesDescriptorHelper();
111
				
112
		createBuildFile(_targetDirectory, EclipseJ2EEAxis2ProjectizerConstants.BUILD_FILE_RESOURCE, EclipseJ2EEAxis2ProjectizerConstants.BUILD_FILE);
113
		progressHelper.recordProgress();
114
		
115
		for(int i=0; i < _capabilitiesList.length; i++) {
116
			Map capabilities = _capabilitiesList[i];
117
			Document wsdl = _wsdls[i];
118
			createDescriptor(_descriptor, wsdl, descriptorFile, capabilities, Axis2ProjectizerConstants.WSDL_RELATIVE_PATH, i);						
119
			MetadataDescriptor rmd = _metadatas[i];
120
			createRMDFile(rmd, wsdl, wsdldir);
121
			createWSDLFile(wsdl, wsdldir);
122
			if(_instances == null) {
123
				createRouterEntries(routerEntriesDir, WsdlUtils.getServiceName(wsdl.getDocumentElement()), _capabilitiesList[i]);
124
			}
125
			updateServicesDescriptor(servicesHelper, wsdl, capabilities);
126
		}		
127
					
128
		if(_instances != null) {
129
			createRouterEntries(routerEntriesDir, _instances);
130
		}
131
		progressHelper.recordProgress(4);
132
		
133
		File servicesFile = new File(webContentDir, Axis2ProjectizerConstants.SERVICES_FILE);
134
		createServicesDescriptor(servicesHelper, servicesFile);
135
		progressHelper.recordProgress();
136
		
137
		helper.refreshProject();
138
		progressHelper.recordProgress();
139
		
140
		helper.setSuspendValidation(false);
141
		} finally {
142
			progressHelper.finishProgressMonitor();
143
		}
144
	}	
145
146
	protected void loadParameters(ConfigurationData data) {
147
		super.loadParameters(data);
148
		
149
		_additionalJars = (File[])data.getParameter(EclipseConfigurationData.ADDITIONAL_JARS);
150
		_instances = (Object[][])data.getParameter(EclipseConfigurationData.INSTANCES);	
151
		_progressMonitor = (IProgressMonitor)data.getParameter(EclipseConfigurationData.PROGRESS_MONITOR);
152
		_filesToCopy = (TargetedFileList[])data.getParameter(EclipseConfigurationData.AXIS2_FILES);
153
		_projectName = (String)data.getParameter(EclipseConfigurationData.PROJECT_NAME);
154
		_projectLocation = (String)data.getParameter(EclipseConfigurationData.PROJECT_LOCATION);		
155
	}
156
157
	private WebProjectHelper createProject() throws Exception {
158
		WebProjectHelper helper = new WebProjectHelper(_projectName, _projectLocation, EclipseJ2EEAxis2ProjectizerConstants.JAVA_BIN_DIR, Axis2ProjectizerConstants.JAVA_SRC_DIR);
159
		
160
		return helper;
161
	}
162
	
163
	protected void createRouterEntries(File routerEntriesDir,Object[][] instances) throws Exception {
164
		routerEntriesDir.mkdirs();
165
		
166
		for (int i = 0; i < _instances.length; i++) {
167
			Object[] instancePair = _instances[i];
168
169
			//
170
			// This is really tacky, but it's the only real way to do this
171
			// since there are no pairs. The File use is to get the last element
172
			// of the path in a nice, non-hack way.
173
			//
174
			String path = (String) instancePair[0];
175
			String resourcePathName = new File(path).getName();
176
177
			Element instanceElement = (Element) instancePair[1];
178
179
			File serviceDir = new File(routerEntriesDir, resourcePathName);
180
			File routerEntryFile = new File(serviceDir, getResourceFileName());
181
182
			writeToFileCheck(instanceElement, routerEntryFile);
183
		}
184
	}
185
	
186
	protected String getResourceFileName() {
187
		return Axis2ProjectizerConstants.RESOURCE_FILE.replaceFirst(PLACE_HOLDER, String.valueOf(_resourceCounter++));
188
	}
189
	
190
	protected File copyTemplate(File destination) throws Exception {	
191
		URL url = Platform.getBundle(Activator.PLUGIN_ID).getEntry(EclipseJ2EEAxis2ProjectizerConstants.WEBCONTENT_DIR_RESOURCE);
192
		url = FileLocator.toFileURL(url);
193
		
194
		File source = ProjectHelper.toFile(url);
195
		FileUtils.copyDirectory(source, destination);
196
		
197
		File webContentDir = new File(destination, source.getName());
198
		File webContentDestination = new File(webContentDir, "WEB-INF"); //$NON-NLS-1$
199
		
200
		for (int i=0; i < LIB_BUNDLE_IDS.length; i++) {		
201
			url = Platform.getBundle(LIB_BUNDLE_IDS[i]).getEntry(EclipseJ2EEAxis2ProjectizerConstants.PROJECT_LIB_DIR_RESOURCE);
202
			url = FileLocator.toFileURL(url);
203
	
204
			File libSource = ProjectHelper.toFile(url);			
205
			FileUtils.copyDirectory(libSource, webContentDestination);
206
		}
207
		
208
		for (int i=0; i < MODULE_BUNDLE_IDS.length; i++) {		
209
			url = Platform.getBundle(MODULE_BUNDLE_IDS[i]).getEntry(EclipseJ2EEAxis2ProjectizerConstants.PROJECT_MODULE_DIR_RESOURCE);
210
			url = FileLocator.toFileURL(url);
211
	
212
			File libSource = ProjectHelper.toFile(url);			
213
			FileUtils.copyDirectory(libSource, webContentDestination);
214
		}
215
				
216
		File libDestination = new File(webContentDestination, "lib");
217
		
218
		url = Platform.getBundle(CONTAINER_BUNDLE).getEntry(CONTAINER_RESOURCE);
219
		url = FileLocator.toFileURL(url);
220
		
221
		File libSource = ProjectHelper.toFile(url);			
222
		FileUtils.copy(libSource, libDestination);		
223
		
224
		if(_additionalJars != null) {
225
			for (int i=0; i < _additionalJars.length; i++) {
226
				if(!_additionalJars[i].exists()) {
227
					throw new FileNotFoundException(_additionalJars[i].getAbsolutePath());
228
				}
229
				
230
				FileUtils.copyFile(_additionalJars[i], libDestination);
231
			}
232
		}
233
		
234
		for (int i=0; i < _filesToCopy.length; i++) {
235
			String dest = _filesToCopy[i].getRelativePath();
236
			File destDir = new File(webContentDir, dest);
237
			String[] files = _filesToCopy[i].getFiles();
238
			
239
			for (int j=0; j < files.length; j++) {
240
				File file = new File(files[j]);
241
				if(!file.exists()) {
242
					throw new FileNotFoundException(file.getAbsolutePath());
243
				}
244
				
245
				FileUtils.copyFile(file, destDir);
246
			}
247
		}
248
249
		return webContentDir;	
250
	}
251
}
(-)resources/mini/build.xml (+10 lines)
Added Link Here
1
<?xml version="1.0"?>
2
<project name="project" default="default">
3
    <target name="default">
4
    	<jar destfile="${basedir}/WebContent/WEB-INF/lib/capability.jar">
5
    		<fileset dir="bin">
6
    			<include name="**/*.class"/>
7
    		</fileset>
8
    	</jar>
9
    </target>
10
</project>
(-)resources/mini/web.xml (+13 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
3
	<display-name>Apache Muse Servlet</display-name>
4
	<servlet>
5
		<display-name>Apache Muse Servlet</display-name>
6
		<servlet-name>ApacheMuseServlet</servlet-name>
7
		<servlet-class>org.apache.muse.core.platform.mini.MiniServlet</servlet-class>
8
	</servlet>
9
	<servlet-mapping>
10
		<servlet-name>ApacheMuseServlet</servlet-name>
11
		<url-pattern>/*</url-pattern>
12
	</servlet-mapping>
13
</web-app>
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseJ2EEAxis2ProjectizerConstants.java (+34 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.internal.projectizer;
14
15
16
public interface EclipseJ2EEAxis2ProjectizerConstants {
17
	
18
	String RESOURCES_DIR = "/resources/axis2/"; //$NON-NLS-1$
19
	
20
	String BUILD_FILE_RESOURCE = RESOURCES_DIR + "build.xml"; //$NON-NLS-1$
21
	
22
	String BUILD_FILE = "build.xml"; //$NON-NLS-1$
23
24
	String LAUNCH_FILE_RESOURCE = RESOURCES_DIR + ".externalToolBuilders/jarBuilder.launch"; //$NON-NLS-1$
25
26
	String WEBCONTENT_DIR_RESOURCE = RESOURCES_DIR + "WebContent"; //$NON-NLS-1$
27
28
	String PROJECT_LIB_DIR_RESOURCE = "/lib"; //$NON-NLS-1$
29
	
30
	String PROJECT_MODULE_DIR_RESOURCE = "/modules"; //$NON-NLS-1$
31
32
	String JAVA_BIN_DIR = "bin"; //$NON-NLS-1$
33
34
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtMerge.java (-253 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.ByteArrayOutputStream;
16
import java.lang.reflect.InvocationTargetException;
17
import java.util.ArrayList;
18
import java.util.Collection;
19
import java.util.Iterator;
20
import java.util.List;
21
22
import javax.wsdl.WSDLException;
23
import javax.wsdl.factory.WSDLFactory;
24
import javax.wsdl.xml.WSDLReader;
25
import javax.wsdl.xml.WSDLWriter;
26
import javax.xml.namespace.QName;
27
28
import org.apache.muse.tools.generator.WsdlMerge;
29
import org.apache.muse.util.xml.XmlUtils;
30
import org.apache.muse.ws.addressing.soap.SoapFault;
31
import org.apache.muse.ws.notification.WsnConstants;
32
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
33
import org.apache.muse.ws.resource.metadata.WsrmdConstants;
34
import org.apache.muse.ws.resource.metadata.impl.SimpleMetadataDescriptor;
35
import org.apache.muse.ws.wsdl.WsdlUtils;
36
import org.eclipse.emf.common.util.URI;
37
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
38
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
39
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
40
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
41
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
43
import org.w3c.dom.Document;
44
import org.w3c.dom.Element;
45
46
/**
47
 * This class provides the utility method for merging the MRT to get the smashed WSDL and RMD documents.
48
 *
49
 */
50
51
public class MrtMerge 
52
{
53
	private static WSDLReader _reader;
54
	private static WSDLWriter _writer;
55
	private static WSDLFactory _factory;
56
	
57
	/**
58
	 * Creates the smashed WSDL file for representing the resource type
59
	 * 
60
	 * @param mrtFile -
61
	 *            Manageable Resource Type file
62
	 * @throws Exception -
63
	 *             Throws exception while getting WSDL files and also while
64
	 *             merging them
65
	 */
66
	public static Document createMergedWSDL(ManageableResourceType mrt, String address)
67
			throws Exception
68
	{
69
		checkReadersWriters();
70
71
		List wsdlFiles = null;
72
73
		try
74
		{
75
			wsdlFiles = getWsdlFiles(mrt);
76
		}
77
		catch (Exception e)
78
		{
79
			throw new Exception(Messages.HOOKUP_WIZARD_ERROR_7, e);
80
		}
81
82
		String namespaceURI = mrt.getNamespace();
83
84
		Document[] wsdlFragments = (Document[])wsdlFiles.toArray(new Document[wsdlFiles.size()]);
85
		javax.wsdl.Definition def = WsdlMerge.merge(namespaceURI, wsdlFragments,
86
 				address);
87
88
		return _writer.getDocument(def);
89
	}
90
91
	private static void checkReadersWriters() throws InvocationTargetException
92
	{
93
		try
94
		{
95
			_factory = WSDLFactory.newInstance();
96
			_reader = _factory.newWSDLReader();
97
			_writer = _factory.newWSDLWriter();
98
		}
99
		catch (WSDLException e)
100
		{
101
			throw new InvocationTargetException(new Exception(
102
					Messages.HOOKUP_WIZARD_ERROR_3, e));
103
		}
104
	}
105
106
	/**
107
	 * Given an MRT file return a list of <code>Definition</code> objects that
108
	 * correspond to the WSDL files related to this MRT (that is, its
109
	 * Capabilities).
110
	 * 
111
	 * @param mrtFile
112
	 * @return
113
	 * @throws Exception
114
	 */
115
	private static List getWsdlFiles(ManageableResourceType mrt)
116
			throws Exception
117
	{
118
		//Get a list of all of the capabilities in this MRT 
119
		//This should just be a list of URIs
120
		List capabilityList = mrt.getImplements();		
121
		
122
		//Here is our list of clean WSDL documents
123
		//we are returning
124
		ArrayList wsdls = new ArrayList();	
125
126
		//Use an EclipseEnvironment to do the resolution of paths
127
		EclipseEnvironment eclipseEnv = new EclipseEnvironment();
128
		
129
		//Iterate over each capability and load it into a Definition
130
		for (Iterator i = capabilityList.iterator(); i.hasNext();) {
131
			String nextPath = i.next().toString();
132
			
133
			Document document = WsdlUtils.createWSDL(eclipseEnv, nextPath, true);
134
			
135
			//clean up imports
136
			//see the actual functions to understand how 
137
			//the removal is done
138
			Element cleanDocument = WsdlUtils.removeSchemaReferences(document.getDocumentElement());
139
			cleanDocument = WsdlUtils.removeWsdlReferences(cleanDocument);
140
			
141
			wsdls.add(cleanDocument.getOwnerDocument());
142
		}
143
		
144
		return wsdls;
145
	}
146
	
147
	/**
148
	 * Creates the merged RMD file for representing the manageable resource type
149
	 * 
150
	 * @param mrtFile -
151
	 *            Manageable Resource Type file
152
	 * @throws Exception -
153
	 *             Throws exception while getting capabilities defined in MRT and also while
154
	 *             merging their RMDs
155
	 */
156
	public static MetadataDescriptor createMergedRMD(ManageableResourceType mrt) throws Exception
157
	{
158
			List rmds = new ArrayList();
159
			Capability[] capabilities = MrtUtils.getCapabilities(mrt);
160
			List allTopicExpressions = new ArrayList();
161
			for(int i=0;i<capabilities.length;i++)
162
			{
163
				CapabilityDefinition capabilityDef = (CapabilityDefinition)capabilities[i].getWsdlDefinition();
164
				URI capabilityFileLocationURI = capabilityDef.getWSDLResourceProtocolURI();
165
				String metadataDescriptorLocation = capabilityDef.getMetadataDescriptorLocation();
166
				if(metadataDescriptorLocation == null || metadataDescriptorLocation.length() == 0)
167
					continue;
168
				URI rmdFileLocationURI = URI.createURI(capabilityFileLocationURI.trimSegments(1).toString()+ "/" + metadataDescriptorLocation);
169
				org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot root = MetaDataUtils.getDocumentRoot(rmdFileLocationURI);
170
				ByteArrayOutputStream baos = MetaDataUtils.saveRMD(root, rmdFileLocationURI.toString(), null);
171
				String rmdXML = new String(baos.toByteArray());
172
				Element definitionElement = (Element) XmlUtils.createDocument(rmdXML).getFirstChild();
173
				Element metadataDescriptorElement = XmlUtils.getFirstElement(definitionElement);			
174
				MetadataDescriptor rmdDescriptor = new SimpleMetadataDescriptor(metadataDescriptorElement);				
175
				
176
				// Get all the topic expressions defined in different capabilities
177
				String[] topicExpressions = getTopicExpressions(rmdDescriptor);
178
				for(int j=0;j<topicExpressions.length;j++)
179
				{
180
					String prefix = topicExpressions[j].substring(0,topicExpressions[j].indexOf(':'));
181
					String namespace = (String)root.getXMLNSPrefixMap().get(prefix);
182
					String topicPath = topicExpressions[j].substring(topicExpressions[j].indexOf(':')+1);
183
					allTopicExpressions.add(new TopicExpression(namespace, topicPath));
184
				}				
185
				rmdDescriptor.removeProperty(WsnConstants.TOPIC_EXPRESSION_QNAME);
186
				
187
				rmds.add(rmdDescriptor);		
188
			}
189
			MetadataDescriptor[] descriptors = (MetadataDescriptor[]) rmds.toArray(new MetadataDescriptor[rmds.size()]);
190
			QName qname = new QName(mrt.getNamespace(), "PortType");
191
			// TODO Verify with Andrew that is it the way that MUSE creates the smashed wsdl by this name
192
			String name = mrt.getIdentifier()+".wsdl";
193
			MetadataDescriptor mergedRMD = WsdlMerge.merge(name, qname, descriptors);
194
			TopicExpression[] topicExpressions = (TopicExpression[]) allTopicExpressions.toArray(new TopicExpression[allTopicExpressions.size()]);
195
			// Merge all the topic expressions defined in different capabilities
196
			mergeTopicExpressions(mergedRMD, topicExpressions);
197
			return mergedRMD;		
198
	}
199
	
200
	private static String[] getTopicExpressions(MetadataDescriptor rmdDescriptor) throws SoapFault
201
	{
202
		if(rmdDescriptor.hasProperty(WsnConstants.TOPIC_EXPRESSION_QNAME))
203
		{
204
			Collection collection = rmdDescriptor.getInitialValues(WsnConstants.TOPIC_EXPRESSION_QNAME, String.class);
205
			return (String[])collection.toArray(new String[collection.size()]);
206
		}
207
		return new String[0];
208
	}
209
	
210
	private static void mergeTopicExpressions(MetadataDescriptor rmdDescriptor, TopicExpression[] topicExpressions) throws SoapFault
211
	{
212
		if(topicExpressions!=null && topicExpressions.length>0)
213
		{
214
			rmdDescriptor.addProperty(WsnConstants.TOPIC_EXPRESSION_QNAME, WsrmdConstants.READ_ONLY, WsrmdConstants.MUTABLE);
215
			List initValues = new ArrayList();
216
			Document doc = XmlUtils.createDocument();
217
			for(int i=0;i<topicExpressions.length;i++)
218
			{
219
				String namespace = topicExpressions[i].getTopicNamespace();
220
				String topicPath = topicExpressions[i].getTopicPath();
221
				String expression = "pfx:"+topicPath;
222
				Element propertyElement = XmlUtils.createElement(doc, WsnConstants.TOPIC_EXPRESSION_QNAME);
223
				propertyElement.setAttribute("xmlns:pfx", namespace);
224
				XmlUtils.setElementText(propertyElement, expression);
225
				initValues.add(propertyElement);
226
			}
227
			rmdDescriptor.setInitialValues(WsnConstants.TOPIC_EXPRESSION_QNAME, initValues);			
228
		}
229
	}
230
}
231
232
class TopicExpression
233
{
234
	private String _topicNamespace;
235
	private String _topicPath;
236
	
237
	TopicExpression(String topicNamespace, String topicPath)
238
	{
239
		_topicNamespace = topicNamespace;
240
		_topicPath = topicPath;
241
	}
242
	
243
	String getTopicNamespace()
244
	{
245
		return _topicNamespace;
246
	}
247
	
248
	String getTopicPath()
249
	{
250
		return _topicPath;
251
	}
252
}
253
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/Axis2LicenseDialog.java (-140 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.BufferedReader;
16
import java.io.InputStreamReader;
17
import java.net.URL;
18
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.browser.Browser;
21
import org.eclipse.swt.events.SelectionAdapter;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
29
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
30
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
31
import org.osgi.framework.Bundle;
32
33
/**
34
 * This class is used to display the Axis-2 License. 
35
 */
36
public class Axis2LicenseDialog 
37
{
38
	private Shell _shell;
39
	
40
	private Browser _text;
41
	
42
	private Button _btnAgree;
43
	
44
	private Button _btnDecline;
45
	
46
	public static int AGREE = 0;
47
	
48
	public static int DECLINE = 1;
49
	
50
	private int _retInt = DECLINE;
51
		
52
	/**
53
	 * Constructor of the class. It initialises the UI for
54
	 * displaying the license
55
	 */
56
	public Axis2LicenseDialog()
57
	{
58
		initUI();
59
	}
60
	
61
	private void initUI()
62
	{
63
		_shell = new Shell(Display.getCurrent(), SWT.CLOSE | SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.RESIZE);
64
		_shell.setLayout(new GridLayout(2, true));
65
		_shell.setText(Messages.AXIS2_LICENSE_LABEL);
66
		_shell.setSize(300, 300);
67
		
68
		_text = new Browser(_shell, SWT.BORDER | SWT.MULTI | SWT.WRAP);
69
		try 
70
		{
71
			_text.setText(readLicence());
72
		} 
73
		catch (Throwable e)
74
		{
75
			WsdmToolingLog.logError(e.getMessage(), e);
76
		}
77
		
78
		_btnAgree = new Button(_shell, SWT.PUSH);
79
		_btnAgree.setText(Messages.LICENSE_AGREE_TEXT);
80
		_btnAgree.addSelectionListener(new SelectionAdapter()
81
		{
82
			public void widgetSelected(SelectionEvent se)
83
			{
84
				_retInt = AGREE;
85
				_shell.dispose();
86
			}
87
		}
88
		);
89
		
90
		_btnDecline = new Button(_shell, SWT.PUSH);
91
		_btnDecline.setText(Messages.LICENSE_DECLINE_TEXT);
92
		_btnDecline.addSelectionListener(new SelectionAdapter()
93
		{
94
			public void widgetSelected(SelectionEvent se)
95
			{
96
				_retInt = DECLINE;
97
				_shell.dispose();
98
			}
99
		}
100
		);
101
		
102
		GridData gd = new GridData(GridData.FILL_BOTH);
103
		gd.horizontalSpan = 2;
104
		_text.setLayoutData(gd);
105
		
106
		gd = new GridData();
107
		gd.horizontalAlignment = SWT.RIGHT;
108
		_btnAgree.setLayoutData(gd);
109
		
110
		gd = new GridData();
111
		gd.horizontalAlignment = SWT.LEFT;
112
		_btnDecline.setLayoutData(gd);
113
	}
114
	
115
	/**
116
	 * Method  to show the Dialog that displays the Liscense
117
	 */
118
	public int showWindow()
119
	{
120
		_shell.open();
121
		while(!_shell.isDisposed())
122
		{
123
			if(!Display.getCurrent().readAndDispatch())
124
				Display.getCurrent().sleep();
125
		}
126
		return _retInt;
127
	}
128
	
129
	private String readLicence() throws Throwable
130
	{
131
		Bundle bundle = Activator.INSTANCE.getPlugin().getBundle();
132
		URL licenceURL = bundle.getEntry("licence/Licence.txt");
133
		BufferedReader in = new BufferedReader(new InputStreamReader(licenceURL.openStream()));
134
		StringBuffer buffer = new StringBuffer();
135
		String line = null;
136
		while ((line = in.readLine()) != null)
137
			buffer.append(line);
138
		return buffer.toString();
139
	}
140
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/CodeGenerationData.java (-105 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: CodeGenerationData.java,v 1.2 2007/05/07 09:15:10 dnsmith Exp $
8
 * 
9
 * Contributors:
10
 * 	Balan Subramanian (bsubram@us.ibm.com)
11
 *     IBM Corporation - initial API and implementation
12
 *******************************************************************************/
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import org.apache.muse.tools.generator.analyzer.Analyzer;
16
import org.apache.muse.tools.generator.projectizer.Projectizer;
17
import org.apache.muse.tools.generator.synthesizer.Synthesizer;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IConfigurationElement;
20
21
class CodeGenerationData {				
22
	private Analyzer _analyzer;
23
	private Synthesizer _synthesizer;
24
	private Projectizer _projectizer;
25
	
26
	private int _servicePort;
27
	private String _servicePath;
28
	private String _container;
29
	private String _platform;
30
	
31
	public CodeGenerationData(IConfigurationElement[] elements) {
32
		for (int i = 0; i < elements.length; i++)
33
		{
34
			String name = elements[i].getName();
35
						
36
			if(name.equals("description")) {
37
				extractDescription(elements[i]);
38
			} else if (name.equals("projectizer")) {
39
				extractProjectizer(elements[i]);
40
			} else if (name.equals("synthesizer")) {
41
				extractSynthesizer(elements[i]);
42
			} else if (name.equals("analyzer")) {
43
				extractAnalyzer(elements[i]);
44
			}
45
		}
46
	}
47
	
48
	private void extractDescription(IConfigurationElement configurationElement) {
49
		_container = configurationElement.getAttribute("container");
50
		_platform = configurationElement.getAttribute("platform");
51
	}
52
	
53
	private void extractProjectizer(IConfigurationElement configurationElement) {
54
		String port = configurationElement.getAttribute("servicePort");
55
		if(port != null && port.length() != 0) {
56
			_servicePort = Integer.parseInt(port);
57
		}
58
		_servicePath = configurationElement.getAttribute("servicePath");
59
		_projectizer = (Projectizer) createExecutable(configurationElement);
60
	}
61
	
62
	private void extractSynthesizer(IConfigurationElement configurationElement) {
63
		_synthesizer = (Synthesizer) createExecutable(configurationElement);			
64
	}
65
	
66
	private void extractAnalyzer(IConfigurationElement configurationElement) {
67
		_analyzer = (Analyzer) createExecutable(configurationElement);
68
	}	
69
	
70
	private Object createExecutable(IConfigurationElement configurationElement) {
71
		try {
72
			return configurationElement.createExecutableExtension("class");
73
		} catch (CoreException e) {
74
			throw new RuntimeException(configurationElement.getAttribute("class"));
75
		}
76
	}
77
	
78
	public Analyzer getAnalyzer() {
79
		return _analyzer;
80
	}
81
82
	public Synthesizer getSynthesizer() {
83
		return _synthesizer;
84
	}
85
86
	public Projectizer getProjectizer() {
87
		return _projectizer;
88
	}
89
90
	public int getServicePort() {
91
		return _servicePort;
92
	}
93
94
	public String getServicePath() {
95
		return _servicePath;
96
	}
97
98
	public String getContainer() {
99
		return _container;
100
	}
101
102
	public String getPlatform() {
103
		return _platform;
104
	}
105
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/Generation.java (-72 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.jface.action.IAction;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
21
import org.eclipse.ui.IObjectActionDelegate;
22
import org.eclipse.ui.IWorkbenchPart;
23
24
/**
25
 * Access point code from the code generation option in popup
26
 */
27
public class Generation implements IObjectActionDelegate
28
{
29
30
	private IWorkbenchPart _targetPart;
31
32
	private StructuredSelection _selection;
33
34
	/**
35
	 * (non-Javadoc)
36
	 * @see org.eclipse.ui.IObjectActionDelegate#run(org.eclipse.jface.action.IAction)
37
	 */ 
38
	public void run(IAction action)
39
	{
40
		IFile mrtFile = (IFile) _selection.getFirstElement();
41
		MrtUtils.searchAndSaveMRTEditor(mrtFile);
42
		MRTCodeGenerationDelegate codeGenerationDelegate = new MRTCodeGenerationDelegate(
43
				mrtFile);
44
45
		NewProjectWizard npw = new NewProjectWizard(codeGenerationDelegate);
46
		WizardDialog wd = new WizardDialog(_targetPart.getSite().getShell(),
47
				npw);
48
		wd.open();
49
	}
50
51
	/**
52
	 * (non-Javadoc)
53
	 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
54
	 */ 
55
	public void setActivePart(IAction action, IWorkbenchPart targetPart)
56
	{
57
		_targetPart = targetPart;
58
	}
59
60
	/**
61
	 * (non-Javadoc)
62
	 * @see org.eclipse.ui.IObjectActionDelegate#selectionChanged
63
	(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
64
	 */
65
	public void selectionChanged(IAction action, ISelection selection)
66
	{
67
		if (selection instanceof StructuredSelection)
68
		{
69
			_selection = (StructuredSelection) selection;
70
		}
71
	}
72
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/Axis2ServerLocationPage.java (-232 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import org.eclipse.jface.preference.IPreferenceStore;
16
import org.eclipse.jface.wizard.WizardPage;
17
import org.eclipse.osgi.util.TextProcessor;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.ModifyEvent;
20
import org.eclipse.swt.events.ModifyListener;
21
import org.eclipse.swt.events.SelectionAdapter;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.DirectoryDialog;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Text;
30
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
31
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
32
import org.eclipse.tptp.wsdm.tooling.preferences.internal.Axis2ServerLocationPreferencePage;
33
import org.eclipse.tptp.wsdm.tooling.validation.util.internal.ValidationUtils;
34
35
/**
36
 * This is Wizard Page to show the Axis2 server location details
37
 *
38
 */
39
public class Axis2ServerLocationPage extends WizardPage
40
{
41
	
42
	protected Text _serverNameField;
43
	private Button _browseButton;
44
	private Button _preferenceUpdate;
45
	private TargetedFileList[] _filesToCopy;
46
	
47
	private String userDefinedLocation ="";
48
	
49
	/**
50
	 * Instantiates the class.
51
	 */
52
	public Axis2ServerLocationPage() 
53
	{
54
		super("wizardPage");
55
		setTitle(Messages.HOOKUP_WIZARD_TXT1);
56
		setDescription(Messages.HOOKUP_WIZARD_TXT2);
57
	}
58
59
	/**
60
	 *  Creates wizard controls.
61
	 */
62
	public void createControl(Composite parent) 
63
	{
64
		Composite page = new Composite(parent, SWT.NULL);
65
		GridLayout layout = new GridLayout(1, false);
66
		page.setLayout(layout);
67
		createPageControls(page);
68
		//dialogChanged();
69
		setControl(page);
70
	}
71
72
	private void createPageControls(Composite page) 
73
	{
74
		Composite column = new Composite(page, SWT.NULL);
75
		GridLayout layout = new GridLayout(2, false);
76
		column.setLayout(layout);
77
		createServerLocationColumn(column);
78
	}
79
80
	private void createServerLocationColumn(Composite parent) 
81
	{
82
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
83
		data.horizontalSpan = 2;
84
        // new server location label
85
        Label serverLabel = new Label(parent, SWT.NONE);
86
        serverLabel.setText(Messages.CODE_GEN_AXIS2_LOCATION);
87
        serverLabel.setFont(parent.getFont());
88
        serverLabel.setLayoutData(data);
89
90
		// server location entry field
91
        data = new GridData(GridData.FILL_HORIZONTAL);
92
        data.widthHint = 350;
93
        data.horizontalSpan = 1;
94
        _serverNameField = new Text(parent, SWT.BORDER);
95
        _serverNameField.setLayoutData(data);
96
        _serverNameField.setFont(parent.getFont());
97
        _serverNameField.addModifyListener(new ModifyListener()
98
		{
99
			public void modifyText(ModifyEvent e)
100
			{
101
				boolean pageCompleted = true;
102
				userDefinedLocation = _serverNameField.getText();
103
				String errorMsg = validateLocation(); 
104
				if(errorMsg == null)
105
				{
106
					setErrorMessage(errorMsg);
107
					pageCompleted = true;
108
				}
109
				else
110
				{
111
					setErrorMessage(errorMsg);
112
					pageCompleted = false;
113
				}
114
				makePageComplete(pageCompleted);
115
			}
116
		});
117
        
118
    //    _serverNameField.setText(getPreferenceServerLocation());
119
120
        // browse button
121
		_browseButton = new Button(parent, SWT.PUSH);
122
		_browseButton.setText(Messages.HOOKUP_WIZARD_TXT5);
123
		_browseButton.addSelectionListener(new SelectionAdapter() 
124
		{
125
			public void widgetSelected(SelectionEvent event) 
126
			{
127
				handleLocationBrowseButtonPressed();
128
			}
129
		});
130
		
131
		// server location entry field
132
        data = new GridData(GridData.FILL_HORIZONTAL);
133
        //data.widthHint = 350;
134
        data.horizontalSpan = 2;
135
        _preferenceUpdate = new Button(parent, SWT.CHECK);
136
        _preferenceUpdate.setText(Messages.CODE_GEN_UPDATE_PREF);
137
        _preferenceUpdate.setLayoutData(data);
138
        _preferenceUpdate.setFont(parent.getFont());		
139
	}
140
	
141
	protected String getPreferenceServerLocation() 
142
	{
143
		IPreferenceStore store = Activator.getPlugin().getPreferenceStore();
144
		String location = store.getString(Axis2ServerLocationPreferencePage.SERVER_LOCATION_PREFERENCE_KEY).trim();
145
		if(location != null && !location.equals(""))
146
			return location;
147
		return "";
148
	}
149
150
	private void handleLocationBrowseButtonPressed() 
151
	{
152
153
		String selectedDirectory = null;
154
155
		DirectoryDialog dialog = new DirectoryDialog(_serverNameField.getShell());
156
		dialog.setMessage(Messages.CODE_GEN_DIR_LOCATION);
157
		//dialog.setFilterPath(dirName);
158
		selectedDirectory = dialog.open();
159
		
160
		if (selectedDirectory != null)
161
			updateLocationField(selectedDirectory);
162
163
	}
164
	
165
	private void updateLocationField(String selectedPath) 
166
	{
167
		_serverNameField.setText(TextProcessor.process(selectedPath));
168
	}
169
170
	/**
171
	 * Returns the server location.
172
	 * @return
173
	 */
174
	public String getServerLocation() 
175
	{
176
		return _serverNameField.getText();
177
	}
178
179
	/**
180
	 * Checks to see if Update Preferences checkbox is selected
181
	 * @return
182
	 */
183
	public boolean isUpdatePreference()
184
	{
185
		return _preferenceUpdate.getSelection();
186
	}
187
	
188
	private String validateLocation()
189
	{
190
		String serverHome = _serverNameField.getText();
191
		
192
		ISoapServerDependency axisValidators[] = ValidationUtils.getAllAxisValidators();
193
		for(int i = 0 ; i < axisValidators.length ; i++){
194
			
195
			ISoapServerDependency axis2Dependency = (Axis2ServerDependency)axisValidators[i];
196
			String errorMessage = axis2Dependency.validateSoapServerHome(serverHome);
197
			if(errorMessage!=null)
198
				return errorMessage;
199
			_filesToCopy = axis2Dependency.getFilesToCopy();
200
			if(_filesToCopy == null)
201
				_filesToCopy = new TargetedFileList[0];
202
		}
203
		return null;		
204
	}
205
	
206
	/**
207
	 * Returns the Axis2 files to copied to generated code
208
	 * @return
209
	 */
210
	public TargetedFileList[] getAxis2FilesToCopy()
211
	{
212
		return _filesToCopy;
213
	}
214
215
	/**
216
	 * Method to Set the Wizard page to complete state
217
	 * @param validPage 
218
	 */
219
	public synchronized void makePageComplete(boolean completePage)
220
	{
221
		if(completePage){
222
			setPageComplete(true);
223
		}
224
		else
225
			setPageComplete(false);		
226
	}
227
	
228
	protected String getUserDefinedLocation()
229
	{
230
		return userDefinedLocation;
231
	}
232
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/EclipseEnvironment.java (-131 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.File;
16
import java.io.InputStream;
17
import java.net.URI;
18
import java.net.URL;
19
import java.net.URLConnection;
20
21
import org.apache.muse.core.AbstractEnvironment;
22
import org.apache.muse.util.xml.XmlUtils;
23
import org.apache.muse.ws.addressing.EndpointReference;
24
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.FileLocator;
27
import org.eclipse.core.runtime.Path;
28
import org.eclipse.core.runtime.Platform;
29
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
30
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
31
import org.osgi.framework.Bundle;
32
import org.w3c.dom.Document;
33
34
public class EclipseEnvironment extends AbstractEnvironment
35
{
36
37
	public EndpointReference getDeploymentEPR()
38
	{
39
		// TODO Auto-generated method stub
40
		return null;
41
	}
42
43
	public File getRealDirectory()
44
	{
45
		// TODO Auto-generated method stub
46
		return null;
47
	}
48
49
	public Document getDocument(String path)
50
	{
51
		try
52
		{
53
			if(isHttpScheme(path))
54
			{
55
				URLConnection conn = new URL(path).openConnection();
56
				InputStream stream = conn.getInputStream();
57
				return XmlUtils.createDocument(stream);
58
			}			
59
		}
60
		catch(Exception e)
61
		{
62
			WsdmToolingLog.logError(e.getMessage(), e);
63
		}
64
		
65
		
66
		try
67
		{
68
			if (!isBuiltin(path))
69
			{
70
				IFile wsdlFile = EclipseUtils.getIFile(ResourcesPlugin
71
						.getWorkspace().getRoot(), path);
72
				return XmlUtils.createDocument(wsdlFile.getLocation().toFile()
73
						.getAbsoluteFile());
74
			}
75
			else
76
			{
77
				String substr = path.substring(path.indexOf("platform:/plugin/")+"platform:/plugin/".length());
78
				String contributorPlugin = substr.substring(0,substr.indexOf('/'));
79
				String relativePath = substr.substring(substr.indexOf('/')+1);
80
				
81
				Bundle bundle = Platform.getBundle(contributorPlugin);
82
				return XmlUtils.createDocument(FileLocator.openStream(bundle,
83
						new Path(relativePath), false));
84
			}
85
		}
86
		catch (Exception e)
87
		{
88
			WsdmToolingLog.logError(e.getMessage(), e);
89
		}
90
		return null;
91
	}
92
93
	/**
94
	 * Utility method to see if the path is referring to something in the
95
	 * plugins or in the workspace.
96
	 * 
97
	 * @param path
98
	 *            A path to examine
99
	 * @return true if the path starts with <code>"platform:/plugin"</code>
100
	 */
101
	private boolean isBuiltin(String path)
102
	{
103
		return path.startsWith("platform:/plugin");
104
	}
105
	
106
	private boolean isHttpScheme(String path)
107
	{
108
		try{
109
			URI uri = URI.create(path);		
110
			String scheme = uri.getScheme();
111
			if(scheme != null && uri.getScheme().equals("http"))
112
				return true;
113
		}catch(Exception e){
114
			// nuthing to do, just return false
115
		}
116
		return false;
117
	}
118
119
	public String createRelativePath(String original, String relative)
120
	{
121
122
		// If the relative path starts with "platform:/" then it
123
		// is an absolute path, so just return it instead.
124
		if (relative.startsWith("platform:/"))
125
		{
126
			return relative;
127
		}
128
129
		return super.createRelativePath(original, relative);
130
	}
131
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/Axis2ServerDependency.java (-158 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.File;
16
import java.io.FileFilter;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
22
23
/**
24
 * This class verifies the Axis2 Soap Library dependency. 
25
 */
26
27
public class Axis2ServerDependency extends SoapServerDependency implements ISoapServerDependency
28
{
29
	private List _filesToCopy = new LinkedList();
30
	
31
	/**
32
	 * @see ISoapServerDependency#validateSoapServerHome(String)
33
	 */
34
	public String validateSoapServerHome(String serverHome)
35
	{
36
		if(serverHome == null || serverHome.length() == 0)
37
			return Messages.CODE_GEN_AXIS2_PROJECT_DIR;
38
		
39
		File serverHomeDir = new File(serverHome);
40
		if(!serverHomeDir.exists()){
41
			return NLS.bind(Messages.CODE_GEN_AXIS2_LOCATION_ERROR_, serverHome);
42
		}
43
		
44
		TargetedFileList _jarFilesToCopy = new TargetedFileList("WEB-INF/lib/");
45
		TargetedFileList _marFilesToCopy = new TargetedFileList("WEB-INF/modules/");
46
		TargetedFileList _restFilesToCopy = new TargetedFileList("WEB-INF/");
47
		
48
		String[] relativeFilePaths = (String[]) _requiredFiles.toArray(new String[_requiredFiles.size()]);
49
		for(int i=0;i<relativeFilePaths.length;i++)
50
		{
51
			String parentDirectory = getParentDirectory(relativeFilePaths[i]);
52
			if(parentDirectory == null)
53
				parentDirectory = serverHome;
54
			else
55
				parentDirectory = serverHome+File.separatorChar+parentDirectory;
56
			
57
			String fileExtension = getFileExtension(relativeFilePaths[i]);
58
			if(fileExtension == null)
59
				fileExtension = "*";
60
			FileFilter filter = new CustomFileFilter(fileExtension);
61
			
62
			File parentDirectoryFile = new File(parentDirectory);
63
			if(!parentDirectoryFile.exists())
64
				return NLS.bind(Messages.CODE_GEN_AXIS2_LOCATION_ERROR_, parentDirectory);
65
			
66
			File[] allFiles = parentDirectoryFile.listFiles(filter);
67
			String fileName = getFileName(relativeFilePaths[i]);
68
			File matchedFile = getMatchedPatternFile(allFiles, fileName);
69
			if(matchedFile == null)
70
				return NLS.bind(Messages.CODE_GEN_ERROR_INVALID_AXIS_FILE, serverHome+File.separatorChar+relativeFilePaths[i]);
71
						
72
			String absolutePath = matchedFile.getAbsolutePath();
73
			if(absolutePath.endsWith("jar"))
74
				_jarFilesToCopy.add(absolutePath);
75
			else if(absolutePath.endsWith("mar"))
76
				_marFilesToCopy.add(absolutePath);
77
			else
78
				_restFilesToCopy.add(absolutePath);
79
		}
80
		
81
		_filesToCopy.add(_jarFilesToCopy);
82
		_filesToCopy.add(_marFilesToCopy);
83
		_filesToCopy.add(_restFilesToCopy);
84
		
85
		return null;
86
	}
87
	
88
	private String getParentDirectory(String relativePath)
89
	{
90
		if(relativePath.indexOf('/')==-1)
91
			return null;
92
		return relativePath.substring(0,relativePath.lastIndexOf('/'));		
93
	}
94
	
95
	private String getFileExtension(String relativePath)
96
	{
97
		if(relativePath.indexOf('.')==-1)
98
			return null;
99
		return relativePath.substring(relativePath.lastIndexOf('.')+1);
100
	}
101
	
102
	private String getFileName(String relativePath)
103
	{
104
		if(relativePath.indexOf('/')==-1)
105
		{
106
			if(relativePath.indexOf('.')==-1)
107
				return relativePath;
108
			else
109
				return relativePath.substring(0,relativePath.lastIndexOf('.'));
110
		}
111
		else
112
		{
113
			String fileNameWithExtn = relativePath.substring(relativePath.lastIndexOf('/')+1);
114
			if(fileNameWithExtn.indexOf('.')==-1)
115
				return fileNameWithExtn;
116
			else
117
				return fileNameWithExtn.substring(0,fileNameWithExtn.lastIndexOf('.'));
118
		}
119
	}
120
	
121
	private File getMatchedPatternFile(File[] allFiles, String pattern)
122
	{
123
		String strippedPattern = pattern.indexOf("-*")==-1?pattern:pattern.substring(0,pattern.lastIndexOf("-*"));
124
		for(int i=0;i<allFiles.length;i++)
125
		{
126
			if(allFiles[i].getName().startsWith(strippedPattern))
127
				return allFiles[i];
128
		}
129
		return null;
130
	}
131
132
	/**
133
	 * @see ISoapServerDependency#getFilesToCopy()
134
	 */
135
	public TargetedFileList[] getFilesToCopy()
136
	{
137
		return (TargetedFileList[])_filesToCopy.toArray(new TargetedFileList[_filesToCopy.size()]);
138
	}	
139
}
140
141
class CustomFileFilter implements FileFilter
142
{
143
	String fileExtension;
144
	
145
	CustomFileFilter(String extension)
146
	{
147
		fileExtension = extension;
148
	}
149
	
150
	public boolean accept(File pathname) 
151
	{
152
		if(!pathname.isFile())
153
			return false;
154
		if(fileExtension.equals("*"))
155
			return true;
156
		return pathname.getName().endsWith(fileExtension);		
157
 	}	
158
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/BasicMrtInspector.java (-341 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
import java.util.List;
18
19
import javax.wsdl.Definition;
20
21
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
22
import org.apache.ws.muse.descriptor.DescriptorFactory;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
24
import org.apache.ws.muse.descriptor.InitParamType;
25
import org.apache.ws.muse.descriptor.InitialInstancesType;
26
import org.apache.ws.muse.descriptor.ReferenceParametersType;
27
import org.apache.ws.muse.descriptor.ResourceTypeType;
28
import org.apache.ws.muse.descriptor.WsdlType;
29
import org.apache.ws.muse.descriptor.impl.CapabilityTypeImpl;
30
import org.apache.ws.muse.descriptor.impl.ResourceTypeTypeImpl;
31
import org.eclipse.core.resources.IFile;
32
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.IConfigurationElement;
34
import org.eclipse.core.runtime.IExtension;
35
import org.eclipse.core.runtime.IExtensionPoint;
36
import org.eclipse.core.runtime.Platform;
37
import org.eclipse.emf.common.util.EMap;
38
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
39
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
40
import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages;
41
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
44
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
45
46
/**
47
 * This class analyzes the given manageable resource type and provide a resource
48
 * type for muse descriptor.
49
 */
50
51
public class BasicMrtInspector implements MrtInspector
52
{
53
	private DocumentRoot _root;
54
55
	private ResourceTypeType _resourceType;
56
57
	private ManageableResourceType _mrt;
58
	/**
59
	 * Constructor of the class
60
	 * @param mrt
61
	 * @param root
62
	 */
63
	public BasicMrtInspector(ManageableResourceType mrt,DocumentRoot root)
64
	{
65
		_root = root;
66
		_mrt = mrt;
67
	}
68
69
	/**
70
	 *  Get the initial instance for this manageable resource type
71
	 *  @return InitialInstancesType - Array of the initial instances
72
	 */
73
	public InitialInstancesType[] getInitialInstances()
74
	{
75
		InitialInstancesType instance = DescriptorFactory.eINSTANCE
76
				.createInitialInstancesType();
77
		ResourceTypeType rtClone = MRTCodeGenerationDelegate
78
				.cloneResourceType(_resourceType);
79
		instance.setResourceType(rtClone);
80
		ReferenceParametersType refParam = DescriptorFactory.eINSTANCE
81
				.createReferenceParametersType();
82
83
		instance.setReferenceParameters(refParam);
84
		return new InitialInstancesType[] { instance };
85
	}
86
87
	/**
88
	 *  Create a new descriptor resource type for the given manageable resource
89
	 *  type
90
	 *  @param mrtCapabilities
91
	 *  @return {@link ResourceTypeType}
92
	 */
93
	public ResourceTypeType inspect(Capability[] mrtCapabilities)
94
	{
95
		Mrt2DescriptorResourceType mrt2dd = new Mrt2DescriptorResourceType(
96
				_root, _mrt, mrtCapabilities);
97
		_resourceType = mrt2dd.getResourceTypeType();
98
		return _resourceType;
99
	}
100
101
	public void setMrtParentDirectory(String mrtParentDir)
102
	{
103
	}
104
105
	public void persistArtifacts()
106
	{
107
	}
108
109
	public ManageableResourceType getExtraGeneratedMrt() 
110
	{
111
		return null;
112
	}
113
114
	public String getExtraGeneratedMrtPersistanceLocation() 
115
	{
116
		return null;
117
	}
118
119
	public void inspectMetadata(ManageableResourceType mrt,
120
			MetadataDescriptor rmd) 
121
	{
122
	}
123
124
}
125
126
class Mrt2DescriptorResourceType
127
{
128
	private ManageableResourceType _mrt;
129
130
	private DocumentRoot _root;
131
132
	private Capability[] _mrtCapabilities;
133
134
	Mrt2DescriptorResourceType(DocumentRoot root, ManageableResourceType mrt)
135
	{
136
		this(root, mrt, null);
137
	}
138
139
	Mrt2DescriptorResourceType(DocumentRoot root, ManageableResourceType mrt,
140
			Capability[] mrtCapabilities)
141
	{
142
		_mrt = mrt;
143
		_root = root;
144
		if (mrtCapabilities == null)
145
			try
146
			{
147
				_mrtCapabilities = MrtUtils.getCapabilities(mrt);
148
			}
149
			catch (Exception e)
150
			{
151
			}
152
		else
153
			_mrtCapabilities = mrtCapabilities;
154
	}
155
156
	ResourceTypeType getResourceTypeType()
157
	{
158
		ResourceTypeTypeImpl rtd = (ResourceTypeTypeImpl) DescriptorFactory.eINSTANCE
159
				.createResourceTypeType();
160
		rtd.setUseRouterPersistence(true);
161
		rtd.setContextPath("/" + _mrt.getIdentifier()); //$NON-NLS-1$
162
		rtd
163
				.setJavaIdFactoryClass(WsdmConstants.MUSE_RESOURCE_ID_FACTORY_CLASS); //$NON-NLS-1$
164
		rtd
165
				.setJavaResourceClass(WsdmConstants.MUSE_RESOURCE_CLASS); //$NON-NLS-1$
166
		rtd.getCapability().addAll(getCapabilitiesFromMRT());
167
		WsdlType wsdlType = DescriptorFactory.eINSTANCE.createWsdlType();
168
169
		String mrtFileLocation = getMrtFileWorkspaceLocation();
170
		if (mrtFileLocation == null)
171
			;
172
		// TODO Log error not resolved location of given mrt
173
		else
174
		{
175
			String mrtFilePathWithoutExtn = mrtFileLocation.substring(0,
176
					mrtFileLocation.lastIndexOf('.'));
177
			wsdlType.setWsdlFile(mrtFilePathWithoutExtn + ".wsdl");
178
		}
179
180
		String namespace = _mrt.getNamespace();
181
		String prefix = getOrCreatePrefix(_root, namespace);
182
		String localPart = Messages.DU_PORT_TYPE_LOCAL_PART; // Only
183
		// "PortType"
184
		// should come
185
		// with the
186
		// //$NON-NLS-1$
187
		// prefix.
188
		wsdlType.setWsdlPortType(prefix + ":" + localPart);
189
190
		rtd.setWsdl(wsdlType);
191
		
192
		// Fix for Bug 174792 Set "validate-wsrp-schema" to "false" for the dd file generated at the codegen from MRT
193
		// http://bugs.eclipse.org/bugs/show_bug.cgi?id=174792
194
		InitParamType noValidateParam = DescriptorFactory.eINSTANCE.createInitParamType();
195
		noValidateParam.setParamName("validate-wsrp-schema");
196
		noValidateParam.setParamValue("false");		
197
		rtd.getInitParam().add(noValidateParam);
198
		
199
		return rtd;
200
	}
201
202
	private static String getOrCreatePrefix(DocumentRoot root, String namespace)
203
	{
204
		String prefix = getPrefix(root, namespace);
205
		if (prefix != null)
206
			return prefix;
207
		String newPrefix = generateNewPrefix(root);
208
		root.getXMLNSPrefixMap().put(newPrefix, namespace);
209
		return newPrefix;
210
	}
211
212
	private static String generateNewPrefix(DocumentRoot root)
213
	{
214
		int count = 0;
215
		while (isPrefixExists(root, "pfx" + count)) //$NON-NLS-1$
216
			count++;
217
		return "pfx" + count; //$NON-NLS-1$
218
	}
219
220
	private static boolean isPrefixExists(DocumentRoot root, String prefix)
221
	{
222
		EMap map = root.getXMLNSPrefixMap();
223
		Iterator keyIt = map.keySet().iterator();
224
		while (keyIt.hasNext())
225
		{
226
			String pfx = (String) keyIt.next();
227
			if (pfx.equals(prefix))
228
				return true;
229
		}
230
		return false;
231
	}
232
233
	private static String getPrefix(DocumentRoot root, String namespace)
234
	{
235
		if (root == null)
236
			return null;
237
		if (namespace == null)
238
			return null;
239
		EMap map = root.getXMLNSPrefixMap();
240
		Iterator keyIt = map.keySet().iterator();
241
		Iterator valuesIt = map.values().iterator();
242
		while (valuesIt.hasNext())
243
		{
244
			String ns = (String) valuesIt.next();
245
			String prefix = (String) keyIt.next();
246
			if (ns.equals(namespace))
247
				return prefix;
248
		}
249
		return null;
250
	}
251
252
	private List getCapabilitiesFromMRT()
253
	{
254
		if (_mrt == null)
255
			return null;
256
		List capDataList = new ArrayList();
257
		for (int i = 0; i < _mrtCapabilities.length; i++)
258
		{
259
			Capability capability = _mrtCapabilities[i];
260
			String capNS = ""; //$NON-NLS-1$
261
			Definition def = capability.getWsdlDefinition().getDefinition();
262
			if (def != null)
263
			{
264
				capNS = capability.getWsdlDefinition().getNamespace(
265
						"capabilityURI");
266
				if (capNS == null)
267
					capNS = capability.getNamespace();
268
269
			}
270
			CapabilityTypeImpl ctype = (CapabilityTypeImpl) DescriptorFactory.eINSTANCE
271
					.createCapabilityType();
272
			ctype.setCapabilityUri(capNS);
273
			String className = getJavaCapabilityClass(capNS);
274
			ctype.setJavaCapabilityClass(className);
275
			boolean isValid = validateCapability(capDataList, ctype);
276
			if (isValid)
277
				capDataList.add(ctype);
278
		}
279
		return capDataList;
280
	}
281
282
	private boolean validateCapability(List capDataList,
283
			CapabilityTypeImpl ctype)
284
	{
285
		if (capDataList == null || capDataList.size() == 0)
286
		{
287
			capDataList = new ArrayList();
288
			return true;
289
		}
290
		for (int i = 0; i < capDataList.size(); i++)
291
		{
292
			CapabilityTypeImpl tmp = (CapabilityTypeImpl) capDataList.get(i);
293
			if (tmp.getCapabilityUri().trim().equals(
294
					ctype.getCapabilityUri().trim()))
295
				return false;
296
		}
297
		return true;
298
	}
299
300
	private String getMrtFileWorkspaceLocation()
301
	{
302
		try
303
		{
304
			IFile mrtFile = EclipseUtils.getIFile(_mrt.eResource().getURI()
305
					.toString());
306
			return mrtFile.getFullPath().toString();
307
		}
308
		catch (CoreException e)
309
		{
310
			WsdmToolingLog.logError(e.getLocalizedMessage(), e);
311
		}
312
		return null;
313
	}
314
315
	private String getJavaCapabilityClass(String uri)
316
	{
317
		String ns = "org.eclipse.tptp.wsdm.model";
318
		IExtensionPoint iep = Platform.getExtensionRegistry()
319
				.getExtensionPoint(ns, "mrCapability");
320
		if (iep != null)
321
		{
322
			IExtension[] extensions = iep.getExtensions();
323
			for (int i = 0; i < extensions.length; i++)
324
			{
325
				IConfigurationElement[] ice = extensions[i]
326
						.getConfigurationElements();
327
				for (int j = 0; j < ice.length; j++)
328
				{
329
					String capURI = ice[j].getAttribute("uri");
330
					if (uri.equals(capURI))
331
					{
332
						String className = ice[j]
333
								.getAttribute("implementingClass");
334
						return (className == null) ? "" : className;
335
					}
336
				}
337
			}
338
		}
339
		return "";
340
	}
341
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/SoapServerDependency.java (-51 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IConfigurationElement;
20
21
/**
22
 * This class collects the relative paths of required Axis-2 files specified in extension point.
23
 * So if you are extending "axisValidator" extension point, you have to extend this class and implement
24
 * the interface ISoapServerDependency.
25
 */
26
27
public abstract class SoapServerDependency implements ISoapServerDependency 
28
{
29
30
	protected List _requiredFiles = new ArrayList();
31
	
32
	public void setInitializationData(IConfigurationElement config,
33
			String propertyName, Object data) throws CoreException 
34
	{
35
		if(config.getName()!=null && config.getName().equals("axisValidator"))
36
		{
37
			IConfigurationElement requiredFileConfig = config.getChildren()[0];
38
			IConfigurationElement[] relativePathConfig = requiredFileConfig.getChildren();
39
			for(int i=0;i<relativePathConfig.length;i++)
40
			{
41
				if(relativePathConfig[i].getName()!=null && relativePathConfig[i].getName().equals("relativeFilePath"))
42
				{
43
					String value = relativePathConfig[i].getValue();
44
					if(value!=null && !value.equals("null"))
45
						_requiredFiles.add(value);					
46
				}
47
			}
48
		}
49
	}
50
51
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/ServiceGroupInspector.java (-366 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.ByteArrayInputStream;
16
import java.io.InputStream;
17
import java.util.ArrayList;
18
import java.util.HashMap;
19
import java.util.List;
20
21
import javax.xml.namespace.QName;
22
23
import org.apache.muse.util.xml.XmlUtils;
24
import org.apache.muse.ws.addressing.soap.SoapFault;
25
import org.apache.muse.ws.resource.sg.WssgConstants;
26
import org.apache.ws.muse.descriptor.CapabilityType;
27
import org.apache.ws.muse.descriptor.DescriptorFactory;
28
import org.apache.ws.muse.descriptor.DocumentRoot;
29
import org.apache.ws.muse.descriptor.InitParamType;
30
import org.apache.ws.muse.descriptor.InitialInstancesType;
31
import org.apache.ws.muse.descriptor.ReferenceParametersType;
32
import org.apache.ws.muse.descriptor.ResourceTypeType;
33
import org.apache.ws.muse.descriptor.WsdlType;
34
import org.eclipse.core.resources.IFile;
35
import org.eclipse.core.runtime.NullProgressMonitor;
36
import org.eclipse.emf.common.util.URI;
37
import org.eclipse.emf.ecore.resource.Resource;
38
import org.eclipse.emf.ecore.resource.ResourceSet;
39
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
40
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.NewNameGenerator;
41
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
42
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
43
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceTypeFactory;
44
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.MembershipContentRuleType;
45
import org.eclipse.tptp.wsdm.tooling.util.internal.CustomMrtResourceFactoryImpl;
46
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
47
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
48
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
49
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
50
import org.w3c.dom.Document;
51
import org.w3c.dom.Element;
52
/**
53
 * This class analyzes the given manageable resource type and provide an extra
54
 * resource type for muse descriptor (ServiceGroupEntry), if manageable
55
 * resource type contains the ServiceGroupCapability and ServiceGroupRegistration capability.
56
 */
57
58
public class ServiceGroupInspector implements MrtInspector
59
{
60
61
	private String _mrtParentDirName;
62
63
	private DocumentRoot _root;
64
	
65
	private ResourceTypeType _serviceGroupEntryResorceType;
66
	
67
	private ManageableResourceType _serviceGroupEntrymrt;
68
	
69
	private HashMap _prefixNamespaceMap;
70
	
71
	/**
72
	 * Constructor for the ServiceGroupIspector class.
73
	 * @param mrt
74
	 * @param root
75
	 */
76
	
77
	public ServiceGroupInspector(ManageableResourceType mrt,DocumentRoot root)
78
	{
79
		_root = root;
80
	}
81
82
	/**
83
	 * Analyzes the given manageable resource type for ServiceGroupCapability and
84
	 * ServiceGroupRegistrationCapability and if the capabilities available then returns the muse
85
	 * resource type for ServiceGroupEntry  else returns the null.
86
	 */
87
	public ResourceTypeType inspect(Capability[] mrtCapabilities) 
88
	{
89
		
90
		if(hasServiceGroupCapabilities(mrtCapabilities))
91
			return createServiceGroupEntryResourceType();
92
		return null;
93
	}
94
	
95
	private boolean hasServiceGroupCapabilities(Capability[] mrtCapabilities)
96
	{
97
		boolean hasServiceGroupCapability = false;
98
		
99
		boolean hasServiceGroupRegistration = false;
100
		
101
		for(int i =0;i<mrtCapabilities.length;i++)
102
		{
103
			if(mrtCapabilities[i].getNamespace().equals(WsdmConstants.SERVICE_GROUP_NS))
104
					hasServiceGroupCapability = true;
105
			if(mrtCapabilities[i].getNamespace().equals(WsdmConstants.SERVICE_GROUP_REG_NS))
106
					hasServiceGroupRegistration = true;
107
		}
108
		return hasServiceGroupCapability && hasServiceGroupRegistration;
109
	}
110
111
	/**
112
	 * Returns the initial instances
113
	 * @return InitialInstancesType[]
114
	 */
115
	public InitialInstancesType[] getInitialInstances() {
116
117
		InitialInstancesType instance = DescriptorFactory.eINSTANCE
118
				.createInitialInstancesType();
119
		ResourceTypeType rtClone = MRTCodeGenerationDelegate
120
				.cloneResourceType(_serviceGroupEntryResorceType);
121
		instance.setResourceType(rtClone);
122
		ReferenceParametersType refParam = DescriptorFactory.eINSTANCE
123
				.createReferenceParametersType();
124
		instance.setReferenceParameters(refParam);
125
		return new InitialInstancesType[] { instance };
126
	
127
	}
128
	/**
129
	 * Sets the parent directory 
130
	 * @param mrtParentDir
131
	 */
132
	public void setMrtParentDirectory(String mrtParentDir) {
133
		_mrtParentDirName = mrtParentDir;
134
		
135
	}
136
	
137
	private ResourceTypeType createServiceGroupEntryResourceType()
138
	{
139
		createServiceGroupEntryMrt();
140
		_serviceGroupEntryResorceType = createServiceGroupEntryMuseResourceType();
141
		return _serviceGroupEntryResorceType;
142
	}
143
	
144
	private void createServiceGroupEntryMrt()
145
	{
146
		 org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.DocumentRoot documentRoot = ManageableResourceTypeFactory.eINSTANCE.createDocumentRoot();
147
		 _serviceGroupEntrymrt = ManageableResourceTypeFactory.eINSTANCE.createManageableResourceType();
148
		 documentRoot.setManageableResource(_serviceGroupEntrymrt);
149
		_serviceGroupEntrymrt.setIdentifier("ServiceGroupEntry");
150
		_serviceGroupEntrymrt.setNamespace("http://docs.oasis-open.org/wsrf/sgw-2");
151
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.MEX_CAPABILITY_LOCATION);
152
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.GET_CAPABILITY_LOCATION);
153
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.SET_CAPABILITY_LOCATION);
154
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.QUERY_CAPABILITY_LOCATION);
155
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.IMMIDIATE_RESOURCE_TERMINATION_CAPABILITY_LOCATION);
156
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.SCHEDULED_RESOURCE_TERMINATION_CAPABILITY_LOCATION);
157
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.SERVICE_GROUP_ENTRY_CAPABILITY_LOCATION);
158
	}
159
	
160
	private ResourceTypeType createServiceGroupEntryMuseResourceType()
161
	{
162
		ResourceTypeType resourceType = DescriptorFactory.eINSTANCE.createResourceTypeType();
163
		resourceType.setContextPath("/ServiceGroupEntry");
164
		resourceType.setJavaIdFactoryClass("org.apache.muse.core.routing.CounterResourceIdFactory");
165
		resourceType.setJavaResourceClass("org.apache.muse.ws.resource.impl.SimpleWsResource");
166
167
		WsdlType wsdlType = DescriptorFactory.eINSTANCE.createWsdlType();
168
		wsdlType.setWsdlFile(_mrtParentDirName + "/" + "ServiceGroupEntry.wsdl");
169
		_root.getXMLNSPrefixMap().put("wsrf-sge","http://docs.oasis-open.org/wsrf/sgw-2");
170
		wsdlType.setWsdlPortType("wsrf-sge:PortType");
171
		resourceType.setWsdl(wsdlType);
172
173
		CapabilityType metadataExchange = DescriptorFactory.eINSTANCE.createCapabilityType();
174
		metadataExchange.setCapabilityUri(WsdmConstants.MEX_NS);
175
		metadataExchange.setJavaCapabilityClass("");
176
		
177
		CapabilityType getCapability = DescriptorFactory.eINSTANCE.createCapabilityType();
178
		getCapability.setCapabilityUri(WsdmConstants.GET_NS);
179
		getCapability.setJavaCapabilityClass("");
180
		
181
		CapabilityType setCapability = DescriptorFactory.eINSTANCE.createCapabilityType();
182
		setCapability.setCapabilityUri(WsdmConstants.SET_NS);
183
		setCapability.setJavaCapabilityClass("");
184
		
185
		CapabilityType queryCapability = DescriptorFactory.eINSTANCE.createCapabilityType();
186
		queryCapability.setCapabilityUri(WsdmConstants.QUERY_NS);
187
		queryCapability.setJavaCapabilityClass("");
188
189
		CapabilityType immediateDestruction = DescriptorFactory.eINSTANCE.createCapabilityType();
190
		immediateDestruction.setCapabilityUri(WsdmConstants.IMMIDIATE_TERM_NS);
191
		immediateDestruction.setJavaCapabilityClass("");
192
193
		CapabilityType scheduledDestruction = DescriptorFactory.eINSTANCE.createCapabilityType();
194
		scheduledDestruction.setCapabilityUri(WsdmConstants.SCHEDULDED_TERM_NS);
195
		scheduledDestruction.setJavaCapabilityClass("");
196
	
197
		CapabilityType serviceGroupEntry = DescriptorFactory.eINSTANCE.createCapabilityType();
198
		serviceGroupEntry.setCapabilityUri(WsdmConstants.SERVICE_GROUP_ENTRY_NS);
199
		serviceGroupEntry.setJavaCapabilityClass("");
200
		
201
		InitParamType noValidateParam = DescriptorFactory.eINSTANCE	.createInitParamType();
202
		noValidateParam.setParamName("validate-wsrp-schema");
203
		noValidateParam.setParamValue("false");
204
205
		resourceType.getCapability().add(metadataExchange);
206
		resourceType.getCapability().add(getCapability);
207
		resourceType.getCapability().add(setCapability);
208
		resourceType.getCapability().add(queryCapability);
209
		resourceType.getCapability().add(immediateDestruction);
210
		resourceType.getCapability().add(scheduledDestruction);
211
		resourceType.getCapability().add(serviceGroupEntry);
212
		resourceType.getInitParam().add(noValidateParam);
213
214
		return resourceType;
215
	}
216
	
217
	private String getNamespace(String contentElement)
218
	{
219
		return contentElement.substring(1,contentElement.lastIndexOf('}'));
220
	}
221
	
222
	private void preparePrfixNamespaceMap(String contentElement)
223
	{
224
		if(!_prefixNamespaceMap.containsKey(contentElement))
225
		{
226
			NewNameGenerator nameGenerator = new NewNameGenerator("pfx");
227
			String prefix = nameGenerator.getNextName();
228
			
229
			while (nameAlreadyExists(prefix)) 
230
			{
231
				prefix = nameGenerator.getNextName();
232
			}
233
			_prefixNamespaceMap.put(contentElement, prefix);
234
		}
235
	}
236
	
237
	private boolean nameAlreadyExists(String prefix)
238
	{
239
		if(_prefixNamespaceMap.containsValue(prefix))
240
			return true;
241
		return false;
242
	}
243
	
244
	private String getLocalName(String namespace)
245
	{
246
		return namespace.substring(namespace.lastIndexOf('}')+1);
247
	}
248
	
249
	/**
250
	 * This method will returns the extra generated ManageableResourceType object equivalent to ServiceGroupEntry.
251
	 */
252
	public ManageableResourceType getExtraGeneratedMrt() {
253
	
254
		return _serviceGroupEntrymrt;
255
	}
256
	
257
	/**
258
	 * This method should return the persistance location for extra generated ManageableResourceType object equivalent to ServiceGroupEntry.
259
	 */
260
	public String getExtraGeneratedMrtPersistanceLocation() 
261
	{
262
		return _mrtParentDirName + "/"+ "ServiceGroupEntry.mrt";
263
	}
264
	/**
265
	 * This method will persist the extra artifacts generated at the code generation time(ServiceGroupEntry). 
266
	 */
267
	public void persistArtifacts()
268
	{
269
		try{
270
			ResourceSet rs = new ResourceSetImpl();
271
			rs.getResourceFactoryRegistry().getExtensionToFactoryMap()
272
			.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new CustomMrtResourceFactoryImpl());
273
			String serviceGroupMrt = _mrtParentDirName + "/"+ "ServiceGroupEntry.mrt";
274
			URI uri = URI.createPlatformResourceURI(serviceGroupMrt);
275
			byte[] rawNewMRT = MrtUtils.serializeMRT(_serviceGroupEntrymrt, rs, uri, true);
276
			InputStream stream = new ByteArrayInputStream(rawNewMRT);			
277
			IFile subManagerMrtFile = EclipseUtils.getIFile(serviceGroupMrt);
278
			if (subManagerMrtFile.exists())
279
			{
280
				subManagerMrtFile.setContents(stream, true, true,
281
				new NullProgressMonitor());
282
			}
283
			else
284
			{
285
				subManagerMrtFile.create(stream, true,
286
				new NullProgressMonitor());
287
			}
288
			stream.close();			
289
		}
290
		catch(Exception e)
291
		{
292
			e.printStackTrace();
293
		}
294
	}
295
	
296
	/**
297
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
298
	 * merged RMD document for it by having the rules/relationships in it. 
299
	 */
300
	public void inspectMetadata(ManageableResourceType mrt,
301
			org.apache.muse.ws.resource.metadata.MetadataDescriptor rmd) 
302
	{
303
		
304
		_prefixNamespaceMap  = new HashMap();
305
		Capability[] mrtCapabilities = new Capability[0];
306
		try 
307
		{
308
			mrtCapabilities = MrtUtils.getCapabilities(mrt);
309
		} 
310
		catch (Exception e)
311
		{
312
			WsdmToolingLog.logError(e.getMessage(), e);
313
		}
314
		
315
		if(hasServiceGroupCapabilities(mrtCapabilities))
316
		{
317
			List membershipContentRule = mrt.getMembershipContentRule();
318
			List initialValues = new ArrayList();
319
			for(int i=0;i<membershipContentRule.size();i++)
320
			{
321
				MembershipContentRuleType rule = (MembershipContentRuleType) membershipContentRule.get(i);
322
				Element value = createMembershipContentRuleElement(rule);
323
				
324
				initialValues.add(value);
325
			}
326
			if(!initialValues.isEmpty());
327
				try 
328
				{
329
					rmd.setInitialValues(new QName(WssgConstants.NAMESPACE_URI,"MembershipContentRule"), initialValues);
330
				} 
331
				catch (SoapFault e) 
332
				{
333
					WsdmToolingLog.logError(e.getMessage(), e);
334
				}
335
		}
336
	}
337
	
338
	private Element createMembershipContentRuleElement(MembershipContentRuleType rule)
339
	{
340
		Document document = XmlUtils.createDocument();
341
		Element membershipContentRuleElement = XmlUtils.createElement(document, new QName(WssgConstants.NAMESPACE_URI,"MembershipContentRule"));
342
		List contentElements = rule.getContentElements();
343
		String contentElementAttribute="";
344
		
345
		for(int i =0 ;i<contentElements.size();i++)
346
		{
347
			String contentElement = (String)contentElements.get(i);
348
			String tns = getNamespace(contentElement);
349
			String localName = getLocalName(contentElement);
350
			preparePrfixNamespaceMap(tns);
351
			
352
			if(contentElementAttribute.length() !=0)
353
				contentElementAttribute =  contentElementAttribute + " " + (String)_prefixNamespaceMap.get(tns)+":"+ localName;
354
			else
355
				contentElementAttribute =(String)_prefixNamespaceMap.get(tns)+":"+ localName;
356
			String  xmlns = "xmlns:" + _prefixNamespaceMap.get(tns);
357
			 membershipContentRuleElement.setAttribute(xmlns,tns );
358
			
359
		}
360
		membershipContentRuleElement.setAttribute("ContentElements",contentElementAttribute );
361
		
362
		return membershipContentRuleElement;
363
		
364
		
365
	}
366
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/NewProjectWizard.java (-327 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.File;
16
import java.lang.reflect.InvocationTargetException;
17
18
import org.apache.muse.tools.generator.analyzer.Analyzer;
19
import org.apache.muse.tools.generator.analyzer.SimpleAnalyzer;
20
import org.apache.muse.tools.generator.projectizer.Projectizer;
21
import org.apache.muse.tools.generator.synthesizer.ServerSynthesizer;
22
import org.apache.muse.tools.generator.synthesizer.Synthesizer;
23
import org.apache.muse.tools.generator.util.ConfigurationData;
24
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
25
import org.eclipse.core.filesystem.URIUtil;
26
import org.eclipse.core.resources.IWorkspaceRoot;
27
import org.eclipse.core.resources.ResourcesPlugin;
28
import org.eclipse.core.runtime.ILog;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.SubProgressMonitor;
32
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
33
import org.eclipse.jface.operation.IRunnableWithProgress;
34
import org.eclipse.jface.preference.IPreferenceStore;
35
import org.eclipse.jface.resource.ImageDescriptor;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.wizard.Wizard;
38
import org.eclipse.swt.graphics.Image;
39
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
40
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
41
import org.eclipse.tptp.wsdm.tooling.preferences.internal.Axis2ServerLocationPreferencePage;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
44
import org.eclipse.ui.INewWizard;
45
import org.eclipse.ui.IWorkbench;
46
import org.eclipse.ui.IWorkbenchPage;
47
import org.eclipse.ui.PartInitException;
48
import org.eclipse.ui.PlatformUI;
49
import org.eclipse.ui.part.ViewPart;
50
import org.w3c.dom.Document;
51
52
/**
53
 * This wizard accepts projectizer parameters, runtime environment and other
54
 * general parameters from the user so as to invoke Wsdl2Java
55
 */
56
public class NewProjectWizard extends Wizard implements INewWizard {
57
58
	private static ILog LOG = null;
59
60
	// We can't use internal classes, hence using view ID directly
61
	private static String TASK_VIEW_ID = "org.eclipse.ui.views.TaskList";
62
63
	private static String PLUGIN_ID = "org.eclipse.tptp.wsdm.tooling.editor.mrt";
64
65
	private GenerationOptionsPage _generationOptionsPage;
66
67
	private Axis2ServerLocationPage _axis2ServerLocationPage;
68
69
	private String _projectName;
70
71
	private boolean _overwrite;
72
73
	private boolean _shouldPersistArtifacts;
74
75
	private Projectizer _projectizer;
76
77
	private Synthesizer _synthesizer;
78
79
	private Analyzer _analyzer;
80
81
	private String _baseAddress;
82
83
	private CodeGenerationDelegate _codeGenerationDelegate;
84
85
	private Document[] _mergedWsdlDocuments;
86
87
	private MetadataDescriptor[] _mergedRMDs;
88
89
	private DescriptorHelper _helper;
90
91
	private String _serverLocation;
92
93
	private boolean _isAxis2Project;
94
	private boolean updatePreference;
95
96
	private String _projectLocation;
97
98
	private TargetedFileList[] _requiredAxis2Files;
99
100
	private boolean _licenseAccepted = false;
101
102
	/**
103
	 * Class that creates the Code Generation Wizard to create new Project
104
	 * 
105
	 * @param codeGenerationDelegate
106
	 */
107
	public NewProjectWizard(CodeGenerationDelegate codeGenerationDelegate) {
108
		setWindowTitle(Messages.HOOKUP_WIZARD_TXT7);
109
		setNeedsProgressMonitor(true);
110
111
		_codeGenerationDelegate = codeGenerationDelegate;
112
	}
113
114
	public void addPages() {
115
		_generationOptionsPage = new GenerationOptionsPage();
116
		addPage(_generationOptionsPage);
117
118
		_axis2ServerLocationPage = new Axis2ServerLocationPage();
119
		addPage(_axis2ServerLocationPage);
120
121
		// TODO AME why is this hardcoded here? why is it getting reloaded?
122
		Image imgTP = EclipseUtils.loadImage(PlatformUI.getWorkbench().getDisplay(),
123
				"icons/wizban/newEndpointProject_wiz.gif");
124
		ImageDescriptor imgDescrTP = ExtendedImageRegistry.INSTANCE.getImageDescriptor(imgTP);
125
		setDefaultPageImageDescriptor(imgDescrTP);
126
	}
127
128
	private void popupAxis2LicenseDialog() {
129
		IPreferenceStore store = Activator.getPlugin().getPreferenceStore();
130
		String preferencesLocation = store.getString(Axis2ServerLocationPreferencePage.SERVER_LOCATION_PREFERENCE_KEY);
131
		if (!_serverLocation.equals(preferencesLocation)) {
132
			int result = new Axis2LicenseDialog().showWindow();
133
			_licenseAccepted = (result == Axis2LicenseDialog.AGREE);
134
		} else
135
			_licenseAccepted = true;
136
137
	}
138
139
	private void performFinish(IProgressMonitor monitor) throws InvocationTargetException {
140
		try {
141
			monitor.beginTask(Messages.CODE_GEN_START, 7);
142
143
			if (_isAxis2Project) {
144
				try {
145
					// Step 1: Validate the server path
146
					monitor.subTask(Messages.CODE_GEN_VALIDATE_SLOCATION);
147
					// Step 2 : Update the Preferences, if needed
148
					if (updatePreference) {
149
						IPreferenceStore store = Activator.getPlugin().getPreferenceStore();
150
						store.setValue(Axis2ServerLocationPreferencePage.SERVER_LOCATION_PREFERENCE_KEY,
151
								_serverLocation);
152
						// Update the Lib and module location
153
					}
154
					_requiredAxis2Files = _axis2ServerLocationPage.getAxis2FilesToCopy();
155
				} catch (Exception e) {
156
					throw new RuntimeException(e);
157
				}
158
			}
159
			try {
160
				monitor.subTask(Messages.CODE_GEN_STEP1);
161
				_helper = _codeGenerationDelegate.run(new SubProgressMonitor(monitor, 1));
162
163
				monitor.worked(1);
164
			} catch (Exception e) {
165
				throw new RuntimeException(e);
166
				// TODO AME Why is this not defined?
167
				// throw new InvocationTargetException(new
168
				// Exception(Messages.HOOKUP_WIZARD_ERROR4, e));
169
			}
170
171
			try {
172
				monitor.subTask(Messages.CODE_GEN_STEP2);
173
				_mergedWsdlDocuments = _helper.getWsdlDocuments(_baseAddress);
174
				_mergedRMDs = _helper.getMergedRMDs();
175
				monitor.worked(1);
176
			} catch (Exception e) {
177
				e.printStackTrace();
178
				throw new RuntimeException(e);
179
			}
180
181
			try {
182
				monitor.subTask(Messages.CODE_GEN_STEP3);
183
				runProjectizer(monitor);
184
				monitor.worked(1);
185
			} catch (Exception e) {
186
				throw new InvocationTargetException(new Exception(Messages.CODE_GEN_FAILED_ERROR_, e));
187
			}
188
189
			if (_shouldPersistArtifacts) {
190
				monitor.subTask(Messages.CODE_GEN_STEP4);
191
				_codeGenerationDelegate.persistArtifacts();
192
				monitor.worked(1);
193
			}
194
		} finally {
195
			monitor.done();
196
		}
197
	}
198
199
	/*
200
	 * (non-Javadoc)
201
	 * 
202
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
203
	 */
204
	public boolean performFinish() {
205
		_projectizer = _generationOptionsPage.getProjectizer();
206
		_synthesizer = _generationOptionsPage.getSynthesizer();
207
		_analyzer = _generationOptionsPage.getAnalyzer();
208
		_overwrite = _generationOptionsPage.canOverwrite();
209
		_shouldPersistArtifacts = _generationOptionsPage.shouldPersistArtifacts();
210
		_projectName = _generationOptionsPage.getProjectName();
211
		_baseAddress = _generationOptionsPage.getBaseAddress();
212
		_isAxis2Project = _generationOptionsPage.isAxis2Project();
213
		_projectName = _generationOptionsPage.getProjectName();
214
		_projectLocation = _generationOptionsPage.getProjectLocation();
215
216
		if (_isAxis2Project) {
217
			_serverLocation = _axis2ServerLocationPage.getServerLocation();
218
			updatePreference = _axis2ServerLocationPage.isUpdatePreference();
219
			popupAxis2LicenseDialog();
220
		}
221
222
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
223
			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
224
				if (!_isAxis2Project || _licenseAccepted)
225
					performFinish(monitor);
226
			}
227
		};
228
		
229
		_generationOptionsPage.saveCombo();
230
231
		try {
232
			getContainer().run(true, false, runnable);
233
			openTasksView();
234
			
235
			return true;
236
		} catch (Exception e) {
237
			e.printStackTrace();
238
			handle(Messages.CODE_GEN_FAILED_ERROR_, e);
239
		}
240
241
		return false;
242
	}
243
244
	/*
245
	 * (non-Javadoc)
246
	 * 
247
	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
248
	 *      org.eclipse.jface.viewers.IStructuredSelection)
249
	 */
250
	public void init(IWorkbench workbench, IStructuredSelection selection) {
251
		// do nothing
252
	}
253
254
	private void runProjectizer(IProgressMonitor monitor) throws Exception {
255
		ConfigurationData data = new ConfigurationData();
256
257
		data.addParameter(EclipseConfigurationData.AXIS2_FILES, _requiredAxis2Files);
258
259
		data.addParameter(ConfigurationData.DESCRIPTOR_DOCUMENT, _helper.getDescriptorDocument());
260
		data.addParameter(EclipseConfigurationData.ADDITIONAL_JARS, _helper.getJarFiles());
261
		data.addParameter(EclipseConfigurationData.INSTANCES, _helper.getInstances());
262
		data.addParameter(EclipseConfigurationData.PROJECT_NAME, _projectName);
263
		data.addParameter(ConfigurationData.OVERWRITE, Boolean.valueOf(_overwrite));
264
		data.addParameter(EclipseConfigurationData.PROJECT_LOCATION, _projectLocation);
265
		data.addParameter(ConfigurationData.WSDL_DOCUMENT_LIST, _mergedWsdlDocuments);
266
		data.addParameter(ConfigurationData.METADATA_DESCRIPTOR_LIST, _mergedRMDs);
267
		data.addParameter(ConfigurationData.GENERATE_CUSTOM_HEADERS, Boolean.FALSE);
268
269
		// check if the analyzer is null, if it is then default to the
270
		// SimpleAnalyzer
271
		if (_analyzer == null) {
272
			_analyzer = new SimpleAnalyzer();
273
		}
274
275
		// check if the synthesizer is null, if it is then default to the
276
		// ServerSynthesizer
277
		if (_synthesizer == null) {
278
			_synthesizer = new ServerSynthesizer();
279
		}
280
281
		// Below, we make a new SubProgressMonitor for
282
		// each codegeneration component since we can't reuse the progress
283
		// monitor
284
285
		data.addParameter(EclipseConfigurationData.PROGRESS_MONITOR, new SubProgressMonitor(monitor, 1));
286
287
		monitor.subTask(Messages.CODE_GEN_SUBTASK1);
288
		data = _analyzer.analyze(data);
289
		monitor.worked(1);
290
291
		data.addParameter(EclipseConfigurationData.PROGRESS_MONITOR, new SubProgressMonitor(monitor, 1));
292
293
		monitor.subTask(Messages.CODE_GEN_SUBTASK2);
294
		data = _synthesizer.synthesize(data);
295
		monitor.worked(1);
296
297
		data.addParameter(EclipseConfigurationData.PROGRESS_MONITOR, new SubProgressMonitor(monitor, 1));
298
299
		monitor.subTask(Messages.CODE_GEN_SUBTASK3);
300
		_projectizer.projectize(data);
301
		monitor.worked(1);
302
	}
303
304
	private void handle(String message, Exception e) {
305
		_generationOptionsPage.setErrorMessage(message);
306
		_axis2ServerLocationPage.setErrorMessage(message);
307
308
		WsdmToolingLog.log(IStatus.ERROR, IStatus.OK, message, e);
309
	}
310
311
	private void openTasksView() {
312
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
313
		ViewPart view = (ViewPart) page.findView(TASK_VIEW_ID);
314
315
		// If the page isn't showing then show it
316
		if (view == null) {
317
			try {
318
				page.showView(TASK_VIEW_ID);
319
			} catch (PartInitException e) {
320
				WsdmToolingLog.logError(e.getMessage(), e);
321
			}
322
		}else{
323
			page.activate(view);
324
		}
325
	}
326
327
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtInspector.java (-69 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
16
import org.apache.ws.muse.descriptor.InitialInstancesType;
17
import org.apache.ws.muse.descriptor.ResourceTypeType;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
19
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
20
21
/**
22
 * This interface is created for some cases where we expect some extra resource
23
 * type to be added to the muse descriptor based on the capability that
24
 * manageable resource type holds. For example if someone includes the
25
 * Notification producer capability in his manageable resource type, then muse
26
 * runtime requires the Subscription Manager as one of the resource type
27
 * described in muse descriptor file.
28
 */
29
public interface MrtInspector
30
{
31
	public static String WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";
32
33
	/**
34
	 * Analyzes the given manageable resource type capabilities and then returns the muse
35
	 * resource type for some extra generated artifact else returns the null.
36
	 */
37
	ResourceTypeType inspect(Capability[] mrtCapabilities);
38
39
	/**
40
	 * This method should set the parent directory for extra generated artifact. 
41
	 */
42
	void setMrtParentDirectory(String mrtParentDir);
43
44
	/**
45
	 * Returns initial instances for extra generated artifact. 
46
	 */
47
	InitialInstancesType[] getInitialInstances();
48
	
49
	/**
50
	 * This method will persist the extra artifacts generated at codegen time.
51
	 */
52
	void persistArtifacts();
53
	
54
	/**
55
	 * This method will returns the extra ManageableResourceType object generated at codegen time.
56
	 */
57
	ManageableResourceType getExtraGeneratedMrt();
58
	
59
	/**
60
	 * This method should return the persistance location for extra generated ManageableResourceType object.
61
	 */
62
	String getExtraGeneratedMrtPersistanceLocation();
63
	
64
	/**
65
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
66
	 * merged RMD document for it by having the rules/relationships in it. 
67
	 */
68
	void inspectMetadata(ManageableResourceType mrt, MetadataDescriptor rmd);	
69
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/EclipseConfigurationData.java (-22 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
13
14
public class EclipseConfigurationData
15
{
16
	public static final String ADDITIONAL_JARS = "jars";
17
	public static final String INSTANCES = "instances";
18
	public static final String PROGRESS_MONITOR = "progress_monitor";
19
	public static final String AXIS2_FILES = "axis2_files";
20
	public static final String PROJECT_LOCATION = "location";
21
	public static final String PROJECT_NAME = "project_name";
22
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/RelationshipInspector.java (-405 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
13
14
import java.io.ByteArrayInputStream;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.util.ArrayList;
18
import java.util.Iterator;
19
import java.util.List;
20
21
import javax.wsdl.Operation;
22
import javax.xml.namespace.QName;
23
24
import org.apache.muse.util.xml.XmlUtils;
25
import org.apache.muse.ws.addressing.WsaConstants;
26
import org.apache.muse.ws.addressing.soap.SoapFault;
27
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
28
import org.apache.ws.muse.descriptor.CapabilityType;
29
import org.apache.ws.muse.descriptor.DescriptorFactory;
30
import org.apache.ws.muse.descriptor.DocumentRoot;
31
import org.apache.ws.muse.descriptor.InitParamType;
32
import org.apache.ws.muse.descriptor.InitialInstancesType;
33
import org.apache.ws.muse.descriptor.ReferenceParametersType;
34
import org.apache.ws.muse.descriptor.ResourceTypeType;
35
import org.apache.ws.muse.descriptor.WsdlType;
36
import org.eclipse.core.resources.IFile;
37
import org.eclipse.core.runtime.CoreException;
38
import org.eclipse.core.runtime.NullProgressMonitor;
39
import org.eclipse.emf.common.util.URI;
40
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
41
import org.eclipse.emf.ecore.resource.Resource;
42
import org.eclipse.emf.ecore.resource.ResourceSet;
43
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
44
import org.eclipse.emf.ecore.util.FeatureMap;
45
import org.eclipse.emf.ecore.util.BasicExtendedMetaData.EStructuralFeatureExtendedMetaData;
46
import org.eclipse.emf.ecore.xml.type.AnyType;
47
import org.eclipse.tptp.wsdm.tooling.editor.mrt.relationship.internal.RelationshipUtils;
48
import org.eclipse.tptp.wsdm.tooling.model.addressing.AttributedURIType;
49
import org.eclipse.tptp.wsdm.tooling.model.addressing.EndpointReferenceType;
50
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
51
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
52
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceTypeFactory;
53
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.Relationship;
54
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.RelationshipParticipantType;
55
import org.eclipse.tptp.wsdm.tooling.util.internal.CustomMrtResourceFactoryImpl;
56
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
57
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
58
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
59
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
60
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
61
import org.w3c.dom.Document;
62
import org.w3c.dom.Element;
63
import org.w3c.dom.Text;
64
65
public class RelationshipInspector implements MrtInspector
66
{
67
68
	private String _mrtParentDirName;
69
70
	private DocumentRoot _root;
71
72
	private ResourceTypeType _relationshipResourceType;
73
	
74
	private ManageableResourceType _relationshipResourceMRT;
75
	
76
	/**
77
	 * Constructor of the class
78
	 * @param root
79
	 */
80
	public RelationshipInspector(DocumentRoot root)
81
	{
82
		_root = root;
83
	}
84
85
	public ManageableResourceType getExtraGeneratedMrt()
86
	{
87
		return _relationshipResourceMRT;
88
	}
89
90
	public String getExtraGeneratedMrtPersistanceLocation() 
91
	{
92
		return _mrtParentDirName+"/RelationshipResource.mrt";
93
	}
94
95
	public InitialInstancesType[] getInitialInstances() 
96
	{
97
		InitialInstancesType instance = DescriptorFactory.eINSTANCE
98
			.createInitialInstancesType();
99
		ResourceTypeType rtClone = MRTCodeGenerationDelegate
100
			.cloneResourceType(_relationshipResourceType);
101
		instance.setResourceType(rtClone);
102
		ReferenceParametersType refParam = DescriptorFactory.eINSTANCE
103
			.createReferenceParametersType();
104
		instance.setReferenceParameters(refParam);
105
		return new InitialInstancesType[] { instance };
106
	}
107
108
	public ResourceTypeType inspect(Capability[] mrtCapabilities) 
109
	{
110
		for (int i = 0; i < mrtCapabilities.length; i++)
111
		{
112
			if (hasRelationshipCapability(mrtCapabilities[i]))
113
				return createRelationshipResourceType();							
114
		}
115
		return null;
116
	}
117
	
118
	private ResourceTypeType createRelationshipResourceType()
119
	{
120
		createRelationshipResourceMrt();
121
		_relationshipResourceType = createRelationshipResourceMuseType();
122
		return _relationshipResourceType;
123
	}
124
	
125
	private void createRelationshipResourceMrt()
126
	{
127
		org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.DocumentRoot documentRoot = ManageableResourceTypeFactory.eINSTANCE.createDocumentRoot();
128
		_relationshipResourceMRT = ManageableResourceTypeFactory.eINSTANCE
129
				.createManageableResourceType();
130
		documentRoot.setManageableResource(_relationshipResourceMRT);
131
		_relationshipResourceMRT.setIdentifier("RelationshipResource");
132
		_relationshipResourceMRT
133
				.setNamespace("http://docs.oasis-open.org/wsdm/muws2-2.xsd/RelationshipResource");
134
		_relationshipResourceMRT
135
				.getImplements()
136
				.add(WsdmConstants.MEX_CAPABILITY_LOCATION);
137
		_relationshipResourceMRT
138
				.getImplements()
139
				.add(WsdmConstants.GET_CAPABILITY_LOCATION);
140
		_relationshipResourceMRT
141
				.getImplements()
142
				.add(WsdmConstants.SET_CAPABILITY_LOCATION);
143
		_relationshipResourceMRT
144
				.getImplements()
145
				.add(WsdmConstants.QUERY_CAPABILITY_LOCATION);
146
		_relationshipResourceMRT
147
				.getImplements()
148
				.add(WsdmConstants.RELATIONSHIP_RESOURCE_CAPABILITY_LOCATION);
149
	}
150
	
151
	private ResourceTypeType createRelationshipResourceMuseType()
152
	{
153
		ResourceTypeType resourceType = DescriptorFactory.eINSTANCE
154
				.createResourceTypeType();
155
		resourceType.setContextPath("/RelationshipResource");
156
		resourceType
157
				.setJavaIdFactoryClass(WsdmConstants.MUSE_RESOURCE_ID_FACTORY_CLASS);
158
		resourceType
159
				.setJavaResourceClass(WsdmConstants.MUSE_RESOURCE_CLASS);
160
161
		WsdlType wsdlType = DescriptorFactory.eINSTANCE.createWsdlType();
162
		wsdlType.setWsdlFile(_mrtParentDirName + "/"
163
				+ "RelationshipResource.wsdl");
164
		_root.getXMLNSPrefixMap().put("rel",
165
				"http://docs.oasis-open.org/wsdm/muws2-2.xsd/RelationshipResource");
166
		wsdlType.setWsdlPortType("rel:PortType");
167
		resourceType.setWsdl(wsdlType);
168
169
		CapabilityType metadataExchange = DescriptorFactory.eINSTANCE
170
				.createCapabilityType();
171
		metadataExchange
172
				.setCapabilityUri("http://schemas.xmlsoap.org/ws/2004/09/mex");
173
		metadataExchange.setJavaCapabilityClass("");
174
175
		CapabilityType getCapability = DescriptorFactory.eINSTANCE
176
				.createCapabilityType();
177
		getCapability
178
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Get");
179
		getCapability.setJavaCapabilityClass("");
180
181
		CapabilityType setCapability = DescriptorFactory.eINSTANCE
182
				.createCapabilityType();
183
		setCapability
184
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Set");
185
		setCapability.setJavaCapabilityClass("");
186
187
		CapabilityType queryCapability = DescriptorFactory.eINSTANCE
188
				.createCapabilityType();
189
		queryCapability
190
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Query");
191
		queryCapability.setJavaCapabilityClass("");
192
193
		CapabilityType relationshipResource = DescriptorFactory.eINSTANCE
194
				.createCapabilityType();
195
		relationshipResource
196
				.setCapabilityUri("http://docs.oasis-open.org/wsdm/muws/capabilities/RelationshipResource");
197
		relationshipResource
198
				.setJavaCapabilityClass("");
199
200
		InitParamType noValidateParam = DescriptorFactory.eINSTANCE
201
				.createInitParamType();
202
		noValidateParam.setParamName("validate-wsrp-schema");
203
		noValidateParam.setParamValue("false");
204
205
		resourceType.getCapability().add(metadataExchange);
206
		resourceType.getCapability().add(getCapability);
207
		resourceType.getCapability().add(setCapability);
208
		resourceType.getCapability().add(queryCapability);
209
		resourceType.getCapability().add(relationshipResource);
210
		
211
		resourceType.getInitParam().add(noValidateParam);
212
213
		return resourceType;
214
	}
215
	
216
	private boolean hasRelationshipCapability(Capability capability)
217
	{
218
		boolean hasRelationshipNS = "http://docs.oasis-open.org/wsdm/muws2-2.xsd".equals(capability.getNamespace());
219
		String capabilityURI = capability.getWsdlDefinition().getNamespace("capabilityURI");
220
		boolean hasRelationshipURI = "http://docs.oasis-open.org/wsdm/muws/capabilities/Relationships".equals(capabilityURI);
221
		boolean hasRelationshipName = capability.getName().equals("Relationships");
222
		Operation[] operations = capability.getWsdlDefinition().getOperations();
223
		if (operations == null || operations.length < 1)
224
			return false;
225
		boolean hasQueryRelationshipsOp = WsdlUtils.getOperationName(operations[0])
226
				.equals("QueryRelationshipsByType");
227
		return hasRelationshipNS && hasRelationshipURI && hasRelationshipName && hasQueryRelationshipsOp;
228
	}
229
230
	public void persistArtifacts() 
231
	{
232
		ResourceSet rs = new ResourceSetImpl();
233
		rs.getResourceFactoryRegistry().getExtensionToFactoryMap()
234
			.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new CustomMrtResourceFactoryImpl());
235
		byte[] rawNewMRT = MrtUtils.serializeMRT(_relationshipResourceMRT, rs, URI
236
				.createURI("dummy.xml"), true);
237
		InputStream stream = new ByteArrayInputStream(rawNewMRT);
238
239
		try
240
		{
241
			String relationshipResourceMrt = _mrtParentDirName + "/"
242
					+ "RelationshipResource.mrt";
243
			IFile relationshipResourceMrtFile = EclipseUtils.getIFile(relationshipResourceMrt);
244
			if (relationshipResourceMrtFile.exists())
245
			{
246
				relationshipResourceMrtFile.setContents(stream, true, true,
247
						new NullProgressMonitor());
248
			}
249
			else
250
			{
251
				relationshipResourceMrtFile.create(stream, true,
252
						new NullProgressMonitor());
253
			}
254
			try
255
			{
256
				stream.close();
257
			}
258
			catch (IOException e)
259
			{
260
				WsdmToolingLog.logError(e.getMessage(), e);
261
			}
262
		}
263
		catch (CoreException e)
264
		{
265
			WsdmToolingLog.logError(e.getMessage(), e);
266
		}		
267
	}
268
269
	public void setMrtParentDirectory(String mrtParentDir) 
270
	{
271
		_mrtParentDirName = mrtParentDir;
272
	}
273
	
274
	/**
275
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
276
	 * merged RMD document for it by having the rules/relationships in it. 
277
	 */
278
	public void inspectMetadata(ManageableResourceType mrt, MetadataDescriptor rmd)
279
	{
280
		boolean hasRelationshipCapability = false;
281
		Capability[] mrtCapabilities = new Capability[0];
282
		try 
283
		{
284
			mrtCapabilities = MrtUtils.getCapabilities(mrt);
285
		} 
286
		catch (Exception e)
287
		{
288
			WsdmToolingLog.logError(e.getMessage(), e);
289
		}
290
		for (int i = 0; i < mrtCapabilities.length; i++)
291
		{
292
			if (hasRelationshipCapability(mrtCapabilities[i]))
293
			{
294
				hasRelationshipCapability = true;
295
				break;
296
			}
297
		}
298
		if(hasRelationshipCapability)
299
		{
300
			List relationships = mrt.getRelationshipDefinitions();
301
			List initialValues = new ArrayList();
302
			for(int i=0;i<relationships.size();i++)
303
			{
304
				Relationship relationship = (Relationship) relationships.get(i);
305
				Element value = createRelationshipElement(relationship);
306
				initialValues.add(value);
307
			}
308
			if(!initialValues.isEmpty());
309
				try 
310
				{
311
					rmd.setInitialValues(new QName(WsdmConstants.MUWS_P2_NS,"Relationship"), initialValues);
312
				} 
313
				catch (SoapFault e) 
314
				{
315
					WsdmToolingLog.logError(e.getMessage(), e);
316
				}
317
		}
318
	}
319
	
320
	private Element createRelationshipElement(Relationship relationship)
321
	{
322
		Document document = XmlUtils.createDocument();
323
		Element relationshipElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P2_NS,"Relationship"));
324
		
325
		Element nameElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P2_NS,"Name"));
326
		Text name = document.createTextNode(relationship.getName());
327
		nameElement.appendChild(name);		
328
		relationshipElement.appendChild(nameElement);
329
		
330
		Element typeElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P2_NS,"Type"));
331
		QName typeQName = RelationshipUtils.getRelationshipType(relationship);
332
		Element element = XmlUtils.createElement(document, typeQName);
333
		typeElement.appendChild(element);		
334
		relationshipElement.appendChild(typeElement);
335
		
336
		List participants = relationship.getParticipant();
337
		for(int i=0;i<participants.size();i++)
338
		{
339
			RelationshipParticipantType participant = (RelationshipParticipantType) participants.get(i);
340
			Element participantElement = createParticipantElement(participant, document);
341
			relationshipElement.appendChild(participantElement);
342
		}
343
		return relationshipElement;
344
	}
345
	
346
	private Element createParticipantElement(RelationshipParticipantType participant, Document document)
347
	{
348
		Element participantElement = XmlUtils.createElement(document,new QName(WsdmConstants.MUWS_P2_NS,"Participant"));
349
		
350
		// Create epr element 
351
		Element manageabilityEprElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P1_NS,"ManageabilityEndpointReference"));
352
		EndpointReferenceType epr = (EndpointReferenceType) participant.getManageabilityEndpointReference().get(0);
353
		AttributedURIType uri = epr.getAddress();
354
		Element addressElement = XmlUtils.createElement(document, new QName("http://www.w3.org/2005/08/addressing", "Address"));
355
		Text address = document.createTextNode(uri.getValue());
356
		addressElement.appendChild(address);
357
		manageabilityEprElement.appendChild(addressElement);
358
		participantElement.appendChild(manageabilityEprElement);
359
		
360
		// Create reference parameter element
361
		Element referenceParameterElement = XmlUtils.createElement(document, WsaConstants.PARAMETERS_QNAME);
362
		manageabilityEprElement.appendChild(referenceParameterElement);		
363
		org.eclipse.tptp.wsdm.tooling.model.addressing.ReferenceParametersType refParams = epr.getReferenceParameters();
364
		FeatureMap fm = refParams.getAny();
365
		Iterator it = fm.iterator();
366
		while (it.hasNext())
367
		{
368
			Object obj = it.next();
369
			if(obj instanceof EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)
370
			{
371
				EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry containmentEntry = (EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)obj;
372
				EStructuralFeatureExtendedMetaData metadata = ((EStructuralFeatureImpl)containmentEntry.getEStructuralFeature()).getExtendedMetaData();
373
				String namespace = metadata.getNamespace();
374
				String name = metadata.getName();
375
				String value = "";
376
				Object containmentEntryValue = containmentEntry.getValue();
377
				if(containmentEntryValue instanceof AnyType)
378
				{
379
					AnyType anyType = (AnyType) containmentEntryValue;
380
					value = (String) anyType.getMixed().valueListIterator().next();
381
				}
382
				Element paramElement = XmlUtils.createElement(document, new QName(namespace, name));
383
				XmlUtils.setElementText(paramElement, value);
384
				referenceParameterElement.appendChild(paramElement);
385
			}			
386
		}
387
		
388
		// Create resource id element
389
		Element resourceIdElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P1_NS,"ResourceId"));
390
		Text resourceId = document.createTextNode(participant.getResourceId());
391
		resourceIdElement.appendChild(resourceId);
392
		participantElement.appendChild(resourceIdElement);
393
		
394
		// Create role element
395
		Element roleElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P2_NS,"Role"));
396
		Text role = document.createTextNode(participant.getRole());
397
		roleElement.appendChild(role);
398
		participantElement.appendChild(roleElement);
399
		
400
		return participantElement;
401
	}
402
	
403
	
404
405
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/ISoapServerDependency.java (-44 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import org.eclipse.core.runtime.IExecutableExtension;
16
17
/**
18
 * Interface to represent Soap Library dependency used in Tooling codegeneration. 
19
 */
20
21
public interface ISoapServerDependency extends IExecutableExtension
22
{
23
	/**
24
	 * Returns null if the given Server Home has all the required soap jar files.
25
	 */
26
	String validateSoapServerHome(String serverHome);
27
	
28
	/**
29
	 * Returns the absolute path of all the required soap jar files. 
30
	 */
31
	TargetedFileList[] getFilesToCopy();
32
	
33
	/**
34
	 * Returns the absolute path of the lib folder. 
35
	 */
36
//	String getServerLibLocation(String serverName);
37
	
38
	/**
39
	 * Returns the absolute path of the modules folder. 
40
	 */
41
//	String getServerModulesLocation(String serverName);
42
43
	
44
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/CodeGenerationDelegate.java (-51 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
16
import org.eclipse.core.runtime.SubProgressMonitor;
17
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
18
19
/**
20
 * This class acts as a way to capture doing WSDL resolution (which could
21
 * include WSDL manipulation like merging) so that it can be done later on, or
22
 * on another thread since this would be time-consuming.
23
 */
24
public interface CodeGenerationDelegate
25
{
26
27
	/**
28
	 * Do any work related to code generation. This kind of work is passed to
29
	 * this delegate so that it can be run in a separate thread. This can take a
30
	 * (optional) progress monitor which can be used to report progress done in
31
	 * this task. The method returns a DescriptorHelper which aggregates all of
32
	 * the work that was done.
33
	 * 
34
	 * @param progressMonitor
35
	 *            A progress monitor to show the progress done during this task.
36
	 * 
37
	 * @throws Exception
38
	 */
39
	DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception;
40
	
41
	/**
42
	 * Persist the extra artifacts generated during codegeneration such as SubscriptionManager.mrt etc.
43
	 */
44
	void persistArtifacts();
45
	
46
	/**
47
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
48
	 * merged RMD document for it by having the rules/relationships in it. 
49
	 */
50
	void inspectMetadata(ManageableResourceType mrt, MetadataDescriptor metadata);
51
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtPreProcessor.java (-250 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.LinkedList;
19
import java.util.List;
20
import java.util.Map;
21
22
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
24
import org.apache.ws.muse.descriptor.InitialInstancesType;
25
import org.apache.ws.muse.descriptor.MuseType;
26
import org.apache.ws.muse.descriptor.ResourceTypeType;
27
import org.apache.ws.muse.descriptor.RootType;
28
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
31
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
32
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
33
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
34
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
35
36
/**
37
 * This class analyzes the given ManageableResourceType object and check whether it needs
38
 * any other extra ManageableResourceType object such as SubscriptionManager based on the capabilities 
39
 * available in given ManagableResourceType.   
40
 */
41
42
public class MrtPreProcessor 
43
{
44
	private ManageableResourceType _mrt;
45
	private DocumentRoot _ddRoot;
46
	private IFile _mrtFile;
47
	private List _generatedResourceTypes = new LinkedList();
48
	private List _initialInstancesList = new LinkedList();
49
	private List _contributedInspectors = new LinkedList();
50
	private Map _mrtObjectMap = new HashMap();
51
	private List _allInspectors = new LinkedList();
52
	
53
	/**
54
	 * Creates instance of this class.
55
	 * 
56
	 * @param mrt
57
	 * 			Given MRT to analyze.
58
	 * 
59
	 * @param ddRoot
60
	 * 			Given Descriptor file document root, can be null.
61
	 */
62
	public MrtPreProcessor(ManageableResourceType mrt, DocumentRoot ddRoot)
63
	{
64
		_mrt = mrt;
65
		if(ddRoot == null)
66
			ddRoot = DdeUtil.createInitialDDModel();
67
		_ddRoot = ddRoot;
68
		String mrtLocation = _mrt.eResource().getURI().toString();
69
		try 
70
		{
71
			_mrtFile = EclipseUtils.getIFile(mrtLocation);
72
		} 
73
		catch (CoreException e) 
74
		{
75
			e.printStackTrace();
76
		}
77
	}
78
	
79
	/**
80
	 * Creates instance of this class.
81
	 * 
82
	 * @param mrt
83
	 * 			Given MRT to analyze.
84
	 */
85
	public MrtPreProcessor(ManageableResourceType mrt)
86
	{
87
		this(mrt,null);
88
	}
89
	
90
	/**
91
	 * Returns the modified Descriptor document root. 
92
	 */
93
	public DocumentRoot getDDDocumentRoot()
94
	{
95
		return _ddRoot;
96
	}
97
	
98
	/**
99
	 * Analyzes the given MRT file for extra required artifacts. 
100
	 */
101
	public void preProcess()
102
	{
103
		if(_ddRoot!=null)
104
		{
105
			RootType root = _ddRoot.getRoot();
106
			MuseType muse = root.getMuse();		
107
			ResourceTypeType[] resourceTypes = process();
108
			for (int i = 0; i < resourceTypes.length; i++)
109
				muse.getResourceType().add(resourceTypes[i]);
110
			
111
			// Create initial instances
112
			
113
			InitialInstancesType[] instances = getInitialInstances();
114
			for (int i = 0; i < instances.length; i++)
115
				root.getInitialInstances().add(instances[i]);
116
		}
117
	}
118
	
119
	private boolean hasResourceTypeInDD(ResourceTypeType givenResourceType)
120
	{
121
		if(_ddRoot!=null)
122
		{
123
			if(_ddRoot.getRoot()!=null)
124
			{
125
				if(_ddRoot.getRoot().getMuse()!=null)
126
				{
127
					MuseType muse = _ddRoot.getRoot().getMuse();
128
					List resourceTypes = muse.getResourceType();
129
					if(resourceTypes!=null)
130
					{
131
						for(int i=0;i<resourceTypes.size();i++)
132
						{
133
							ResourceTypeType resourceType = (ResourceTypeType)resourceTypes.get(i);
134
							boolean equalContextPath = givenResourceType.getContextPath().equals(resourceType.getContextPath());
135
							boolean equalWsdlFile = givenResourceType.getWsdl().getWsdlFile().equals(resourceType.getWsdl().getWsdlFile());
136
							boolean equalWsdlPortType = givenResourceType.getWsdl().getWsdlPortType().equals(resourceType.getWsdl().getWsdlPortType());
137
							if(equalContextPath && equalWsdlFile && equalWsdlPortType)
138
								return true;
139
						}
140
					}
141
				}
142
			}
143
		}
144
		return false;
145
	}
146
	
147
	/**
148
	 * This method processes the given manageable resource type to check whether
149
	 * we need any extra resource type in muse descriptor file such as
150
	 * Subscription manager etc. It will returns all the proper ResourceTypeType
151
	 * objects. So it will return atleast one ResourceTypeType object that
152
	 * represents the given manageable resource type.
153
	 */
154
	private ResourceTypeType[] process()
155
	{
156
		Capability[] mrtCapabilities = new Capability[0];
157
		try
158
		{
159
			mrtCapabilities = MrtUtils.getCapabilities(_mrt);
160
		}
161
		catch (Exception e)
162
		{
163
		}
164
		// Analyze the given manageable resource type for Subscription manager
165
		// etc.
166
		// If needed add the extra resource type for Subscription manager
167
		List inspectors = getAllMrtInspectors();
168
		for (int i = 0; i < inspectors.size(); i++)
169
		{
170
			MrtInspector inspector = (MrtInspector) inspectors.get(i);
171
			inspector.setMrtParentDirectory(_mrtFile.getParent().getFullPath()
172
					.toString());
173
			ResourceTypeType resourceType = inspector.inspect(mrtCapabilities);
174
			if (resourceType != null)
175
			{
176
				if(!hasResourceTypeInDD(resourceType))
177
				{
178
					_generatedResourceTypes.add(resourceType);
179
					InitialInstancesType[] instances = inspector
180
							.getInitialInstances();
181
					for (int j = 0; j < instances.length; j++)
182
						_initialInstancesList.add(instances[j]);
183
					if(inspector.getExtraGeneratedMrt()!=null)
184
						_mrtObjectMap.put(inspector.getExtraGeneratedMrtPersistanceLocation(), inspector.getExtraGeneratedMrt());
185
					_contributedInspectors.add(inspector);
186
				}
187
			}
188
			_allInspectors.add(inspector);
189
		}
190
		return (ResourceTypeType[]) _generatedResourceTypes
191
				.toArray(new ResourceTypeType[_generatedResourceTypes.size()]);
192
	}
193
194
	private List getAllMrtInspectors()
195
	{
196
		List inspectors = new ArrayList();
197
		inspectors.add(new BasicMrtInspector(_mrt, _ddRoot));
198
		// We don't analyze MRT for SubscriptionManager
199
		// As it is already handled in MUSE-2.1
200
		//inspectors.add(new SubscriptionManagerInspector(_ddRoot));
201
		inspectors.add(new ServiceGroupInspector(_mrt, _ddRoot));
202
		inspectors.add(new RelationshipInspector(_ddRoot));
203
		return inspectors;
204
	}
205
	
206
	/**
207
	 * Returns the initial instances
208
	 * @return IntialInstancesType[]
209
	 */
210
	private InitialInstancesType[] getInitialInstances()
211
	{
212
		return (InitialInstancesType[]) _initialInstancesList
213
				.toArray(new InitialInstancesType[_initialInstancesList.size()]);
214
	}
215
216
	/**
217
	 * Returns the map.
218
	 * Key will be the persisted location of MRT and 
219
	 * value will be the ManageableREsourceType object. 
220
	 */
221
	public Map getMrtObjectMap() 
222
	{
223
		return _mrtObjectMap;
224
	}
225
	
226
	/**
227
	 * This method will persist the extra artifacts generated at codegen time.
228
	 */
229
	public void persistArtifacts()
230
	{
231
		for(int i=0;i<_contributedInspectors.size();i++)
232
		{
233
			MrtInspector inspector = (MrtInspector)_contributedInspectors.get(i);
234
			inspector.persistArtifacts();
235
		}		
236
	}
237
	
238
	/**
239
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
240
	 * merged RMD document for it by having the rules/relationships in it. 
241
	 */
242
	public void inspectMetadata(ManageableResourceType mrt, MetadataDescriptor rmd)
243
	{
244
		for(Iterator iter = _allInspectors.iterator();iter.hasNext();)
245
		{
246
			MrtInspector inspector = (MrtInspector) iter.next();
247
			inspector.inspectMetadata(mrt, rmd);
248
		}
249
	}
250
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MRTCodeGenerationDelegate.java (-156 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.ByteArrayInputStream;
16
import java.io.ByteArrayOutputStream;
17
import java.io.IOException;
18
import java.util.HashMap;
19
import java.util.Map;
20
21
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
22
import org.apache.ws.muse.descriptor.DescriptorFactory;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
24
import org.apache.ws.muse.descriptor.ResourceTypeType;
25
import org.apache.ws.muse.descriptor.WsdlType;
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.SubProgressMonitor;
29
import org.eclipse.emf.common.util.URI;
30
import org.eclipse.emf.ecore.resource.Resource;
31
import org.eclipse.emf.ecore.resource.ResourceSet;
32
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
33
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
34
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
35
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
36
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
37
38
/**
39
 * This class acts as a way during the Code Generation of MRT to capture doing WSDL 
40
 * resolution so that it can be done later on, or on
41
 * another thread since this would be time-consuming.
42
 */
43
public class MRTCodeGenerationDelegate implements CodeGenerationDelegate
44
{
45
	private ManageableResourceType _mrt;
46
	private MrtPreProcessor _mrtPreProcessor;
47
	private String _ddFilePath;
48
	private IFile _mrtFile;
49
	private DocumentRoot _ddRoot;
50
	
51
	/**
52
	 * Constructor of the class
53
	 * @param mrtFile
54
	 */
55
	public MRTCodeGenerationDelegate(IFile mrtFile)
56
	{
57
		_mrtFile = mrtFile;
58
		URI mrtURI = URI.createPlatformResourceURI(mrtFile.getFullPath()
59
				.toString());
60
		_mrt = MrtUtils.loadMRT(mrtURI);
61
		_mrtPreProcessor = new MrtPreProcessor(_mrt);
62
	}
63
64
	/**
65
	 * Creates the DD file. 
66
	 * The method returns a DescriptorHelper which
67
	 * aggregates all of the work that was done.
68
	 * 
69
	 * @param progressMonitor 	A progress monitor to 
70
	 * 							show the progress done during this 
71
	 * 							task. 
72
	 * @throws Exception
73
	 */
74
	public DescriptorHelper run(SubProgressMonitor progressMonitor)
75
			throws Exception
76
	{
77
		byte[] serializedDD = createDD();
78
		Map mrtObjectMap = _mrtPreProcessor.getMrtObjectMap();
79
		return new DescriptorHelper(this, new ByteArrayInputStream(serializedDD), mrtObjectMap, false);
80
	}
81
	
82
	private byte[] createDD()
83
	{
84
		_mrtPreProcessor.preProcess();
85
		_ddRoot = _mrtPreProcessor.getDDDocumentRoot();
86
		ResourceSet resourceSet = new ResourceSetImpl();
87
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
88
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
89
				new MyDescriptorResourceFactoryImpl());
90
		URI uri = URI.createURI("dummy.xml");
91
		Resource resource = resourceSet.createResource(uri);
92
		resource.getContents().add(_ddRoot);
93
		Map map = new HashMap();
94
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
95
		try 
96
		{
97
			resource.save(baos, map);
98
		} 
99
		catch (IOException e) 
100
		{
101
			e.printStackTrace();
102
		}
103
		return baos.toByteArray();
104
	}
105
	
106
	private String createDDFilePath()
107
	{
108
		IPath ddIPath = _mrtFile.getFullPath().removeFileExtension()
109
				.addFileExtension("dd");
110
		return ddIPath.toString();
111
	}
112
113
	/**
114
	 * Create and return a new instance of given ResourceTypeType. Only
115
	 * ContextPath, JavaIdFactoryClass, JavaResourceClass and WsdlType fields
116
	 * have been copied.
117
	 */
118
	public static ResourceTypeType cloneResourceType(ResourceTypeType rt)
119
	{
120
		ResourceTypeType clone = DescriptorFactory.eINSTANCE
121
				.createResourceTypeType();
122
		clone.setContextPath(rt.getContextPath());
123
		clone.setJavaIdFactoryClass(rt.getJavaIdFactoryClass());
124
		clone.setJavaResourceClass(rt.getJavaResourceClass());
125
		WsdlType wClone = DescriptorFactory.eINSTANCE.createWsdlType();
126
		wClone.setWsdlFile(rt.getWsdl().getWsdlFile());
127
		wClone.setWsdlPortType(rt.getWsdl().getWsdlPortType());
128
		clone.setWsdl(wClone);
129
		return clone;
130
	}
131
132
	/**
133
	 * This method will persist the extra artifacts generated at codegen time.
134
	 */
135
	public void persistArtifacts() 
136
	{
137
		_mrtPreProcessor.persistArtifacts();
138
		persistDDFile();		
139
	}
140
	
141
	private void persistDDFile()
142
	{
143
		_ddFilePath = createDDFilePath();
144
		DdeUtil.serializeDescriptorRoot(_ddRoot, URI.createPlatformResourceURI(_ddFilePath));
145
	}
146
147
	/**
148
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
149
	 * merged RMD document for it by having the rules/relationships in it. 
150
	 */
151
	public void inspectMetadata(ManageableResourceType mrt,
152
			MetadataDescriptor metadata) 
153
	{
154
		_mrtPreProcessor.inspectMetadata(mrt, metadata);		
155
	}
156
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/SubscriptionManagerInspector.java (-334 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.ByteArrayInputStream;
16
import java.io.IOException;
17
import java.io.InputStream;
18
19
import javax.wsdl.Operation;
20
21
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
22
import org.apache.ws.muse.descriptor.CapabilityType;
23
import org.apache.ws.muse.descriptor.DescriptorFactory;
24
import org.apache.ws.muse.descriptor.DocumentRoot;
25
import org.apache.ws.muse.descriptor.InitParamType;
26
import org.apache.ws.muse.descriptor.InitialInstancesType;
27
import org.apache.ws.muse.descriptor.ReferenceParametersType;
28
import org.apache.ws.muse.descriptor.ResourceTypeType;
29
import org.apache.ws.muse.descriptor.WsdlType;
30
import org.eclipse.core.resources.IFile;
31
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.NullProgressMonitor;
33
import org.eclipse.emf.common.util.URI;
34
import org.eclipse.emf.ecore.resource.Resource;
35
import org.eclipse.emf.ecore.resource.ResourceSet;
36
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
37
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
38
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
39
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceTypeFactory;
40
import org.eclipse.tptp.wsdm.tooling.util.internal.CustomMrtResourceFactoryImpl;
41
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
44
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
45
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
46
47
/**
48
 * This class analyzes the given manageable resource type and provide an extra
49
 * resource type for muse descriptor (SubscriptionManager), if manageable
50
 * resource type contains the NotificationProducer capability.
51
 */
52
public class SubscriptionManagerInspector implements MrtInspector
53
{
54
55
	private String _mrtParentDirName;
56
57
	private DocumentRoot _root;
58
59
	private ResourceTypeType _subManagerResourceType;
60
	
61
	private ManageableResourceType _subManagerMRT;
62
	/**
63
	 * Constructor of the class
64
	 * @param root
65
	 */
66
	public SubscriptionManagerInspector(DocumentRoot root)
67
	{
68
		_root = root;
69
	}
70
71
	/**
72
	 * Analyzes the given manageable resource type for NotificationProducer
73
	 * capability, and if the capability available then returns the muse
74
	 * resource type for SubscriptionManager else returns the null.
75
	 */
76
	public ResourceTypeType inspect(Capability[] mrtCapabilities)
77
	{
78
		for (int i = 0; i < mrtCapabilities.length; i++)
79
		{
80
			if (isNotificationProducerCapability(mrtCapabilities[i]))
81
				return createSubscriptionManagerResourceType();
82
		}
83
		return null;
84
	}
85
86
	private ResourceTypeType createSubscriptionManagerResourceType()
87
	{
88
		createSubManagerMrt();
89
		_subManagerResourceType = createSubManagerMuseResourceType();
90
		return _subManagerResourceType;
91
	}
92
93
	private void createSubManagerMrt()
94
	{
95
		org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.DocumentRoot documentRoot = ManageableResourceTypeFactory.eINSTANCE.createDocumentRoot();
96
		_subManagerMRT = ManageableResourceTypeFactory.eINSTANCE
97
				.createManageableResourceType();
98
		documentRoot.setManageableResource(_subManagerMRT);
99
		_subManagerMRT.setIdentifier("SubscriptionManager");
100
		_subManagerMRT
101
				.setNamespace("http://docs.oasis-open.org/wsn/b-2/SubscriptionManager");
102
		_subManagerMRT
103
				.getImplements()
104
				.add(WsdmConstants.IDENTITY_CAPABILITY_LOCATION);
105
		_subManagerMRT
106
				.getImplements()
107
				.add(WsdmConstants.MANAGEABLITY_CAPABILITY_LOCATION);
108
		_subManagerMRT
109
				.getImplements()
110
				.add(WsdmConstants.MEX_CAPABILITY_LOCATION);
111
		_subManagerMRT
112
				.getImplements()
113
				.add(WsdmConstants.GET_CAPABILITY_LOCATION);
114
		_subManagerMRT
115
				.getImplements()
116
				.add(WsdmConstants.SET_CAPABILITY_LOCATION);
117
		_subManagerMRT
118
				.getImplements()
119
				.add(WsdmConstants.QUERY_CAPABILITY_LOCATION);
120
		_subManagerMRT
121
				.getImplements()
122
				.add(WsdmConstants.IMMIDIATE_RESOURCE_TERMINATION_CAPABILITY_LOCATION);
123
		_subManagerMRT
124
				.getImplements()
125
				.add(WsdmConstants.SCHEDULED_RESOURCE_TERMINATION_CAPABILITY_LOCATION);
126
		_subManagerMRT
127
				.getImplements()
128
				.add(WsdmConstants.SUBSCRIPTION_MANAGER_CAPABILITY_LOCATION);		
129
	}
130
131
	private ResourceTypeType createSubManagerMuseResourceType()
132
	{
133
		ResourceTypeType resourceType = DescriptorFactory.eINSTANCE
134
				.createResourceTypeType();
135
		resourceType.setContextPath("/SubscriptionManager");
136
		resourceType
137
				.setJavaIdFactoryClass(WsdmConstants.MUSE_RESOURCE_ID_FACTORY_CLASS);
138
		resourceType
139
				.setJavaResourceClass(WsdmConstants.MUSE_RESOURCE_CLASS);
140
141
		WsdlType wsdlType = DescriptorFactory.eINSTANCE.createWsdlType();
142
		wsdlType.setWsdlFile(_mrtParentDirName + "/"
143
				+ "SubscriptionManager.wsdl");
144
		_root.getXMLNSPrefixMap().put("wsn",
145
				"http://docs.oasis-open.org/wsn/b-2/SubscriptionManager");
146
		wsdlType.setWsdlPortType("wsn:PortType");
147
		resourceType.setWsdl(wsdlType);
148
149
		CapabilityType identity = DescriptorFactory.eINSTANCE
150
				.createCapabilityType();
151
		identity
152
				.setCapabilityUri("http://docs.oasis-open.org/wsdm/muws/capabilities/Identity");
153
		identity.setJavaCapabilityClass("");
154
155
		CapabilityType manageabilityCharacteristics = DescriptorFactory.eINSTANCE
156
				.createCapabilityType();
157
		manageabilityCharacteristics
158
				.setCapabilityUri("http://docs.oasis-open.org/wsdm/muws/capabilities/ManageabilityCharacteristics");
159
		manageabilityCharacteristics.setJavaCapabilityClass("");
160
161
		CapabilityType metadataExchange = DescriptorFactory.eINSTANCE
162
				.createCapabilityType();
163
		metadataExchange
164
				.setCapabilityUri("http://schemas.xmlsoap.org/ws/2004/09/mex");
165
		metadataExchange.setJavaCapabilityClass("");
166
167
		CapabilityType getCapability = DescriptorFactory.eINSTANCE
168
				.createCapabilityType();
169
		getCapability
170
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Get");
171
		getCapability.setJavaCapabilityClass("");
172
173
		CapabilityType setCapability = DescriptorFactory.eINSTANCE
174
				.createCapabilityType();
175
		setCapability
176
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Set");
177
		setCapability.setJavaCapabilityClass("");
178
179
		CapabilityType queryCapability = DescriptorFactory.eINSTANCE
180
				.createCapabilityType();
181
		queryCapability
182
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Query");
183
		queryCapability.setJavaCapabilityClass("");
184
185
		CapabilityType immediateDestruction = DescriptorFactory.eINSTANCE
186
				.createCapabilityType();
187
		immediateDestruction
188
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rlw-2/ImmediateResourceTermination");
189
		immediateDestruction
190
				.setJavaCapabilityClass("org.apache.muse.ws.resource.lifetime.impl.SimpleImmediateTermination");
191
192
		CapabilityType scheduledDestruction = DescriptorFactory.eINSTANCE
193
				.createCapabilityType();
194
		scheduledDestruction
195
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rlw-2/ScheduledResourceTermination");
196
		scheduledDestruction
197
				.setJavaCapabilityClass("org.apache.muse.ws.resource.lifetime.impl.SimpleScheduledTermination");
198
199
		CapabilityType subscriptionManager = DescriptorFactory.eINSTANCE
200
				.createCapabilityType();
201
		subscriptionManager
202
				.setCapabilityUri("http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager");
203
		subscriptionManager
204
				.setJavaCapabilityClass("org.apache.muse.ws.notification.impl.SimpleSubscriptionManager");
205
206
		InitParamType noValidateParam = DescriptorFactory.eINSTANCE
207
				.createInitParamType();
208
		noValidateParam.setParamName("validate-wsrp-schema");
209
		noValidateParam.setParamValue("false");
210
211
		resourceType.getCapability().add(identity);
212
		resourceType.getCapability().add(manageabilityCharacteristics);
213
		resourceType.getCapability().add(metadataExchange);
214
		resourceType.getCapability().add(getCapability);
215
		resourceType.getCapability().add(setCapability);
216
		resourceType.getCapability().add(queryCapability);
217
		resourceType.getCapability().add(immediateDestruction);
218
		resourceType.getCapability().add(scheduledDestruction);
219
		resourceType.getCapability().add(subscriptionManager);
220
221
		resourceType.getInitParam().add(noValidateParam);
222
223
		return resourceType;
224
	}
225
226
	private boolean isNotificationProducerCapability(Capability capability)
227
	{
228
		boolean isNpNS = capability.getNamespace().equals(
229
				"http://docs.oasis-open.org/wsn/bw-2");
230
		boolean isNpName = capability.getName().equals("NotificationProducer");
231
		Operation[] operations = capability.getWsdlDefinition().getOperations();
232
		if (operations == null || operations.length < 2)
233
			return false;
234
		boolean isSubscribeOp = WsdlUtils.getOperationName(operations[0])
235
				.equals("Subscribe");
236
		boolean isGetCurrentMessageOp = WsdlUtils.getOperationName(
237
				operations[1]).equals("GetCurrentMessage");
238
		return isNpNS && isNpName && isSubscribeOp && isGetCurrentMessageOp;
239
	}
240
241
	/**
242
	 * Sets the parent directory 
243
	 * @param mrtParentDir
244
	 */
245
	public void setMrtParentDirectory(String mrtParentDir)
246
	{
247
		_mrtParentDirName = mrtParentDir;
248
	}
249
	/**
250
	 * Returns the initial instances
251
	 * @return InitialInstancesType[]
252
	 */
253
	public InitialInstancesType[] getInitialInstances()
254
	{
255
		InitialInstancesType instance = DescriptorFactory.eINSTANCE
256
				.createInitialInstancesType();
257
		ResourceTypeType rtClone = MRTCodeGenerationDelegate
258
				.cloneResourceType(_subManagerResourceType);
259
		instance.setResourceType(rtClone);
260
		ReferenceParametersType refParam = DescriptorFactory.eINSTANCE
261
				.createReferenceParametersType();
262
		instance.setReferenceParameters(refParam);
263
		return new InitialInstancesType[] { instance };
264
	}
265
266
	/**
267
	 * This method will persist the extra artifacts generated at codegen time (SubscriptionManager.mrt file).
268
	 */
269
	public void persistArtifacts()
270
	{
271
		ResourceSet rs = new ResourceSetImpl();
272
		rs.getResourceFactoryRegistry().getExtensionToFactoryMap()
273
			.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new CustomMrtResourceFactoryImpl());
274
		byte[] rawNewMRT = MrtUtils.serializeMRT(_subManagerMRT, rs, URI
275
				.createURI("dummy.xml"), true);
276
		InputStream stream = new ByteArrayInputStream(rawNewMRT);
277
278
		try
279
		{
280
			String subManagerMrt = _mrtParentDirName + "/"
281
					+ "SubscriptionManager.mrt";
282
			IFile subManagerMrtFile = EclipseUtils.getIFile(subManagerMrt);
283
			if (subManagerMrtFile.exists())
284
			{
285
				subManagerMrtFile.setContents(stream, true, true,
286
						new NullProgressMonitor());
287
			}
288
			else
289
			{
290
				subManagerMrtFile.create(stream, true,
291
						new NullProgressMonitor());
292
			}
293
			try
294
			{
295
				stream.close();
296
			}
297
			catch (IOException e)
298
			{
299
				WsdmToolingLog.logError(e.getMessage(), e);
300
			}
301
		}
302
		catch (CoreException e)
303
		{
304
			WsdmToolingLog.logError(e.getMessage(), e);
305
		}
306
	}
307
308
	/**
309
	 * This method will returns the extra generated ManageableResourceType object equivalent to SubscriptionManager.
310
	 */
311
	public ManageableResourceType getExtraGeneratedMrt() 
312
	{
313
		return _subManagerMRT;
314
	}
315
316
	/**
317
	 * This method should return the persistance location for extra generated ManageableResourceType object equivalent to SubscriptionManager.
318
	 */
319
	public String getExtraGeneratedMrtPersistanceLocation() 
320
	{
321
		return _mrtParentDirName+"/SubscriptionManager.mrt";
322
	}
323
324
	/**
325
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
326
	 * merged RMD document for it by having the rules/relationships in it. 
327
	 */
328
	public void inspectMetadata(ManageableResourceType mrt,
329
			MetadataDescriptor rmd)
330
	{
331
	}
332
333
	
334
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/DescriptorHelper.java (-588 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.io.File;
16
import java.io.FileInputStream;
17
import java.io.IOException;
18
import java.io.InputStream;
19
import java.net.URL;
20
import java.util.ArrayList;
21
import java.util.Arrays;
22
import java.util.HashMap;
23
import java.util.LinkedList;
24
import java.util.List;
25
import java.util.Map;
26
27
import javax.xml.namespace.QName;
28
29
import org.apache.muse.core.descriptor.DescriptorConstants;
30
import org.apache.muse.util.xml.XmlUtils;
31
import org.apache.muse.ws.addressing.WsaConstants;
32
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
33
import org.eclipse.core.resources.IFile;
34
import org.eclipse.core.resources.IWorkspace;
35
import org.eclipse.core.resources.IWorkspaceRoot;
36
import org.eclipse.core.resources.ResourcesPlugin;
37
import org.eclipse.core.runtime.FileLocator;
38
import org.eclipse.core.runtime.IPath;
39
import org.eclipse.core.runtime.Path;
40
import org.eclipse.emf.common.util.URI;
41
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
44
import org.w3c.dom.Document;
45
import org.w3c.dom.Element;
46
import org.w3c.dom.NamedNodeMap;
47
import org.w3c.dom.Node;
48
49
/**
50
 * A class that takes some of the pain out of working with the deployment
51
 * descriptor. Note, there's no EMF in this approach, just plain old XML.
52
 */
53
public class DescriptorHelper
54
{
55
56
	/**
57
	 * File Extension of MRT files
58
	 */
59
	private static final String MRT_EXTN = ".mrt";
60
61
	/**
62
	 * Element name constants
63
	 */
64
	public static final QName ADDITIONAL_JARS_QNAME = new QName(
65
			DescriptorConstants.NAMESPACE_URI, "additional-jars");
66
	public static final QName JAR_PATH_QNAME = new QName(
67
			DescriptorConstants.NAMESPACE_URI, "jar-path");
68
	public static final QName INITIAL_INSTANCES_QNAME = new QName(
69
			DescriptorConstants.NAMESPACE_URI, "initial-instances");
70
	public static final QName REFERENCE_PARAMETERS_QNAME = new QName(
71
			DescriptorConstants.NAMESPACE_URI, "referenceParameters");
72
73
	/**
74
	 * Constant for empty files
75
	 */
76
	private static final File[] EMPTY_FILES = new File[0];
77
78
	/**
79
	 * Constant for empty instances.
80
	 */
81
	private static final Object[][] EMPTY_INSTANCES = new Object[0][0];
82
83
	/**
84
	 * Constant for the xmlns prefix on namespace binding declarations
85
	 */
86
	private static final Object XMLNS_PREFIX = "xmlns";
87
88
	/**
89
	 * The descriptor document we pull out of the <code>Root</code> element
90
	 */
91
	private Document _descriptorDocument;
92
93
	/**
94
	 * A list of jar files that we pull out of the
95
	 * <code>Root/additional-jars</code> element
96
	 */
97
	private File[] _jarFiles;
98
99
	/**
100
	 * A list of instances which is really just a n by 2 list of arrays. The
101
	 * sub-arrays have the instance-path (<code>String</code>) as the first
102
	 * element and the reference parameters (<code>Element</code>) as the
103
	 * second element. This is tacky, but otherwise I'd be making a pretty
104
	 * useless "Pair" class.
105
	 */
106
	private Object[][] _instances;
107
	
108
	private IFile ddIFile;
109
	
110
	/**
111
	 * Descriptor file stores the MRT file reference in Wsdl-File element.
112
	 * When we do the codegeneration we generate some extra MRTs such as SubscriptionManager,
113
	 * so we pass the map of these MRTs to this class.
114
	 * Key will be the persisted location of MRT and value will be the ManageableREsourceType object.
115
	 */
116
	private Map _mrtObjectMap = new HashMap();
117
	
118
	private CodeGenerationDelegate _codeGenerationDelegate = null;
119
120
	/**
121
	 * A do-something constructor. Take a file, if that file is null, then load
122
	 * up a default template. Otherwise load up the file and pull out the
123
	 * instances, descriptor and additional jars. For the null file case, there
124
	 * will be no instances of additional-jars, hence the constants defined
125
	 * above.
126
	 * 
127
	 * @param file - The file to analyze, can be null.
128
	 * @throws Exception - If anything goes wrong.
129
	 */
130
	public DescriptorHelper(CodeGenerationDelegate codeGenerationDelegate, IFile descriptorFile) throws Exception
131
	{
132
		this(codeGenerationDelegate, new File(descriptorFile.getLocation().toString()));
133
		ddIFile = descriptorFile;		
134
	}
135
136
	/**
137
	 * A do-something constructor. Take a file, if that file is null, then load
138
	 * up a default template. Otherwise load up the file and pull out the
139
	 * instances, descriptor and additional jars. For the null file case, there
140
	 * will be no instances of additional-jars, hence the constants defined
141
	 * above.
142
	 * 
143
	 * @param file - The file to analyze, can be null.
144
	 * @throws Exception - If anything goes wrong.
145
	 */
146
	public DescriptorHelper(CodeGenerationDelegate codeGenerationDelegate, File file) throws Exception
147
	{
148
		this(codeGenerationDelegate, new FileInputStream(file), null);
149
	}
150
	
151
	/**
152
	 * A do-something constructor. Take a inputstream, if that inputstream is null, then load
153
	 * up a default template. Otherwise load up the inputstream and pull out the
154
	 * instances, descriptor and additional jars. For the null inputstream case, there
155
	 * will be no instances of additional-jars, hence the constants defined
156
	 * above.
157
	 * 
158
	 * @param inputstream - The inputstream to analyze, can be null.
159
	 * @param mrtObjectMap - The map of MRTLocation-MRTObject pair, can be null.
160
	 * @throws Exception - If anything goes wrong.
161
	 */
162
	public DescriptorHelper(CodeGenerationDelegate codeGenerationDelegate, InputStream inputStream, Map mrtObjectMap, boolean extractExtraInfo) throws Exception
163
	{
164
		if(mrtObjectMap!=null)
165
			_mrtObjectMap = mrtObjectMap;
166
		_codeGenerationDelegate = codeGenerationDelegate;
167
		
168
		Document rootDocument = XmlUtils.createDocument(inputStream);
169
170
		_descriptorDocument = extractDescriptorDocument(rootDocument);
171
		
172
		if(extractExtraInfo) {
173
			_instances = extractInstances(rootDocument);
174
			_jarFiles = extractJarFiles(rootDocument);
175
		} else {
176
			_instances = null;
177
			_jarFiles = null;
178
		}
179
		// Add Muse tools.jar
180
		if(_jarFiles == null)
181
			_jarFiles = new File[0];
182
		String toolsJarLocation = getMuseToolsJarLocation();
183
		if(toolsJarLocation == null)
184
			return;
185
		List jars = Arrays.asList(_jarFiles);
186
		List allJars = new ArrayList();
187
		allJars.addAll(jars);		
188
		allJars.add(new File(toolsJarLocation));
189
		_jarFiles = (File[])allJars.toArray(new File[allJars.size()]);		
190
	}
191
	
192
	public DescriptorHelper(CodeGenerationDelegate codeGenerationDelegate, InputStream inputStream, Map mrtObjectMap) throws Exception {
193
		this(codeGenerationDelegate, inputStream, mrtObjectMap, true);
194
	}
195
196
	/**
197
	 * Extract the instances from the initial-instances element.
198
	 * 
199
	 * TODO this needs to be updated when the initial instances element actually
200
	 * works.
201
	 * 
202
	 * @param rootDocument
203
	 * @return
204
	 */
205
	private Object[][] extractInstances(Document rootDocument)
206
	{
207
		Element[] initialInstancesElements = XmlUtils.findInSubTree(
208
				rootDocument.getDocumentElement(), INITIAL_INSTANCES_QNAME);
209
		if (initialInstancesElements.length == 0)
210
		{
211
			return EMPTY_INSTANCES;
212
		}
213
214
		// sorry about this, maybe someday java will have a Pair type
215
		Object[][] instances = new Object[initialInstancesElements.length][2];
216
217
		for (int i = 0; i < initialInstancesElements.length; i++)
218
		{
219
			Element contextElement = XmlUtils.findFirstInSubTree(
220
					initialInstancesElements[i],
221
					DescriptorConstants.CONTEXT_PATH_QNAME);
222
			instances[i][0] = XmlUtils.extractText(contextElement);
223
			Element instancesElement = XmlUtils.findFirstInSubTree(
224
					initialInstancesElements[i], REFERENCE_PARAMETERS_QNAME);
225
			
226
			Element referenceParametersElement = XmlUtils.createElement(WsaConstants.PARAMETERS_QNAME);
227
			
228
			Element[] referenceParameters = XmlUtils.getAllElements(instancesElement);
229
			Document owner = referenceParametersElement.getOwnerDocument();
230
			for(int j=0; j < referenceParameters.length; j++) {
231
				referenceParametersElement.appendChild(owner.importNode(referenceParameters[j], true));
232
			}
233
			instances[i][1] = referenceParametersElement;	
234
		}
235
236
		return instances;
237
	}
238
239
	/**
240
	 * Extract the jars from the additional jars element. Just read through each
241
	 * element, take the text content (which should be an absolute path) and put
242
	 * it into a <code>File</code> object. Returns a list of these
243
	 * <code>File</code>s.
244
	 * 
245
	 * @param rootDocument
246
	 *            The <code>Root</code> element-containing
247
	 *            <code>Document</code>
248
	 * 
249
	 * @return A list of <code>File</code>s for each path found under
250
	 *         additional-jars
251
	 */
252
	private File[] extractJarFiles(Document rootDocument)
253
	{
254
		Element additionalJarsElement = XmlUtils.findFirstInSubTree(
255
				rootDocument.getDocumentElement(), ADDITIONAL_JARS_QNAME);
256
		if (additionalJarsElement == null)
257
		{
258
			return EMPTY_FILES;
259
		}
260
261
		Element[] jarPaths = XmlUtils.findInSubTree(additionalJarsElement,
262
				JAR_PATH_QNAME);
263
		if (jarPaths.length == 0)
264
		{
265
			return EMPTY_FILES;
266
		}
267
268
		File[] files = new File[jarPaths.length];
269
270
		for (int i = 0; i < jarPaths.length; i++)
271
		{
272
			files[i] = new File(XmlUtils.extractText(jarPaths[i]));
273
		}		
274
		return files;
275
	}
276
	
277
	private String getMuseToolsJarLocation()
278
	{
279
		URL url = FileLocator.find(org.apache.muse.tools.Activator.getDefault().getBundle(), new Path("runtime/tools.jar"), null);
280
		try 
281
		{
282
			url = FileLocator.resolve(url);			
283
			return url.getFile();
284
		}
285
		catch (IOException ioe)
286
		{
287
			WsdmToolingLog.logError(ioe.getMessage(), ioe);
288
		}
289
		return null;
290
	}
291
292
	/**
293
	 * Get the Muse descriptor out of the document. Just looks for the
294
	 * <code>DescriptorConstants.MUSE_QNAME</code> QName.
295
	 * 
296
	 * @param rootDocument
297
	 *            The <code>Root</code> element-containing
298
	 *            <code>Document</code>
299
	 * @return The new <code>Document</code> that has as its document element
300
	 *         the muse descriptor
301
	 */
302
	private Document extractDescriptorDocument(Document rootDocument)
303
	{
304
		Element museElement = XmlUtils.findFirstInSubTree(rootDocument
305
				.getDocumentElement(), DescriptorConstants.MUSE_QNAME);
306
		Document descriptorDocument = XmlUtils.createDocument();
307
		descriptorDocument.appendChild(descriptorDocument.importNode(
308
				museElement, true));
309
310
		copyNamespacePrefixes(rootDocument.getDocumentElement(),
311
				descriptorDocument.getDocumentElement());
312
		
313
		museElement = XmlUtils.getElement(descriptorDocument,DescriptorConstants.MUSE_QNAME);
314
		adjustCustomSerializers(museElement);
315
316
		return descriptorDocument;
317
	}
318
319
	/**
320
	 * Given a source <code>Element</code> and a destination
321
	 * <code>Element</code> copy all of the namespace prefixese from the
322
	 * source to the destination. This is really horrid because of DOM's API
323
	 * being what it is and we treat the declarations as attributes. Yes, we do
324
	 * check to make sure we don't do double prefix declarations.
325
	 * 
326
	 * TODO this should go into a namespace utility class, I've had to write
327
	 * this in about 3 places now.
328
	 * 
329
	 * @param source
330
	 *            The source <code>Element</code>
331
	 * @param destination
332
	 *            The destination <code>Element</code>
333
	 */
334
	private void copyNamespacePrefixes(Element source, Element destination)
335
	{
336
		NamedNodeMap attributes = source.getAttributes();
337
		int size = attributes.getLength();
338
		for (int i = 0; i < size; i++)
339
		{
340
			Node nextAttribute = attributes.item(i);
341
			String prefix = nextAttribute.getPrefix();
342
343
			if (prefix == null || !prefix.equals(XMLNS_PREFIX))
344
			{
345
				continue;
346
			}
347
348
			if (destination.hasAttribute(nextAttribute.getNodeName()))
349
			{
350
				continue;
351
			}
352
353
			destination.setAttribute(nextAttribute.getNodeName(), nextAttribute
354
					.getNodeValue());
355
		}
356
	}
357
	
358
	/**
359
	 * Descriptor editor stores the xsd-serializer-type for custom-serializer as
360
	 * 
361
	 * <custom-serializer>
362
	 * 		<xsd-serializer-type>{http://www.eclipse.org/TP}StateType</xsd-serializer-type>
363
	 * <custom-serializer>
364
	 * 
365
	 * We have to convert the QName to prefix:localpart format so we adjust this part as
366
	 * 
367
	 * <custom-serializer>
368
	 * 		<xsd-serializer-type xmlns:pfx="http://www.eclipse.org/TP">pfx:StateType</xsd-serializer-type>
369
	 * <custom-serializer>
370
	 *   
371
	 */
372
	private void adjustCustomSerializers(Element museElement)
373
	{
374
		Element[] serializerElements = XmlUtils.getElements(museElement, DescriptorConstants.CUSTOM_SERIALIZER_QNAME);
375
		for(int i=0;i<serializerElements.length;i++)
376
		{
377
			// TODO Replace the QName with MUSE constant in MUSE 2.2
378
			Element xsdSerializerElement = XmlUtils.getElement(serializerElements[i], new QName(DescriptorConstants.NAMESPACE_URI,"xsd-serializable-type"));
379
			String qNameAsString = XmlUtils.extractText(xsdSerializerElement);
380
			if(qNameAsString!=null && !qNameAsString.equals(""))
381
			{
382
				try
383
				{
384
					QName qname = QName.valueOf(qNameAsString);
385
					String namespace = qname.getNamespaceURI();
386
					String localPart = qname.getLocalPart();
387
					if(namespace.equals(""))
388
						break;
389
					xsdSerializerElement.setAttribute("pfx", namespace);
390
					XmlUtils.setElementText(xsdSerializerElement, "pfx:"+localPart);									
391
				}
392
				catch(IllegalArgumentException e)
393
				{
394
					WsdmToolingLog.logError(e.getMessage(), e);
395
				}				
396
			}			
397
		}
398
	}
399
	
400
	/**
401
	 * Returns the Descriptor document
402
	 * @return Document
403
	 */
404
	public Document getDescriptorDocument()
405
	{
406
		return _descriptorDocument;
407
	}
408
	/**
409
	 * Returns the Jar files
410
	 * @return File[]
411
	 */
412
	public File[] getJarFiles()
413
	{
414
		return _jarFiles;
415
	}
416
417
	/**
418
	 * Returns the instances
419
	 * @return Object[][]
420
	 */
421
	public Object[][] getInstances()
422
	{
423
		return _instances;
424
	}
425
426
	/**
427
	 * Go through the parsed Muse descriptor associated with this object and
428
	 * find all of the MRT files referenced therein. For each MRT file use
429
	 * <code>WsdlMerge</code> to merge the MRT's WSDL into a consolidate WSDL.
430
	 * Return the Muse Descriptor document-order list of the WSDL files.
431
	 * The passed map will contain the MRT file location as key and MRT object as value.
432
	 * So first search the map for MRT if not found then load the MRT from location.
433
	 * 
434
	 * @return A list of merged WSDL files as gathered from the deployment
435
	 *         descriptor
436
	 * 
437
	 * @see org.eclipse.tptp.wsdm.tooling.wizard.mrt.internal.WsdlResolverDelegate#getWsdlDocuments()
438
	 */
439
	public Document[] getWsdlDocuments(String baseAddress)
440
	{
441
		Element[] resourceTypes = XmlUtils.findInSubTree(_descriptorDocument
442
				.getDocumentElement(), DescriptorConstants.RESOURCE_TYPE_QNAME);
443
		int mrtCount = resourceTypes.length;
444
		Document[] mergedWSDLs = new Document[mrtCount];
445
446
		for (int i = 0; i < mrtCount; i++)
447
		{
448
			Element wsdlFileElement = XmlUtils.findFirstInSubTree(
449
					resourceTypes[i], DescriptorConstants.WSDL_FILE_QNAME);
450
451
			String wsdlPath = XmlUtils.extractText(wsdlFileElement);
452
			String mrtPath = getMRTPathFromWSDLPath(wsdlPath);
453
			ManageableResourceType mrt = null;
454
			String serviceAddress = null;
455
			if(_mrtObjectMap!=null && _mrtObjectMap.containsKey(mrtPath))
456
			{
457
				mrt = (ManageableResourceType) _mrtObjectMap.get(mrtPath);
458
				serviceAddress = baseAddress+"/"+mrt.getIdentifier();
459
			}
460
			else
461
			{
462
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
463
				IWorkspaceRoot root = workspace.getRoot();
464
				IPath mrtFilePath = root.findMember(mrtPath).getFullPath();
465
				URI uri = URI.createFileURI(mrtFilePath.toString());
466
				mrt = MrtUtils.loadMRT(uri);
467
				serviceAddress = makeServiceAddress(baseAddress, mrtFilePath);
468
			}
469
			if(mrt!=null)
470
			{
471
				try
472
				{
473
					mergedWSDLs[i] = MrtMerge.createMergedWSDL(mrt, serviceAddress);
474
				}
475
				catch (Exception e)
476
				{
477
					e.printStackTrace();
478
					// TODO AME add externalized message
479
					throw new RuntimeException(e);
480
				}
481
			}
482
			else
483
			{
484
				// TODO AME add externalized message
485
				throw new RuntimeException();
486
			}
487
		}
488
		return mergedWSDLs;
489
	}
490
491
	/**
492
	 * Given a base address add the service name. This is done by getting the
493
	 * name of the MRT file and stripping off the file extension.
494
	 * 
495
	 * @param baseAddress
496
	 *            Base address
497
	 * @param file
498
	 *            MRT file to use
499
	 * @return the combined address
500
	 */
501
	private String makeServiceAddress(String baseAddress, IPath file)
502
	{
503
		String fileName = file.toFile().getName();
504
		fileName = fileName.substring(0, fileName.lastIndexOf("."));
505
		return baseAddress + "/" + fileName;
506
	}
507
508
	private String getMRTPathFromWSDLPath(String fileName)
509
	{
510
		return fileName.substring(0, fileName.lastIndexOf(".")) + MRT_EXTN;
511
	}
512
	
513
	/**
514
	 * Adds the additional jar files to Descriptor file.
515
	 *  
516
	 * @param serverLocation
517
	 * 			Parent directory of Axis2-lib folder.
518
	 * 
519
	 * @param axis2files
520
	 * 			Axis2 jar files path.
521
	 */
522
	public void addAdditionalJars(String serverLocation, String[] axis2files)
523
	{
524
		List additionalJarFiles = new LinkedList();
525
		if(_jarFiles!=null)
526
			additionalJarFiles.addAll(Arrays.asList(_jarFiles));
527
		for(int i = 0 ; i < axis2files.length ; i++ )
528
			additionalJarFiles.add(new File(serverLocation + File.separator + axis2files[i]));
529
		_jarFiles = (File[]) additionalJarFiles.toArray(new File[additionalJarFiles.size()]);
530
	}
531
532
	/**
533
	 * Go through the parsed Muse descriptor associated with this object and
534
	 * find all of the MRT files referenced therein. For each MRT file create
535
	 * a merged RMD document.
536
	 * 
537
	 * @return A list of merged RMD documents as gathered from the deployment
538
	 *         descriptor
539
	 * 
540
	 */
541
	public MetadataDescriptor[] getMergedRMDs() 
542
	{
543
		Element[] resourceTypes = XmlUtils.findInSubTree(_descriptorDocument
544
				.getDocumentElement(), DescriptorConstants.RESOURCE_TYPE_QNAME);
545
		int mrtCount = resourceTypes.length;
546
		MetadataDescriptor[] mergedRMDs = new MetadataDescriptor[mrtCount];
547
548
		for (int i = 0; i < mrtCount; i++)
549
		{
550
			Element wsdlFileElement = XmlUtils.findFirstInSubTree(
551
					resourceTypes[i], DescriptorConstants.WSDL_FILE_QNAME);
552
553
			String wsdlPath = XmlUtils.extractText(wsdlFileElement);
554
			String mrtPath = getMRTPathFromWSDLPath(wsdlPath);
555
			ManageableResourceType mrt = null;
556
			String serviceAddress = null;
557
			if(_mrtObjectMap!=null && _mrtObjectMap.containsKey(mrtPath))
558
			{
559
				mrt = (ManageableResourceType) _mrtObjectMap.get(mrtPath);				
560
			}
561
			else
562
			{
563
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
564
				IWorkspaceRoot root = workspace.getRoot();
565
				IPath mrtFilePath = root.findMember(mrtPath).getFullPath();
566
				URI uri = URI.createFileURI(mrtFilePath.toString());
567
				mrt = MrtUtils.loadMRT(uri);				
568
			}
569
			if(mrt!=null)
570
			{
571
				try
572
				{
573
					mergedRMDs[i] = MrtMerge.createMergedRMD(mrt);
574
					_codeGenerationDelegate.inspectMetadata(mrt, mergedRMDs[i]);
575
				}
576
				catch (Exception e)
577
				{
578
					throw new RuntimeException(e);
579
				}
580
			}
581
			else
582
			{
583
				throw new RuntimeException();
584
			}
585
		}		
586
		return mergedRMDs;		
587
	} 	
588
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/TargetedFileList.java (-41 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
13
14
import java.util.ArrayList;
15
16
public class TargetedFileList {
17
	private String _relativePath;	// path relative to webcontent folder
18
	private ArrayList _absoluteFilePaths;
19
	
20
	public TargetedFileList(String relativePath){
21
		_relativePath = relativePath;
22
		_absoluteFilePaths = new ArrayList();
23
	}
24
	
25
	public void add(String absolutePath){
26
		if(absolutePath!=null && !absolutePath.trim().equals("")){
27
			_absoluteFilePaths.add(absolutePath);
28
		}
29
	}
30
	
31
	public String[] getFiles(){
32
		if(_absoluteFilePaths==null) return new String[]{};
33
		return (String[]) _absoluteFilePaths.toArray(new String[]{});
34
	}
35
	
36
	public String getRelativePath(){
37
		return _relativePath;
38
	}
39
	
40
	
41
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/GenerationOptionsPage.java (-674 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.util.HashMap;
16
import java.util.Iterator;
17
import java.util.Map;
18
import java.util.prefs.Preferences;
19
20
import org.apache.muse.tools.generator.analyzer.Analyzer;
21
import org.apache.muse.tools.generator.projectizer.Projectizer;
22
import org.apache.muse.tools.generator.synthesizer.Synthesizer;
23
import org.eclipse.core.filesystem.URIUtil;
24
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.IWorkspace;
26
import org.eclipse.core.resources.IWorkspaceRoot;
27
import org.eclipse.core.resources.ResourcesPlugin;
28
import org.eclipse.core.runtime.IConfigurationElement;
29
import org.eclipse.core.runtime.IExtension;
30
import org.eclipse.core.runtime.IExtensionPoint;
31
import org.eclipse.core.runtime.IExtensionRegistry;
32
import org.eclipse.core.runtime.IPath;
33
import org.eclipse.core.runtime.IStatus;
34
import org.eclipse.core.runtime.Path;
35
import org.eclipse.core.runtime.Platform;
36
import org.eclipse.jface.dialogs.DialogPage;
37
import org.eclipse.jface.util.Util;
38
import org.eclipse.jface.wizard.WizardPage;
39
import org.eclipse.osgi.util.TextProcessor;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.events.ModifyEvent;
42
import org.eclipse.swt.events.ModifyListener;
43
import org.eclipse.swt.events.SelectionAdapter;
44
import org.eclipse.swt.events.SelectionEvent;
45
import org.eclipse.swt.layout.GridData;
46
import org.eclipse.swt.layout.GridLayout;
47
import org.eclipse.swt.widgets.Button;
48
import org.eclipse.swt.widgets.Combo;
49
import org.eclipse.swt.widgets.Composite;
50
import org.eclipse.swt.widgets.DirectoryDialog;
51
import org.eclipse.swt.widgets.Event;
52
import org.eclipse.swt.widgets.Group;
53
import org.eclipse.swt.widgets.Label;
54
import org.eclipse.swt.widgets.Listener;
55
import org.eclipse.swt.widgets.Text;
56
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
57
import org.eclipse.tptp.wsdm.tooling.editor.mrt.relationship.dialog.internal.MemoryComboBox;
58
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
59
import org.eclipse.tptp.wsdm.tooling.util.internal.Validation;
60
61
/**
62
 * This wizard enables the use to specify the projectizer options and also the
63
 * runtime environment and general options
64
 */
65
public class GenerationOptionsPage extends WizardPage
66
{
67
	private static final String PROJECT_MEMORY_COMBO_ID = "project_memory_combo";
68
	
69
	private static final String EXT_PT = "codeGeneration";
70
	
71
	private Button _overwriteButton;
72
73
	private Combo _projectNameField;
74
75
	private String _userPath = Util.ZERO_LENGTH_STRING;// IDEResourceInfoUtils.EMPTY_STRING;
76
77
	private Button _useDefaultsButton;
78
79
	private Label _locationLabel;
80
81
	private Text _locationPathField;
82
83
	private Button _browseButton;
84
85
	private IProject _existingProject;
86
	
87
	private Combo _projectizerCombo;
88
89
	private Button _persistExtraArtifactsButton;
90
			
91
	private Map _platformContainerMap = new HashMap();
92
93
	private Combo _containerCombo;
94
95
	private Label _containerLabel;
96
97
	public GenerationOptionsPage() {
98
		super("wizardPage");
99
		setTitle(Messages.HOOKUP_WIZARD_TXT1);
100
		setDescription(Messages.HOOKUP_WIZARD_TXT2);
101
		
102
		loadExtensionData();
103
	}
104
	
105
	private void loadExtensionData() {
106
		IExtensionRegistry er = Platform.getExtensionRegistry();
107
		IExtensionPoint ep = er.getExtensionPoint(Activator.PLUGIN_ID, EXT_PT);
108
		IExtension[] extensions = ep.getExtensions();
109
110
		for (int i = 0; i < extensions.length; i++) {	
111
			IConfigurationElement[] elements = extensions[i].getConfigurationElements();			
112
			CodeGenerationData codeGenData = new CodeGenerationData(elements);				
113
			updatePlatformContainerMap(codeGenData);	
114
		}
115
	}
116
117
	private void updatePlatformContainerMap(CodeGenerationData codeGenData) {
118
		Map containerCodeGenDataMap = (Map) _platformContainerMap.get(codeGenData.getPlatform());
119
		if(containerCodeGenDataMap == null) {					
120
			//
121
			// handles the case of proxy which doesn't have a container
122
			//
123
			if(codeGenData.getContainer() == null) {			
124
				containerCodeGenDataMap = new SingleValueMap();
125
			} else {
126
				containerCodeGenDataMap = new HashMap();
127
			}
128
			
129
			_platformContainerMap.put(codeGenData.getPlatform(), containerCodeGenDataMap);
130
		}
131
132
		//
133
		// if the platform was null then it means we're using a
134
		// singlevaluemap which doesn't look at the key ever
135
		//
136
		containerCodeGenDataMap.put(codeGenData.getContainer(), codeGenData);
137
	}
138
139
	public void createControl(Composite parent) {
140
		setControl(doLayout(parent));
141
		dialogChanged();
142
	}
143
144
	private Composite doLayout(Composite parent) {
145
		Composite container = new Composite(parent, SWT.NULL);
146
		container.setLayout(new GridLayout(2, false));	
147
		
148
		GridData data = new GridData();
149
		data.horizontalAlignment = SWT.FILL;
150
		data.grabExcessHorizontalSpace = true;
151
		container.setLayoutData(data);
152
								
153
		createProjectInput(container);
154
		
155
		Composite composite = createProjectTypeGroup(container);
156
		
157
		data = new GridData();
158
		data.grabExcessHorizontalSpace = true;
159
		data.horizontalAlignment = SWT.FILL;
160
		data.horizontalSpan = 2;
161
		composite.setLayoutData(data);
162
				
163
		composite = createProjectOptionsGroup(container);
164
		
165
		data = new GridData();
166
		data.grabExcessHorizontalSpace = true;
167
		data.horizontalAlignment = SWT.FILL;
168
		data.horizontalSpan = 2;
169
		composite.setLayoutData(data);
170
		return container;
171
	}
172
173
	private void createProjectInput(Composite parent) {
174
		Label projectNameLabel = new Label(parent, SWT.NONE);
175
		projectNameLabel.setText(Messages.HOOKUP_WIZARD_TXT4);
176
177
		GridData data = new GridData();		
178
		data.horizontalAlignment = SWT.FILL;
179
		data.grabExcessHorizontalSpace = false;	
180
		projectNameLabel.setLayoutData(data);
181
		
182
		_projectNameField = MemoryComboBox.createMemoryComboBox(parent, Preferences.userNodeForPackage(GenerationOptionsPage.class), PROJECT_MEMORY_COMBO_ID);				
183
		
184
		data = new GridData();		
185
		data.horizontalAlignment = SWT.FILL;
186
		data.grabExcessHorizontalSpace = true;
187
		_projectNameField.setLayoutData(data);	
188
		
189
		_projectNameField.addListener(SWT.Modify, nameModifyListener);
190
	}
191
	
192
	private Group createProjectTypeGroup(Composite parent) {
193
		Group page = new Group(parent, SWT.SHADOW_IN);
194
		page.setText("Code Generation Options");
195
		page.setLayout(new GridLayout(2, false));
196
197
		Label platformLabel = new Label(page, SWT.NONE);
198
		platformLabel.setText("Platform:");//TODO AME
199
		_projectizerCombo = makePlatformCombo(page);
200
		
201
		_containerLabel = new Label(page, SWT.NONE);
202
		_containerLabel.setText("Container:");//TODO AME
203
		_containerLabel.setEnabled(false);
204
		
205
		_containerCombo = makeContainerCombo(page);		
206
		
207
		return page;
208
	}
209
210
	private Group createProjectOptionsGroup(Composite parent) {
211
		Group  group = new Group(parent, SWT.SHADOW_IN);
212
		group.setText("Project Options");
213
		group.setLayout(new GridLayout(3, false));
214
		
215
		_useDefaultsButton = createDefaultsButton(group);
216
		
217
		GridData buttonData = new GridData();
218
		buttonData.horizontalSpan = 3;
219
		_useDefaultsButton.setLayoutData(buttonData);
220
221
		createUserEntryArea(group, true);				
222
		createCheckboxes(group);	
223
	
224
		return group;		
225
	}
226
227
	private Button createDefaultsButton(Composite parent) {
228
		Button button = new Button(parent, SWT.CHECK | SWT.RIGHT);
229
		button.setText(Messages.CODE_GEN_DEFAULT_LOCATION);// IDEWorkbenchMessages.ProjectLocationSelectionDialog_useDefaultLabel);
230
		button.setSelection(true);
231
		
232
		button.addSelectionListener(new SelectionAdapter()
233
		{
234
			public void widgetSelected(SelectionEvent e)
235
			{
236
				boolean useDefaults = _useDefaultsButton.getSelection();
237
238
				if (!useDefaults)
239
				{
240
					_userPath = _locationPathField.getText();
241
					_locationPathField.setText(TextProcessor
242
							.process(getDefaultPathDisplayString()));
243
				}
244
				else
245
				{
246
					_locationPathField
247
							.setText(TextProcessor.process(_userPath));
248
				}
249
				setUserAreaEnabled(!useDefaults);
250
			}
251
		});
252
		
253
		return button;
254
	}
255
256
	private void createCheckboxes(Composite parent) {
257
		GridData data = null;
258
	
259
		_overwriteButton = makeButton(parent, Messages.HOOKUP_WIZARD_TXT3, SWT.CHECK);		
260
		
261
		data = new GridData();
262
		data.horizontalSpan = 2;
263
		_overwriteButton.setLayoutData(data);
264
		
265
		_persistExtraArtifactsButton = makeButton(parent, Messages.HOOKUP_WIZARD_PERSIST, SWT.CHECK);
266
		
267
		data = new GridData();
268
		data.horizontalSpan = 2;
269
		_persistExtraArtifactsButton.setLayoutData(data);
270
	}
271
272
	private Combo makeContainerCombo(Group page) {
273
		Combo combo = new Combo(page, SWT.BORDER | SWT.READ_ONLY);
274
		combo.setEnabled(false);	
275
		
276
		return combo;
277
	}
278
279
	private Combo makePlatformCombo(Group page)
280
	{
281
		Combo combo = new Combo(page, SWT.BORDER | SWT.READ_ONLY);
282
		for(Iterator i=_platformContainerMap.keySet().iterator(); i.hasNext();) {
283
			combo.add(i.next().toString());
284
		}
285
		combo.select(0);		
286
		combo.addListener(SWT.Modify, comboChangeListener);
287
		
288
		return combo;
289
	}
290
291
	private void setUserAreaEnabled(boolean enabled)
292
	{
293
		_locationLabel.setEnabled(enabled);
294
		_locationPathField.setEnabled(enabled);
295
		_browseButton.setEnabled(enabled);
296
	}
297
298
	private void createUserEntryArea(Composite composite, boolean defaultEnabled)
299
	{
300
		GridData data = null;
301
		
302
		// location label
303
		_locationLabel = new Label(composite, SWT.NONE);
304
		_locationLabel.setText(Messages.HOOKUP_WIZARD_TXT6);
305
306
		// project location entry field
307
		_locationPathField = new Text(composite, SWT.BORDER);
308
		data = new GridData(GridData.FILL_HORIZONTAL);
309
		_locationPathField.setLayoutData(data);
310
311
		// browse button
312
		_browseButton = new Button(composite, SWT.PUSH);
313
		_browseButton.setText(Messages.HOOKUP_WIZARD_TXT5);
314
		_browseButton.addSelectionListener(new SelectionAdapter()
315
		{
316
			public void widgetSelected(SelectionEvent event)
317
			{
318
				handleLocationBrowseButtonPressed();
319
			}
320
		});
321
322
		if (defaultEnabled)
323
		{
324
			_locationPathField.setText(TextProcessor
325
					.process(getDefaultPathDisplayString()));
326
		}
327
		else
328
		{
329
			if (_existingProject == null)
330
			{
331
				_locationPathField.setText(Util.ZERO_LENGTH_STRING);// IDEResourceInfoUtils.EMPTY_STRING);
332
			}
333
			else
334
			{
335
				_locationPathField.setText(TextProcessor
336
						.process(_existingProject.getLocation().toString()));
337
			}
338
		}
339
340
		_locationPathField.addModifyListener(new ModifyListener()
341
		{
342
			public void modifyText(ModifyEvent e)
343
			{
344
				setErrorMessage(checkValidLocation());
345
			}
346
		});
347
		
348
		setUserAreaEnabled(false);
349
	}
350
351
	public boolean isDefault()
352
	{
353
		return _useDefaultsButton.getSelection();
354
	}
355
356
	public String getProjectLocation()
357
	{
358
		if(isDefault()) {
359
			return null;
360
		}
361
		
362
		String projectLocation = _locationPathField.getText();		
363
		return projectLocation.length() == 0?null:projectLocation;
364
	}
365
366
	public String checkValidLocation()
367
	{
368
369
		if (isDefault())
370
		{
371
			return null;
372
		}
373
374
		String newPath = getProjectLocation();
375
		if (newPath == null)
376
		{
377
			return Messages.CODE_GEN_LOCATION_ERROR_;
378
		}
379
380
		if (_existingProject == null)
381
		{
382
			IPath projectPath = new Path(newPath);
383
			if (Platform.getLocation().isPrefixOf(projectPath))
384
			{
385
				return Messages.NEW_PROJECT_CREATION_PAGE_DEFAULT_LOCATION_ERROR_;
386
			}
387
388
		}
389
		else
390
		{
391
			
392
			IStatus locationStatus = _existingProject.getWorkspace()
393
					.validateProjectLocationURI(_existingProject, URIUtil.toURI(newPath));
394
395
			if (!locationStatus.isOK())
396
			{
397
				return locationStatus.getMessage();
398
			}
399
400
			java.net.URI projectPath = _existingProject.getLocationURI();
401
			if (projectPath != null && URIUtil.equals(projectPath, URIUtil.toURI(newPath)))
402
			{
403
				return Messages.CODE_GEN_LOCATION_ERROR_;
404
			}
405
		}
406
407
		return null;
408
	}
409
410
	private String getDefaultPathDisplayString()
411
	{
412
413
		java.net.URI defaultURI = null;
414
		if (_existingProject != null)
415
		{
416
			defaultURI = _existingProject.getLocationURI();
417
		}
418
419
		// Handle files specially. Assume a file if there is no project to query
420
		if (defaultURI == null || defaultURI.getScheme().equals("file"))
421
		{
422
			return Platform.getLocation().append(_projectNameField.getText())
423
					.toString();
424
		}
425
		return defaultURI.toString();
426
427
	}
428
429
	private String getPathFromLocationField()
430
	{
431
		java.net.URI fieldURI;
432
		try
433
		{
434
			fieldURI = new java.net.URI(_locationPathField.getText());
435
		}
436
		catch (java.net.URISyntaxException e)
437
		{
438
			return _locationPathField.getText();
439
		}
440
		return fieldURI.getPath();
441
	}
442
443
	private void updateLocationField(String selectedPath)
444
	{
445
		_locationPathField.setText(TextProcessor.process(selectedPath));
446
	}
447
448
	private void handleLocationBrowseButtonPressed()
449
	{
450
451
		String selectedDirectory = null;
452
		String dirName = getPathFromLocationField();
453
454
		DirectoryDialog dialog = new DirectoryDialog(_locationPathField
455
				.getShell());
456
		dialog.setMessage(Messages.CODE_GEN_DIR_LOCATION);// IDEWorkbenchMessages.ProjectLocationSelectionDialog_directoryLabel);
457
		dialog.setFilterPath(dirName);
458
		selectedDirectory = dialog.open();
459
460
		if (selectedDirectory != null)
461
			updateLocationField(selectedDirectory);
462
	}
463
464
	private Listener nameModifyListener = new Listener()
465
	{
466
		public void handleEvent(Event e)
467
		{
468
			setLocationForSelection();
469
			dialogChanged();
470
		}
471
	};
472
473
	private Listener comboChangeListener = new Listener() {
474
		public void handleEvent(Event e) {
475
			String platform = _projectizerCombo.getText();
476
			
477
			Map containerCodeGenDataMap = (Map) _platformContainerMap.get(platform);
478
			_containerCombo.removeAll();
479
			
480
			boolean hasContainers = containerCodeGenDataMap.size() != 0;
481
			
482
			if(hasContainers) {
483
				for(Iterator i=containerCodeGenDataMap.keySet().iterator(); i.hasNext();) {
484
					_containerCombo.add(i.next().toString());
485
				}
486
				_containerCombo.select(0);
487
			}
488
			
489
			_containerCombo.setEnabled(hasContainers);
490
			_containerLabel.setEnabled(hasContainers);
491
492
		   	dialogChanged();
493
		}
494
	};
495
	
496
	void setLocationForSelection()
497
	{
498
//		 _locationArea.updateProjectName(getProjectNameFieldValue());
499
	}
500
501
	protected void dialogChanged()
502
	{
503
		if(true) return;
504
		String prjName = getProjectName();
505
506
		if (prjName.length() == 0)
507
		{
508
			updateStatus(Messages.HOOKUP_WIZARD_ERROR_1);
509
			return;
510
		}
511
512
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
513
		IWorkspaceRoot root = workspace.getRoot();
514
515
		IProject project = root.getProject(prjName);
516
517
		if (project != null && project.exists())
518
		{
519
			updateStatus(Messages.PROJECT_EXISTS_WARN_, DialogPage.WARNING);
520
			return;
521
		}
522
523
		if (!Validation.isQName(prjName))
524
		{
525
			updateStatus(Messages.HOOKUP_WIZARD_ERROR_2);
526
			return;
527
		}
528
		
529
		canFlipToNextPage();
530
		
531
		updateStatus(null, DialogPage.NONE);
532
	}
533
534
	private void updateStatus(String message)
535
	{
536
		updateStatus(message, DialogPage.ERROR);
537
	}
538
539
	private void updateStatus(String message, int type)
540
	{
541
		setMessage(message, type);
542
		setPageComplete(type != DialogPage.ERROR);
543
	}
544
545
	private Button makeButton(Composite parent, String title, int style)
546
	{
547
		Button b = new Button(parent, style);
548
		b.setText(title);
549
		return b;
550
	}
551
552
	public boolean shouldPersistArtifacts()
553
	{
554
		return _persistExtraArtifactsButton.isEnabled();
555
	}
556
557
	/**
558
	 * Return the value of the output project
559
	 * @return String
560
	 */
561
	public String getProjectName()
562
	{
563
		return _projectNameField.getText();
564
	}
565
566
	/**
567
	 * Returns if Overwrite button is enabled
568
	 * @return boolean
569
	 */
570
	public boolean canOverwrite()
571
	{
572
		return _overwriteButton.getSelection();
573
	}
574
	
575
	public CodeGenerationData getSelectedData() {
576
		String platform = _projectizerCombo.getText();
577
		Map containerCodeGenDataMap = (Map) _platformContainerMap.get(platform);
578
		String container = _containerCombo.getText();
579
		return (CodeGenerationData) containerCodeGenDataMap.get(container);
580
	}
581
582
	/**
583
	 * Return the projectizer
584
	 * @return {@link Projectizer}
585
	 */
586
	public Projectizer getProjectizer()
587
	{
588
		return getSelectedData().getProjectizer();
589
	}
590
591
	/**
592
	 * Return the synthesizer
593
	 * @return {@link Synthesizer}
594
	 */
595
	public Synthesizer getSynthesizer()
596
	{
597
		return getSelectedData().getSynthesizer();
598
	}
599
600
	/**
601
	 * Return the analyzer
602
	 * @return {@link Analyzer}
603
	 */
604
	public Analyzer getAnalyzer()
605
	{
606
		return getSelectedData().getAnalyzer();
607
	}
608
609
	/**
610
	 * Returns the base address
611
	 * 
612
	 * @return String
613
	 */
614
	public String getBaseAddress()
615
	{
616
		String baseAddress = "http://localhost";
617
618
		int port = getSelectedData().getServicePort();
619
		if (port != 0)
620
		{
621
			baseAddress += ":" + port;
622
		}
623
624
		baseAddress += "/" + getProjectName();
625
626
		String servicePath = getSelectedData().getServicePath();
627
628
		if (servicePath != null)
629
		{
630
			baseAddress += servicePath;
631
		}
632
		
633
		return baseAddress;
634
	}
635
	
636
	/**
637
	 * Checks to see if the Next Page can be enabled or not.
638
	 */
639
	public boolean canFlipToNextPage(){
640
		return true;
641
//		Axis2ServerLocationPage nextPage = (Axis2ServerLocationPage)this.getNextPage();
642
//		if(isPageComplete() && isAxis2Project())
643
//		{			
644
//			nextPage.makePageComplete(false);
645
//			String userLocation = nextPage.getUserDefinedLocation();
646
//			if(userLocation != null && userLocation.trim().length() > 0)
647
//			{
648
//				nextPage._serverNameField.setText(userLocation);
649
//			}else
650
//			{
651
//				nextPage._serverNameField.setText(nextPage.getPreferenceServerLocation());
652
//			}
653
//
654
//			return true;
655
//		}
656
//		
657
//		nextPage.makePageComplete(true);
658
//		
659
//		return false;
660
	}
661
662
	/**
663
	 * Returns whether the new Project to be created is a Axis2 project
664
	 * @return
665
	 */
666
	public boolean isAxis2Project(){
667
		String container = getSelectedData().getContainer();
668
		return container != null && container.equals("Axis2");
669
	}	
670
	
671
	public void saveCombo() {
672
		MemoryComboBox.save(_projectNameField, PROJECT_MEMORY_COMBO_ID, Preferences.userNodeForPackage(GenerationOptionsPage.class));
673
	}
674
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/SingleValueMap.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.util.AbstractMap;
16
import java.util.HashSet;
17
import java.util.Set;
18
19
public class SingleValueMap extends AbstractMap {
20
	Object _value;
21
	Set _entrySet = new HashSet();
22
			
23
	public Object get(Object key) {
24
		return _value;
25
	}
26
	
27
	public Object put(Object key, Object value) {
28
		Object oldValue = _value;
29
		_value = value;		
30
		return oldValue;
31
	}
32
	
33
	public Set entrySet() {
34
		return _entrySet;
35
	}
36
}
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 24-30 Link Here
24
Bundle-Vendor: %providerName
24
Bundle-Vendor: %providerName
25
Bundle-RequiredExecutionEnvironment: J2SE-1.4
25
Bundle-RequiredExecutionEnvironment: J2SE-1.4
26
Export-Package: org.eclipse.tptp.wsdm.tooling.codegen.dd.internal;x-friends:="org.eclipse.tptp.wsdm.editor.test",
26
Export-Package: org.eclipse.tptp.wsdm.tooling.codegen.dd.internal;x-friends:="org.eclipse.tptp.wsdm.editor.test",
27
 org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional,
27
 org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;x-internal:=true,
28
 org.eclipse.tptp.wsdm.tooling.dialog.provisional;x-friends:="org.eclipse.tptp.wsdm.editor.test",
28
 org.eclipse.tptp.wsdm.tooling.dialog.provisional;x-friends:="org.eclipse.tptp.wsdm.editor.test",
29
 org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal;x-friends:="org.eclipse.tptp.wsdm.editor.test",
29
 org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal;x-friends:="org.eclipse.tptp.wsdm.editor.test",
30
 org.eclipse.tptp.wsdm.tooling.editor.capability.command.overview.internal;x-friends:="org.eclipse.tptp.wsdm.editor.test",
30
 org.eclipse.tptp.wsdm.tooling.editor.capability.command.overview.internal;x-friends:="org.eclipse.tptp.wsdm.editor.test",
(-)plugin.xml (-2 / +2 lines)
Lines 72-78 Link Here
72
         name="Axis2 Validator"
72
         name="Axis2 Validator"
73
         point="org.eclipse.tptp.wsdm.editor.axisValidator">
73
         point="org.eclipse.tptp.wsdm.editor.axisValidator">
74
      <axisValidator
74
      <axisValidator
75
            validator="org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.Axis2ServerDependency">
75
            validator="org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.Axis2ServerDependency">
76
         <requiredFiles>
76
         <requiredFiles>
77
               <relativeFilePath>lib/annogen-*.jar</relativeFilePath>
77
               <relativeFilePath>lib/annogen-*.jar</relativeFilePath>
78
               <relativeFilePath>lib/axiom-api-*.jar</relativeFilePath>
78
               <relativeFilePath>lib/axiom-api-*.jar</relativeFilePath>
Lines 192-198 Link Here
192
              enablesFor="1"
192
              enablesFor="1"
193
              label="%Generate_Java_Code_Action"
193
              label="%Generate_Java_Code_Action"
194
              icon="icons/obj16/mrt_obj.gif"
194
              icon="icons/obj16/mrt_obj.gif"
195
              class="org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.Generation"
195
              class="org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.Generation"
196
              id="org.eclipse.tptp.wsdm.tooling.codegen.mrt.action"/>
196
              id="org.eclipse.tptp.wsdm.tooling.codegen.mrt.action"/>
197
     </objectContribution>
197
     </objectContribution>
198
     
198
     
(-)src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/messages.properties (-1 / +1 lines)
Lines 32-38 Link Here
32
SYSTEM_CAPS_ERROR_2 = IWAT0646E Access Denied
32
SYSTEM_CAPS_ERROR_2 = IWAT0646E Access Denied
33
HOOKUP_WIZARD_TXT1 = Deployment target and generation options
33
HOOKUP_WIZARD_TXT1 = Deployment target and generation options
34
HOOKUP_WIZARD_TXT2 = This wizard creates code for touchpoint
34
HOOKUP_WIZARD_TXT2 = This wizard creates code for touchpoint
35
HOOKUP_WIZARD_TXT3 = Overwrite files if necessary
35
HOOKUP_WIZARD_TXT3 = Overwrite files
36
HOOKUP_WIZARD_PERSIST = Persist generated artifacts
36
HOOKUP_WIZARD_PERSIST = Persist generated artifacts
37
HOOKUP_WIZARD_TXT4 = Output project
37
HOOKUP_WIZARD_TXT4 = Output project
38
HOOKUP_WIZARD_TXT5 = Browse...
38
HOOKUP_WIZARD_TXT5 = Browse...
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/Generation.java (-1 / +1 lines)
Lines 18-24 Link Here
18
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.NewProjectWizard;
21
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.NewProjectWizard;
22
import org.eclipse.ui.IObjectActionDelegate;
22
import org.eclipse.ui.IObjectActionDelegate;
23
import org.eclipse.ui.IWorkbenchPart;
23
import org.eclipse.ui.IWorkbenchPart;
24
24
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/DDCodeGenerationDelegate.java (-3 / +3 lines)
Lines 31-39 Link Here
31
import org.eclipse.emf.ecore.resource.Resource;
31
import org.eclipse.emf.ecore.resource.Resource;
32
import org.eclipse.emf.ecore.resource.ResourceSet;
32
import org.eclipse.emf.ecore.resource.ResourceSet;
33
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
33
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
34
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.CodeGenerationDelegate;
34
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.CodeGenerationDelegate;
35
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.DescriptorHelper;
35
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.DescriptorHelper;
36
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.MrtPreProcessor;
36
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.MrtPreProcessor;
37
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
37
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
38
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
38
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
(-)src/org/eclipse/tptp/wsdm/tooling/validation/util/internal/ValidationUtils.java (-1 / +1 lines)
Lines 20-26 Link Here
20
import org.eclipse.core.runtime.IExtensionPoint;
20
import org.eclipse.core.runtime.IExtensionPoint;
21
import org.eclipse.core.runtime.IExtensionRegistry;
21
import org.eclipse.core.runtime.IExtensionRegistry;
22
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.ISoapServerDependency;
23
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.ISoapServerDependency;
24
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
24
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
25
import org.eclipse.tptp.wsdm.tooling.nls.messages.validation.internal.Messages;
25
import org.eclipse.tptp.wsdm.tooling.nls.messages.validation.internal.Messages;
26
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
26
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
(-)src/org/eclipse/tptp/wsdm/tooling/preferences/internal/Axis2ServerLocationPreferencePage.java (-1 / +1 lines)
Lines 27-33 Link Here
27
import org.eclipse.swt.widgets.DirectoryDialog;
27
import org.eclipse.swt.widgets.DirectoryDialog;
28
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Text;
29
import org.eclipse.swt.widgets.Text;
30
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.Axis2LicenseDialog;
30
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.Axis2LicenseDialog;
31
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
31
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
32
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
32
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
33
import org.eclipse.ui.IWorkbench;
33
import org.eclipse.ui.IWorkbench;
(-)src/org/eclipse/tptp/wsdm/tooling/editor/dde/util/internal/DdeUtil.java (-1 / +1 lines)
Lines 68-74 Link Here
68
import org.eclipse.swt.widgets.Table;
68
import org.eclipse.swt.widgets.Table;
69
import org.eclipse.swt.widgets.TableItem;
69
import org.eclipse.swt.widgets.TableItem;
70
import org.eclipse.swt.widgets.Text;
70
import org.eclipse.swt.widgets.Text;
71
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.Generation;
71
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.Generation;
72
import org.eclipse.tptp.wsdm.tooling.editor.dde.internal.DescriptorEditor;
72
import org.eclipse.tptp.wsdm.tooling.editor.dde.internal.DescriptorEditor;
73
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
73
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
74
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
74
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/operation/internal/ImportWSDLOperationCommand.java (-1 / +1 lines)
Lines 32-38 Link Here
32
import org.eclipse.core.runtime.IProgressMonitor;
32
import org.eclipse.core.runtime.IProgressMonitor;
33
import org.eclipse.core.runtime.NullProgressMonitor;
33
import org.eclipse.core.runtime.NullProgressMonitor;
34
import org.eclipse.emf.common.util.URI;
34
import org.eclipse.emf.common.util.URI;
35
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.EclipseEnvironment;
35
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseEnvironment;
36
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
36
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
37
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
37
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
38
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
38
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
(-)schema/axisValidator.exsd (-6 / +6 lines)
Lines 6-12 Link Here
6
         <meta.schema plugin="org.eclipse.tptp.wsdm.editor" id="axisValidator" name="axisValidator"/>
6
         <meta.schema plugin="org.eclipse.tptp.wsdm.editor" id="axisValidator" name="axisValidator"/>
7
      </appInfo>
7
      </appInfo>
8
      <documentation>
8
      <documentation>
9
         This extension point will be used for validation of Axis2 required files(Jar files and Module files).
9
         This extension point will be used for validation of Axis2 required files(Jar files and Module files). This extension point is meant for internal use only and tool extenders are not expected to use this extension point in 4.4.
10
      </documentation>
10
      </documentation>
11
   </annotation>
11
   </annotation>
12
12
Lines 55-64 Link Here
55
         <attribute name="validator" type="string" use="required">
55
         <attribute name="validator" type="string" use="required">
56
            <annotation>
56
            <annotation>
57
               <documentation>
57
               <documentation>
58
                  Specify the class that validates the Axis Server Location. Specified class should extend &quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.SoapServerDependency&quot; class and should implement the interface &quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.ISoapServerDependency&quot;.
58
                  Specify the class that validates the Axis Server Location. Specified class should extend &quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.SoapServerDependency&quot; class and should implement the interface &quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.ISoapServerDependency&quot;.
59
               </documentation>
59
               </documentation>
60
               <appInfo>
60
               <appInfo>
61
                  <meta.attribute kind="java" basedOn="org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.SoapServerDependency:org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.ISoapServerDependency"/>
61
                  <meta.attribute kind="java" basedOn="org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.SoapServerDependency:org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.ISoapServerDependency"/>
62
               </appInfo>
62
               </appInfo>
63
            </annotation>
63
            </annotation>
64
         </attribute>
64
         </attribute>
Lines 105-111 Link Here
105
         name=&quot;Axis2 Validator&quot;
105
         name=&quot;Axis2 Validator&quot;
106
         point=&quot;org.eclipse.tptp.wsdm.editor.axisValidator&quot;&gt;
106
         point=&quot;org.eclipse.tptp.wsdm.editor.axisValidator&quot;&gt;
107
      &lt;axisValidator
107
      &lt;axisValidator
108
            validator=&quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.Axis2ServerDependency&quot;&gt;
108
            validator=&quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.Axis2ServerDependency&quot;&gt;
109
         &lt;requiredFiles&gt;
109
         &lt;requiredFiles&gt;
110
               &lt;relativeFilePath&gt;lib/annogen-*.jar&lt;/relativeFilePath&gt;
110
               &lt;relativeFilePath&gt;lib/annogen-*.jar&lt;/relativeFilePath&gt;
111
               &lt;relativeFilePath&gt;lib/axiom-api-*.jar&lt;/relativeFilePath&gt;
111
               &lt;relativeFilePath&gt;lib/axiom-api-*.jar&lt;/relativeFilePath&gt;
Lines 123-129 Link Here
123
         <meta.section type="apiInfo"/>
123
         <meta.section type="apiInfo"/>
124
      </appInfo>
124
      </appInfo>
125
      <documentation>
125
      <documentation>
126
         Provided validator class must implement the &quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.ISoapServerDependency&quot; interface.
126
         Provided validator class must implement the &quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.ISoapServerDependency&quot; interface. This extension point is meant for internal use only and tool extenders are not expected to use this extension point in 4.4.
127
      </documentation>
127
      </documentation>
128
   </annotation>
128
   </annotation>
129
129
Lines 132-138 Link Here
132
         <meta.section type="implementation"/>
132
         <meta.section type="implementation"/>
133
      </appInfo>
133
      </appInfo>
134
      <documentation>
134
      <documentation>
135
         Provided validator class can extend the &quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.SoapServerDependency&quot; class to get the required files specified in extension point.
135
         Provided validator class can extend the &quot;org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.SoapServerDependency&quot; class to get the required files specified in extension point. This extension point is meant for internal use only and tool extenders are not expected to use this extension point in 4.4.
136
      </documentation>
136
      </documentation>
137
   </annotation>
137
   </annotation>
138
138
(-)src/org/eclipse/tptp/wsdm/tooling/editor/mrt/internal/GenerateDDTemplateAction.java (-2 / +2 lines)
Lines 25-32 Link Here
25
import org.eclipse.jface.action.IAction;
25
import org.eclipse.jface.action.IAction;
26
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.StructuredSelection;
27
import org.eclipse.jface.viewers.StructuredSelection;
28
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.BasicMrtInspector;
28
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.BasicMrtInspector;
29
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.MrtInspector;
29
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.MrtInspector;
30
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
30
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
31
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.INewNameGenerator;
31
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.INewNameGenerator;
32
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.NewIFileNameGenerator;
32
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.NewIFileNameGenerator;
(-)src/org/eclipse/tptp/wsdm/tooling/editor/mrt/internal/MrtPrototypeForm.java (-2 / +2 lines)
Lines 53-60 Link Here
53
import org.eclipse.swt.widgets.Listener;
53
import org.eclipse.swt.widgets.Listener;
54
import org.eclipse.swt.widgets.Shell;
54
import org.eclipse.swt.widgets.Shell;
55
import org.eclipse.swt.widgets.Text;
55
import org.eclipse.swt.widgets.Text;
56
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.MRTCodeGenerationDelegate;
56
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.MRTCodeGenerationDelegate;
57
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.NewProjectWizard;
57
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.NewProjectWizard;
58
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
58
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
59
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityStorage;
59
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityStorage;
60
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityStorageEditorInput;
60
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityStorageEditorInput;
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/WsdlUtils.java (-1 / +1 lines)
Lines 39-45 Link Here
39
import org.eclipse.core.resources.IFile;
39
import org.eclipse.core.resources.IFile;
40
import org.eclipse.core.runtime.CoreException;
40
import org.eclipse.core.runtime.CoreException;
41
import org.eclipse.emf.common.util.URI;
41
import org.eclipse.emf.common.util.URI;
42
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.EclipseEnvironment;
42
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseEnvironment;
43
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
43
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
44
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
44
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
45
import org.eclipse.xsd.XSDComplexTypeDefinition;
45
import org.eclipse.xsd.XSDComplexTypeDefinition;
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/IFile2Capability.java (-1 / +1 lines)
Lines 18-24 Link Here
18
18
19
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.emf.common.util.URI;
20
import org.eclipse.emf.common.util.URI;
21
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.EclipseEnvironment;
21
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseEnvironment;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
23
import org.w3c.dom.Document;
23
import org.w3c.dom.Document;
24
import org.w3c.dom.Element;
24
import org.w3c.dom.Element;
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/MrtMerge.java (+253 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.ByteArrayOutputStream;
16
import java.lang.reflect.InvocationTargetException;
17
import java.util.ArrayList;
18
import java.util.Collection;
19
import java.util.Iterator;
20
import java.util.List;
21
22
import javax.wsdl.WSDLException;
23
import javax.wsdl.factory.WSDLFactory;
24
import javax.wsdl.xml.WSDLReader;
25
import javax.wsdl.xml.WSDLWriter;
26
import javax.xml.namespace.QName;
27
28
import org.apache.muse.tools.generator.WsdlMerge;
29
import org.apache.muse.util.xml.XmlUtils;
30
import org.apache.muse.ws.addressing.soap.SoapFault;
31
import org.apache.muse.ws.notification.WsnConstants;
32
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
33
import org.apache.muse.ws.resource.metadata.WsrmdConstants;
34
import org.apache.muse.ws.resource.metadata.impl.SimpleMetadataDescriptor;
35
import org.apache.muse.ws.wsdl.WsdlUtils;
36
import org.eclipse.emf.common.util.URI;
37
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
38
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
39
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
40
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
41
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
43
import org.w3c.dom.Document;
44
import org.w3c.dom.Element;
45
46
/**
47
 * This class provides the utility method for merging the MRT to get the smashed WSDL and RMD documents.
48
 *
49
 */
50
51
public class MrtMerge 
52
{
53
	private static WSDLReader _reader;
54
	private static WSDLWriter _writer;
55
	private static WSDLFactory _factory;
56
	
57
	/**
58
	 * Creates the smashed WSDL file for representing the resource type
59
	 * 
60
	 * @param mrtFile -
61
	 *            Manageable Resource Type file
62
	 * @throws Exception -
63
	 *             Throws exception while getting WSDL files and also while
64
	 *             merging them
65
	 */
66
	public static Document createMergedWSDL(ManageableResourceType mrt, String address)
67
			throws Exception
68
	{
69
		checkReadersWriters();
70
71
		List wsdlFiles = null;
72
73
		try
74
		{
75
			wsdlFiles = getWsdlFiles(mrt);
76
		}
77
		catch (Exception e)
78
		{
79
			throw new Exception(Messages.HOOKUP_WIZARD_ERROR_7, e);
80
		}
81
82
		String namespaceURI = mrt.getNamespace();
83
84
		Document[] wsdlFragments = (Document[])wsdlFiles.toArray(new Document[wsdlFiles.size()]);
85
		javax.wsdl.Definition def = WsdlMerge.merge(namespaceURI, wsdlFragments,
86
 				address);
87
88
		return _writer.getDocument(def);
89
	}
90
91
	private static void checkReadersWriters() throws InvocationTargetException
92
	{
93
		try
94
		{
95
			_factory = WSDLFactory.newInstance();
96
			_reader = _factory.newWSDLReader();
97
			_writer = _factory.newWSDLWriter();
98
		}
99
		catch (WSDLException e)
100
		{
101
			throw new InvocationTargetException(new Exception(
102
					Messages.HOOKUP_WIZARD_ERROR_3, e));
103
		}
104
	}
105
106
	/**
107
	 * Given an MRT file return a list of <code>Definition</code> objects that
108
	 * correspond to the WSDL files related to this MRT (that is, its
109
	 * Capabilities).
110
	 * 
111
	 * @param mrtFile
112
	 * @return
113
	 * @throws Exception
114
	 */
115
	private static List getWsdlFiles(ManageableResourceType mrt)
116
			throws Exception
117
	{
118
		//Get a list of all of the capabilities in this MRT 
119
		//This should just be a list of URIs
120
		List capabilityList = mrt.getImplements();		
121
		
122
		//Here is our list of clean WSDL documents
123
		//we are returning
124
		ArrayList wsdls = new ArrayList();	
125
126
		//Use an EclipseEnvironment to do the resolution of paths
127
		EclipseEnvironment eclipseEnv = new EclipseEnvironment();
128
		
129
		//Iterate over each capability and load it into a Definition
130
		for (Iterator i = capabilityList.iterator(); i.hasNext();) {
131
			String nextPath = i.next().toString();
132
			
133
			Document document = WsdlUtils.createWSDL(eclipseEnv, nextPath, true);
134
			
135
			//clean up imports
136
			//see the actual functions to understand how 
137
			//the removal is done
138
			Element cleanDocument = WsdlUtils.removeSchemaReferences(document.getDocumentElement());
139
			cleanDocument = WsdlUtils.removeWsdlReferences(cleanDocument);
140
			
141
			wsdls.add(cleanDocument.getOwnerDocument());
142
		}
143
		
144
		return wsdls;
145
	}
146
	
147
	/**
148
	 * Creates the merged RMD file for representing the manageable resource type
149
	 * 
150
	 * @param mrtFile -
151
	 *            Manageable Resource Type file
152
	 * @throws Exception -
153
	 *             Throws exception while getting capabilities defined in MRT and also while
154
	 *             merging their RMDs
155
	 */
156
	public static MetadataDescriptor createMergedRMD(ManageableResourceType mrt) throws Exception
157
	{
158
			List rmds = new ArrayList();
159
			Capability[] capabilities = MrtUtils.getCapabilities(mrt);
160
			List allTopicExpressions = new ArrayList();
161
			for(int i=0;i<capabilities.length;i++)
162
			{
163
				CapabilityDefinition capabilityDef = (CapabilityDefinition)capabilities[i].getWsdlDefinition();
164
				URI capabilityFileLocationURI = capabilityDef.getWSDLResourceProtocolURI();
165
				String metadataDescriptorLocation = capabilityDef.getMetadataDescriptorLocation();
166
				if(metadataDescriptorLocation == null || metadataDescriptorLocation.length() == 0)
167
					continue;
168
				URI rmdFileLocationURI = URI.createURI(capabilityFileLocationURI.trimSegments(1).toString()+ "/" + metadataDescriptorLocation);
169
				org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot root = MetaDataUtils.getDocumentRoot(rmdFileLocationURI);
170
				ByteArrayOutputStream baos = MetaDataUtils.saveRMD(root, rmdFileLocationURI.toString(), null);
171
				String rmdXML = new String(baos.toByteArray());
172
				Element definitionElement = (Element) XmlUtils.createDocument(rmdXML).getFirstChild();
173
				Element metadataDescriptorElement = XmlUtils.getFirstElement(definitionElement);			
174
				MetadataDescriptor rmdDescriptor = new SimpleMetadataDescriptor(metadataDescriptorElement);				
175
				
176
				// Get all the topic expressions defined in different capabilities
177
				String[] topicExpressions = getTopicExpressions(rmdDescriptor);
178
				for(int j=0;j<topicExpressions.length;j++)
179
				{
180
					String prefix = topicExpressions[j].substring(0,topicExpressions[j].indexOf(':'));
181
					String namespace = (String)root.getXMLNSPrefixMap().get(prefix);
182
					String topicPath = topicExpressions[j].substring(topicExpressions[j].indexOf(':')+1);
183
					allTopicExpressions.add(new TopicExpression(namespace, topicPath));
184
				}				
185
				rmdDescriptor.removeProperty(WsnConstants.TOPIC_EXPRESSION_QNAME);
186
				
187
				rmds.add(rmdDescriptor);		
188
			}
189
			MetadataDescriptor[] descriptors = (MetadataDescriptor[]) rmds.toArray(new MetadataDescriptor[rmds.size()]);
190
			QName qname = new QName(mrt.getNamespace(), "PortType");
191
			// TODO Verify with Andrew that is it the way that MUSE creates the smashed wsdl by this name
192
			String name = mrt.getIdentifier()+".wsdl";
193
			MetadataDescriptor mergedRMD = WsdlMerge.merge(name, qname, descriptors);
194
			TopicExpression[] topicExpressions = (TopicExpression[]) allTopicExpressions.toArray(new TopicExpression[allTopicExpressions.size()]);
195
			// Merge all the topic expressions defined in different capabilities
196
			mergeTopicExpressions(mergedRMD, topicExpressions);
197
			return mergedRMD;		
198
	}
199
	
200
	private static String[] getTopicExpressions(MetadataDescriptor rmdDescriptor) throws SoapFault
201
	{
202
		if(rmdDescriptor.hasProperty(WsnConstants.TOPIC_EXPRESSION_QNAME))
203
		{
204
			Collection collection = rmdDescriptor.getInitialValues(WsnConstants.TOPIC_EXPRESSION_QNAME, String.class);
205
			return (String[])collection.toArray(new String[collection.size()]);
206
		}
207
		return new String[0];
208
	}
209
	
210
	private static void mergeTopicExpressions(MetadataDescriptor rmdDescriptor, TopicExpression[] topicExpressions) throws SoapFault
211
	{
212
		if(topicExpressions!=null && topicExpressions.length>0)
213
		{
214
			rmdDescriptor.addProperty(WsnConstants.TOPIC_EXPRESSION_QNAME, WsrmdConstants.READ_ONLY, WsrmdConstants.MUTABLE);
215
			List initValues = new ArrayList();
216
			Document doc = XmlUtils.createDocument();
217
			for(int i=0;i<topicExpressions.length;i++)
218
			{
219
				String namespace = topicExpressions[i].getTopicNamespace();
220
				String topicPath = topicExpressions[i].getTopicPath();
221
				String expression = "pfx:"+topicPath;
222
				Element propertyElement = XmlUtils.createElement(doc, WsnConstants.TOPIC_EXPRESSION_QNAME);
223
				propertyElement.setAttribute("xmlns:pfx", namespace);
224
				XmlUtils.setElementText(propertyElement, expression);
225
				initValues.add(propertyElement);
226
			}
227
			rmdDescriptor.setInitialValues(WsnConstants.TOPIC_EXPRESSION_QNAME, initValues);			
228
		}
229
	}
230
}
231
232
class TopicExpression
233
{
234
	private String _topicNamespace;
235
	private String _topicPath;
236
	
237
	TopicExpression(String topicNamespace, String topicPath)
238
	{
239
		_topicNamespace = topicNamespace;
240
		_topicPath = topicPath;
241
	}
242
	
243
	String getTopicNamespace()
244
	{
245
		return _topicNamespace;
246
	}
247
	
248
	String getTopicPath()
249
	{
250
		return _topicPath;
251
	}
252
}
253
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/Axis2LicenseDialog.java (+140 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.BufferedReader;
16
import java.io.InputStreamReader;
17
import java.net.URL;
18
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.browser.Browser;
21
import org.eclipse.swt.events.SelectionAdapter;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
29
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
30
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
31
import org.osgi.framework.Bundle;
32
33
/**
34
 * This class is used to display the Axis-2 License. 
35
 */
36
public class Axis2LicenseDialog 
37
{
38
	private Shell _shell;
39
	
40
	private Browser _text;
41
	
42
	private Button _btnAgree;
43
	
44
	private Button _btnDecline;
45
	
46
	public static int AGREE = 0;
47
	
48
	public static int DECLINE = 1;
49
	
50
	private int _retInt = DECLINE;
51
		
52
	/**
53
	 * Constructor of the class. It initialises the UI for
54
	 * displaying the license
55
	 */
56
	public Axis2LicenseDialog()
57
	{
58
		initUI();
59
	}
60
	
61
	private void initUI()
62
	{
63
		_shell = new Shell(Display.getCurrent(), SWT.CLOSE | SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.RESIZE);
64
		_shell.setLayout(new GridLayout(2, true));
65
		_shell.setText(Messages.AXIS2_LICENSE_LABEL);
66
		_shell.setSize(300, 300);
67
		
68
		_text = new Browser(_shell, SWT.BORDER | SWT.MULTI | SWT.WRAP);
69
		try 
70
		{
71
			_text.setText(readLicence());
72
		} 
73
		catch (Throwable e)
74
		{
75
			WsdmToolingLog.logError(e.getMessage(), e);
76
		}
77
		
78
		_btnAgree = new Button(_shell, SWT.PUSH);
79
		_btnAgree.setText(Messages.LICENSE_AGREE_TEXT);
80
		_btnAgree.addSelectionListener(new SelectionAdapter()
81
		{
82
			public void widgetSelected(SelectionEvent se)
83
			{
84
				_retInt = AGREE;
85
				_shell.dispose();
86
			}
87
		}
88
		);
89
		
90
		_btnDecline = new Button(_shell, SWT.PUSH);
91
		_btnDecline.setText(Messages.LICENSE_DECLINE_TEXT);
92
		_btnDecline.addSelectionListener(new SelectionAdapter()
93
		{
94
			public void widgetSelected(SelectionEvent se)
95
			{
96
				_retInt = DECLINE;
97
				_shell.dispose();
98
			}
99
		}
100
		);
101
		
102
		GridData gd = new GridData(GridData.FILL_BOTH);
103
		gd.horizontalSpan = 2;
104
		_text.setLayoutData(gd);
105
		
106
		gd = new GridData();
107
		gd.horizontalAlignment = SWT.RIGHT;
108
		_btnAgree.setLayoutData(gd);
109
		
110
		gd = new GridData();
111
		gd.horizontalAlignment = SWT.LEFT;
112
		_btnDecline.setLayoutData(gd);
113
	}
114
	
115
	/**
116
	 * Method  to show the Dialog that displays the Liscense
117
	 */
118
	public int showWindow()
119
	{
120
		_shell.open();
121
		while(!_shell.isDisposed())
122
		{
123
			if(!Display.getCurrent().readAndDispatch())
124
				Display.getCurrent().sleep();
125
		}
126
		return _retInt;
127
	}
128
	
129
	private String readLicence() throws Throwable
130
	{
131
		Bundle bundle = Activator.INSTANCE.getPlugin().getBundle();
132
		URL licenceURL = bundle.getEntry("licence/Licence.txt");
133
		BufferedReader in = new BufferedReader(new InputStreamReader(licenceURL.openStream()));
134
		StringBuffer buffer = new StringBuffer();
135
		String line = null;
136
		while ((line = in.readLine()) != null)
137
			buffer.append(line);
138
		return buffer.toString();
139
	}
140
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/SubscriptionManagerInspector.java (+334 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.ByteArrayInputStream;
16
import java.io.IOException;
17
import java.io.InputStream;
18
19
import javax.wsdl.Operation;
20
21
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
22
import org.apache.ws.muse.descriptor.CapabilityType;
23
import org.apache.ws.muse.descriptor.DescriptorFactory;
24
import org.apache.ws.muse.descriptor.DocumentRoot;
25
import org.apache.ws.muse.descriptor.InitParamType;
26
import org.apache.ws.muse.descriptor.InitialInstancesType;
27
import org.apache.ws.muse.descriptor.ReferenceParametersType;
28
import org.apache.ws.muse.descriptor.ResourceTypeType;
29
import org.apache.ws.muse.descriptor.WsdlType;
30
import org.eclipse.core.resources.IFile;
31
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.NullProgressMonitor;
33
import org.eclipse.emf.common.util.URI;
34
import org.eclipse.emf.ecore.resource.Resource;
35
import org.eclipse.emf.ecore.resource.ResourceSet;
36
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
37
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
38
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
39
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceTypeFactory;
40
import org.eclipse.tptp.wsdm.tooling.util.internal.CustomMrtResourceFactoryImpl;
41
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
44
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
45
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
46
47
/**
48
 * This class analyzes the given manageable resource type and provide an extra
49
 * resource type for muse descriptor (SubscriptionManager), if manageable
50
 * resource type contains the NotificationProducer capability.
51
 */
52
public class SubscriptionManagerInspector implements MrtInspector
53
{
54
55
	private String _mrtParentDirName;
56
57
	private DocumentRoot _root;
58
59
	private ResourceTypeType _subManagerResourceType;
60
	
61
	private ManageableResourceType _subManagerMRT;
62
	/**
63
	 * Constructor of the class
64
	 * @param root
65
	 */
66
	public SubscriptionManagerInspector(DocumentRoot root)
67
	{
68
		_root = root;
69
	}
70
71
	/**
72
	 * Analyzes the given manageable resource type for NotificationProducer
73
	 * capability, and if the capability available then returns the muse
74
	 * resource type for SubscriptionManager else returns the null.
75
	 */
76
	public ResourceTypeType inspect(Capability[] mrtCapabilities)
77
	{
78
		for (int i = 0; i < mrtCapabilities.length; i++)
79
		{
80
			if (isNotificationProducerCapability(mrtCapabilities[i]))
81
				return createSubscriptionManagerResourceType();
82
		}
83
		return null;
84
	}
85
86
	private ResourceTypeType createSubscriptionManagerResourceType()
87
	{
88
		createSubManagerMrt();
89
		_subManagerResourceType = createSubManagerMuseResourceType();
90
		return _subManagerResourceType;
91
	}
92
93
	private void createSubManagerMrt()
94
	{
95
		org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.DocumentRoot documentRoot = ManageableResourceTypeFactory.eINSTANCE.createDocumentRoot();
96
		_subManagerMRT = ManageableResourceTypeFactory.eINSTANCE
97
				.createManageableResourceType();
98
		documentRoot.setManageableResource(_subManagerMRT);
99
		_subManagerMRT.setIdentifier("SubscriptionManager");
100
		_subManagerMRT
101
				.setNamespace("http://docs.oasis-open.org/wsn/b-2/SubscriptionManager");
102
		_subManagerMRT
103
				.getImplements()
104
				.add(WsdmConstants.IDENTITY_CAPABILITY_LOCATION);
105
		_subManagerMRT
106
				.getImplements()
107
				.add(WsdmConstants.MANAGEABLITY_CAPABILITY_LOCATION);
108
		_subManagerMRT
109
				.getImplements()
110
				.add(WsdmConstants.MEX_CAPABILITY_LOCATION);
111
		_subManagerMRT
112
				.getImplements()
113
				.add(WsdmConstants.GET_CAPABILITY_LOCATION);
114
		_subManagerMRT
115
				.getImplements()
116
				.add(WsdmConstants.SET_CAPABILITY_LOCATION);
117
		_subManagerMRT
118
				.getImplements()
119
				.add(WsdmConstants.QUERY_CAPABILITY_LOCATION);
120
		_subManagerMRT
121
				.getImplements()
122
				.add(WsdmConstants.IMMIDIATE_RESOURCE_TERMINATION_CAPABILITY_LOCATION);
123
		_subManagerMRT
124
				.getImplements()
125
				.add(WsdmConstants.SCHEDULED_RESOURCE_TERMINATION_CAPABILITY_LOCATION);
126
		_subManagerMRT
127
				.getImplements()
128
				.add(WsdmConstants.SUBSCRIPTION_MANAGER_CAPABILITY_LOCATION);		
129
	}
130
131
	private ResourceTypeType createSubManagerMuseResourceType()
132
	{
133
		ResourceTypeType resourceType = DescriptorFactory.eINSTANCE
134
				.createResourceTypeType();
135
		resourceType.setContextPath("/SubscriptionManager");
136
		resourceType
137
				.setJavaIdFactoryClass(WsdmConstants.MUSE_RESOURCE_ID_FACTORY_CLASS);
138
		resourceType
139
				.setJavaResourceClass(WsdmConstants.MUSE_RESOURCE_CLASS);
140
141
		WsdlType wsdlType = DescriptorFactory.eINSTANCE.createWsdlType();
142
		wsdlType.setWsdlFile(_mrtParentDirName + "/"
143
				+ "SubscriptionManager.wsdl");
144
		_root.getXMLNSPrefixMap().put("wsn",
145
				"http://docs.oasis-open.org/wsn/b-2/SubscriptionManager");
146
		wsdlType.setWsdlPortType("wsn:PortType");
147
		resourceType.setWsdl(wsdlType);
148
149
		CapabilityType identity = DescriptorFactory.eINSTANCE
150
				.createCapabilityType();
151
		identity
152
				.setCapabilityUri("http://docs.oasis-open.org/wsdm/muws/capabilities/Identity");
153
		identity.setJavaCapabilityClass("");
154
155
		CapabilityType manageabilityCharacteristics = DescriptorFactory.eINSTANCE
156
				.createCapabilityType();
157
		manageabilityCharacteristics
158
				.setCapabilityUri("http://docs.oasis-open.org/wsdm/muws/capabilities/ManageabilityCharacteristics");
159
		manageabilityCharacteristics.setJavaCapabilityClass("");
160
161
		CapabilityType metadataExchange = DescriptorFactory.eINSTANCE
162
				.createCapabilityType();
163
		metadataExchange
164
				.setCapabilityUri("http://schemas.xmlsoap.org/ws/2004/09/mex");
165
		metadataExchange.setJavaCapabilityClass("");
166
167
		CapabilityType getCapability = DescriptorFactory.eINSTANCE
168
				.createCapabilityType();
169
		getCapability
170
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Get");
171
		getCapability.setJavaCapabilityClass("");
172
173
		CapabilityType setCapability = DescriptorFactory.eINSTANCE
174
				.createCapabilityType();
175
		setCapability
176
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Set");
177
		setCapability.setJavaCapabilityClass("");
178
179
		CapabilityType queryCapability = DescriptorFactory.eINSTANCE
180
				.createCapabilityType();
181
		queryCapability
182
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Query");
183
		queryCapability.setJavaCapabilityClass("");
184
185
		CapabilityType immediateDestruction = DescriptorFactory.eINSTANCE
186
				.createCapabilityType();
187
		immediateDestruction
188
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rlw-2/ImmediateResourceTermination");
189
		immediateDestruction
190
				.setJavaCapabilityClass("org.apache.muse.ws.resource.lifetime.impl.SimpleImmediateTermination");
191
192
		CapabilityType scheduledDestruction = DescriptorFactory.eINSTANCE
193
				.createCapabilityType();
194
		scheduledDestruction
195
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rlw-2/ScheduledResourceTermination");
196
		scheduledDestruction
197
				.setJavaCapabilityClass("org.apache.muse.ws.resource.lifetime.impl.SimpleScheduledTermination");
198
199
		CapabilityType subscriptionManager = DescriptorFactory.eINSTANCE
200
				.createCapabilityType();
201
		subscriptionManager
202
				.setCapabilityUri("http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager");
203
		subscriptionManager
204
				.setJavaCapabilityClass("org.apache.muse.ws.notification.impl.SimpleSubscriptionManager");
205
206
		InitParamType noValidateParam = DescriptorFactory.eINSTANCE
207
				.createInitParamType();
208
		noValidateParam.setParamName("validate-wsrp-schema");
209
		noValidateParam.setParamValue("false");
210
211
		resourceType.getCapability().add(identity);
212
		resourceType.getCapability().add(manageabilityCharacteristics);
213
		resourceType.getCapability().add(metadataExchange);
214
		resourceType.getCapability().add(getCapability);
215
		resourceType.getCapability().add(setCapability);
216
		resourceType.getCapability().add(queryCapability);
217
		resourceType.getCapability().add(immediateDestruction);
218
		resourceType.getCapability().add(scheduledDestruction);
219
		resourceType.getCapability().add(subscriptionManager);
220
221
		resourceType.getInitParam().add(noValidateParam);
222
223
		return resourceType;
224
	}
225
226
	private boolean isNotificationProducerCapability(Capability capability)
227
	{
228
		boolean isNpNS = capability.getNamespace().equals(
229
				"http://docs.oasis-open.org/wsn/bw-2");
230
		boolean isNpName = capability.getName().equals("NotificationProducer");
231
		Operation[] operations = capability.getWsdlDefinition().getOperations();
232
		if (operations == null || operations.length < 2)
233
			return false;
234
		boolean isSubscribeOp = WsdlUtils.getOperationName(operations[0])
235
				.equals("Subscribe");
236
		boolean isGetCurrentMessageOp = WsdlUtils.getOperationName(
237
				operations[1]).equals("GetCurrentMessage");
238
		return isNpNS && isNpName && isSubscribeOp && isGetCurrentMessageOp;
239
	}
240
241
	/**
242
	 * Sets the parent directory 
243
	 * @param mrtParentDir
244
	 */
245
	public void setMrtParentDirectory(String mrtParentDir)
246
	{
247
		_mrtParentDirName = mrtParentDir;
248
	}
249
	/**
250
	 * Returns the initial instances
251
	 * @return InitialInstancesType[]
252
	 */
253
	public InitialInstancesType[] getInitialInstances()
254
	{
255
		InitialInstancesType instance = DescriptorFactory.eINSTANCE
256
				.createInitialInstancesType();
257
		ResourceTypeType rtClone = MRTCodeGenerationDelegate
258
				.cloneResourceType(_subManagerResourceType);
259
		instance.setResourceType(rtClone);
260
		ReferenceParametersType refParam = DescriptorFactory.eINSTANCE
261
				.createReferenceParametersType();
262
		instance.setReferenceParameters(refParam);
263
		return new InitialInstancesType[] { instance };
264
	}
265
266
	/**
267
	 * This method will persist the extra artifacts generated at codegen time (SubscriptionManager.mrt file).
268
	 */
269
	public void persistArtifacts()
270
	{
271
		ResourceSet rs = new ResourceSetImpl();
272
		rs.getResourceFactoryRegistry().getExtensionToFactoryMap()
273
			.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new CustomMrtResourceFactoryImpl());
274
		byte[] rawNewMRT = MrtUtils.serializeMRT(_subManagerMRT, rs, URI
275
				.createURI("dummy.xml"), true);
276
		InputStream stream = new ByteArrayInputStream(rawNewMRT);
277
278
		try
279
		{
280
			String subManagerMrt = _mrtParentDirName + "/"
281
					+ "SubscriptionManager.mrt";
282
			IFile subManagerMrtFile = EclipseUtils.getIFile(subManagerMrt);
283
			if (subManagerMrtFile.exists())
284
			{
285
				subManagerMrtFile.setContents(stream, true, true,
286
						new NullProgressMonitor());
287
			}
288
			else
289
			{
290
				subManagerMrtFile.create(stream, true,
291
						new NullProgressMonitor());
292
			}
293
			try
294
			{
295
				stream.close();
296
			}
297
			catch (IOException e)
298
			{
299
				WsdmToolingLog.logError(e.getMessage(), e);
300
			}
301
		}
302
		catch (CoreException e)
303
		{
304
			WsdmToolingLog.logError(e.getMessage(), e);
305
		}
306
	}
307
308
	/**
309
	 * This method will returns the extra generated ManageableResourceType object equivalent to SubscriptionManager.
310
	 */
311
	public ManageableResourceType getExtraGeneratedMrt() 
312
	{
313
		return _subManagerMRT;
314
	}
315
316
	/**
317
	 * This method should return the persistance location for extra generated ManageableResourceType object equivalent to SubscriptionManager.
318
	 */
319
	public String getExtraGeneratedMrtPersistanceLocation() 
320
	{
321
		return _mrtParentDirName+"/SubscriptionManager.mrt";
322
	}
323
324
	/**
325
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
326
	 * merged RMD document for it by having the rules/relationships in it. 
327
	 */
328
	public void inspectMetadata(ManageableResourceType mrt,
329
			MetadataDescriptor rmd)
330
	{
331
	}
332
333
	
334
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/RelationshipInspector.java (+405 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
13
14
import java.io.ByteArrayInputStream;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.util.ArrayList;
18
import java.util.Iterator;
19
import java.util.List;
20
21
import javax.wsdl.Operation;
22
import javax.xml.namespace.QName;
23
24
import org.apache.muse.util.xml.XmlUtils;
25
import org.apache.muse.ws.addressing.WsaConstants;
26
import org.apache.muse.ws.addressing.soap.SoapFault;
27
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
28
import org.apache.ws.muse.descriptor.CapabilityType;
29
import org.apache.ws.muse.descriptor.DescriptorFactory;
30
import org.apache.ws.muse.descriptor.DocumentRoot;
31
import org.apache.ws.muse.descriptor.InitParamType;
32
import org.apache.ws.muse.descriptor.InitialInstancesType;
33
import org.apache.ws.muse.descriptor.ReferenceParametersType;
34
import org.apache.ws.muse.descriptor.ResourceTypeType;
35
import org.apache.ws.muse.descriptor.WsdlType;
36
import org.eclipse.core.resources.IFile;
37
import org.eclipse.core.runtime.CoreException;
38
import org.eclipse.core.runtime.NullProgressMonitor;
39
import org.eclipse.emf.common.util.URI;
40
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
41
import org.eclipse.emf.ecore.resource.Resource;
42
import org.eclipse.emf.ecore.resource.ResourceSet;
43
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
44
import org.eclipse.emf.ecore.util.FeatureMap;
45
import org.eclipse.emf.ecore.util.BasicExtendedMetaData.EStructuralFeatureExtendedMetaData;
46
import org.eclipse.emf.ecore.xml.type.AnyType;
47
import org.eclipse.tptp.wsdm.tooling.editor.mrt.relationship.internal.RelationshipUtils;
48
import org.eclipse.tptp.wsdm.tooling.model.addressing.AttributedURIType;
49
import org.eclipse.tptp.wsdm.tooling.model.addressing.EndpointReferenceType;
50
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
51
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
52
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceTypeFactory;
53
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.Relationship;
54
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.RelationshipParticipantType;
55
import org.eclipse.tptp.wsdm.tooling.util.internal.CustomMrtResourceFactoryImpl;
56
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
57
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
58
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
59
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
60
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
61
import org.w3c.dom.Document;
62
import org.w3c.dom.Element;
63
import org.w3c.dom.Text;
64
65
public class RelationshipInspector implements MrtInspector
66
{
67
68
	private String _mrtParentDirName;
69
70
	private DocumentRoot _root;
71
72
	private ResourceTypeType _relationshipResourceType;
73
	
74
	private ManageableResourceType _relationshipResourceMRT;
75
	
76
	/**
77
	 * Constructor of the class
78
	 * @param root
79
	 */
80
	public RelationshipInspector(DocumentRoot root)
81
	{
82
		_root = root;
83
	}
84
85
	public ManageableResourceType getExtraGeneratedMrt()
86
	{
87
		return _relationshipResourceMRT;
88
	}
89
90
	public String getExtraGeneratedMrtPersistanceLocation() 
91
	{
92
		return _mrtParentDirName+"/RelationshipResource.mrt";
93
	}
94
95
	public InitialInstancesType[] getInitialInstances() 
96
	{
97
		InitialInstancesType instance = DescriptorFactory.eINSTANCE
98
			.createInitialInstancesType();
99
		ResourceTypeType rtClone = MRTCodeGenerationDelegate
100
			.cloneResourceType(_relationshipResourceType);
101
		instance.setResourceType(rtClone);
102
		ReferenceParametersType refParam = DescriptorFactory.eINSTANCE
103
			.createReferenceParametersType();
104
		instance.setReferenceParameters(refParam);
105
		return new InitialInstancesType[] { instance };
106
	}
107
108
	public ResourceTypeType inspect(Capability[] mrtCapabilities) 
109
	{
110
		for (int i = 0; i < mrtCapabilities.length; i++)
111
		{
112
			if (hasRelationshipCapability(mrtCapabilities[i]))
113
				return createRelationshipResourceType();							
114
		}
115
		return null;
116
	}
117
	
118
	private ResourceTypeType createRelationshipResourceType()
119
	{
120
		createRelationshipResourceMrt();
121
		_relationshipResourceType = createRelationshipResourceMuseType();
122
		return _relationshipResourceType;
123
	}
124
	
125
	private void createRelationshipResourceMrt()
126
	{
127
		org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.DocumentRoot documentRoot = ManageableResourceTypeFactory.eINSTANCE.createDocumentRoot();
128
		_relationshipResourceMRT = ManageableResourceTypeFactory.eINSTANCE
129
				.createManageableResourceType();
130
		documentRoot.setManageableResource(_relationshipResourceMRT);
131
		_relationshipResourceMRT.setIdentifier("RelationshipResource");
132
		_relationshipResourceMRT
133
				.setNamespace("http://docs.oasis-open.org/wsdm/muws2-2.xsd/RelationshipResource");
134
		_relationshipResourceMRT
135
				.getImplements()
136
				.add(WsdmConstants.MEX_CAPABILITY_LOCATION);
137
		_relationshipResourceMRT
138
				.getImplements()
139
				.add(WsdmConstants.GET_CAPABILITY_LOCATION);
140
		_relationshipResourceMRT
141
				.getImplements()
142
				.add(WsdmConstants.SET_CAPABILITY_LOCATION);
143
		_relationshipResourceMRT
144
				.getImplements()
145
				.add(WsdmConstants.QUERY_CAPABILITY_LOCATION);
146
		_relationshipResourceMRT
147
				.getImplements()
148
				.add(WsdmConstants.RELATIONSHIP_RESOURCE_CAPABILITY_LOCATION);
149
	}
150
	
151
	private ResourceTypeType createRelationshipResourceMuseType()
152
	{
153
		ResourceTypeType resourceType = DescriptorFactory.eINSTANCE
154
				.createResourceTypeType();
155
		resourceType.setContextPath("/RelationshipResource");
156
		resourceType
157
				.setJavaIdFactoryClass(WsdmConstants.MUSE_RESOURCE_ID_FACTORY_CLASS);
158
		resourceType
159
				.setJavaResourceClass(WsdmConstants.MUSE_RESOURCE_CLASS);
160
161
		WsdlType wsdlType = DescriptorFactory.eINSTANCE.createWsdlType();
162
		wsdlType.setWsdlFile(_mrtParentDirName + "/"
163
				+ "RelationshipResource.wsdl");
164
		_root.getXMLNSPrefixMap().put("rel",
165
				"http://docs.oasis-open.org/wsdm/muws2-2.xsd/RelationshipResource");
166
		wsdlType.setWsdlPortType("rel:PortType");
167
		resourceType.setWsdl(wsdlType);
168
169
		CapabilityType metadataExchange = DescriptorFactory.eINSTANCE
170
				.createCapabilityType();
171
		metadataExchange
172
				.setCapabilityUri("http://schemas.xmlsoap.org/ws/2004/09/mex");
173
		metadataExchange.setJavaCapabilityClass("");
174
175
		CapabilityType getCapability = DescriptorFactory.eINSTANCE
176
				.createCapabilityType();
177
		getCapability
178
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Get");
179
		getCapability.setJavaCapabilityClass("");
180
181
		CapabilityType setCapability = DescriptorFactory.eINSTANCE
182
				.createCapabilityType();
183
		setCapability
184
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Set");
185
		setCapability.setJavaCapabilityClass("");
186
187
		CapabilityType queryCapability = DescriptorFactory.eINSTANCE
188
				.createCapabilityType();
189
		queryCapability
190
				.setCapabilityUri("http://docs.oasis-open.org/wsrf/rpw-2/Query");
191
		queryCapability.setJavaCapabilityClass("");
192
193
		CapabilityType relationshipResource = DescriptorFactory.eINSTANCE
194
				.createCapabilityType();
195
		relationshipResource
196
				.setCapabilityUri("http://docs.oasis-open.org/wsdm/muws/capabilities/RelationshipResource");
197
		relationshipResource
198
				.setJavaCapabilityClass("");
199
200
		InitParamType noValidateParam = DescriptorFactory.eINSTANCE
201
				.createInitParamType();
202
		noValidateParam.setParamName("validate-wsrp-schema");
203
		noValidateParam.setParamValue("false");
204
205
		resourceType.getCapability().add(metadataExchange);
206
		resourceType.getCapability().add(getCapability);
207
		resourceType.getCapability().add(setCapability);
208
		resourceType.getCapability().add(queryCapability);
209
		resourceType.getCapability().add(relationshipResource);
210
		
211
		resourceType.getInitParam().add(noValidateParam);
212
213
		return resourceType;
214
	}
215
	
216
	private boolean hasRelationshipCapability(Capability capability)
217
	{
218
		boolean hasRelationshipNS = "http://docs.oasis-open.org/wsdm/muws2-2.xsd".equals(capability.getNamespace());
219
		String capabilityURI = capability.getWsdlDefinition().getNamespace("capabilityURI");
220
		boolean hasRelationshipURI = "http://docs.oasis-open.org/wsdm/muws/capabilities/Relationships".equals(capabilityURI);
221
		boolean hasRelationshipName = capability.getName().equals("Relationships");
222
		Operation[] operations = capability.getWsdlDefinition().getOperations();
223
		if (operations == null || operations.length < 1)
224
			return false;
225
		boolean hasQueryRelationshipsOp = WsdlUtils.getOperationName(operations[0])
226
				.equals("QueryRelationshipsByType");
227
		return hasRelationshipNS && hasRelationshipURI && hasRelationshipName && hasQueryRelationshipsOp;
228
	}
229
230
	public void persistArtifacts() 
231
	{
232
		ResourceSet rs = new ResourceSetImpl();
233
		rs.getResourceFactoryRegistry().getExtensionToFactoryMap()
234
			.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new CustomMrtResourceFactoryImpl());
235
		byte[] rawNewMRT = MrtUtils.serializeMRT(_relationshipResourceMRT, rs, URI
236
				.createURI("dummy.xml"), true);
237
		InputStream stream = new ByteArrayInputStream(rawNewMRT);
238
239
		try
240
		{
241
			String relationshipResourceMrt = _mrtParentDirName + "/"
242
					+ "RelationshipResource.mrt";
243
			IFile relationshipResourceMrtFile = EclipseUtils.getIFile(relationshipResourceMrt);
244
			if (relationshipResourceMrtFile.exists())
245
			{
246
				relationshipResourceMrtFile.setContents(stream, true, true,
247
						new NullProgressMonitor());
248
			}
249
			else
250
			{
251
				relationshipResourceMrtFile.create(stream, true,
252
						new NullProgressMonitor());
253
			}
254
			try
255
			{
256
				stream.close();
257
			}
258
			catch (IOException e)
259
			{
260
				WsdmToolingLog.logError(e.getMessage(), e);
261
			}
262
		}
263
		catch (CoreException e)
264
		{
265
			WsdmToolingLog.logError(e.getMessage(), e);
266
		}		
267
	}
268
269
	public void setMrtParentDirectory(String mrtParentDir) 
270
	{
271
		_mrtParentDirName = mrtParentDir;
272
	}
273
	
274
	/**
275
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
276
	 * merged RMD document for it by having the rules/relationships in it. 
277
	 */
278
	public void inspectMetadata(ManageableResourceType mrt, MetadataDescriptor rmd)
279
	{
280
		boolean hasRelationshipCapability = false;
281
		Capability[] mrtCapabilities = new Capability[0];
282
		try 
283
		{
284
			mrtCapabilities = MrtUtils.getCapabilities(mrt);
285
		} 
286
		catch (Exception e)
287
		{
288
			WsdmToolingLog.logError(e.getMessage(), e);
289
		}
290
		for (int i = 0; i < mrtCapabilities.length; i++)
291
		{
292
			if (hasRelationshipCapability(mrtCapabilities[i]))
293
			{
294
				hasRelationshipCapability = true;
295
				break;
296
			}
297
		}
298
		if(hasRelationshipCapability)
299
		{
300
			List relationships = mrt.getRelationshipDefinitions();
301
			List initialValues = new ArrayList();
302
			for(int i=0;i<relationships.size();i++)
303
			{
304
				Relationship relationship = (Relationship) relationships.get(i);
305
				Element value = createRelationshipElement(relationship);
306
				initialValues.add(value);
307
			}
308
			if(!initialValues.isEmpty());
309
				try 
310
				{
311
					rmd.setInitialValues(new QName(WsdmConstants.MUWS_P2_NS,"Relationship"), initialValues);
312
				} 
313
				catch (SoapFault e) 
314
				{
315
					WsdmToolingLog.logError(e.getMessage(), e);
316
				}
317
		}
318
	}
319
	
320
	private Element createRelationshipElement(Relationship relationship)
321
	{
322
		Document document = XmlUtils.createDocument();
323
		Element relationshipElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P2_NS,"Relationship"));
324
		
325
		Element nameElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P2_NS,"Name"));
326
		Text name = document.createTextNode(relationship.getName());
327
		nameElement.appendChild(name);		
328
		relationshipElement.appendChild(nameElement);
329
		
330
		Element typeElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P2_NS,"Type"));
331
		QName typeQName = RelationshipUtils.getRelationshipType(relationship);
332
		Element element = XmlUtils.createElement(document, typeQName);
333
		typeElement.appendChild(element);		
334
		relationshipElement.appendChild(typeElement);
335
		
336
		List participants = relationship.getParticipant();
337
		for(int i=0;i<participants.size();i++)
338
		{
339
			RelationshipParticipantType participant = (RelationshipParticipantType) participants.get(i);
340
			Element participantElement = createParticipantElement(participant, document);
341
			relationshipElement.appendChild(participantElement);
342
		}
343
		return relationshipElement;
344
	}
345
	
346
	private Element createParticipantElement(RelationshipParticipantType participant, Document document)
347
	{
348
		Element participantElement = XmlUtils.createElement(document,new QName(WsdmConstants.MUWS_P2_NS,"Participant"));
349
		
350
		// Create epr element 
351
		Element manageabilityEprElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P1_NS,"ManageabilityEndpointReference"));
352
		EndpointReferenceType epr = (EndpointReferenceType) participant.getManageabilityEndpointReference().get(0);
353
		AttributedURIType uri = epr.getAddress();
354
		Element addressElement = XmlUtils.createElement(document, new QName("http://www.w3.org/2005/08/addressing", "Address"));
355
		Text address = document.createTextNode(uri.getValue());
356
		addressElement.appendChild(address);
357
		manageabilityEprElement.appendChild(addressElement);
358
		participantElement.appendChild(manageabilityEprElement);
359
		
360
		// Create reference parameter element
361
		Element referenceParameterElement = XmlUtils.createElement(document, WsaConstants.PARAMETERS_QNAME);
362
		manageabilityEprElement.appendChild(referenceParameterElement);		
363
		org.eclipse.tptp.wsdm.tooling.model.addressing.ReferenceParametersType refParams = epr.getReferenceParameters();
364
		FeatureMap fm = refParams.getAny();
365
		Iterator it = fm.iterator();
366
		while (it.hasNext())
367
		{
368
			Object obj = it.next();
369
			if(obj instanceof EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)
370
			{
371
				EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry containmentEntry = (EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)obj;
372
				EStructuralFeatureExtendedMetaData metadata = ((EStructuralFeatureImpl)containmentEntry.getEStructuralFeature()).getExtendedMetaData();
373
				String namespace = metadata.getNamespace();
374
				String name = metadata.getName();
375
				String value = "";
376
				Object containmentEntryValue = containmentEntry.getValue();
377
				if(containmentEntryValue instanceof AnyType)
378
				{
379
					AnyType anyType = (AnyType) containmentEntryValue;
380
					value = (String) anyType.getMixed().valueListIterator().next();
381
				}
382
				Element paramElement = XmlUtils.createElement(document, new QName(namespace, name));
383
				XmlUtils.setElementText(paramElement, value);
384
				referenceParameterElement.appendChild(paramElement);
385
			}			
386
		}
387
		
388
		// Create resource id element
389
		Element resourceIdElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P1_NS,"ResourceId"));
390
		Text resourceId = document.createTextNode(participant.getResourceId());
391
		resourceIdElement.appendChild(resourceId);
392
		participantElement.appendChild(resourceIdElement);
393
		
394
		// Create role element
395
		Element roleElement = XmlUtils.createElement(document, new QName(WsdmConstants.MUWS_P2_NS,"Role"));
396
		Text role = document.createTextNode(participant.getRole());
397
		roleElement.appendChild(role);
398
		participantElement.appendChild(roleElement);
399
		
400
		return participantElement;
401
	}
402
	
403
	
404
405
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/SoapServerDependency.java (+51 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IConfigurationElement;
20
21
/**
22
 * This class collects the relative paths of required Axis-2 files specified in extension point.
23
 * So if you are extending "axisValidator" extension point, you have to extend this class and implement
24
 * the interface ISoapServerDependency.
25
 */
26
27
public abstract class SoapServerDependency implements ISoapServerDependency 
28
{
29
30
	protected List _requiredFiles = new ArrayList();
31
	
32
	public void setInitializationData(IConfigurationElement config,
33
			String propertyName, Object data) throws CoreException 
34
	{
35
		if(config.getName()!=null && config.getName().equals("axisValidator"))
36
		{
37
			IConfigurationElement requiredFileConfig = config.getChildren()[0];
38
			IConfigurationElement[] relativePathConfig = requiredFileConfig.getChildren();
39
			for(int i=0;i<relativePathConfig.length;i++)
40
			{
41
				if(relativePathConfig[i].getName()!=null && relativePathConfig[i].getName().equals("relativeFilePath"))
42
				{
43
					String value = relativePathConfig[i].getValue();
44
					if(value!=null && !value.equals("null"))
45
						_requiredFiles.add(value);					
46
				}
47
			}
48
		}
49
	}
50
51
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/SingleValueMap.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.util.AbstractMap;
16
import java.util.HashSet;
17
import java.util.Set;
18
19
public class SingleValueMap extends AbstractMap {
20
	Object _value;
21
	Set _entrySet = new HashSet();
22
			
23
	public Object get(Object key) {
24
		return _value;
25
	}
26
	
27
	public Object put(Object key, Object value) {
28
		Object oldValue = _value;
29
		_value = value;		
30
		return oldValue;
31
	}
32
	
33
	public Set entrySet() {
34
		return _entrySet;
35
	}
36
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/BasicMrtInspector.java (+341 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
import java.util.List;
18
19
import javax.wsdl.Definition;
20
21
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
22
import org.apache.ws.muse.descriptor.DescriptorFactory;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
24
import org.apache.ws.muse.descriptor.InitParamType;
25
import org.apache.ws.muse.descriptor.InitialInstancesType;
26
import org.apache.ws.muse.descriptor.ReferenceParametersType;
27
import org.apache.ws.muse.descriptor.ResourceTypeType;
28
import org.apache.ws.muse.descriptor.WsdlType;
29
import org.apache.ws.muse.descriptor.impl.CapabilityTypeImpl;
30
import org.apache.ws.muse.descriptor.impl.ResourceTypeTypeImpl;
31
import org.eclipse.core.resources.IFile;
32
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.IConfigurationElement;
34
import org.eclipse.core.runtime.IExtension;
35
import org.eclipse.core.runtime.IExtensionPoint;
36
import org.eclipse.core.runtime.Platform;
37
import org.eclipse.emf.common.util.EMap;
38
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
39
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
40
import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages;
41
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
44
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
45
46
/**
47
 * This class analyzes the given manageable resource type and provide a resource
48
 * type for muse descriptor.
49
 */
50
51
public class BasicMrtInspector implements MrtInspector
52
{
53
	private DocumentRoot _root;
54
55
	private ResourceTypeType _resourceType;
56
57
	private ManageableResourceType _mrt;
58
	/**
59
	 * Constructor of the class
60
	 * @param mrt
61
	 * @param root
62
	 */
63
	public BasicMrtInspector(ManageableResourceType mrt,DocumentRoot root)
64
	{
65
		_root = root;
66
		_mrt = mrt;
67
	}
68
69
	/**
70
	 *  Get the initial instance for this manageable resource type
71
	 *  @return InitialInstancesType - Array of the initial instances
72
	 */
73
	public InitialInstancesType[] getInitialInstances()
74
	{
75
		InitialInstancesType instance = DescriptorFactory.eINSTANCE
76
				.createInitialInstancesType();
77
		ResourceTypeType rtClone = MRTCodeGenerationDelegate
78
				.cloneResourceType(_resourceType);
79
		instance.setResourceType(rtClone);
80
		ReferenceParametersType refParam = DescriptorFactory.eINSTANCE
81
				.createReferenceParametersType();
82
83
		instance.setReferenceParameters(refParam);
84
		return new InitialInstancesType[] { instance };
85
	}
86
87
	/**
88
	 *  Create a new descriptor resource type for the given manageable resource
89
	 *  type
90
	 *  @param mrtCapabilities
91
	 *  @return {@link ResourceTypeType}
92
	 */
93
	public ResourceTypeType inspect(Capability[] mrtCapabilities)
94
	{
95
		Mrt2DescriptorResourceType mrt2dd = new Mrt2DescriptorResourceType(
96
				_root, _mrt, mrtCapabilities);
97
		_resourceType = mrt2dd.getResourceTypeType();
98
		return _resourceType;
99
	}
100
101
	public void setMrtParentDirectory(String mrtParentDir)
102
	{
103
	}
104
105
	public void persistArtifacts()
106
	{
107
	}
108
109
	public ManageableResourceType getExtraGeneratedMrt() 
110
	{
111
		return null;
112
	}
113
114
	public String getExtraGeneratedMrtPersistanceLocation() 
115
	{
116
		return null;
117
	}
118
119
	public void inspectMetadata(ManageableResourceType mrt,
120
			MetadataDescriptor rmd) 
121
	{
122
	}
123
124
}
125
126
class Mrt2DescriptorResourceType
127
{
128
	private ManageableResourceType _mrt;
129
130
	private DocumentRoot _root;
131
132
	private Capability[] _mrtCapabilities;
133
134
	Mrt2DescriptorResourceType(DocumentRoot root, ManageableResourceType mrt)
135
	{
136
		this(root, mrt, null);
137
	}
138
139
	Mrt2DescriptorResourceType(DocumentRoot root, ManageableResourceType mrt,
140
			Capability[] mrtCapabilities)
141
	{
142
		_mrt = mrt;
143
		_root = root;
144
		if (mrtCapabilities == null)
145
			try
146
			{
147
				_mrtCapabilities = MrtUtils.getCapabilities(mrt);
148
			}
149
			catch (Exception e)
150
			{
151
			}
152
		else
153
			_mrtCapabilities = mrtCapabilities;
154
	}
155
156
	ResourceTypeType getResourceTypeType()
157
	{
158
		ResourceTypeTypeImpl rtd = (ResourceTypeTypeImpl) DescriptorFactory.eINSTANCE
159
				.createResourceTypeType();
160
		rtd.setUseRouterPersistence(true);
161
		rtd.setContextPath("/" + _mrt.getIdentifier()); //$NON-NLS-1$
162
		rtd
163
				.setJavaIdFactoryClass(WsdmConstants.MUSE_RESOURCE_ID_FACTORY_CLASS); //$NON-NLS-1$
164
		rtd
165
				.setJavaResourceClass(WsdmConstants.MUSE_RESOURCE_CLASS); //$NON-NLS-1$
166
		rtd.getCapability().addAll(getCapabilitiesFromMRT());
167
		WsdlType wsdlType = DescriptorFactory.eINSTANCE.createWsdlType();
168
169
		String mrtFileLocation = getMrtFileWorkspaceLocation();
170
		if (mrtFileLocation == null)
171
			;
172
		// TODO Log error not resolved location of given mrt
173
		else
174
		{
175
			String mrtFilePathWithoutExtn = mrtFileLocation.substring(0,
176
					mrtFileLocation.lastIndexOf('.'));
177
			wsdlType.setWsdlFile(mrtFilePathWithoutExtn + ".wsdl");
178
		}
179
180
		String namespace = _mrt.getNamespace();
181
		String prefix = getOrCreatePrefix(_root, namespace);
182
		String localPart = Messages.DU_PORT_TYPE_LOCAL_PART; // Only
183
		// "PortType"
184
		// should come
185
		// with the
186
		// //$NON-NLS-1$
187
		// prefix.
188
		wsdlType.setWsdlPortType(prefix + ":" + localPart);
189
190
		rtd.setWsdl(wsdlType);
191
		
192
		// Fix for Bug 174792 Set "validate-wsrp-schema" to "false" for the dd file generated at the codegen from MRT
193
		// http://bugs.eclipse.org/bugs/show_bug.cgi?id=174792
194
		InitParamType noValidateParam = DescriptorFactory.eINSTANCE.createInitParamType();
195
		noValidateParam.setParamName("validate-wsrp-schema");
196
		noValidateParam.setParamValue("false");		
197
		rtd.getInitParam().add(noValidateParam);
198
		
199
		return rtd;
200
	}
201
202
	private static String getOrCreatePrefix(DocumentRoot root, String namespace)
203
	{
204
		String prefix = getPrefix(root, namespace);
205
		if (prefix != null)
206
			return prefix;
207
		String newPrefix = generateNewPrefix(root);
208
		root.getXMLNSPrefixMap().put(newPrefix, namespace);
209
		return newPrefix;
210
	}
211
212
	private static String generateNewPrefix(DocumentRoot root)
213
	{
214
		int count = 0;
215
		while (isPrefixExists(root, "pfx" + count)) //$NON-NLS-1$
216
			count++;
217
		return "pfx" + count; //$NON-NLS-1$
218
	}
219
220
	private static boolean isPrefixExists(DocumentRoot root, String prefix)
221
	{
222
		EMap map = root.getXMLNSPrefixMap();
223
		Iterator keyIt = map.keySet().iterator();
224
		while (keyIt.hasNext())
225
		{
226
			String pfx = (String) keyIt.next();
227
			if (pfx.equals(prefix))
228
				return true;
229
		}
230
		return false;
231
	}
232
233
	private static String getPrefix(DocumentRoot root, String namespace)
234
	{
235
		if (root == null)
236
			return null;
237
		if (namespace == null)
238
			return null;
239
		EMap map = root.getXMLNSPrefixMap();
240
		Iterator keyIt = map.keySet().iterator();
241
		Iterator valuesIt = map.values().iterator();
242
		while (valuesIt.hasNext())
243
		{
244
			String ns = (String) valuesIt.next();
245
			String prefix = (String) keyIt.next();
246
			if (ns.equals(namespace))
247
				return prefix;
248
		}
249
		return null;
250
	}
251
252
	private List getCapabilitiesFromMRT()
253
	{
254
		if (_mrt == null)
255
			return null;
256
		List capDataList = new ArrayList();
257
		for (int i = 0; i < _mrtCapabilities.length; i++)
258
		{
259
			Capability capability = _mrtCapabilities[i];
260
			String capNS = ""; //$NON-NLS-1$
261
			Definition def = capability.getWsdlDefinition().getDefinition();
262
			if (def != null)
263
			{
264
				capNS = capability.getWsdlDefinition().getNamespace(
265
						"capabilityURI");
266
				if (capNS == null)
267
					capNS = capability.getNamespace();
268
269
			}
270
			CapabilityTypeImpl ctype = (CapabilityTypeImpl) DescriptorFactory.eINSTANCE
271
					.createCapabilityType();
272
			ctype.setCapabilityUri(capNS);
273
			String className = getJavaCapabilityClass(capNS);
274
			ctype.setJavaCapabilityClass(className);
275
			boolean isValid = validateCapability(capDataList, ctype);
276
			if (isValid)
277
				capDataList.add(ctype);
278
		}
279
		return capDataList;
280
	}
281
282
	private boolean validateCapability(List capDataList,
283
			CapabilityTypeImpl ctype)
284
	{
285
		if (capDataList == null || capDataList.size() == 0)
286
		{
287
			capDataList = new ArrayList();
288
			return true;
289
		}
290
		for (int i = 0; i < capDataList.size(); i++)
291
		{
292
			CapabilityTypeImpl tmp = (CapabilityTypeImpl) capDataList.get(i);
293
			if (tmp.getCapabilityUri().trim().equals(
294
					ctype.getCapabilityUri().trim()))
295
				return false;
296
		}
297
		return true;
298
	}
299
300
	private String getMrtFileWorkspaceLocation()
301
	{
302
		try
303
		{
304
			IFile mrtFile = EclipseUtils.getIFile(_mrt.eResource().getURI()
305
					.toString());
306
			return mrtFile.getFullPath().toString();
307
		}
308
		catch (CoreException e)
309
		{
310
			WsdmToolingLog.logError(e.getLocalizedMessage(), e);
311
		}
312
		return null;
313
	}
314
315
	private String getJavaCapabilityClass(String uri)
316
	{
317
		String ns = "org.eclipse.tptp.wsdm.model";
318
		IExtensionPoint iep = Platform.getExtensionRegistry()
319
				.getExtensionPoint(ns, "mrCapability");
320
		if (iep != null)
321
		{
322
			IExtension[] extensions = iep.getExtensions();
323
			for (int i = 0; i < extensions.length; i++)
324
			{
325
				IConfigurationElement[] ice = extensions[i]
326
						.getConfigurationElements();
327
				for (int j = 0; j < ice.length; j++)
328
				{
329
					String capURI = ice[j].getAttribute("uri");
330
					if (uri.equals(capURI))
331
					{
332
						String className = ice[j]
333
								.getAttribute("implementingClass");
334
						return (className == null) ? "" : className;
335
					}
336
				}
337
			}
338
		}
339
		return "";
340
	}
341
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/TargetedFileList.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
13
14
import java.util.ArrayList;
15
16
public class TargetedFileList {
17
	private String _relativePath;	// path relative to webcontent folder
18
	private ArrayList _absoluteFilePaths;
19
	
20
	public TargetedFileList(String relativePath){
21
		_relativePath = relativePath;
22
		_absoluteFilePaths = new ArrayList();
23
	}
24
	
25
	public void add(String absolutePath){
26
		if(absolutePath!=null && !absolutePath.trim().equals("")){
27
			_absoluteFilePaths.add(absolutePath);
28
		}
29
	}
30
	
31
	public String[] getFiles(){
32
		if(_absoluteFilePaths==null) return new String[]{};
33
		return (String[]) _absoluteFilePaths.toArray(new String[]{});
34
	}
35
	
36
	public String getRelativePath(){
37
		return _relativePath;
38
	}
39
	
40
	
41
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/ServiceGroupInspector.java (+366 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.ByteArrayInputStream;
16
import java.io.InputStream;
17
import java.util.ArrayList;
18
import java.util.HashMap;
19
import java.util.List;
20
21
import javax.xml.namespace.QName;
22
23
import org.apache.muse.util.xml.XmlUtils;
24
import org.apache.muse.ws.addressing.soap.SoapFault;
25
import org.apache.muse.ws.resource.sg.WssgConstants;
26
import org.apache.ws.muse.descriptor.CapabilityType;
27
import org.apache.ws.muse.descriptor.DescriptorFactory;
28
import org.apache.ws.muse.descriptor.DocumentRoot;
29
import org.apache.ws.muse.descriptor.InitParamType;
30
import org.apache.ws.muse.descriptor.InitialInstancesType;
31
import org.apache.ws.muse.descriptor.ReferenceParametersType;
32
import org.apache.ws.muse.descriptor.ResourceTypeType;
33
import org.apache.ws.muse.descriptor.WsdlType;
34
import org.eclipse.core.resources.IFile;
35
import org.eclipse.core.runtime.NullProgressMonitor;
36
import org.eclipse.emf.common.util.URI;
37
import org.eclipse.emf.ecore.resource.Resource;
38
import org.eclipse.emf.ecore.resource.ResourceSet;
39
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
40
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.NewNameGenerator;
41
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
42
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
43
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceTypeFactory;
44
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.MembershipContentRuleType;
45
import org.eclipse.tptp.wsdm.tooling.util.internal.CustomMrtResourceFactoryImpl;
46
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
47
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
48
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
49
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
50
import org.w3c.dom.Document;
51
import org.w3c.dom.Element;
52
/**
53
 * This class analyzes the given manageable resource type and provide an extra
54
 * resource type for muse descriptor (ServiceGroupEntry), if manageable
55
 * resource type contains the ServiceGroupCapability and ServiceGroupRegistration capability.
56
 */
57
58
public class ServiceGroupInspector implements MrtInspector
59
{
60
61
	private String _mrtParentDirName;
62
63
	private DocumentRoot _root;
64
	
65
	private ResourceTypeType _serviceGroupEntryResorceType;
66
	
67
	private ManageableResourceType _serviceGroupEntrymrt;
68
	
69
	private HashMap _prefixNamespaceMap;
70
	
71
	/**
72
	 * Constructor for the ServiceGroupIspector class.
73
	 * @param mrt
74
	 * @param root
75
	 */
76
	
77
	public ServiceGroupInspector(ManageableResourceType mrt,DocumentRoot root)
78
	{
79
		_root = root;
80
	}
81
82
	/**
83
	 * Analyzes the given manageable resource type for ServiceGroupCapability and
84
	 * ServiceGroupRegistrationCapability and if the capabilities available then returns the muse
85
	 * resource type for ServiceGroupEntry  else returns the null.
86
	 */
87
	public ResourceTypeType inspect(Capability[] mrtCapabilities) 
88
	{
89
		
90
		if(hasServiceGroupCapabilities(mrtCapabilities))
91
			return createServiceGroupEntryResourceType();
92
		return null;
93
	}
94
	
95
	private boolean hasServiceGroupCapabilities(Capability[] mrtCapabilities)
96
	{
97
		boolean hasServiceGroupCapability = false;
98
		
99
		boolean hasServiceGroupRegistration = false;
100
		
101
		for(int i =0;i<mrtCapabilities.length;i++)
102
		{
103
			if(mrtCapabilities[i].getNamespace().equals(WsdmConstants.SERVICE_GROUP_NS))
104
					hasServiceGroupCapability = true;
105
			if(mrtCapabilities[i].getNamespace().equals(WsdmConstants.SERVICE_GROUP_REG_NS))
106
					hasServiceGroupRegistration = true;
107
		}
108
		return hasServiceGroupCapability && hasServiceGroupRegistration;
109
	}
110
111
	/**
112
	 * Returns the initial instances
113
	 * @return InitialInstancesType[]
114
	 */
115
	public InitialInstancesType[] getInitialInstances() {
116
117
		InitialInstancesType instance = DescriptorFactory.eINSTANCE
118
				.createInitialInstancesType();
119
		ResourceTypeType rtClone = MRTCodeGenerationDelegate
120
				.cloneResourceType(_serviceGroupEntryResorceType);
121
		instance.setResourceType(rtClone);
122
		ReferenceParametersType refParam = DescriptorFactory.eINSTANCE
123
				.createReferenceParametersType();
124
		instance.setReferenceParameters(refParam);
125
		return new InitialInstancesType[] { instance };
126
	
127
	}
128
	/**
129
	 * Sets the parent directory 
130
	 * @param mrtParentDir
131
	 */
132
	public void setMrtParentDirectory(String mrtParentDir) {
133
		_mrtParentDirName = mrtParentDir;
134
		
135
	}
136
	
137
	private ResourceTypeType createServiceGroupEntryResourceType()
138
	{
139
		createServiceGroupEntryMrt();
140
		_serviceGroupEntryResorceType = createServiceGroupEntryMuseResourceType();
141
		return _serviceGroupEntryResorceType;
142
	}
143
	
144
	private void createServiceGroupEntryMrt()
145
	{
146
		 org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.DocumentRoot documentRoot = ManageableResourceTypeFactory.eINSTANCE.createDocumentRoot();
147
		 _serviceGroupEntrymrt = ManageableResourceTypeFactory.eINSTANCE.createManageableResourceType();
148
		 documentRoot.setManageableResource(_serviceGroupEntrymrt);
149
		_serviceGroupEntrymrt.setIdentifier("ServiceGroupEntry");
150
		_serviceGroupEntrymrt.setNamespace("http://docs.oasis-open.org/wsrf/sgw-2");
151
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.MEX_CAPABILITY_LOCATION);
152
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.GET_CAPABILITY_LOCATION);
153
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.SET_CAPABILITY_LOCATION);
154
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.QUERY_CAPABILITY_LOCATION);
155
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.IMMIDIATE_RESOURCE_TERMINATION_CAPABILITY_LOCATION);
156
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.SCHEDULED_RESOURCE_TERMINATION_CAPABILITY_LOCATION);
157
		_serviceGroupEntrymrt.getImplements().add(WsdmConstants.SERVICE_GROUP_ENTRY_CAPABILITY_LOCATION);
158
	}
159
	
160
	private ResourceTypeType createServiceGroupEntryMuseResourceType()
161
	{
162
		ResourceTypeType resourceType = DescriptorFactory.eINSTANCE.createResourceTypeType();
163
		resourceType.setContextPath("/ServiceGroupEntry");
164
		resourceType.setJavaIdFactoryClass("org.apache.muse.core.routing.CounterResourceIdFactory");
165
		resourceType.setJavaResourceClass("org.apache.muse.ws.resource.impl.SimpleWsResource");
166
167
		WsdlType wsdlType = DescriptorFactory.eINSTANCE.createWsdlType();
168
		wsdlType.setWsdlFile(_mrtParentDirName + "/" + "ServiceGroupEntry.wsdl");
169
		_root.getXMLNSPrefixMap().put("wsrf-sge","http://docs.oasis-open.org/wsrf/sgw-2");
170
		wsdlType.setWsdlPortType("wsrf-sge:PortType");
171
		resourceType.setWsdl(wsdlType);
172
173
		CapabilityType metadataExchange = DescriptorFactory.eINSTANCE.createCapabilityType();
174
		metadataExchange.setCapabilityUri(WsdmConstants.MEX_NS);
175
		metadataExchange.setJavaCapabilityClass("");
176
		
177
		CapabilityType getCapability = DescriptorFactory.eINSTANCE.createCapabilityType();
178
		getCapability.setCapabilityUri(WsdmConstants.GET_NS);
179
		getCapability.setJavaCapabilityClass("");
180
		
181
		CapabilityType setCapability = DescriptorFactory.eINSTANCE.createCapabilityType();
182
		setCapability.setCapabilityUri(WsdmConstants.SET_NS);
183
		setCapability.setJavaCapabilityClass("");
184
		
185
		CapabilityType queryCapability = DescriptorFactory.eINSTANCE.createCapabilityType();
186
		queryCapability.setCapabilityUri(WsdmConstants.QUERY_NS);
187
		queryCapability.setJavaCapabilityClass("");
188
189
		CapabilityType immediateDestruction = DescriptorFactory.eINSTANCE.createCapabilityType();
190
		immediateDestruction.setCapabilityUri(WsdmConstants.IMMIDIATE_TERM_NS);
191
		immediateDestruction.setJavaCapabilityClass("");
192
193
		CapabilityType scheduledDestruction = DescriptorFactory.eINSTANCE.createCapabilityType();
194
		scheduledDestruction.setCapabilityUri(WsdmConstants.SCHEDULDED_TERM_NS);
195
		scheduledDestruction.setJavaCapabilityClass("");
196
	
197
		CapabilityType serviceGroupEntry = DescriptorFactory.eINSTANCE.createCapabilityType();
198
		serviceGroupEntry.setCapabilityUri(WsdmConstants.SERVICE_GROUP_ENTRY_NS);
199
		serviceGroupEntry.setJavaCapabilityClass("");
200
		
201
		InitParamType noValidateParam = DescriptorFactory.eINSTANCE	.createInitParamType();
202
		noValidateParam.setParamName("validate-wsrp-schema");
203
		noValidateParam.setParamValue("false");
204
205
		resourceType.getCapability().add(metadataExchange);
206
		resourceType.getCapability().add(getCapability);
207
		resourceType.getCapability().add(setCapability);
208
		resourceType.getCapability().add(queryCapability);
209
		resourceType.getCapability().add(immediateDestruction);
210
		resourceType.getCapability().add(scheduledDestruction);
211
		resourceType.getCapability().add(serviceGroupEntry);
212
		resourceType.getInitParam().add(noValidateParam);
213
214
		return resourceType;
215
	}
216
	
217
	private String getNamespace(String contentElement)
218
	{
219
		return contentElement.substring(1,contentElement.lastIndexOf('}'));
220
	}
221
	
222
	private void preparePrfixNamespaceMap(String contentElement)
223
	{
224
		if(!_prefixNamespaceMap.containsKey(contentElement))
225
		{
226
			NewNameGenerator nameGenerator = new NewNameGenerator("pfx");
227
			String prefix = nameGenerator.getNextName();
228
			
229
			while (nameAlreadyExists(prefix)) 
230
			{
231
				prefix = nameGenerator.getNextName();
232
			}
233
			_prefixNamespaceMap.put(contentElement, prefix);
234
		}
235
	}
236
	
237
	private boolean nameAlreadyExists(String prefix)
238
	{
239
		if(_prefixNamespaceMap.containsValue(prefix))
240
			return true;
241
		return false;
242
	}
243
	
244
	private String getLocalName(String namespace)
245
	{
246
		return namespace.substring(namespace.lastIndexOf('}')+1);
247
	}
248
	
249
	/**
250
	 * This method will returns the extra generated ManageableResourceType object equivalent to ServiceGroupEntry.
251
	 */
252
	public ManageableResourceType getExtraGeneratedMrt() {
253
	
254
		return _serviceGroupEntrymrt;
255
	}
256
	
257
	/**
258
	 * This method should return the persistance location for extra generated ManageableResourceType object equivalent to ServiceGroupEntry.
259
	 */
260
	public String getExtraGeneratedMrtPersistanceLocation() 
261
	{
262
		return _mrtParentDirName + "/"+ "ServiceGroupEntry.mrt";
263
	}
264
	/**
265
	 * This method will persist the extra artifacts generated at the code generation time(ServiceGroupEntry). 
266
	 */
267
	public void persistArtifacts()
268
	{
269
		try{
270
			ResourceSet rs = new ResourceSetImpl();
271
			rs.getResourceFactoryRegistry().getExtensionToFactoryMap()
272
			.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new CustomMrtResourceFactoryImpl());
273
			String serviceGroupMrt = _mrtParentDirName + "/"+ "ServiceGroupEntry.mrt";
274
			URI uri = URI.createPlatformResourceURI(serviceGroupMrt);
275
			byte[] rawNewMRT = MrtUtils.serializeMRT(_serviceGroupEntrymrt, rs, uri, true);
276
			InputStream stream = new ByteArrayInputStream(rawNewMRT);			
277
			IFile subManagerMrtFile = EclipseUtils.getIFile(serviceGroupMrt);
278
			if (subManagerMrtFile.exists())
279
			{
280
				subManagerMrtFile.setContents(stream, true, true,
281
				new NullProgressMonitor());
282
			}
283
			else
284
			{
285
				subManagerMrtFile.create(stream, true,
286
				new NullProgressMonitor());
287
			}
288
			stream.close();			
289
		}
290
		catch(Exception e)
291
		{
292
			e.printStackTrace();
293
		}
294
	}
295
	
296
	/**
297
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
298
	 * merged RMD document for it by having the rules/relationships in it. 
299
	 */
300
	public void inspectMetadata(ManageableResourceType mrt,
301
			org.apache.muse.ws.resource.metadata.MetadataDescriptor rmd) 
302
	{
303
		
304
		_prefixNamespaceMap  = new HashMap();
305
		Capability[] mrtCapabilities = new Capability[0];
306
		try 
307
		{
308
			mrtCapabilities = MrtUtils.getCapabilities(mrt);
309
		} 
310
		catch (Exception e)
311
		{
312
			WsdmToolingLog.logError(e.getMessage(), e);
313
		}
314
		
315
		if(hasServiceGroupCapabilities(mrtCapabilities))
316
		{
317
			List membershipContentRule = mrt.getMembershipContentRule();
318
			List initialValues = new ArrayList();
319
			for(int i=0;i<membershipContentRule.size();i++)
320
			{
321
				MembershipContentRuleType rule = (MembershipContentRuleType) membershipContentRule.get(i);
322
				Element value = createMembershipContentRuleElement(rule);
323
				
324
				initialValues.add(value);
325
			}
326
			if(!initialValues.isEmpty());
327
				try 
328
				{
329
					rmd.setInitialValues(new QName(WssgConstants.NAMESPACE_URI,"MembershipContentRule"), initialValues);
330
				} 
331
				catch (SoapFault e) 
332
				{
333
					WsdmToolingLog.logError(e.getMessage(), e);
334
				}
335
		}
336
	}
337
	
338
	private Element createMembershipContentRuleElement(MembershipContentRuleType rule)
339
	{
340
		Document document = XmlUtils.createDocument();
341
		Element membershipContentRuleElement = XmlUtils.createElement(document, new QName(WssgConstants.NAMESPACE_URI,"MembershipContentRule"));
342
		List contentElements = rule.getContentElements();
343
		String contentElementAttribute="";
344
		
345
		for(int i =0 ;i<contentElements.size();i++)
346
		{
347
			String contentElement = (String)contentElements.get(i);
348
			String tns = getNamespace(contentElement);
349
			String localName = getLocalName(contentElement);
350
			preparePrfixNamespaceMap(tns);
351
			
352
			if(contentElementAttribute.length() !=0)
353
				contentElementAttribute =  contentElementAttribute + " " + (String)_prefixNamespaceMap.get(tns)+":"+ localName;
354
			else
355
				contentElementAttribute =(String)_prefixNamespaceMap.get(tns)+":"+ localName;
356
			String  xmlns = "xmlns:" + _prefixNamespaceMap.get(tns);
357
			 membershipContentRuleElement.setAttribute(xmlns,tns );
358
			
359
		}
360
		membershipContentRuleElement.setAttribute("ContentElements",contentElementAttribute );
361
		
362
		return membershipContentRuleElement;
363
		
364
		
365
	}
366
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/Generation.java (+72 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.jface.action.IAction;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
21
import org.eclipse.ui.IObjectActionDelegate;
22
import org.eclipse.ui.IWorkbenchPart;
23
24
/**
25
 * Access point code from the code generation option in popup
26
 */
27
public class Generation implements IObjectActionDelegate
28
{
29
30
	private IWorkbenchPart _targetPart;
31
32
	private StructuredSelection _selection;
33
34
	/**
35
	 * (non-Javadoc)
36
	 * @see org.eclipse.ui.IObjectActionDelegate#run(org.eclipse.jface.action.IAction)
37
	 */ 
38
	public void run(IAction action)
39
	{
40
		IFile mrtFile = (IFile) _selection.getFirstElement();
41
		MrtUtils.searchAndSaveMRTEditor(mrtFile);
42
		MRTCodeGenerationDelegate codeGenerationDelegate = new MRTCodeGenerationDelegate(
43
				mrtFile);
44
45
		NewProjectWizard npw = new NewProjectWizard(codeGenerationDelegate);
46
		WizardDialog wd = new WizardDialog(_targetPart.getSite().getShell(),
47
				npw);
48
		wd.open();
49
	}
50
51
	/**
52
	 * (non-Javadoc)
53
	 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
54
	 */ 
55
	public void setActivePart(IAction action, IWorkbenchPart targetPart)
56
	{
57
		_targetPart = targetPart;
58
	}
59
60
	/**
61
	 * (non-Javadoc)
62
	 * @see org.eclipse.ui.IObjectActionDelegate#selectionChanged
63
	(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
64
	 */
65
	public void selectionChanged(IAction action, ISelection selection)
66
	{
67
		if (selection instanceof StructuredSelection)
68
		{
69
			_selection = (StructuredSelection) selection;
70
		}
71
	}
72
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/MrtPreProcessor.java (+250 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.LinkedList;
19
import java.util.List;
20
import java.util.Map;
21
22
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
24
import org.apache.ws.muse.descriptor.InitialInstancesType;
25
import org.apache.ws.muse.descriptor.MuseType;
26
import org.apache.ws.muse.descriptor.ResourceTypeType;
27
import org.apache.ws.muse.descriptor.RootType;
28
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
31
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
32
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
33
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
34
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
35
36
/**
37
 * This class analyzes the given ManageableResourceType object and check whether it needs
38
 * any other extra ManageableResourceType object such as SubscriptionManager based on the capabilities 
39
 * available in given ManagableResourceType.   
40
 */
41
42
public class MrtPreProcessor 
43
{
44
	private ManageableResourceType _mrt;
45
	private DocumentRoot _ddRoot;
46
	private IFile _mrtFile;
47
	private List _generatedResourceTypes = new LinkedList();
48
	private List _initialInstancesList = new LinkedList();
49
	private List _contributedInspectors = new LinkedList();
50
	private Map _mrtObjectMap = new HashMap();
51
	private List _allInspectors = new LinkedList();
52
	
53
	/**
54
	 * Creates instance of this class.
55
	 * 
56
	 * @param mrt
57
	 * 			Given MRT to analyze.
58
	 * 
59
	 * @param ddRoot
60
	 * 			Given Descriptor file document root, can be null.
61
	 */
62
	public MrtPreProcessor(ManageableResourceType mrt, DocumentRoot ddRoot)
63
	{
64
		_mrt = mrt;
65
		if(ddRoot == null)
66
			ddRoot = DdeUtil.createInitialDDModel();
67
		_ddRoot = ddRoot;
68
		String mrtLocation = _mrt.eResource().getURI().toString();
69
		try 
70
		{
71
			_mrtFile = EclipseUtils.getIFile(mrtLocation);
72
		} 
73
		catch (CoreException e) 
74
		{
75
			e.printStackTrace();
76
		}
77
	}
78
	
79
	/**
80
	 * Creates instance of this class.
81
	 * 
82
	 * @param mrt
83
	 * 			Given MRT to analyze.
84
	 */
85
	public MrtPreProcessor(ManageableResourceType mrt)
86
	{
87
		this(mrt,null);
88
	}
89
	
90
	/**
91
	 * Returns the modified Descriptor document root. 
92
	 */
93
	public DocumentRoot getDDDocumentRoot()
94
	{
95
		return _ddRoot;
96
	}
97
	
98
	/**
99
	 * Analyzes the given MRT file for extra required artifacts. 
100
	 */
101
	public void preProcess()
102
	{
103
		if(_ddRoot!=null)
104
		{
105
			RootType root = _ddRoot.getRoot();
106
			MuseType muse = root.getMuse();		
107
			ResourceTypeType[] resourceTypes = process();
108
			for (int i = 0; i < resourceTypes.length; i++)
109
				muse.getResourceType().add(resourceTypes[i]);
110
			
111
			// Create initial instances
112
			
113
			InitialInstancesType[] instances = getInitialInstances();
114
			for (int i = 0; i < instances.length; i++)
115
				root.getInitialInstances().add(instances[i]);
116
		}
117
	}
118
	
119
	private boolean hasResourceTypeInDD(ResourceTypeType givenResourceType)
120
	{
121
		if(_ddRoot!=null)
122
		{
123
			if(_ddRoot.getRoot()!=null)
124
			{
125
				if(_ddRoot.getRoot().getMuse()!=null)
126
				{
127
					MuseType muse = _ddRoot.getRoot().getMuse();
128
					List resourceTypes = muse.getResourceType();
129
					if(resourceTypes!=null)
130
					{
131
						for(int i=0;i<resourceTypes.size();i++)
132
						{
133
							ResourceTypeType resourceType = (ResourceTypeType)resourceTypes.get(i);
134
							boolean equalContextPath = givenResourceType.getContextPath().equals(resourceType.getContextPath());
135
							boolean equalWsdlFile = givenResourceType.getWsdl().getWsdlFile().equals(resourceType.getWsdl().getWsdlFile());
136
							boolean equalWsdlPortType = givenResourceType.getWsdl().getWsdlPortType().equals(resourceType.getWsdl().getWsdlPortType());
137
							if(equalContextPath && equalWsdlFile && equalWsdlPortType)
138
								return true;
139
						}
140
					}
141
				}
142
			}
143
		}
144
		return false;
145
	}
146
	
147
	/**
148
	 * This method processes the given manageable resource type to check whether
149
	 * we need any extra resource type in muse descriptor file such as
150
	 * Subscription manager etc. It will returns all the proper ResourceTypeType
151
	 * objects. So it will return atleast one ResourceTypeType object that
152
	 * represents the given manageable resource type.
153
	 */
154
	private ResourceTypeType[] process()
155
	{
156
		Capability[] mrtCapabilities = new Capability[0];
157
		try
158
		{
159
			mrtCapabilities = MrtUtils.getCapabilities(_mrt);
160
		}
161
		catch (Exception e)
162
		{
163
		}
164
		// Analyze the given manageable resource type for Subscription manager
165
		// etc.
166
		// If needed add the extra resource type for Subscription manager
167
		List inspectors = getAllMrtInspectors();
168
		for (int i = 0; i < inspectors.size(); i++)
169
		{
170
			MrtInspector inspector = (MrtInspector) inspectors.get(i);
171
			inspector.setMrtParentDirectory(_mrtFile.getParent().getFullPath()
172
					.toString());
173
			ResourceTypeType resourceType = inspector.inspect(mrtCapabilities);
174
			if (resourceType != null)
175
			{
176
				if(!hasResourceTypeInDD(resourceType))
177
				{
178
					_generatedResourceTypes.add(resourceType);
179
					InitialInstancesType[] instances = inspector
180
							.getInitialInstances();
181
					for (int j = 0; j < instances.length; j++)
182
						_initialInstancesList.add(instances[j]);
183
					if(inspector.getExtraGeneratedMrt()!=null)
184
						_mrtObjectMap.put(inspector.getExtraGeneratedMrtPersistanceLocation(), inspector.getExtraGeneratedMrt());
185
					_contributedInspectors.add(inspector);
186
				}
187
			}
188
			_allInspectors.add(inspector);
189
		}
190
		return (ResourceTypeType[]) _generatedResourceTypes
191
				.toArray(new ResourceTypeType[_generatedResourceTypes.size()]);
192
	}
193
194
	private List getAllMrtInspectors()
195
	{
196
		List inspectors = new ArrayList();
197
		inspectors.add(new BasicMrtInspector(_mrt, _ddRoot));
198
		// We don't analyze MRT for SubscriptionManager
199
		// As it is already handled in MUSE-2.1
200
		//inspectors.add(new SubscriptionManagerInspector(_ddRoot));
201
		inspectors.add(new ServiceGroupInspector(_mrt, _ddRoot));
202
		inspectors.add(new RelationshipInspector(_ddRoot));
203
		return inspectors;
204
	}
205
	
206
	/**
207
	 * Returns the initial instances
208
	 * @return IntialInstancesType[]
209
	 */
210
	private InitialInstancesType[] getInitialInstances()
211
	{
212
		return (InitialInstancesType[]) _initialInstancesList
213
				.toArray(new InitialInstancesType[_initialInstancesList.size()]);
214
	}
215
216
	/**
217
	 * Returns the map.
218
	 * Key will be the persisted location of MRT and 
219
	 * value will be the ManageableREsourceType object. 
220
	 */
221
	public Map getMrtObjectMap() 
222
	{
223
		return _mrtObjectMap;
224
	}
225
	
226
	/**
227
	 * This method will persist the extra artifacts generated at codegen time.
228
	 */
229
	public void persistArtifacts()
230
	{
231
		for(int i=0;i<_contributedInspectors.size();i++)
232
		{
233
			MrtInspector inspector = (MrtInspector)_contributedInspectors.get(i);
234
			inspector.persistArtifacts();
235
		}		
236
	}
237
	
238
	/**
239
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
240
	 * merged RMD document for it by having the rules/relationships in it. 
241
	 */
242
	public void inspectMetadata(ManageableResourceType mrt, MetadataDescriptor rmd)
243
	{
244
		for(Iterator iter = _allInspectors.iterator();iter.hasNext();)
245
		{
246
			MrtInspector inspector = (MrtInspector) iter.next();
247
			inspector.inspectMetadata(mrt, rmd);
248
		}
249
	}
250
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/MrtInspector.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
16
import org.apache.ws.muse.descriptor.InitialInstancesType;
17
import org.apache.ws.muse.descriptor.ResourceTypeType;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
19
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
20
21
/**
22
 * This interface is created for some cases where we expect some extra resource
23
 * type to be added to the muse descriptor based on the capability that
24
 * manageable resource type holds. For example if someone includes the
25
 * Notification producer capability in his manageable resource type, then muse
26
 * runtime requires the Subscription Manager as one of the resource type
27
 * described in muse descriptor file.
28
 */
29
public interface MrtInspector
30
{
31
	public static String WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";
32
33
	/**
34
	 * Analyzes the given manageable resource type capabilities and then returns the muse
35
	 * resource type for some extra generated artifact else returns the null.
36
	 */
37
	ResourceTypeType inspect(Capability[] mrtCapabilities);
38
39
	/**
40
	 * This method should set the parent directory for extra generated artifact. 
41
	 */
42
	void setMrtParentDirectory(String mrtParentDir);
43
44
	/**
45
	 * Returns initial instances for extra generated artifact. 
46
	 */
47
	InitialInstancesType[] getInitialInstances();
48
	
49
	/**
50
	 * This method will persist the extra artifacts generated at codegen time.
51
	 */
52
	void persistArtifacts();
53
	
54
	/**
55
	 * This method will returns the extra ManageableResourceType object generated at codegen time.
56
	 */
57
	ManageableResourceType getExtraGeneratedMrt();
58
	
59
	/**
60
	 * This method should return the persistance location for extra generated ManageableResourceType object.
61
	 */
62
	String getExtraGeneratedMrtPersistanceLocation();
63
	
64
	/**
65
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
66
	 * merged RMD document for it by having the rules/relationships in it. 
67
	 */
68
	void inspectMetadata(ManageableResourceType mrt, MetadataDescriptor rmd);	
69
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/GenerationOptionsPage.java (+691 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.util.HashMap;
16
import java.util.Iterator;
17
import java.util.Map;
18
import java.util.prefs.Preferences;
19
20
import org.apache.muse.tools.generator.analyzer.Analyzer;
21
import org.apache.muse.tools.generator.projectizer.Projectizer;
22
import org.apache.muse.tools.generator.synthesizer.Synthesizer;
23
import org.eclipse.core.filesystem.URIUtil;
24
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.IWorkspace;
26
import org.eclipse.core.resources.IWorkspaceRoot;
27
import org.eclipse.core.resources.ResourcesPlugin;
28
import org.eclipse.core.runtime.IConfigurationElement;
29
import org.eclipse.core.runtime.IExtension;
30
import org.eclipse.core.runtime.IExtensionPoint;
31
import org.eclipse.core.runtime.IExtensionRegistry;
32
import org.eclipse.core.runtime.IPath;
33
import org.eclipse.core.runtime.IStatus;
34
import org.eclipse.core.runtime.Path;
35
import org.eclipse.core.runtime.Platform;
36
import org.eclipse.jface.dialogs.DialogPage;
37
import org.eclipse.jface.preference.IPreferenceStore;
38
import org.eclipse.jface.util.Util;
39
import org.eclipse.jface.wizard.WizardPage;
40
import org.eclipse.osgi.util.TextProcessor;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.events.ModifyEvent;
43
import org.eclipse.swt.events.ModifyListener;
44
import org.eclipse.swt.events.SelectionAdapter;
45
import org.eclipse.swt.events.SelectionEvent;
46
import org.eclipse.swt.layout.GridData;
47
import org.eclipse.swt.layout.GridLayout;
48
import org.eclipse.swt.widgets.Button;
49
import org.eclipse.swt.widgets.Combo;
50
import org.eclipse.swt.widgets.Composite;
51
import org.eclipse.swt.widgets.DirectoryDialog;
52
import org.eclipse.swt.widgets.Event;
53
import org.eclipse.swt.widgets.Group;
54
import org.eclipse.swt.widgets.Label;
55
import org.eclipse.swt.widgets.Listener;
56
import org.eclipse.swt.widgets.Text;
57
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
58
import org.eclipse.tptp.wsdm.tooling.editor.mrt.relationship.dialog.internal.MemoryComboBox;
59
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
60
import org.eclipse.tptp.wsdm.tooling.preferences.internal.Axis2ServerLocationPreferencePage;
61
import org.eclipse.tptp.wsdm.tooling.util.internal.Validation;
62
import org.eclipse.tptp.wsdm.tooling.validation.util.internal.ValidationUtils;
63
64
/**
65
 * This wizard enables the use to specify the projectizer options and also the
66
 * runtime environment and general options
67
 */
68
public class GenerationOptionsPage extends WizardPage
69
{
70
	private static final String PROJECT_MEMORY_COMBO_ID = "project_memory_combo";
71
	
72
	private static final String EXT_PT = "codeGeneration";
73
	
74
	private Button _overwriteButton;
75
76
	private Combo _projectNameField;
77
78
	private String _userPath = Util.ZERO_LENGTH_STRING;// IDEResourceInfoUtils.EMPTY_STRING;
79
80
	private Button _useDefaultsButton;
81
82
	private Label _locationLabel;
83
84
	private Text _locationPathField;
85
86
	private Button _browseButton;
87
88
	private IProject _existingProject;
89
	
90
	private Combo _projectizerCombo;
91
92
	private Button _persistExtraArtifactsButton;
93
			
94
	private Map _platformContainerMap = new HashMap();
95
96
	private Combo _containerCombo;
97
98
	private Label _containerLabel;
99
100
	private Listener _containerComboListener = new Listener() {
101
102
		public void handleEvent(Event event) {
103
			dialogChanged();
104
		}
105
		
106
	};
107
108
	public GenerationOptionsPage() {
109
		super("wizardPage");
110
		setTitle(Messages.HOOKUP_WIZARD_TXT1);
111
		setDescription(Messages.HOOKUP_WIZARD_TXT2);
112
		
113
		loadExtensionData();
114
		setPageComplete(false);
115
	}
116
	
117
	private void loadExtensionData() {
118
		IExtensionRegistry er = Platform.getExtensionRegistry();
119
		IExtensionPoint ep = er.getExtensionPoint(Activator.PLUGIN_ID, EXT_PT);
120
		IExtension[] extensions = ep.getExtensions();
121
122
		for (int i = 0; i < extensions.length; i++) {	
123
			IConfigurationElement[] elements = extensions[i].getConfigurationElements();			
124
			CodeGenerationData codeGenData = new CodeGenerationData(elements);
125
			updatePlatformContainerMap(codeGenData);	
126
		}
127
	}
128
129
	private void updatePlatformContainerMap(CodeGenerationData codeGenData) {
130
		Map containerCodeGenDataMap = (Map) _platformContainerMap.get(codeGenData.getPlatform());
131
		if(containerCodeGenDataMap == null) {					
132
			//
133
			// handles the case of proxy which doesn't have a container
134
			//
135
			if(codeGenData.getContainer() == null) {			
136
				containerCodeGenDataMap = new SingleValueMap();
137
			} else {
138
				containerCodeGenDataMap = new HashMap();
139
			}
140
			
141
			_platformContainerMap.put(codeGenData.getPlatform(), containerCodeGenDataMap);
142
		}
143
144
		//
145
		// if the platform was null then it means we're using a
146
		// singlevaluemap which doesn't look at the key ever
147
		//
148
		containerCodeGenDataMap.put(codeGenData.getContainer(), codeGenData);
149
	}
150
151
	public void createControl(Composite parent) {
152
		setControl(doLayout(parent));
153
	}
154
155
	private Composite doLayout(Composite parent) {
156
		Composite container = new Composite(parent, SWT.NULL);
157
		container.setLayout(new GridLayout(2, false));	
158
		
159
		GridData data = new GridData();
160
		data.horizontalAlignment = SWT.FILL;
161
		data.grabExcessHorizontalSpace = true;
162
		container.setLayoutData(data);
163
								
164
		createProjectInput(container);
165
		
166
		Composite composite = createProjectTypeGroup(container);
167
		
168
		data = new GridData();
169
		data.grabExcessHorizontalSpace = true;
170
		data.horizontalAlignment = SWT.FILL;
171
		data.horizontalSpan = 2;
172
		composite.setLayoutData(data);
173
				
174
		composite = createProjectOptionsGroup(container);
175
		
176
		data = new GridData();
177
		data.grabExcessHorizontalSpace = true;
178
		data.horizontalAlignment = SWT.FILL;
179
		data.horizontalSpan = 2;
180
		composite.setLayoutData(data);
181
		return container;
182
	}
183
184
	private void createProjectInput(Composite parent) {
185
		Label projectNameLabel = new Label(parent, SWT.NONE);
186
		projectNameLabel.setText(Messages.HOOKUP_WIZARD_TXT4);
187
188
		GridData data = new GridData();		
189
		data.horizontalAlignment = SWT.FILL;
190
		data.grabExcessHorizontalSpace = false;	
191
		projectNameLabel.setLayoutData(data);
192
		
193
		_projectNameField = MemoryComboBox.createMemoryComboBox(parent, Preferences.userNodeForPackage(GenerationOptionsPage.class), PROJECT_MEMORY_COMBO_ID);				
194
		
195
		data = new GridData();		
196
		data.horizontalAlignment = SWT.FILL;
197
		data.grabExcessHorizontalSpace = true;
198
		_projectNameField.setLayoutData(data);	
199
		
200
		_projectNameField.addListener(SWT.Modify, nameModifyListener);
201
	}
202
	
203
	private Group createProjectTypeGroup(Composite parent) {
204
		Group page = new Group(parent, SWT.SHADOW_IN);
205
		page.setText("Code Generation Options");
206
		page.setLayout(new GridLayout(2, false));
207
208
		Label platformLabel = new Label(page, SWT.NONE);
209
		platformLabel.setText("Platform:");//TODO AME
210
		_projectizerCombo = makePlatformCombo(page);
211
		
212
		_containerLabel = new Label(page, SWT.NONE);
213
		_containerLabel.setText("Container:");//TODO AME
214
		_containerLabel.setEnabled(false);
215
		
216
		_containerCombo = makeContainerCombo(page);		
217
		
218
		return page;
219
	}
220
221
	private Group createProjectOptionsGroup(Composite parent) {
222
		Group  group = new Group(parent, SWT.SHADOW_IN);
223
		group.setText("Project Options");
224
		group.setLayout(new GridLayout(3, false));
225
		
226
		_useDefaultsButton = createDefaultsButton(group);
227
		
228
		GridData buttonData = new GridData();
229
		buttonData.horizontalSpan = 3;
230
		_useDefaultsButton.setLayoutData(buttonData);
231
232
		createUserEntryArea(group, true);				
233
		createCheckboxes(group);	
234
	
235
		return group;		
236
	}
237
238
	private Button createDefaultsButton(Composite parent) {
239
		Button button = new Button(parent, SWT.CHECK | SWT.RIGHT);
240
		button.setText(Messages.CODE_GEN_DEFAULT_LOCATION);// IDEWorkbenchMessages.ProjectLocationSelectionDialog_useDefaultLabel);
241
		button.setSelection(true);
242
		
243
		button.addSelectionListener(new SelectionAdapter()
244
		{
245
			public void widgetSelected(SelectionEvent e)
246
			{
247
				boolean useDefaults = _useDefaultsButton.getSelection();
248
249
				if (!useDefaults)
250
				{
251
					_userPath = _locationPathField.getText();
252
					_locationPathField.setText(TextProcessor
253
							.process(getDefaultPathDisplayString()));
254
				}
255
				else
256
				{
257
					_locationPathField
258
							.setText(TextProcessor.process(_userPath));
259
				}
260
				setUserAreaEnabled(!useDefaults);
261
			}
262
		});
263
		
264
		return button;
265
	}
266
267
	private void createCheckboxes(Composite parent) {
268
		GridData data = null;
269
	
270
		_overwriteButton = makeButton(parent, Messages.HOOKUP_WIZARD_TXT3, SWT.CHECK);		
271
		
272
		data = new GridData();
273
		data.horizontalSpan = 2;
274
		_overwriteButton.setLayoutData(data);
275
		
276
		_persistExtraArtifactsButton = makeButton(parent, Messages.HOOKUP_WIZARD_PERSIST, SWT.CHECK);
277
		
278
		data = new GridData();
279
		data.horizontalSpan = 2;
280
		_persistExtraArtifactsButton.setLayoutData(data);
281
	}
282
283
	private Combo makeContainerCombo(Group page) {
284
		Combo combo = new Combo(page, SWT.BORDER | SWT.READ_ONLY);
285
		combo.setEnabled(false);	
286
		
287
		combo.addListener(SWT.Modify, _containerComboListener);
288
		return combo;
289
	}
290
291
	private Combo makePlatformCombo(Group page)
292
	{
293
		Combo combo = new Combo(page, SWT.BORDER | SWT.READ_ONLY);
294
		for(Iterator i=_platformContainerMap.keySet().iterator(); i.hasNext();) {
295
			combo.add(i.next().toString());
296
		}
297
		combo.select(0);		
298
		combo.addListener(SWT.Modify, comboChangeListener);
299
		
300
		return combo;
301
	}
302
303
	private void setUserAreaEnabled(boolean enabled)
304
	{
305
		_locationLabel.setEnabled(enabled);
306
		_locationPathField.setEnabled(enabled);
307
		_browseButton.setEnabled(enabled);
308
	}
309
310
	private void createUserEntryArea(Composite composite, boolean defaultEnabled)
311
	{
312
		GridData data = null;
313
		
314
		// location label
315
		_locationLabel = new Label(composite, SWT.NONE);
316
		_locationLabel.setText(Messages.HOOKUP_WIZARD_TXT6);
317
318
		// project location entry field
319
		_locationPathField = new Text(composite, SWT.BORDER);
320
		data = new GridData(GridData.FILL_HORIZONTAL);
321
		_locationPathField.setLayoutData(data);
322
323
		// browse button
324
		_browseButton = new Button(composite, SWT.PUSH);
325
		_browseButton.setText(Messages.HOOKUP_WIZARD_TXT5);
326
		_browseButton.addSelectionListener(new SelectionAdapter()
327
		{
328
			public void widgetSelected(SelectionEvent event)
329
			{
330
				handleLocationBrowseButtonPressed();
331
			}
332
		});
333
334
		if (defaultEnabled)
335
		{
336
			_locationPathField.setText(TextProcessor
337
					.process(getDefaultPathDisplayString()));
338
		}
339
		else
340
		{
341
			if (_existingProject == null)
342
			{
343
				_locationPathField.setText(Util.ZERO_LENGTH_STRING);// IDEResourceInfoUtils.EMPTY_STRING);
344
			}
345
			else
346
			{
347
				_locationPathField.setText(TextProcessor
348
						.process(_existingProject.getLocation().toString()));
349
			}
350
		}
351
352
		_locationPathField.addModifyListener(new ModifyListener()
353
		{
354
			public void modifyText(ModifyEvent e)
355
			{
356
				setErrorMessage(checkValidLocation());
357
			}
358
		});
359
		
360
		setUserAreaEnabled(false);
361
	}
362
363
	public boolean isDefault()
364
	{
365
		return _useDefaultsButton.getSelection();
366
	}
367
368
	public String getProjectLocation()
369
	{
370
		if(isDefault()) {
371
			return null;
372
		}
373
		
374
		String projectLocation = _locationPathField.getText();		
375
		return projectLocation.length() == 0?null:projectLocation;
376
	}
377
378
	public String checkValidLocation()
379
	{
380
381
		if (isDefault())
382
		{
383
			return null;
384
		}
385
386
		String newPath = getProjectLocation();
387
		if (newPath == null)
388
		{
389
			return Messages.CODE_GEN_LOCATION_ERROR_;
390
		}
391
392
		if (_existingProject == null)
393
		{
394
			IPath projectPath = new Path(newPath);
395
			if (Platform.getLocation().isPrefixOf(projectPath))
396
			{
397
				return Messages.NEW_PROJECT_CREATION_PAGE_DEFAULT_LOCATION_ERROR_;
398
			}
399
400
		}
401
		else
402
		{
403
			
404
			IStatus locationStatus = _existingProject.getWorkspace()
405
					.validateProjectLocationURI(_existingProject, URIUtil.toURI(newPath));
406
407
			if (!locationStatus.isOK())
408
			{
409
				return locationStatus.getMessage();
410
			}
411
412
			java.net.URI projectPath = _existingProject.getLocationURI();
413
			if (projectPath != null && URIUtil.equals(projectPath, URIUtil.toURI(newPath)))
414
			{
415
				return Messages.CODE_GEN_LOCATION_ERROR_;
416
			}
417
		}
418
419
		return null;
420
	}
421
422
	private String getDefaultPathDisplayString()
423
	{
424
425
		java.net.URI defaultURI = null;
426
		if (_existingProject != null)
427
		{
428
			defaultURI = _existingProject.getLocationURI();
429
		}
430
431
		// Handle files specially. Assume a file if there is no project to query
432
		if (defaultURI == null || defaultURI.getScheme().equals("file"))
433
		{
434
			return Platform.getLocation().append(_projectNameField.getText())
435
					.toString();
436
		}
437
		return defaultURI.toString();
438
439
	}
440
441
	private String getPathFromLocationField()
442
	{
443
		java.net.URI fieldURI;
444
		try
445
		{
446
			fieldURI = new java.net.URI(_locationPathField.getText());
447
		}
448
		catch (java.net.URISyntaxException e)
449
		{
450
			return _locationPathField.getText();
451
		}
452
		return fieldURI.getPath();
453
	}
454
455
	private void updateLocationField(String selectedPath)
456
	{
457
		_locationPathField.setText(TextProcessor.process(selectedPath));
458
	}
459
460
	private void handleLocationBrowseButtonPressed()
461
	{
462
463
		String selectedDirectory = null;
464
		String dirName = getPathFromLocationField();
465
466
		DirectoryDialog dialog = new DirectoryDialog(_locationPathField
467
				.getShell());
468
		dialog.setMessage(Messages.CODE_GEN_DIR_LOCATION);// IDEWorkbenchMessages.ProjectLocationSelectionDialog_directoryLabel);
469
		dialog.setFilterPath(dirName);
470
		selectedDirectory = dialog.open();
471
472
		if (selectedDirectory != null)
473
			updateLocationField(selectedDirectory);
474
	}
475
476
	private Listener nameModifyListener = new Listener()
477
	{
478
		public void handleEvent(Event e)
479
		{
480
			dialogChanged();
481
		}
482
	};
483
484
	private Listener comboChangeListener = new Listener() {
485
		public void handleEvent(Event e) {
486
			String platform = _projectizerCombo.getText();
487
			
488
			Map containerCodeGenDataMap = (Map) _platformContainerMap.get(platform);
489
			_containerCombo.removeListener(SWT.Modify, _containerComboListener);
490
			_containerCombo.removeAll();
491
			
492
			boolean hasContainers = containerCodeGenDataMap.size() != 0;
493
			
494
			if(hasContainers) {
495
				for(Iterator i=containerCodeGenDataMap.keySet().iterator(); i.hasNext();) {
496
					_containerCombo.add(i.next().toString());
497
				}
498
				_containerCombo.select(0);
499
			}
500
			
501
			_containerCombo.addListener(SWT.Modify, _containerComboListener);
502
			_containerCombo.setEnabled(hasContainers);
503
			_containerLabel.setEnabled(hasContainers);
504
505
		   	dialogChanged();
506
		}
507
	};
508
509
	private TargetedFileList[] _filesToCopy;
510
	
511
	protected void dialogChanged()
512
	{
513
		String prjName = getProjectName();
514
515
		if (prjName.length() == 0)
516
		{
517
			updateStatus(Messages.HOOKUP_WIZARD_ERROR_1);
518
			return;
519
		}
520
521
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
522
		IWorkspaceRoot root = workspace.getRoot();
523
524
		IProject project = root.getProject(prjName);
525
526
		if (project != null && project.exists())
527
		{
528
			updateStatus(Messages.PROJECT_EXISTS_WARN_, DialogPage.WARNING);
529
			return;
530
		}
531
532
		if (!Validation.isQName(prjName))
533
		{
534
			updateStatus(Messages.HOOKUP_WIZARD_ERROR_2);
535
			return;
536
		}
537
		
538
		updateStatus(null, DialogPage.NONE);
539
	}
540
541
	private void updateStatus(String message)
542
	{
543
		updateStatus(message, DialogPage.ERROR);
544
	}
545
546
	private void updateStatus(String message, int type)
547
	{
548
		setMessage(message, type);
549
		setPageComplete(type != DialogPage.ERROR);
550
	}
551
552
	private Button makeButton(Composite parent, String title, int style)
553
	{
554
		Button b = new Button(parent, style);
555
		b.setText(title);
556
		return b;
557
	}
558
559
	public boolean shouldPersistArtifacts()
560
	{
561
		return _persistExtraArtifactsButton.getSelection();
562
	}
563
564
	/**
565
	 * Return the value of the output project
566
	 * @return String
567
	 */
568
	public String getProjectName()
569
	{
570
		return _projectNameField.getText();
571
	}
572
573
	/**
574
	 * Returns if Overwrite button is enabled
575
	 * @return boolean
576
	 */
577
	public boolean canOverwrite()
578
	{
579
		return _overwriteButton.getSelection();
580
	}
581
	
582
	public CodeGenerationData getSelectedData() {
583
		String platform = _projectizerCombo.getText();
584
		Map containerCodeGenDataMap = (Map) _platformContainerMap.get(platform);
585
		String container = _containerCombo.getText();
586
		return (CodeGenerationData) containerCodeGenDataMap.get(container);
587
	}
588
589
	/**
590
	 * Return the projectizer
591
	 * @return {@link Projectizer}
592
	 */
593
	public Projectizer getProjectizer()
594
	{
595
		return getSelectedData().getProjectizer();
596
	}
597
598
	/**
599
	 * Return the synthesizer
600
	 * @return {@link Synthesizer}
601
	 */
602
	public Synthesizer getSynthesizer()
603
	{
604
		return getSelectedData().getSynthesizer();
605
	}
606
607
	/**
608
	 * Return the analyzer
609
	 * @return {@link Analyzer}
610
	 */
611
	public Analyzer getAnalyzer()
612
	{
613
		return getSelectedData().getAnalyzer();
614
	}
615
616
	/**
617
	 * Returns the base address
618
	 * 
619
	 * @return String
620
	 */
621
	public String getBaseAddress()
622
	{
623
		String baseAddress = "http://localhost";
624
625
		int port = getSelectedData().getServicePort();
626
		if (port != 0)
627
		{
628
			baseAddress += ":" + port;
629
		}
630
631
		baseAddress += "/" + getProjectName();
632
633
		String servicePath = getSelectedData().getServicePath();
634
635
		if (servicePath != null)
636
		{
637
			baseAddress += servicePath;
638
		}
639
		
640
		return baseAddress;
641
	}
642
643
	public boolean canFlipToNextPage() {
644
		return isPageComplete() && isAxis2Project();
645
	}
646
	public boolean isAxis2Project(){
647
		String container = getSelectedData().getContainer();
648
		return container != null && container.equals("Axis2");
649
	}	
650
	
651
	public void saveCombo() {
652
		MemoryComboBox.save(_projectNameField, PROJECT_MEMORY_COMBO_ID, Preferences.userNodeForPackage(GenerationOptionsPage.class));
653
	}
654
	
655
	private String validateLocation()
656
	{
657
		String serverHome = getPreferenceServerLocation();
658
		
659
		ISoapServerDependency axisValidators[] = ValidationUtils.getAllAxisValidators();
660
		for(int i = 0 ; i < axisValidators.length ; i++){
661
			
662
			ISoapServerDependency axis2Dependency = (Axis2ServerDependency)axisValidators[i];
663
			String errorMessage = axis2Dependency.validateSoapServerHome(serverHome);
664
			if(errorMessage!=null)
665
				return errorMessage;
666
			_filesToCopy = axis2Dependency.getFilesToCopy();
667
			if(_filesToCopy == null)
668
				_filesToCopy = new TargetedFileList[0];
669
		}
670
		return null;		
671
	}
672
	
673
	/**
674
	 * Returns the Axis2 files to copied to generated code
675
	 * @return
676
	 */
677
	public TargetedFileList[] getAxis2FilesToCopy()
678
	{
679
		validateLocation();
680
		return _filesToCopy;
681
	}
682
	
683
	protected String getPreferenceServerLocation() 
684
	{
685
		IPreferenceStore store = Activator.getPlugin().getPreferenceStore();
686
		String location = store.getString(Axis2ServerLocationPreferencePage.SERVER_LOCATION_PREFERENCE_KEY).trim();
687
		if(location != null && !location.equals(""))
688
			return location;
689
		return "";
690
	}
691
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/Axis2ServerDependency.java (+158 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.File;
16
import java.io.FileFilter;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
22
23
/**
24
 * This class verifies the Axis2 Soap Library dependency. 
25
 */
26
27
public class Axis2ServerDependency extends SoapServerDependency implements ISoapServerDependency
28
{
29
	private List _filesToCopy = new LinkedList();
30
	
31
	/**
32
	 * @see ISoapServerDependency#validateSoapServerHome(String)
33
	 */
34
	public String validateSoapServerHome(String serverHome)
35
	{
36
		if(serverHome == null || serverHome.length() == 0)
37
			return Messages.CODE_GEN_AXIS2_PROJECT_DIR;
38
		
39
		File serverHomeDir = new File(serverHome);
40
		if(!serverHomeDir.exists()){
41
			return NLS.bind(Messages.CODE_GEN_AXIS2_LOCATION_ERROR_, serverHome);
42
		}
43
		
44
		TargetedFileList _jarFilesToCopy = new TargetedFileList("WEB-INF/lib/");
45
		TargetedFileList _marFilesToCopy = new TargetedFileList("WEB-INF/modules/");
46
		TargetedFileList _restFilesToCopy = new TargetedFileList("WEB-INF/");
47
		
48
		String[] relativeFilePaths = (String[]) _requiredFiles.toArray(new String[_requiredFiles.size()]);
49
		for(int i=0;i<relativeFilePaths.length;i++)
50
		{
51
			String parentDirectory = getParentDirectory(relativeFilePaths[i]);
52
			if(parentDirectory == null)
53
				parentDirectory = serverHome;
54
			else
55
				parentDirectory = serverHome+File.separatorChar+parentDirectory;
56
			
57
			String fileExtension = getFileExtension(relativeFilePaths[i]);
58
			if(fileExtension == null)
59
				fileExtension = "*";
60
			FileFilter filter = new CustomFileFilter(fileExtension);
61
			
62
			File parentDirectoryFile = new File(parentDirectory);
63
			if(!parentDirectoryFile.exists())
64
				return NLS.bind(Messages.CODE_GEN_AXIS2_LOCATION_ERROR_, parentDirectory);
65
			
66
			File[] allFiles = parentDirectoryFile.listFiles(filter);
67
			String fileName = getFileName(relativeFilePaths[i]);
68
			File matchedFile = getMatchedPatternFile(allFiles, fileName);
69
			if(matchedFile == null)
70
				return NLS.bind(Messages.CODE_GEN_ERROR_INVALID_AXIS_FILE, serverHome+File.separatorChar+relativeFilePaths[i]);
71
						
72
			String absolutePath = matchedFile.getAbsolutePath();
73
			if(absolutePath.endsWith("jar"))
74
				_jarFilesToCopy.add(absolutePath);
75
			else if(absolutePath.endsWith("mar"))
76
				_marFilesToCopy.add(absolutePath);
77
			else
78
				_restFilesToCopy.add(absolutePath);
79
		}
80
		
81
		_filesToCopy.add(_jarFilesToCopy);
82
		_filesToCopy.add(_marFilesToCopy);
83
		_filesToCopy.add(_restFilesToCopy);
84
		
85
		return null;
86
	}
87
	
88
	private String getParentDirectory(String relativePath)
89
	{
90
		if(relativePath.indexOf('/')==-1)
91
			return null;
92
		return relativePath.substring(0,relativePath.lastIndexOf('/'));		
93
	}
94
	
95
	private String getFileExtension(String relativePath)
96
	{
97
		if(relativePath.indexOf('.')==-1)
98
			return null;
99
		return relativePath.substring(relativePath.lastIndexOf('.')+1);
100
	}
101
	
102
	private String getFileName(String relativePath)
103
	{
104
		if(relativePath.indexOf('/')==-1)
105
		{
106
			if(relativePath.indexOf('.')==-1)
107
				return relativePath;
108
			else
109
				return relativePath.substring(0,relativePath.lastIndexOf('.'));
110
		}
111
		else
112
		{
113
			String fileNameWithExtn = relativePath.substring(relativePath.lastIndexOf('/')+1);
114
			if(fileNameWithExtn.indexOf('.')==-1)
115
				return fileNameWithExtn;
116
			else
117
				return fileNameWithExtn.substring(0,fileNameWithExtn.lastIndexOf('.'));
118
		}
119
	}
120
	
121
	private File getMatchedPatternFile(File[] allFiles, String pattern)
122
	{
123
		String strippedPattern = pattern.indexOf("-*")==-1?pattern:pattern.substring(0,pattern.lastIndexOf("-*"));
124
		for(int i=0;i<allFiles.length;i++)
125
		{
126
			if(allFiles[i].getName().startsWith(strippedPattern))
127
				return allFiles[i];
128
		}
129
		return null;
130
	}
131
132
	/**
133
	 * @see ISoapServerDependency#getFilesToCopy()
134
	 */
135
	public TargetedFileList[] getFilesToCopy()
136
	{
137
		return (TargetedFileList[])_filesToCopy.toArray(new TargetedFileList[_filesToCopy.size()]);
138
	}	
139
}
140
141
class CustomFileFilter implements FileFilter
142
{
143
	String fileExtension;
144
	
145
	CustomFileFilter(String extension)
146
	{
147
		fileExtension = extension;
148
	}
149
	
150
	public boolean accept(File pathname) 
151
	{
152
		if(!pathname.isFile())
153
			return false;
154
		if(fileExtension.equals("*"))
155
			return true;
156
		return pathname.getName().endsWith(fileExtension);		
157
 	}	
158
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/EclipseConfigurationData.java (+22 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
13
14
public class EclipseConfigurationData
15
{
16
	public static final String ADDITIONAL_JARS = "jars";
17
	public static final String INSTANCES = "instances";
18
	public static final String PROGRESS_MONITOR = "progress_monitor";
19
	public static final String AXIS2_FILES = "axis2_files";
20
	public static final String PROJECT_LOCATION = "location";
21
	public static final String PROJECT_NAME = "project_name";
22
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/MRTCodeGenerationDelegate.java (+156 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.ByteArrayInputStream;
16
import java.io.ByteArrayOutputStream;
17
import java.io.IOException;
18
import java.util.HashMap;
19
import java.util.Map;
20
21
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
22
import org.apache.ws.muse.descriptor.DescriptorFactory;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
24
import org.apache.ws.muse.descriptor.ResourceTypeType;
25
import org.apache.ws.muse.descriptor.WsdlType;
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.SubProgressMonitor;
29
import org.eclipse.emf.common.util.URI;
30
import org.eclipse.emf.ecore.resource.Resource;
31
import org.eclipse.emf.ecore.resource.ResourceSet;
32
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
33
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
34
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
35
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
36
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
37
38
/**
39
 * This class acts as a way during the Code Generation of MRT to capture doing WSDL 
40
 * resolution so that it can be done later on, or on
41
 * another thread since this would be time-consuming.
42
 */
43
public class MRTCodeGenerationDelegate implements CodeGenerationDelegate
44
{
45
	private ManageableResourceType _mrt;
46
	private MrtPreProcessor _mrtPreProcessor;
47
	private String _ddFilePath;
48
	private IFile _mrtFile;
49
	private DocumentRoot _ddRoot;
50
	
51
	/**
52
	 * Constructor of the class
53
	 * @param mrtFile
54
	 */
55
	public MRTCodeGenerationDelegate(IFile mrtFile)
56
	{
57
		_mrtFile = mrtFile;
58
		URI mrtURI = URI.createPlatformResourceURI(mrtFile.getFullPath()
59
				.toString());
60
		_mrt = MrtUtils.loadMRT(mrtURI);
61
		_mrtPreProcessor = new MrtPreProcessor(_mrt);
62
	}
63
64
	/**
65
	 * Creates the DD file. 
66
	 * The method returns a DescriptorHelper which
67
	 * aggregates all of the work that was done.
68
	 * 
69
	 * @param progressMonitor 	A progress monitor to 
70
	 * 							show the progress done during this 
71
	 * 							task. 
72
	 * @throws Exception
73
	 */
74
	public DescriptorHelper run(SubProgressMonitor progressMonitor)
75
			throws Exception
76
	{
77
		byte[] serializedDD = createDD();
78
		Map mrtObjectMap = _mrtPreProcessor.getMrtObjectMap();
79
		return new DescriptorHelper(this, new ByteArrayInputStream(serializedDD), mrtObjectMap, false);
80
	}
81
	
82
	private byte[] createDD()
83
	{
84
		_mrtPreProcessor.preProcess();
85
		_ddRoot = _mrtPreProcessor.getDDDocumentRoot();
86
		ResourceSet resourceSet = new ResourceSetImpl();
87
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
88
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
89
				new MyDescriptorResourceFactoryImpl());
90
		URI uri = URI.createURI("dummy.xml");
91
		Resource resource = resourceSet.createResource(uri);
92
		resource.getContents().add(_ddRoot);
93
		Map map = new HashMap();
94
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
95
		try 
96
		{
97
			resource.save(baos, map);
98
		} 
99
		catch (IOException e) 
100
		{
101
			e.printStackTrace();
102
		}
103
		return baos.toByteArray();
104
	}
105
	
106
	private String createDDFilePath()
107
	{
108
		IPath ddIPath = _mrtFile.getFullPath().removeFileExtension()
109
				.addFileExtension("dd");
110
		return ddIPath.toString();
111
	}
112
113
	/**
114
	 * Create and return a new instance of given ResourceTypeType. Only
115
	 * ContextPath, JavaIdFactoryClass, JavaResourceClass and WsdlType fields
116
	 * have been copied.
117
	 */
118
	public static ResourceTypeType cloneResourceType(ResourceTypeType rt)
119
	{
120
		ResourceTypeType clone = DescriptorFactory.eINSTANCE
121
				.createResourceTypeType();
122
		clone.setContextPath(rt.getContextPath());
123
		clone.setJavaIdFactoryClass(rt.getJavaIdFactoryClass());
124
		clone.setJavaResourceClass(rt.getJavaResourceClass());
125
		WsdlType wClone = DescriptorFactory.eINSTANCE.createWsdlType();
126
		wClone.setWsdlFile(rt.getWsdl().getWsdlFile());
127
		wClone.setWsdlPortType(rt.getWsdl().getWsdlPortType());
128
		clone.setWsdl(wClone);
129
		return clone;
130
	}
131
132
	/**
133
	 * This method will persist the extra artifacts generated at codegen time.
134
	 */
135
	public void persistArtifacts() 
136
	{
137
		_mrtPreProcessor.persistArtifacts();
138
		persistDDFile();		
139
	}
140
	
141
	private void persistDDFile()
142
	{
143
		_ddFilePath = createDDFilePath();
144
		DdeUtil.serializeDescriptorRoot(_ddRoot, URI.createPlatformResourceURI(_ddFilePath));
145
	}
146
147
	/**
148
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
149
	 * merged RMD document for it by having the rules/relationships in it. 
150
	 */
151
	public void inspectMetadata(ManageableResourceType mrt,
152
			MetadataDescriptor metadata) 
153
	{
154
		_mrtPreProcessor.inspectMetadata(mrt, metadata);		
155
	}
156
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/NewProjectWizard.java (+320 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.File;
16
import java.lang.reflect.InvocationTargetException;
17
18
import org.apache.muse.tools.generator.analyzer.Analyzer;
19
import org.apache.muse.tools.generator.analyzer.SimpleAnalyzer;
20
import org.apache.muse.tools.generator.projectizer.Projectizer;
21
import org.apache.muse.tools.generator.synthesizer.ServerSynthesizer;
22
import org.apache.muse.tools.generator.synthesizer.Synthesizer;
23
import org.apache.muse.tools.generator.util.ConfigurationData;
24
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
25
import org.eclipse.core.filesystem.URIUtil;
26
import org.eclipse.core.resources.IWorkspaceRoot;
27
import org.eclipse.core.resources.ResourcesPlugin;
28
import org.eclipse.core.runtime.ILog;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.SubProgressMonitor;
32
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
33
import org.eclipse.jface.operation.IRunnableWithProgress;
34
import org.eclipse.jface.preference.IPreferenceStore;
35
import org.eclipse.jface.resource.ImageDescriptor;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.wizard.Wizard;
38
import org.eclipse.swt.graphics.Image;
39
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
40
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
41
import org.eclipse.tptp.wsdm.tooling.preferences.internal.Axis2ServerLocationPreferencePage;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
44
import org.eclipse.ui.INewWizard;
45
import org.eclipse.ui.IWorkbench;
46
import org.eclipse.ui.IWorkbenchPage;
47
import org.eclipse.ui.PartInitException;
48
import org.eclipse.ui.PlatformUI;
49
import org.eclipse.ui.part.ViewPart;
50
import org.w3c.dom.Document;
51
52
/**
53
 * This wizard accepts projectizer parameters, runtime environment and other
54
 * general parameters from the user so as to invoke Wsdl2Java
55
 */
56
public class NewProjectWizard extends Wizard implements INewWizard {
57
58
	private static ILog LOG = null;
59
60
	// We can't use internal classes, hence using view ID directly
61
	private static String TASK_VIEW_ID = "org.eclipse.ui.views.TaskList";
62
63
	private static String PLUGIN_ID = "org.eclipse.tptp.wsdm.tooling.editor.mrt";
64
65
	private GenerationOptionsPage _generationOptionsPage;
66
67
	private String _projectName;
68
69
	private boolean _overwrite;
70
71
	private boolean _shouldPersistArtifacts;
72
73
	private Projectizer _projectizer;
74
75
	private Synthesizer _synthesizer;
76
77
	private Analyzer _analyzer;
78
79
	private String _baseAddress;
80
81
	private CodeGenerationDelegate _codeGenerationDelegate;
82
83
	private Document[] _mergedWsdlDocuments;
84
85
	private MetadataDescriptor[] _mergedRMDs;
86
87
	private DescriptorHelper _helper;
88
89
	private String _serverLocation;
90
91
	private boolean _isAxis2Project;
92
	private boolean updatePreference;
93
94
	private String _projectLocation;
95
96
	private TargetedFileList[] _requiredAxis2Files;
97
98
	private boolean _licenseAccepted = false;
99
100
	/**
101
	 * Class that creates the Code Generation Wizard to create new Project
102
	 * 
103
	 * @param codeGenerationDelegate
104
	 */
105
	public NewProjectWizard(CodeGenerationDelegate codeGenerationDelegate) {
106
		setWindowTitle(Messages.HOOKUP_WIZARD_TXT7);
107
		setNeedsProgressMonitor(true);
108
109
		_codeGenerationDelegate = codeGenerationDelegate;
110
	}
111
112
	public void addPages() {
113
		_generationOptionsPage = new GenerationOptionsPage();
114
		addPage(_generationOptionsPage);
115
116
		// TODO AME why is this hardcoded here? why is it getting reloaded?
117
		Image imgTP = EclipseUtils.loadImage(PlatformUI.getWorkbench().getDisplay(),
118
				"icons/wizban/newEndpointProject_wiz.gif");
119
		ImageDescriptor imgDescrTP = ExtendedImageRegistry.INSTANCE.getImageDescriptor(imgTP);
120
		setDefaultPageImageDescriptor(imgDescrTP);
121
	}
122
123
	private void popupAxis2LicenseDialog() {
124
		IPreferenceStore store = Activator.getPlugin().getPreferenceStore();
125
		String preferencesLocation = store.getString(Axis2ServerLocationPreferencePage.SERVER_LOCATION_PREFERENCE_KEY);
126
		if (!_serverLocation.equals(preferencesLocation)) {
127
			int result = new Axis2LicenseDialog().showWindow();
128
			_licenseAccepted = (result == Axis2LicenseDialog.AGREE);
129
		} else
130
			_licenseAccepted = true;
131
132
	}
133
134
	private void performFinish(IProgressMonitor monitor) throws InvocationTargetException {
135
		try {
136
			monitor.beginTask(Messages.CODE_GEN_START, 7);
137
138
			if (_isAxis2Project) {
139
				try {
140
					// Step 1: Validate the server path
141
					monitor.subTask(Messages.CODE_GEN_VALIDATE_SLOCATION);
142
					// Step 2 : Update the Preferences, if needed
143
					if (updatePreference) {
144
						IPreferenceStore store = Activator.getPlugin().getPreferenceStore();
145
						store.setValue(Axis2ServerLocationPreferencePage.SERVER_LOCATION_PREFERENCE_KEY,
146
								_serverLocation);
147
						// Update the Lib and module location
148
					}
149
					_requiredAxis2Files = _generationOptionsPage.getAxis2FilesToCopy();
150
				} catch (Exception e) {
151
					throw new RuntimeException(e);
152
				}
153
			}
154
			try {
155
				monitor.subTask(Messages.CODE_GEN_STEP1);
156
				_helper = _codeGenerationDelegate.run(new SubProgressMonitor(monitor, 1));
157
158
				monitor.worked(1);
159
			} catch (Exception e) {
160
				throw new RuntimeException(e);
161
				// TODO AME Why is this not defined?
162
				// throw new InvocationTargetException(new
163
				// Exception(Messages.HOOKUP_WIZARD_ERROR4, e));
164
			}
165
166
			try {
167
				monitor.subTask(Messages.CODE_GEN_STEP2);
168
				_mergedWsdlDocuments = _helper.getWsdlDocuments(_baseAddress);
169
				_mergedRMDs = _helper.getMergedRMDs();
170
				monitor.worked(1);
171
			} catch (Exception e) {
172
				e.printStackTrace();
173
				throw new RuntimeException(e);
174
			}
175
176
			try {
177
				monitor.subTask(Messages.CODE_GEN_STEP3);
178
				runProjectizer(monitor);
179
				monitor.worked(1);
180
			} catch (Exception e) {
181
				throw new InvocationTargetException(new Exception(Messages.CODE_GEN_FAILED_ERROR_, e));
182
			}
183
184
			if (_shouldPersistArtifacts) {
185
				monitor.subTask(Messages.CODE_GEN_STEP4);
186
				_codeGenerationDelegate.persistArtifacts();
187
				monitor.worked(1);
188
			}
189
		} finally {
190
			monitor.done();
191
		}
192
	}
193
194
	/*
195
	 * (non-Javadoc)
196
	 * 
197
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
198
	 */
199
	public boolean performFinish() {
200
		_projectizer = _generationOptionsPage.getProjectizer();
201
		_synthesizer = _generationOptionsPage.getSynthesizer();
202
		_analyzer = _generationOptionsPage.getAnalyzer();
203
		_overwrite = _generationOptionsPage.canOverwrite();
204
		_shouldPersistArtifacts = _generationOptionsPage.shouldPersistArtifacts();
205
		_projectName = _generationOptionsPage.getProjectName();
206
		_baseAddress = _generationOptionsPage.getBaseAddress();
207
		_isAxis2Project = _generationOptionsPage.isAxis2Project();
208
		_projectName = _generationOptionsPage.getProjectName();
209
		_projectLocation = _generationOptionsPage.getProjectLocation();
210
211
		if (_isAxis2Project) {
212
			_serverLocation = _generationOptionsPage.getPreferenceServerLocation();
213
		}
214
215
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
216
			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
217
				performFinish(monitor);
218
			}
219
		};
220
		
221
		_generationOptionsPage.saveCombo();
222
223
		try {
224
			getContainer().run(true, false, runnable);
225
			openTasksView();
226
			
227
			return true;
228
		} catch (Exception e) {
229
			e.printStackTrace();
230
			handle(Messages.CODE_GEN_FAILED_ERROR_, e);
231
		}
232
233
		return false;
234
	}
235
236
	/*
237
	 * (non-Javadoc)
238
	 * 
239
	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
240
	 *      org.eclipse.jface.viewers.IStructuredSelection)
241
	 */
242
	public void init(IWorkbench workbench, IStructuredSelection selection) {
243
		// do nothing
244
	}
245
246
	private void runProjectizer(IProgressMonitor monitor) throws Exception {
247
		ConfigurationData data = new ConfigurationData();
248
249
		data.addParameter(EclipseConfigurationData.AXIS2_FILES, _requiredAxis2Files);
250
251
		data.addParameter(ConfigurationData.DESCRIPTOR_DOCUMENT, _helper.getDescriptorDocument());
252
		data.addParameter(EclipseConfigurationData.ADDITIONAL_JARS, _helper.getJarFiles());
253
		data.addParameter(EclipseConfigurationData.INSTANCES, _helper.getInstances());
254
		data.addParameter(EclipseConfigurationData.PROJECT_NAME, _projectName);
255
		data.addParameter(ConfigurationData.OVERWRITE, Boolean.valueOf(_overwrite));
256
		data.addParameter(EclipseConfigurationData.PROJECT_LOCATION, _projectLocation);
257
		data.addParameter(ConfigurationData.WSDL_DOCUMENT_LIST, _mergedWsdlDocuments);
258
		data.addParameter(ConfigurationData.METADATA_DESCRIPTOR_LIST, _mergedRMDs);
259
		data.addParameter(ConfigurationData.GENERATE_CUSTOM_HEADERS, Boolean.FALSE);
260
261
		// check if the analyzer is null, if it is then default to the
262
		// SimpleAnalyzer
263
		if (_analyzer == null) {
264
			_analyzer = new SimpleAnalyzer();
265
		}
266
267
		// check if the synthesizer is null, if it is then default to the
268
		// ServerSynthesizer
269
		if (_synthesizer == null) {
270
			_synthesizer = new ServerSynthesizer();
271
		}
272
273
		// Below, we make a new SubProgressMonitor for
274
		// each codegeneration component since we can't reuse the progress
275
		// monitor
276
277
		data.addParameter(EclipseConfigurationData.PROGRESS_MONITOR, new SubProgressMonitor(monitor, 1));
278
279
		monitor.subTask(Messages.CODE_GEN_SUBTASK1);
280
		data = _analyzer.analyze(data);
281
		monitor.worked(1);
282
283
		data.addParameter(EclipseConfigurationData.PROGRESS_MONITOR, new SubProgressMonitor(monitor, 1));
284
285
		monitor.subTask(Messages.CODE_GEN_SUBTASK2);
286
		data = _synthesizer.synthesize(data);
287
		monitor.worked(1);
288
289
		data.addParameter(EclipseConfigurationData.PROGRESS_MONITOR, new SubProgressMonitor(monitor, 1));
290
291
		monitor.subTask(Messages.CODE_GEN_SUBTASK3);
292
		_projectizer.projectize(data);
293
		monitor.worked(1);
294
	}
295
296
	private void handle(String message, Exception e) {
297
		_generationOptionsPage.setErrorMessage(message);
298
		WsdmToolingLog.log(IStatus.ERROR, IStatus.OK, message, e);
299
	}
300
	
301
	private void openTasksView() {
302
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
303
		ViewPart view = (ViewPart) page.findView(TASK_VIEW_ID);
304
305
		// If the page isn't showing then show it
306
		if (view == null) {
307
			try {
308
				page.showView(TASK_VIEW_ID);
309
			} catch (PartInitException e) {
310
				WsdmToolingLog.logError(e.getMessage(), e);
311
			}
312
		}else{
313
			page.activate(view);
314
		}
315
	}
316
	
317
	public boolean canFinish() {
318
		return _generationOptionsPage.isPageComplete();
319
	}
320
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/ISoapServerDependency.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import org.eclipse.core.runtime.IExecutableExtension;
16
17
/**
18
 * Interface to represent Soap Library dependency used in Tooling codegeneration. 
19
 */
20
21
public interface ISoapServerDependency extends IExecutableExtension
22
{
23
	/**
24
	 * Returns null if the given Server Home has all the required soap jar files.
25
	 */
26
	String validateSoapServerHome(String serverHome);
27
	
28
	/**
29
	 * Returns the absolute path of all the required soap jar files. 
30
	 */
31
	TargetedFileList[] getFilesToCopy();
32
	
33
	/**
34
	 * Returns the absolute path of the lib folder. 
35
	 */
36
//	String getServerLibLocation(String serverName);
37
	
38
	/**
39
	 * Returns the absolute path of the modules folder. 
40
	 */
41
//	String getServerModulesLocation(String serverName);
42
43
	
44
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/CodeGenerationDelegate.java (+51 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
16
import org.eclipse.core.runtime.SubProgressMonitor;
17
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
18
19
/**
20
 * This class acts as a way to capture doing WSDL resolution (which could
21
 * include WSDL manipulation like merging) so that it can be done later on, or
22
 * on another thread since this would be time-consuming.
23
 */
24
public interface CodeGenerationDelegate
25
{
26
27
	/**
28
	 * Do any work related to code generation. This kind of work is passed to
29
	 * this delegate so that it can be run in a separate thread. This can take a
30
	 * (optional) progress monitor which can be used to report progress done in
31
	 * this task. The method returns a DescriptorHelper which aggregates all of
32
	 * the work that was done.
33
	 * 
34
	 * @param progressMonitor
35
	 *            A progress monitor to show the progress done during this task.
36
	 * 
37
	 * @throws Exception
38
	 */
39
	DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception;
40
	
41
	/**
42
	 * Persist the extra artifacts generated during codegeneration such as SubscriptionManager.mrt etc.
43
	 */
44
	void persistArtifacts();
45
	
46
	/**
47
	 * Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given
48
	 * merged RMD document for it by having the rules/relationships in it. 
49
	 */
50
	void inspectMetadata(ManageableResourceType mrt, MetadataDescriptor metadata);
51
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/CodeGenerationData.java (+105 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: CodeGenerationData.java,v 1.2 2007/05/07 09:15:10 dnsmith Exp $
8
 * 
9
 * Contributors:
10
 * 	Balan Subramanian (bsubram@us.ibm.com)
11
 *     IBM Corporation - initial API and implementation
12
 *******************************************************************************/
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import org.apache.muse.tools.generator.analyzer.Analyzer;
16
import org.apache.muse.tools.generator.projectizer.Projectizer;
17
import org.apache.muse.tools.generator.synthesizer.Synthesizer;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IConfigurationElement;
20
21
class CodeGenerationData {				
22
	private Analyzer _analyzer;
23
	private Synthesizer _synthesizer;
24
	private Projectizer _projectizer;
25
	
26
	private int _servicePort;
27
	private String _servicePath;
28
	private String _container;
29
	private String _platform;
30
	
31
	public CodeGenerationData(IConfigurationElement[] elements) {
32
		for (int i = 0; i < elements.length; i++)
33
		{
34
			String name = elements[i].getName();
35
						
36
			if(name.equals("description")) {
37
				extractDescription(elements[i]);
38
			} else if (name.equals("projectizer")) {
39
				extractProjectizer(elements[i]);
40
			} else if (name.equals("synthesizer")) {
41
				extractSynthesizer(elements[i]);
42
			} else if (name.equals("analyzer")) {
43
				extractAnalyzer(elements[i]);
44
			}
45
		}
46
	}
47
	
48
	private void extractDescription(IConfigurationElement configurationElement) {
49
		_container = configurationElement.getAttribute("container");
50
		_platform = configurationElement.getAttribute("platform");
51
	}
52
	
53
	private void extractProjectizer(IConfigurationElement configurationElement) {
54
		String port = configurationElement.getAttribute("servicePort");
55
		if(port != null && port.length() != 0) {
56
			_servicePort = Integer.parseInt(port);
57
		}
58
		_servicePath = configurationElement.getAttribute("servicePath");
59
		_projectizer = (Projectizer) createExecutable(configurationElement);
60
	}
61
	
62
	private void extractSynthesizer(IConfigurationElement configurationElement) {
63
		_synthesizer = (Synthesizer) createExecutable(configurationElement);			
64
	}
65
	
66
	private void extractAnalyzer(IConfigurationElement configurationElement) {
67
		_analyzer = (Analyzer) createExecutable(configurationElement);
68
	}	
69
	
70
	private Object createExecutable(IConfigurationElement configurationElement) {
71
		try {
72
			return configurationElement.createExecutableExtension("class");
73
		} catch (CoreException e) {
74
			throw new RuntimeException(configurationElement.getAttribute("class"));
75
		}
76
	}
77
	
78
	public Analyzer getAnalyzer() {
79
		return _analyzer;
80
	}
81
82
	public Synthesizer getSynthesizer() {
83
		return _synthesizer;
84
	}
85
86
	public Projectizer getProjectizer() {
87
		return _projectizer;
88
	}
89
90
	public int getServicePort() {
91
		return _servicePort;
92
	}
93
94
	public String getServicePath() {
95
		return _servicePath;
96
	}
97
98
	public String getContainer() {
99
		return _container;
100
	}
101
102
	public String getPlatform() {
103
		return _platform;
104
	}
105
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/DescriptorHelper.java (+588 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.File;
16
import java.io.FileInputStream;
17
import java.io.IOException;
18
import java.io.InputStream;
19
import java.net.URL;
20
import java.util.ArrayList;
21
import java.util.Arrays;
22
import java.util.HashMap;
23
import java.util.LinkedList;
24
import java.util.List;
25
import java.util.Map;
26
27
import javax.xml.namespace.QName;
28
29
import org.apache.muse.core.descriptor.DescriptorConstants;
30
import org.apache.muse.util.xml.XmlUtils;
31
import org.apache.muse.ws.addressing.WsaConstants;
32
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
33
import org.eclipse.core.resources.IFile;
34
import org.eclipse.core.resources.IWorkspace;
35
import org.eclipse.core.resources.IWorkspaceRoot;
36
import org.eclipse.core.resources.ResourcesPlugin;
37
import org.eclipse.core.runtime.FileLocator;
38
import org.eclipse.core.runtime.IPath;
39
import org.eclipse.core.runtime.Path;
40
import org.eclipse.emf.common.util.URI;
41
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
44
import org.w3c.dom.Document;
45
import org.w3c.dom.Element;
46
import org.w3c.dom.NamedNodeMap;
47
import org.w3c.dom.Node;
48
49
/**
50
 * A class that takes some of the pain out of working with the deployment
51
 * descriptor. Note, there's no EMF in this approach, just plain old XML.
52
 */
53
public class DescriptorHelper
54
{
55
56
	/**
57
	 * File Extension of MRT files
58
	 */
59
	private static final String MRT_EXTN = ".mrt";
60
61
	/**
62
	 * Element name constants
63
	 */
64
	public static final QName ADDITIONAL_JARS_QNAME = new QName(
65
			DescriptorConstants.NAMESPACE_URI, "additional-jars");
66
	public static final QName JAR_PATH_QNAME = new QName(
67
			DescriptorConstants.NAMESPACE_URI, "jar-path");
68
	public static final QName INITIAL_INSTANCES_QNAME = new QName(
69
			DescriptorConstants.NAMESPACE_URI, "initial-instances");
70
	public static final QName REFERENCE_PARAMETERS_QNAME = new QName(
71
			DescriptorConstants.NAMESPACE_URI, "referenceParameters");
72
73
	/**
74
	 * Constant for empty files
75
	 */
76
	private static final File[] EMPTY_FILES = new File[0];
77
78
	/**
79
	 * Constant for empty instances.
80
	 */
81
	private static final Object[][] EMPTY_INSTANCES = new Object[0][0];
82
83
	/**
84
	 * Constant for the xmlns prefix on namespace binding declarations
85
	 */
86
	private static final Object XMLNS_PREFIX = "xmlns";
87
88
	/**
89
	 * The descriptor document we pull out of the <code>Root</code> element
90
	 */
91
	private Document _descriptorDocument;
92
93
	/**
94
	 * A list of jar files that we pull out of the
95
	 * <code>Root/additional-jars</code> element
96
	 */
97
	private File[] _jarFiles;
98
99
	/**
100
	 * A list of instances which is really just a n by 2 list of arrays. The
101
	 * sub-arrays have the instance-path (<code>String</code>) as the first
102
	 * element and the reference parameters (<code>Element</code>) as the
103
	 * second element. This is tacky, but otherwise I'd be making a pretty
104
	 * useless "Pair" class.
105
	 */
106
	private Object[][] _instances;
107
	
108
	private IFile ddIFile;
109
	
110
	/**
111
	 * Descriptor file stores the MRT file reference in Wsdl-File element.
112
	 * When we do the codegeneration we generate some extra MRTs such as SubscriptionManager,
113
	 * so we pass the map of these MRTs to this class.
114
	 * Key will be the persisted location of MRT and value will be the ManageableREsourceType object.
115
	 */
116
	private Map _mrtObjectMap = new HashMap();
117
	
118
	private CodeGenerationDelegate _codeGenerationDelegate = null;
119
120
	/**
121
	 * A do-something constructor. Take a file, if that file is null, then load
122
	 * up a default template. Otherwise load up the file and pull out the
123
	 * instances, descriptor and additional jars. For the null file case, there
124
	 * will be no instances of additional-jars, hence the constants defined
125
	 * above.
126
	 * 
127
	 * @param file - The file to analyze, can be null.
128
	 * @throws Exception - If anything goes wrong.
129
	 */
130
	public DescriptorHelper(CodeGenerationDelegate codeGenerationDelegate, IFile descriptorFile) throws Exception
131
	{
132
		this(codeGenerationDelegate, new File(descriptorFile.getLocation().toString()));
133
		ddIFile = descriptorFile;		
134
	}
135
136
	/**
137
	 * A do-something constructor. Take a file, if that file is null, then load
138
	 * up a default template. Otherwise load up the file and pull out the
139
	 * instances, descriptor and additional jars. For the null file case, there
140
	 * will be no instances of additional-jars, hence the constants defined
141
	 * above.
142
	 * 
143
	 * @param file - The file to analyze, can be null.
144
	 * @throws Exception - If anything goes wrong.
145
	 */
146
	public DescriptorHelper(CodeGenerationDelegate codeGenerationDelegate, File file) throws Exception
147
	{
148
		this(codeGenerationDelegate, new FileInputStream(file), null);
149
	}
150
	
151
	/**
152
	 * A do-something constructor. Take a inputstream, if that inputstream is null, then load
153
	 * up a default template. Otherwise load up the inputstream and pull out the
154
	 * instances, descriptor and additional jars. For the null inputstream case, there
155
	 * will be no instances of additional-jars, hence the constants defined
156
	 * above.
157
	 * 
158
	 * @param inputstream - The inputstream to analyze, can be null.
159
	 * @param mrtObjectMap - The map of MRTLocation-MRTObject pair, can be null.
160
	 * @throws Exception - If anything goes wrong.
161
	 */
162
	public DescriptorHelper(CodeGenerationDelegate codeGenerationDelegate, InputStream inputStream, Map mrtObjectMap, boolean extractExtraInfo) throws Exception
163
	{
164
		if(mrtObjectMap!=null)
165
			_mrtObjectMap = mrtObjectMap;
166
		_codeGenerationDelegate = codeGenerationDelegate;
167
		
168
		Document rootDocument = XmlUtils.createDocument(inputStream);
169
170
		_descriptorDocument = extractDescriptorDocument(rootDocument);
171
		
172
		if(extractExtraInfo) {
173
			_instances = extractInstances(rootDocument);
174
			_jarFiles = extractJarFiles(rootDocument);
175
		} else {
176
			_instances = null;
177
			_jarFiles = null;
178
		}
179
		// Add Muse tools.jar
180
		if(_jarFiles == null)
181
			_jarFiles = new File[0];
182
		String toolsJarLocation = getMuseToolsJarLocation();
183
		if(toolsJarLocation == null)
184
			return;
185
		List jars = Arrays.asList(_jarFiles);
186
		List allJars = new ArrayList();
187
		allJars.addAll(jars);		
188
		allJars.add(new File(toolsJarLocation));
189
		_jarFiles = (File[])allJars.toArray(new File[allJars.size()]);		
190
	}
191
	
192
	public DescriptorHelper(CodeGenerationDelegate codeGenerationDelegate, InputStream inputStream, Map mrtObjectMap) throws Exception {
193
		this(codeGenerationDelegate, inputStream, mrtObjectMap, true);
194
	}
195
196
	/**
197
	 * Extract the instances from the initial-instances element.
198
	 * 
199
	 * TODO this needs to be updated when the initial instances element actually
200
	 * works.
201
	 * 
202
	 * @param rootDocument
203
	 * @return
204
	 */
205
	private Object[][] extractInstances(Document rootDocument)
206
	{
207
		Element[] initialInstancesElements = XmlUtils.findInSubTree(
208
				rootDocument.getDocumentElement(), INITIAL_INSTANCES_QNAME);
209
		if (initialInstancesElements.length == 0)
210
		{
211
			return EMPTY_INSTANCES;
212
		}
213
214
		// sorry about this, maybe someday java will have a Pair type
215
		Object[][] instances = new Object[initialInstancesElements.length][2];
216
217
		for (int i = 0; i < initialInstancesElements.length; i++)
218
		{
219
			Element contextElement = XmlUtils.findFirstInSubTree(
220
					initialInstancesElements[i],
221
					DescriptorConstants.CONTEXT_PATH_QNAME);
222
			instances[i][0] = XmlUtils.extractText(contextElement);
223
			Element instancesElement = XmlUtils.findFirstInSubTree(
224
					initialInstancesElements[i], REFERENCE_PARAMETERS_QNAME);
225
			
226
			Element referenceParametersElement = XmlUtils.createElement(WsaConstants.PARAMETERS_QNAME);
227
			
228
			Element[] referenceParameters = XmlUtils.getAllElements(instancesElement);
229
			Document owner = referenceParametersElement.getOwnerDocument();
230
			for(int j=0; j < referenceParameters.length; j++) {
231
				referenceParametersElement.appendChild(owner.importNode(referenceParameters[j], true));
232
			}
233
			instances[i][1] = referenceParametersElement;	
234
		}
235
236
		return instances;
237
	}
238
239
	/**
240
	 * Extract the jars from the additional jars element. Just read through each
241
	 * element, take the text content (which should be an absolute path) and put
242
	 * it into a <code>File</code> object. Returns a list of these
243
	 * <code>File</code>s.
244
	 * 
245
	 * @param rootDocument
246
	 *            The <code>Root</code> element-containing
247
	 *            <code>Document</code>
248
	 * 
249
	 * @return A list of <code>File</code>s for each path found under
250
	 *         additional-jars
251
	 */
252
	private File[] extractJarFiles(Document rootDocument)
253
	{
254
		Element additionalJarsElement = XmlUtils.findFirstInSubTree(
255
				rootDocument.getDocumentElement(), ADDITIONAL_JARS_QNAME);
256
		if (additionalJarsElement == null)
257
		{
258
			return EMPTY_FILES;
259
		}
260
261
		Element[] jarPaths = XmlUtils.findInSubTree(additionalJarsElement,
262
				JAR_PATH_QNAME);
263
		if (jarPaths.length == 0)
264
		{
265
			return EMPTY_FILES;
266
		}
267
268
		File[] files = new File[jarPaths.length];
269
270
		for (int i = 0; i < jarPaths.length; i++)
271
		{
272
			files[i] = new File(XmlUtils.extractText(jarPaths[i]));
273
		}		
274
		return files;
275
	}
276
	
277
	private String getMuseToolsJarLocation()
278
	{
279
		URL url = FileLocator.find(org.apache.muse.tools.Activator.getDefault().getBundle(), new Path("runtime/tools.jar"), null);
280
		try 
281
		{
282
			url = FileLocator.resolve(url);			
283
			return url.getFile();
284
		}
285
		catch (IOException ioe)
286
		{
287
			WsdmToolingLog.logError(ioe.getMessage(), ioe);
288
		}
289
		return null;
290
	}
291
292
	/**
293
	 * Get the Muse descriptor out of the document. Just looks for the
294
	 * <code>DescriptorConstants.MUSE_QNAME</code> QName.
295
	 * 
296
	 * @param rootDocument
297
	 *            The <code>Root</code> element-containing
298
	 *            <code>Document</code>
299
	 * @return The new <code>Document</code> that has as its document element
300
	 *         the muse descriptor
301
	 */
302
	private Document extractDescriptorDocument(Document rootDocument)
303
	{
304
		Element museElement = XmlUtils.findFirstInSubTree(rootDocument
305
				.getDocumentElement(), DescriptorConstants.MUSE_QNAME);
306
		Document descriptorDocument = XmlUtils.createDocument();
307
		descriptorDocument.appendChild(descriptorDocument.importNode(
308
				museElement, true));
309
310
		copyNamespacePrefixes(rootDocument.getDocumentElement(),
311
				descriptorDocument.getDocumentElement());
312
		
313
		museElement = XmlUtils.getElement(descriptorDocument,DescriptorConstants.MUSE_QNAME);
314
		adjustCustomSerializers(museElement);
315
316
		return descriptorDocument;
317
	}
318
319
	/**
320
	 * Given a source <code>Element</code> and a destination
321
	 * <code>Element</code> copy all of the namespace prefixese from the
322
	 * source to the destination. This is really horrid because of DOM's API
323
	 * being what it is and we treat the declarations as attributes. Yes, we do
324
	 * check to make sure we don't do double prefix declarations.
325
	 * 
326
	 * TODO this should go into a namespace utility class, I've had to write
327
	 * this in about 3 places now.
328
	 * 
329
	 * @param source
330
	 *            The source <code>Element</code>
331
	 * @param destination
332
	 *            The destination <code>Element</code>
333
	 */
334
	private void copyNamespacePrefixes(Element source, Element destination)
335
	{
336
		NamedNodeMap attributes = source.getAttributes();
337
		int size = attributes.getLength();
338
		for (int i = 0; i < size; i++)
339
		{
340
			Node nextAttribute = attributes.item(i);
341
			String prefix = nextAttribute.getPrefix();
342
343
			if (prefix == null || !prefix.equals(XMLNS_PREFIX))
344
			{
345
				continue;
346
			}
347
348
			if (destination.hasAttribute(nextAttribute.getNodeName()))
349
			{
350
				continue;
351
			}
352
353
			destination.setAttribute(nextAttribute.getNodeName(), nextAttribute
354
					.getNodeValue());
355
		}
356
	}
357
	
358
	/**
359
	 * Descriptor editor stores the xsd-serializer-type for custom-serializer as
360
	 * 
361
	 * <custom-serializer>
362
	 * 		<xsd-serializer-type>{http://www.eclipse.org/TP}StateType</xsd-serializer-type>
363
	 * <custom-serializer>
364
	 * 
365
	 * We have to convert the QName to prefix:localpart format so we adjust this part as
366
	 * 
367
	 * <custom-serializer>
368
	 * 		<xsd-serializer-type xmlns:pfx="http://www.eclipse.org/TP">pfx:StateType</xsd-serializer-type>
369
	 * <custom-serializer>
370
	 *   
371
	 */
372
	private void adjustCustomSerializers(Element museElement)
373
	{
374
		Element[] serializerElements = XmlUtils.getElements(museElement, DescriptorConstants.CUSTOM_SERIALIZER_QNAME);
375
		for(int i=0;i<serializerElements.length;i++)
376
		{
377
			// TODO Replace the QName with MUSE constant in MUSE 2.2
378
			Element xsdSerializerElement = XmlUtils.getElement(serializerElements[i], new QName(DescriptorConstants.NAMESPACE_URI,"xsd-serializable-type"));
379
			String qNameAsString = XmlUtils.extractText(xsdSerializerElement);
380
			if(qNameAsString!=null && !qNameAsString.equals(""))
381
			{
382
				try
383
				{
384
					QName qname = QName.valueOf(qNameAsString);
385
					String namespace = qname.getNamespaceURI();
386
					String localPart = qname.getLocalPart();
387
					if(namespace.equals(""))
388
						break;
389
					xsdSerializerElement.setAttribute("pfx", namespace);
390
					XmlUtils.setElementText(xsdSerializerElement, "pfx:"+localPart);									
391
				}
392
				catch(IllegalArgumentException e)
393
				{
394
					WsdmToolingLog.logError(e.getMessage(), e);
395
				}				
396
			}			
397
		}
398
	}
399
	
400
	/**
401
	 * Returns the Descriptor document
402
	 * @return Document
403
	 */
404
	public Document getDescriptorDocument()
405
	{
406
		return _descriptorDocument;
407
	}
408
	/**
409
	 * Returns the Jar files
410
	 * @return File[]
411
	 */
412
	public File[] getJarFiles()
413
	{
414
		return _jarFiles;
415
	}
416
417
	/**
418
	 * Returns the instances
419
	 * @return Object[][]
420
	 */
421
	public Object[][] getInstances()
422
	{
423
		return _instances;
424
	}
425
426
	/**
427
	 * Go through the parsed Muse descriptor associated with this object and
428
	 * find all of the MRT files referenced therein. For each MRT file use
429
	 * <code>WsdlMerge</code> to merge the MRT's WSDL into a consolidate WSDL.
430
	 * Return the Muse Descriptor document-order list of the WSDL files.
431
	 * The passed map will contain the MRT file location as key and MRT object as value.
432
	 * So first search the map for MRT if not found then load the MRT from location.
433
	 * 
434
	 * @return A list of merged WSDL files as gathered from the deployment
435
	 *         descriptor
436
	 * 
437
	 * @see org.eclipse.tptp.wsdm.tooling.wizard.mrt.internal.WsdlResolverDelegate#getWsdlDocuments()
438
	 */
439
	public Document[] getWsdlDocuments(String baseAddress)
440
	{
441
		Element[] resourceTypes = XmlUtils.findInSubTree(_descriptorDocument
442
				.getDocumentElement(), DescriptorConstants.RESOURCE_TYPE_QNAME);
443
		int mrtCount = resourceTypes.length;
444
		Document[] mergedWSDLs = new Document[mrtCount];
445
446
		for (int i = 0; i < mrtCount; i++)
447
		{
448
			Element wsdlFileElement = XmlUtils.findFirstInSubTree(
449
					resourceTypes[i], DescriptorConstants.WSDL_FILE_QNAME);
450
451
			String wsdlPath = XmlUtils.extractText(wsdlFileElement);
452
			String mrtPath = getMRTPathFromWSDLPath(wsdlPath);
453
			ManageableResourceType mrt = null;
454
			String serviceAddress = null;
455
			if(_mrtObjectMap!=null && _mrtObjectMap.containsKey(mrtPath))
456
			{
457
				mrt = (ManageableResourceType) _mrtObjectMap.get(mrtPath);
458
				serviceAddress = baseAddress+"/"+mrt.getIdentifier();
459
			}
460
			else
461
			{
462
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
463
				IWorkspaceRoot root = workspace.getRoot();
464
				IPath mrtFilePath = root.findMember(mrtPath).getFullPath();
465
				URI uri = URI.createFileURI(mrtFilePath.toString());
466
				mrt = MrtUtils.loadMRT(uri);
467
				serviceAddress = makeServiceAddress(baseAddress, mrtFilePath);
468
			}
469
			if(mrt!=null)
470
			{
471
				try
472
				{
473
					mergedWSDLs[i] = MrtMerge.createMergedWSDL(mrt, serviceAddress);
474
				}
475
				catch (Exception e)
476
				{
477
					e.printStackTrace();
478
					// TODO AME add externalized message
479
					throw new RuntimeException(e);
480
				}
481
			}
482
			else
483
			{
484
				// TODO AME add externalized message
485
				throw new RuntimeException();
486
			}
487
		}
488
		return mergedWSDLs;
489
	}
490
491
	/**
492
	 * Given a base address add the service name. This is done by getting the
493
	 * name of the MRT file and stripping off the file extension.
494
	 * 
495
	 * @param baseAddress
496
	 *            Base address
497
	 * @param file
498
	 *            MRT file to use
499
	 * @return the combined address
500
	 */
501
	private String makeServiceAddress(String baseAddress, IPath file)
502
	{
503
		String fileName = file.toFile().getName();
504
		fileName = fileName.substring(0, fileName.lastIndexOf("."));
505
		return baseAddress + "/" + fileName;
506
	}
507
508
	private String getMRTPathFromWSDLPath(String fileName)
509
	{
510
		return fileName.substring(0, fileName.lastIndexOf(".")) + MRT_EXTN;
511
	}
512
	
513
	/**
514
	 * Adds the additional jar files to Descriptor file.
515
	 *  
516
	 * @param serverLocation
517
	 * 			Parent directory of Axis2-lib folder.
518
	 * 
519
	 * @param axis2files
520
	 * 			Axis2 jar files path.
521
	 */
522
	public void addAdditionalJars(String serverLocation, String[] axis2files)
523
	{
524
		List additionalJarFiles = new LinkedList();
525
		if(_jarFiles!=null)
526
			additionalJarFiles.addAll(Arrays.asList(_jarFiles));
527
		for(int i = 0 ; i < axis2files.length ; i++ )
528
			additionalJarFiles.add(new File(serverLocation + File.separator + axis2files[i]));
529
		_jarFiles = (File[]) additionalJarFiles.toArray(new File[additionalJarFiles.size()]);
530
	}
531
532
	/**
533
	 * Go through the parsed Muse descriptor associated with this object and
534
	 * find all of the MRT files referenced therein. For each MRT file create
535
	 * a merged RMD document.
536
	 * 
537
	 * @return A list of merged RMD documents as gathered from the deployment
538
	 *         descriptor
539
	 * 
540
	 */
541
	public MetadataDescriptor[] getMergedRMDs() 
542
	{
543
		Element[] resourceTypes = XmlUtils.findInSubTree(_descriptorDocument
544
				.getDocumentElement(), DescriptorConstants.RESOURCE_TYPE_QNAME);
545
		int mrtCount = resourceTypes.length;
546
		MetadataDescriptor[] mergedRMDs = new MetadataDescriptor[mrtCount];
547
548
		for (int i = 0; i < mrtCount; i++)
549
		{
550
			Element wsdlFileElement = XmlUtils.findFirstInSubTree(
551
					resourceTypes[i], DescriptorConstants.WSDL_FILE_QNAME);
552
553
			String wsdlPath = XmlUtils.extractText(wsdlFileElement);
554
			String mrtPath = getMRTPathFromWSDLPath(wsdlPath);
555
			ManageableResourceType mrt = null;
556
			String serviceAddress = null;
557
			if(_mrtObjectMap!=null && _mrtObjectMap.containsKey(mrtPath))
558
			{
559
				mrt = (ManageableResourceType) _mrtObjectMap.get(mrtPath);				
560
			}
561
			else
562
			{
563
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
564
				IWorkspaceRoot root = workspace.getRoot();
565
				IPath mrtFilePath = root.findMember(mrtPath).getFullPath();
566
				URI uri = URI.createFileURI(mrtFilePath.toString());
567
				mrt = MrtUtils.loadMRT(uri);				
568
			}
569
			if(mrt!=null)
570
			{
571
				try
572
				{
573
					mergedRMDs[i] = MrtMerge.createMergedRMD(mrt);
574
					_codeGenerationDelegate.inspectMetadata(mrt, mergedRMDs[i]);
575
				}
576
				catch (Exception e)
577
				{
578
					throw new RuntimeException(e);
579
				}
580
			}
581
			else
582
			{
583
				throw new RuntimeException();
584
			}
585
		}		
586
		return mergedRMDs;		
587
	} 	
588
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/EclipseEnvironment.java (+131 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal;
14
15
import java.io.File;
16
import java.io.InputStream;
17
import java.net.URI;
18
import java.net.URL;
19
import java.net.URLConnection;
20
21
import org.apache.muse.core.AbstractEnvironment;
22
import org.apache.muse.util.xml.XmlUtils;
23
import org.apache.muse.ws.addressing.EndpointReference;
24
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.FileLocator;
27
import org.eclipse.core.runtime.Path;
28
import org.eclipse.core.runtime.Platform;
29
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
30
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
31
import org.osgi.framework.Bundle;
32
import org.w3c.dom.Document;
33
34
public class EclipseEnvironment extends AbstractEnvironment
35
{
36
37
	public EndpointReference getDeploymentEPR()
38
	{
39
		// TODO Auto-generated method stub
40
		return null;
41
	}
42
43
	public File getRealDirectory()
44
	{
45
		// TODO Auto-generated method stub
46
		return null;
47
	}
48
49
	public Document getDocument(String path)
50
	{
51
		try
52
		{
53
			if(isHttpScheme(path))
54
			{
55
				URLConnection conn = new URL(path).openConnection();
56
				InputStream stream = conn.getInputStream();
57
				return XmlUtils.createDocument(stream);
58
			}			
59
		}
60
		catch(Exception e)
61
		{
62
			WsdmToolingLog.logError(e.getMessage(), e);
63
		}
64
		
65
		
66
		try
67
		{
68
			if (!isBuiltin(path))
69
			{
70
				IFile wsdlFile = EclipseUtils.getIFile(ResourcesPlugin
71
						.getWorkspace().getRoot(), path);
72
				return XmlUtils.createDocument(wsdlFile.getLocation().toFile()
73
						.getAbsoluteFile());
74
			}
75
			else
76
			{
77
				String substr = path.substring(path.indexOf("platform:/plugin/")+"platform:/plugin/".length());
78
				String contributorPlugin = substr.substring(0,substr.indexOf('/'));
79
				String relativePath = substr.substring(substr.indexOf('/')+1);
80
				
81
				Bundle bundle = Platform.getBundle(contributorPlugin);
82
				return XmlUtils.createDocument(FileLocator.openStream(bundle,
83
						new Path(relativePath), false));
84
			}
85
		}
86
		catch (Exception e)
87
		{
88
			WsdmToolingLog.logError(e.getMessage(), e);
89
		}
90
		return null;
91
	}
92
93
	/**
94
	 * Utility method to see if the path is referring to something in the
95
	 * plugins or in the workspace.
96
	 * 
97
	 * @param path
98
	 *            A path to examine
99
	 * @return true if the path starts with <code>"platform:/plugin"</code>
100
	 */
101
	private boolean isBuiltin(String path)
102
	{
103
		return path.startsWith("platform:/plugin");
104
	}
105
	
106
	private boolean isHttpScheme(String path)
107
	{
108
		try{
109
			URI uri = URI.create(path);		
110
			String scheme = uri.getScheme();
111
			if(scheme != null && uri.getScheme().equals("http"))
112
				return true;
113
		}catch(Exception e){
114
			// nuthing to do, just return false
115
		}
116
		return false;
117
	}
118
119
	public String createRelativePath(String original, String relative)
120
	{
121
122
		// If the relative path starts with "platform:/" then it
123
		// is an absolute path, so just return it instead.
124
		if (relative.startsWith("platform:/"))
125
		{
126
			return relative;
127
		}
128
129
		return super.createRelativePath(original, relative);
130
	}
131
}
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseProxyProjectizer.java (-1 / +1 lines)
Lines 22-28 Link Here
22
import org.apache.muse.util.FileUtils;
22
import org.apache.muse.util.FileUtils;
23
import org.eclipse.core.runtime.FileLocator;
23
import org.eclipse.core.runtime.FileLocator;
24
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.EclipseConfigurationData;
25
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseConfigurationData;
26
import org.eclipse.tptp.wsdm.tooling.internal.util.JavaProjectHelper;
26
import org.eclipse.tptp.wsdm.tooling.internal.util.JavaProjectHelper;
27
27
28
28
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseOsgiMiniProjectizer.java (-19 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: EclipseOsgiMiniProjectizer.java,v 1.2 2007/05/07 09:15:19 dnsmith Exp $
8
 * 
9
 * Contributors:
10
 * 	Balan Subramanian (bsubram@us.ibm.com)
11
 *     IBM Corporation - initial API and implementation
12
 *******************************************************************************/
13
package org.eclipse.tptp.wsdm.tooling.internal.projectizer;
14
15
import org.apache.muse.tools.generator.projectizer.OsgiMiniProjectizer;
16
17
public class EclipseOsgiMiniProjectizer extends OsgiMiniProjectizer {
18
19
}
(-)src/org/eclipse/tptp/wsdm/tooling/internal/projectizer/EclipseOsgiProjectizer.java (-30 / +40 lines)
Lines 29-35 Link Here
29
import org.apache.muse.util.FileUtils;
29
import org.apache.muse.util.FileUtils;
30
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
30
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
31
import org.apache.muse.ws.wsdl.WsdlUtils;
31
import org.apache.muse.ws.wsdl.WsdlUtils;
32
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.EclipseConfigurationData;
32
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseConfigurationData;
33
import org.eclipse.tptp.wsdm.tooling.internal.util.PluginProjectHelper;
33
import org.eclipse.tptp.wsdm.tooling.internal.util.PluginProjectHelper;
34
import org.w3c.dom.Document;
34
import org.w3c.dom.Document;
35
import org.w3c.dom.Element;
35
import org.w3c.dom.Element;
Lines 49-56 Link Here
49
	private File[] _additionalJars;
49
	private File[] _additionalJars;
50
	private Object[][] _instances;
50
	private Object[][] _instances;
51
51
52
	private int _resourceCounter = 0;
53
54
	private String _projectLocation;
52
	private String _projectLocation;
55
53
56
	private String _projectName;
54
	private String _projectName;
Lines 60-80 Link Here
60
		
58
		
61
		loadParameters(data);		
59
		loadParameters(data);		
62
		
60
		
63
		PluginProjectHelper helper = createProject(_projectLocation, _projectName);
61
		PluginProjectHelper helper = createProject(_projectLocation, _projectName);		
64
		
65
		_targetDirectory = helper.getProjectDirectory();
62
		_targetDirectory = helper.getProjectDirectory();
66
63
		
67
		File descriptorFile = new File(_targetDirectory, EclipseOsgiProjectizerConstants.MUSE_DESCRIPTOR_FILE);
68
				
69
		File javaSourceDir = new File(_targetDirectory, OsgiProjectizerConstants.JAVA_SRC_DIR);
64
		File javaSourceDir = new File(_targetDirectory, OsgiProjectizerConstants.JAVA_SRC_DIR);
65
				
70
		createJavaSources(javaSourceDir, _filesMaps);
66
		createJavaSources(javaSourceDir, _filesMaps);
71
67
		createArtifacts(javaSourceDir);						
72
		File wsdldir = new File(_targetDirectory, OsgiProjectizerConstants.WSDL_DIR);
68
						
73
		
69
		helper.refreshProject();
70
	}
71
	
72
	protected void createArtifacts(File javaSourceDir) throws Exception {
74
		createActivatorFile(javaSourceDir, EclipseOsgiProjectizerConstants.ACTIVATOR_FILE_RESOURCE);
73
		createActivatorFile(javaSourceDir, EclipseOsgiProjectizerConstants.ACTIVATOR_FILE_RESOURCE);
75
		
74
		
76
		File routerEntriesDir = new File(_targetDirectory,OsgiProjectizerConstants.ROUTER_ENTRIES_DIR);
75
		File routerEntriesDir = new File(_targetDirectory,OsgiProjectizerConstants.ROUTER_ENTRIES_DIR);
77
		
76
		
77
		File descriptorFile = new File(_targetDirectory, EclipseOsgiProjectizerConstants.MUSE_DESCRIPTOR_FILE);
78
		
79
		File wsdldir = new File(_targetDirectory, OsgiProjectizerConstants.WSDL_DIR);
80
		
78
		createManifest(_targetDirectory, EclipseOsgiProjectizerConstants.OSGI_MANIFEST_FILE_RESOURCE, EclipseOsgiProjectizerConstants.OSGI_MANIFEST_FILE);				
81
		createManifest(_targetDirectory, EclipseOsgiProjectizerConstants.OSGI_MANIFEST_FILE_RESOURCE, EclipseOsgiProjectizerConstants.OSGI_MANIFEST_FILE);				
79
		
82
		
80
		for(int i=0; i < _capabilitiesList.length; i++) {
83
		for(int i=0; i < _capabilitiesList.length; i++) {
Lines 94-110 Link Here
94
		}
97
		}
95
		
98
		
96
		createBuildProperties(_targetDirectory, EclipseOsgiProjectizerConstants.BUILD_PROPERTIES_FILE_RESOURCE, EclipseOsgiProjectizerConstants.BUILD_PROPERTIES_FILE);
99
		createBuildProperties(_targetDirectory, EclipseOsgiProjectizerConstants.BUILD_PROPERTIES_FILE_RESOURCE, EclipseOsgiProjectizerConstants.BUILD_PROPERTIES_FILE);
97
		
100
	}
98
		helper.refreshProject();
101
	
102
	protected void loadParameters(ConfigurationData data) {
103
		super.loadParameters(data);
104
		_additionalJars = (File[])data.getParameter(EclipseConfigurationData.ADDITIONAL_JARS);
105
		_instances = (Object[][])data.getParameter(EclipseConfigurationData.INSTANCES);
106
		_projectName = (String)data.getParameter(EclipseConfigurationData.PROJECT_NAME);
107
		_projectLocation = (String)data.getParameter(EclipseConfigurationData.PROJECT_LOCATION);
99
	}
108
	}
100
		
109
		
101
	protected void createRouterEntries(File routerEntriesDir, Object[][] instances)
110
	protected void createRouterEntries(File routerEntriesDir, Object[][] instances)
102
			throws Exception {
111
			throws Exception {
103
		
112
			
104
		routerEntriesDir.mkdirs();
113
		for(int i=0; i < instances.length; i++) {
105
		
114
			Object[] instancePair = instances[i];
106
		for(int i=0; i < _instances.length; i++) {
107
			Object[] instancePair = _instances[i];
108
			
115
			
109
			//
116
			//
110
			//This is really tacky, but it's the only real way to do this
117
			//This is really tacky, but it's the only real way to do this
Lines 117-138 Link Here
117
			Element instanceElement = (Element) instancePair[1];
124
			Element instanceElement = (Element) instancePair[1];
118
			
125
			
119
			File serviceDir = new File(routerEntriesDir, resourcePathName);				
126
			File serviceDir = new File(routerEntriesDir, resourcePathName);				
120
			File routerEntryFile = new File(serviceDir, getResourceFileName());
127
			File routerEntryFile = new File(serviceDir, getResourceFileName(i));
121
			
128
			
122
			writeToFileCheck(instanceElement, routerEntryFile);				
129
			writeToFileCheck(instanceElement, routerEntryFile);				
123
		}
130
		}
124
	}
131
	}
125
	
132
	
126
	protected String getResourceFileName() {
133
	/**
127
		return Axis2ProjectizerConstants.RESOURCE_FILE.replaceFirst(PLACE_HOLDER, String.valueOf(_resourceCounter++));
134
	 * Get the name of a resource-instance file with the appropriate counter. This is 
128
	}
135
	 * really just a string-replace of the PLACE_HOLDER value with the given counter
129
136
	 * 
130
	protected void loadParameters(ConfigurationData data) {
137
	 * @param counter	The number to use in the string replace
131
		super.loadParameters(data);
138
	 * @return 			The string with PLACE_HOLDER replaced by the string value of counter
132
		_additionalJars = (File[])data.getParameter(EclipseConfigurationData.ADDITIONAL_JARS);
139
	 */
133
		_instances = (Object[][])data.getParameter(EclipseConfigurationData.INSTANCES);
140
	protected String getResourceFileName(int counter) {
134
		_projectName = (String)data.getParameter(EclipseConfigurationData.PROJECT_NAME);
141
		return Axis2ProjectizerConstants.RESOURCE_FILE.replaceFirst(PLACE_HOLDER, String.valueOf(counter));
135
		_projectLocation = (String)data.getParameter(EclipseConfigurationData.PROJECT_LOCATION);
136
	}
142
	}
137
143
138
	protected void createManifest(File baseTargetDir, String manifestFileResource, String manifestFileName) throws Exception {
144
	protected void createManifest(File baseTargetDir, String manifestFileResource, String manifestFileName) throws Exception {
Lines 140-146 Link Here
140
		
146
		
141
		String packageName = getSymbolicName().toString();
147
		String packageName = getSymbolicName().toString();
142
		
148
		
143
		Object[] filler = { getSymbolicName(), packageName + "." + EclipseOsgiProjectizerConstants.ACTIVATOR_CLASSNAME, getSymbolicName()};
149
		Object[] filler = { getSymbolicName(), makeActivatorName(packageName), getSymbolicName()};
144
		String newManifest = loadString(manifestTemplateIS, filler);
150
		String newManifest = loadString(manifestTemplateIS, filler);
145
		
151
		
146
		newManifest = addAdditionalJars(newManifest);
152
		newManifest = addAdditionalJars(newManifest);
Lines 149-154 Link Here
149
		writeToFileCheck(newManifest, manifestFile);
155
		writeToFileCheck(newManifest, manifestFile);
150
	}
156
	}
151
	
157
	
158
	protected String makeActivatorName(String packageName) {
159
		return packageName + "." + EclipseOsgiProjectizerConstants.ACTIVATOR_CLASSNAME;
160
	}
161
152
	private String addAdditionalJars(String newManifest) throws IOException {
162
	private String addAdditionalJars(String newManifest) throws IOException {
153
		ByteArrayInputStream bais = new ByteArrayInputStream(newManifest.getBytes());
163
		ByteArrayInputStream bais = new ByteArrayInputStream(newManifest.getBytes());
154
		Manifest manifest = null;			
164
		Manifest manifest = null;			
(-)src/org/eclipse/tptp/wsdm/tooling/internal/util/JavaProjectHelper.java (-5 / +10 lines)
Lines 25-43 Link Here
25
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.JavaCore;
26
import org.eclipse.jdt.core.JavaModelException;
26
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.launching.JavaRuntime;
27
import org.eclipse.jdt.launching.JavaRuntime;
28
import org.eclipse.tptp.wsdm.tooling.provisional.util.ProjectHelper;
29
28
30
public class JavaProjectHelper extends ProjectHelper {
29
public class JavaProjectHelper extends ProjectHelper {
31
30
32
	IProject _project = null;
31
	IProject _project = null;
33
32
34
	public JavaProjectHelper(String location, String projectName) throws Exception {
33
	public JavaProjectHelper(String location, String projectName, String natureId) throws Exception {
35
		_project = getProject(location, projectName);
34
		if(natureId == null) {
36
		addNature(JavaCore.NATURE_ID);
35
			natureId = JavaCore.NATURE_ID;
36
		}
37
		_project = getProject(location, projectName, natureId, true);		
37
		initializeClasspath();
38
		initializeClasspath();
38
	}
39
	}
40
	
41
	public JavaProjectHelper(String location, String projectName) throws Exception {
42
		this(location, projectName, JavaCore.NATURE_ID);
43
	}
39
44
40
	private void initializeClasspath() throws JavaModelException {
45
	protected void initializeClasspath() throws JavaModelException {
41
		IJavaProject javaProj = JavaCore.create(_project);
46
		IJavaProject javaProj = JavaCore.create(_project);
42
		javaProj.setRawClasspath(new IClasspathEntry[] {}, null);
47
		javaProj.setRawClasspath(new IClasspathEntry[] {}, null);
43
		addClasspathEntry(JavaRuntime.getDefaultJREContainerEntry());
48
		addClasspathEntry(JavaRuntime.getDefaultJREContainerEntry());
(-)src/org/eclipse/tptp/wsdm/tooling/internal/util/PluginProjectHelper.java (-2 / +2 lines)
Lines 21-28 Link Here
21
	private static final String PLUGIN_NATURE = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$
21
	private static final String PLUGIN_NATURE = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$
22
22
23
	public PluginProjectHelper(String projectLocation, String projectName) throws Exception {
23
	public PluginProjectHelper(String projectLocation, String projectName) throws Exception {
24
		super(projectLocation, projectName);
24
		super(projectLocation, projectName, JavaCore.NATURE_ID);		
25
		addNature(PLUGIN_NATURE);
25
		initializeClasspath();
26
		IClasspathEntry cpe = JavaCore.newContainerEntry(Path.fromOSString("org.eclipse.pde.core.requiredPlugins")); //$NON-NLS-1$
26
		IClasspathEntry cpe = JavaCore.newContainerEntry(Path.fromOSString("org.eclipse.pde.core.requiredPlugins")); //$NON-NLS-1$
27
		addClasspathEntry(cpe);
27
		addClasspathEntry(cpe);
28
	}
28
	}
(-)src/org/eclipse/tptp/wsdm/tooling/provisional/util/ProjectHelper.java (-76 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.provisional.util;
14
15
import java.net.URI;
16
17
import org.eclipse.core.filesystem.URIUtil;
18
import org.eclipse.core.resources.ICommand;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IProjectDescription;
22
import org.eclipse.core.resources.IWorkspace;
23
import org.eclipse.core.resources.IWorkspaceRoot;
24
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.runtime.CoreException;
26
27
public abstract class ProjectHelper {
28
29
	protected IProject getProject(String location, String name) throws CoreException {
30
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
31
		IWorkspaceRoot root = workspace.getRoot();	
32
33
		IProjectDescription desc= workspace.newProjectDescription(name);
34
35
		URI projectURI = location==null?null:URIUtil.toURI(location);
36
		desc.setLocationURI(projectURI);
37
		
38
		IProject project = root.getProject(name);
39
		
40
		if(project != null) {
41
			project.create(desc, null);
42
			project.open(null);
43
		}
44
		
45
		return project;
46
	}
47
	
48
	public void addNature(String natureId) throws CoreException {		
49
		IProject project = getProject();
50
		IProjectDescription description = project.getDescription();
51
		String[] natures = description.getNatureIds();
52
		String[] newNatures = new String[natures.length + 1];
53
		System.arraycopy(natures, 0, newNatures, 0, natures.length);
54
		newNatures[natures.length] = natureId;
55
		description.setNatureIds(newNatures);
56
		project.setDescription(description, null);
57
	}
58
	
59
	public void refreshProject() throws Exception {
60
		getProject().refreshLocal(IFile.DEPTH_INFINITE, null);    	
61
	}
62
	
63
	public void addBuilder(String builder) throws CoreException {
64
		IProjectDescription desc = getProject().getDescription();
65
		ICommand command = desc.newCommand();
66
		command.setBuilderName(builder);
67
		ICommand[] commands = desc.getBuildSpec();
68
		ICommand[] nc = new ICommand[commands.length + 1];
69
		System.arraycopy(commands, 0, nc, 0, commands.length);
70
		nc[commands.length] = command;
71
		desc.setBuildSpec(nc);
72
		getProject().setDescription(desc, null);
73
	}
74
	
75
	public abstract IProject getProject();
76
}
(-)plugin.xml (+13 lines)
Lines 24-27 Link Here
24
            servicePath="/"
24
            servicePath="/"
25
            servicePort="80"/>
25
            servicePort="80"/>
26
   </extension>
26
   </extension>
27
   <extension
28
         point="org.eclipse.tptp.wsdm.editor.codeGeneration">
29
      <description
30
            container="Mini"
31
            platform="OSGi">
32
      </description>
33
      <projectizer
34
            class="org.eclipse.tptp.wsdm.tooling.internal.projectizer.EclipseOsgiProjectizer"
35
            name="OSGi mini"
36
            servicePath="/"
37
            servicePort="80">
38
      </projectizer>
39
   </extension>
27
</plugin>
40
</plugin>
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 21-24 Link Here
21
Bundle-ClassPath: .,runtime/code-generation.jar
21
Bundle-ClassPath: .,runtime/code-generation.jar
22
Bundle-Vendor: %plugin.provider
22
Bundle-Vendor: %plugin.provider
23
Bundle-RequiredExecutionEnvironment: J2SE-1.4
23
Bundle-RequiredExecutionEnvironment: J2SE-1.4
24
Export-Package: org.eclipse.tptp.wsdm.tooling.provisional.util
24
Export-Package: org.eclipse.tptp.wsdm.tooling.internal.util;x-friends:="org.eclipse.tptp.wsdm.tooling.codegeneration.j2ee"
(-)src/org/eclipse/tptp/wsdm/tooling/internal/util/ProgressMonitorHelper.java (+34 lines)
Added Link Here
1
package org.eclipse.tptp.wsdm.tooling.internal.util;
2
3
import org.eclipse.core.runtime.IProgressMonitor;
4
5
public class ProgressMonitorHelper {
6
	
7
	private IProgressMonitor _monitor;
8
9
	public ProgressMonitorHelper(IProgressMonitor monitor) {
10
		_monitor = monitor;
11
	}
12
	
13
	public void finishProgressMonitor() {
14
		if (_monitor != null) {
15
			_monitor.done();
16
		}
17
	}
18
19
	public void recordProgress(int i) {
20
		if (_monitor != null) {
21
			_monitor.worked(1);
22
		}
23
	}
24
25
	public void startProgressMonitor(int i) {
26
		if(_monitor != null) {
27
			_monitor.beginTask("Running Projectizer", i);
28
		}
29
	}
30
31
	public void recordProgress() {
32
		recordProgress(1);
33
	}
34
}
(-)src/org/eclipse/tptp/wsdm/tooling/internal/util/ProjectHelper.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.internal.util;
14
15
import java.io.File;
16
import java.net.URI;
17
import java.net.URL;
18
19
import org.eclipse.core.filesystem.URIUtil;
20
import org.eclipse.core.resources.ICommand;
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IProjectDescription;
24
import org.eclipse.core.resources.IWorkspace;
25
import org.eclipse.core.resources.IWorkspaceRoot;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.runtime.CoreException;
28
29
public abstract class ProjectHelper {
30
	
31
	protected IProject getProject(String location, String name, String natureId, boolean create) throws CoreException {
32
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
33
		IWorkspaceRoot root = workspace.getRoot();	
34
35
		IProjectDescription desc= workspace.newProjectDescription(name);
36
37
		URI projectURI = location==null?null:URIUtil.toURI(location);
38
		desc.setLocationURI(projectURI);
39
		
40
		if(natureId != null) {
41
			addNature(natureId, desc);
42
		}
43
		
44
		IProject project = root.getProject(name);
45
		
46
		if(create && project != null) {
47
			project.create(desc, null);
48
			project.open(null);
49
		}
50
		
51
		return project;
52
	}
53
	
54
	private void addNature(String natureId, IProjectDescription description) throws CoreException {		
55
		String[] natures = description.getNatureIds();
56
		String[] newNatures = new String[natures.length + 1];
57
		System.arraycopy(natures, 0, newNatures, 0, natures.length);
58
		newNatures[natures.length] = natureId;
59
		description.setNatureIds(newNatures);		
60
	}
61
	
62
	public void refreshProject() throws Exception {
63
		getProject().refreshLocal(IFile.DEPTH_INFINITE, null);    	
64
	}
65
	
66
	public void addBuilder(String builder) throws CoreException {
67
		IProjectDescription desc = getProject().getDescription();
68
		ICommand command = desc.newCommand();
69
		command.setBuilderName(builder);
70
		ICommand[] commands = desc.getBuildSpec();
71
		ICommand[] nc = new ICommand[commands.length + 1];
72
		System.arraycopy(commands, 0, nc, 0, commands.length);
73
		nc[commands.length] = command;
74
		desc.setBuildSpec(nc);
75
		getProject().setDescription(desc, null);
76
	}
77
	
78
	public static File toFile(URL url) {
79
		return new File(url.getFile());
80
	}
81
	
82
	public abstract IProject getProject();
83
}

Return to bug 179329