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 172617
Collapse All | Expand All

(-)src/org/eclipse/tptp/wsdm/tooling/editor/dde/util/internal/DdeUtil.java (-14 / +25 lines)
Lines 356-380 Link Here
356
	 */
356
	 */
357
	public static MuseType loadDecriptorFile(IFile file)
357
	public static MuseType loadDecriptorFile(IFile file)
358
	{
358
	{
359
		URI uri = URI.createPlatformResourceURI(file.getFullPath().toString());
359
		MuseType mt = loadMuseType(file);
360
		if (uri == null)
361
			return null;
362
		MuseType mt = loadMuseType(uri);
363
		return mt;
360
		return mt;
364
	}
361
	}
365
362
366
	// Return MuseType at URI.
363
	// Return MuseType at URI.
367
	private static MuseType loadMuseType(URI uri)
364
	private static MuseType loadMuseType(IFile file)
368
	{
365
	{
369
		ensureMusePackagePresent();
366
		DocumentRoot root = getDocRoot(file);
370
		ResourceSet resourceSet = new ResourceSetImpl();
371
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
372
				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
373
						new MyDescriptorResourceFactoryImpl());
374
		resourceSet.getPackageRegistry().put(DescriptorPackage.eNS_URI,
375
				DescriptorPackage.eINSTANCE);
376
		Resource resource = resourceSet.getResource(uri, true);
377
		DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
378
		RootType rt = root.getRoot();
367
		RootType rt = root.getRoot();
379
		return rt.getMuse();
368
		return rt.getMuse();
380
	}
369
	}
Lines 932-935 Link Here
932
				muse.getCustomSerializer().add(serializers[serializersIndex]);
921
				muse.getCustomSerializer().add(serializers[serializersIndex]);
933
		}
922
		}
934
	}
923
	}
924
	
925
	/**
926
	 * This method takes a dd file and returns the document root of the file
927
	 * @param file - IFile which is a dd file
928
	 * @return DocumentRoot of the file.
929
	 */
930
	public static DocumentRoot getDocRoot(IFile file)
931
	{
932
		URI uri = URI.createPlatformResourceURI(file.getFullPath().toString());
933
		if (uri == null)
934
			return null;
935
		ensureMusePackagePresent();
936
		ResourceSet resourceSet = new ResourceSetImpl();
937
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
938
				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
939
						new MyDescriptorResourceFactoryImpl());
940
		resourceSet.getPackageRegistry().put(DescriptorPackage.eNS_URI,
941
				DescriptorPackage.eINSTANCE);
942
		Resource resource = resourceSet.getResource(uri, true);
943
		DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
944
		return root;
945
	}
935
}
946
}
(-)plugin.xml (-2 / +15 lines)
Lines 144-156 Link Here
144
           adaptable="false"
144
           adaptable="false"
145
           objectClass="org.eclipse.core.resources.IResource"
145
           objectClass="org.eclipse.core.resources.IResource"
146
           nameFilter="*.mrt"
146
           nameFilter="*.mrt"
147
           id="org.eclipse.tptp.wsdm.tooling.objectContribution1">
147
           id="org.eclipse.tptp.wsdm.tooling.codegen.mrt">
148
        <action
148
        <action
149
              enablesFor="1"
149
              enablesFor="1"
150
              label="Generate Java Code"
150
              label="Generate Java Code"
151
              icon="icons/obj16/mrt_obj.gif"
151
              icon="icons/obj16/mrt_obj.gif"
152
              class="org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.Generation"
152
              class="org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.Generation"
153
              id="org.eclipse.tptp.wsdm.tooling.action1"/>
153
              id="org.eclipse.tptp.wsdm.tooling.codegen.mrt.action"/>
154
     </objectContribution>
155
     
156
     <objectContribution
157
           adaptable="false"
158
           objectClass="org.eclipse.core.resources.IResource"
159
           nameFilter="*.dd"
160
           id="org.eclipse.tptp.wsdm.tooling.codegen.dd">
161
        <action
162
              enablesFor="1"
163
              label="Generate Java Code"
164
              icon="icons/obj16/mrt_obj.gif"
165
              class="org.eclipse.tptp.wsdm.tooling.codegen.dd.internal.Generation"
166
              id="org.eclipse.tptp.wsdm.tooling.codegen.dd.action"/>
154
     </objectContribution>
167
     </objectContribution>
155
   </extension>
168
   </extension>
156
   
169
   
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/Generation.java (+64 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
 *  Andrew Eberbach (aeberbac@us.ibm.com)
11
 *     IBM Corporation - initial API and implementation
12
 *******************************************************************************/
13
14
package org.eclipse.tptp.wsdm.tooling.codegen.dd.internal;
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.NewProjectWizard;
22
import org.eclipse.ui.IObjectActionDelegate;
23
import org.eclipse.ui.IWorkbenchPart;
24
25
/**
26
 * This class provides the action to generate smashed WSDL and Java code from a
27
 * Deployment Descriptore file. 
28
 */
29
public class Generation implements IObjectActionDelegate {
30
	
31
	private IWorkbenchPart _targetPart;
32
33
	private StructuredSelection _selection;
34
35
	/**
36
	 * Shows the <code>NewProjectWizards</code> after wrapping the selected
37
	 * Deployment Descriptor file in a <code>DescriptorHelper</code>.
38
	 */
39
	public void run(IAction action) {
40
		//Get the file from the selected element
41
		//It should be the first element in the selection
42
		IFile ddFile = (IFile) _selection.getFirstElement();	
43
		
44
		//Create a code generation delegate which will
45
		//some of the heavy-lifting during code generation so
46
		//the UI thread can stay responsive
47
		DDCodeGenerationDelegate delegate = new DDCodeGenerationDelegate(ddFile);		
48
		
49
		//Open up the wizard dialog for code generation
50
		NewProjectWizard npw = new NewProjectWizard(delegate);
51
		WizardDialog wd = new WizardDialog(_targetPart.getSite().getShell(),npw);
52
		wd.open();
53
	}
54
55
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
56
		_targetPart = targetPart;
57
	}
58
	
59
	public void selectionChanged(IAction action, ISelection selection) {
60
		if (selection instanceof StructuredSelection) {
61
			_selection = (StructuredSelection) selection;
62
		}
63
	}
64
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/DDCodeGenerationDelegate.java (+186 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.dd.internal;
14
15
import java.io.IOException;
16
import java.util.ArrayList;
17
import java.util.Collections;
18
import java.util.List;
19
20
import org.apache.ws.muse.descriptor.CapabilityType;
21
import org.apache.ws.muse.descriptor.DescriptorPackage;
22
import org.apache.ws.muse.descriptor.DocumentRoot;
23
import org.apache.ws.muse.descriptor.MuseType;
24
import org.apache.ws.muse.descriptor.ResourceTypeType;
25
import org.apache.ws.muse.descriptor.RootType;
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.runtime.SubProgressMonitor;
28
import org.eclipse.emf.common.util.URI;
29
import org.eclipse.emf.ecore.resource.Resource;
30
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
31
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.CodeGenerationDelegate;
32
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.DescriptorHelper;
33
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.SubscriptionManagerInspector;
34
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
35
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
36
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
37
import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages;
38
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
40
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
41
42
/**
43
 * A Deployment Descriptor-specifc resolver. This will go through the Deployment
44
 * Descriptor and find all of the MCap files and resolve them and merge them
45
 * into WSDL documents.
46
 */
47
public class DDCodeGenerationDelegate implements CodeGenerationDelegate {
48
	
49
	/**
50
	 * The IFile of the unparsed descriptor file
51
	 */
52
	private IFile _descriptorFile;
53
54
	public DDCodeGenerationDelegate(IFile descriptorFile) {
55
		_descriptorFile = descriptorFile;
56
	}
57
	
58
	public DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception {		
59
		inspectForSubscriptionManager();
60
		return new DescriptorHelper(_descriptorFile);
61
	}
62
	
63
	private void inspectForSubscriptionManager()
64
	{
65
		DocumentRoot docRoot = DdeUtil.getDocRoot(_descriptorFile);
66
		SubscriptionManagerInspector inspector = new SubscriptionManagerInspector(docRoot);
67
		inspector.setMrtParentDirectory(_descriptorFile.getParent().getFullPath()
68
				.toString());
69
		RootType root = docRoot.getRoot();
70
		MuseType mt = root.getMuse();
71
		List rts = mt.getResourceType();
72
		if(rts == null || rts.size() == 0)
73
		{
74
			return;
75
		}
76
		List mrts = subManagerAdded(rts);// This method returns a list of mrts if subscriptionmanager is not already added. else null
77
		if(mrts == null || mrts.size() == 0) 
78
		{
79
			return;
80
		}
81
		for(int i = 0; i < mrts.size(); i++)
82
		{
83
			ManageableResourceType mrt = (ManageableResourceType) mrts.get(i);
84
			Capability[] capDefs = getMrtCapabilities(mrt);
85
			ResourceTypeType subMgr = inspector.inspect(capDefs);
86
			if(subMgr == null)
87
			{
88
				continue;
89
			}
90
			else
91
			{
92
				mt.getResourceType().add(subMgr);
93
				root.setMuse(mt);
94
				docRoot.setRoot(root);
95
				save(docRoot);
96
				break;
97
			}
98
		}
99
	}
100
	
101
	private Capability[] getMrtCapabilities(ManageableResourceType mrt) {
102
		Capability[] capList = null;
103
		try {
104
			capList = MrtUtils.getCapabilities(mrt);
105
		} catch (Exception e) {
106
			WsdmToolingLog
107
					.logError(
108
							org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages.MRT_ERROR_CANNOT_TRACE_CAPS,
109
							e);
110
		}
111
112
		if (capList != null)
113
			return capList;
114
		return new Capability[0];
115
	}
116
	
117
	private void save(DocumentRoot root)
118
	{
119
		ensureMusePackagePresent();
120
		URI ddFileURI = URI.createPlatformResourceURI(_descriptorFile.getFullPath().toString());
121
		ResourceSetImpl rsImpl = new ResourceSetImpl();
122
		rsImpl.getResourceFactoryRegistry().getExtensionToFactoryMap()
123
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
124
				new MyDescriptorResourceFactoryImpl());
125
		rsImpl.getPackageRegistry().put(DescriptorPackage.eNS_URI,
126
		DescriptorPackage.eINSTANCE);
127
		Resource ddRes = rsImpl.getResource(ddFileURI, true);
128
		ddRes.getContents().remove(0);
129
		ddRes.getContents().add(root);
130
		try {
131
			ddRes.save(Collections.EMPTY_MAP);
132
		} catch (IOException e) {
133
			e.printStackTrace();
134
		}
135
	}
136
	
137
	private void ensureMusePackagePresent()
138
	{
139
		// Ensure EMF knows about Muse descriptor
140
		if (DescriptorPackage.eINSTANCE == null)
141
		{
142
			WsdmToolingLog.logError(Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_, new Throwable());
143
		}
144
	}
145
	
146
	/**
147
	 * This method takes alist of resourceTypes and checks whether subscriptionmanager is already present.<br>
148
	 * if so returns null. else converts the resourcetypes into mrts and returns the list.
149
	 * @param rts
150
	 * @return
151
	 */
152
	private List subManagerAdded(List rts)
153
	{
154
		List mrts = new ArrayList();
155
		if(rts == null || rts.size() == 0)
156
		{
157
			return null;
158
		}
159
		for(int i = 0; i < rts.size(); i++)
160
		{
161
			ResourceTypeType rt = (ResourceTypeType) rts.get(i);
162
			IFile mrtFile = DdeUtil.getIFileFromName(DdeUtil
163
					.getMrtFileName(rt.getWsdl().getWsdlFile()), "mrt"); 
164
			if(mrtFile == null)
165
			{
166
				continue;
167
			}
168
			ManageableResourceType mrt = DdeUtil.loadMrtFile(mrtFile);
169
			mrts.add(mrt);
170
			List capList = DdeUtil.getCapabilitiesFromMRT(mrt);
171
			if(capList == null || capList.size() == 0)
172
			{
173
				continue;
174
			}
175
			for(int j = 0; j < capList.size(); j++)
176
			{
177
				CapabilityType ctype = (CapabilityType) capList.get(j);
178
				if(ctype.getCapabilityUri().equals("http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager"))
179
				{
180
					return null;
181
				}
182
			}
183
		}
184
		return mrts;
185
	}
186
}

Return to bug 172617