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

(-)a/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml (-2 / +9 lines)
Lines 81-86 Link Here
81
			<adapter type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription"/>
81
			<adapter type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription"/>
82
		</factory>
82
		</factory>
83
83
84
		<!-- XmlFile -> JpaPlatformDescription -->
85
		<factory
86
			adaptableType="org.eclipse.jpt.jpa.core.context.XmlFile"
87
			class="org.eclipse.jpt.jpa.core.internal.XmlFileAdapterFactory">
88
			<adapter type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription"/>
89
		</factory>
90
84
	</extension>
91
	</extension>
85
92
86
93
Lines 189-202 Link Here
189
			id="org.eclipse.jpt.jpa.core.propertyTester.XmlFile"
196
			id="org.eclipse.jpt.jpa.core.propertyTester.XmlFile"
190
			type="org.eclipse.jpt.jpa.core.context.XmlFile"
197
			type="org.eclipse.jpt.jpa.core.context.XmlFile"
191
			namespace="org.eclipse.jpt.jpa.core"
198
			namespace="org.eclipse.jpt.jpa.core"
192
			properties="isLatestSupportedVersion, isNotLatestSupportedVersion"
199
			properties="isLatestSupportedVersion, isNotLatestSupportedVersion, isGenericMappingFile"
193
			class="org.eclipse.jpt.jpa.core.internal.context.XmlFilePropertyTester"/>
200
			class="org.eclipse.jpt.jpa.core.internal.context.XmlFilePropertyTester"/>
194
201
195
		<propertyTester
202
		<propertyTester
196
			id="org.eclipse.jpt.jpa.core.propertyTester.JptResourceModel"
203
			id="org.eclipse.jpt.jpa.core.propertyTester.JptResourceModel"
197
			type="org.eclipse.jpt.common.core.JptResourceModel"
204
			type="org.eclipse.jpt.common.core.JptResourceModel"
198
			namespace="org.eclipse.jpt.jpa.core"
205
			namespace="org.eclipse.jpt.jpa.core"
199
			properties="isLatestSupportedVersion, isNotLatestSupportedVersion"
206
			properties="isLatestSupportedVersion, isNotLatestSupportedVersion, isGenericMappingFile"
200
			class="org.eclipse.jpt.jpa.core.internal.JptResourceModelPropertyTester"/>
207
			class="org.eclipse.jpt.jpa.core.internal.JptResourceModelPropertyTester"/>
201
208
202
	</extension>
209
	</extension>
(-)a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/XmlFile.java (+15 lines)
Lines 9-16 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.jpa.core.context;
10
package org.eclipse.jpt.jpa.core.context;
11
11
12
import org.eclipse.core.runtime.content.IContentType;
12
import org.eclipse.jpt.common.utility.internal.Tools;
13
import org.eclipse.jpt.common.utility.internal.Tools;
13
import org.eclipse.jpt.jpa.core.JpaStructureNode;
14
import org.eclipse.jpt.jpa.core.JpaStructureNode;
15
import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings;
14
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
16
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
15
17
16
/**
18
/**
Lines 49-54 Link Here
49
	 * JPA platform.
51
	 * JPA platform.
50
	 */
52
	 */
51
	boolean isLatestSupportedVersion();
53
	boolean isLatestSupportedVersion();
54
	
55
	/**
56
	 * Return whether the XML file is a generic mapping file
57
	 */
58
	boolean isGenericMappingFile();
52
59
53
60
54
	// ********** XML file root element **********
61
	// ********** XML file root element **********
Lines 76-81 Link Here
76
			String latestVersion = xmlFile.getJpaProject().getJpaPlatform().getMostRecentSupportedResourceType(xmlFile.getXmlResource().getContentType()).getVersion();
83
			String latestVersion = xmlFile.getJpaProject().getJpaPlatform().getMostRecentSupportedResourceType(xmlFile.getXmlResource().getContentType()).getVersion();
77
			return Tools.valuesAreEqual(xmlFileVersion, latestVersion);
84
			return Tools.valuesAreEqual(xmlFileVersion, latestVersion);
78
		}
85
		}
86
		
87
		/**
88
		 * @see #isGenericMappingFile()
89
		 */
90
		public static boolean isGenericMappingFile(XmlFile xmlFile) {
91
			IContentType contentType = xmlFile.getXmlResource().getContentType();
92
			return Tools.valuesAreEqual(contentType, XmlEntityMappings.CONTENT_TYPE);
93
		}
79
94
80
		private XmlFile_() {
95
		private XmlFile_() {
81
			super();
96
			super();
(-)a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptResourceModelPropertyTester.java (-1 / +23 lines)
Lines 11-20 Link Here
11
11
12
import org.eclipse.core.expressions.PropertyTester;
12
import org.eclipse.core.expressions.PropertyTester;
13
import org.eclipse.core.resources.IProject;
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.runtime.content.IContentType;
14
import org.eclipse.jpt.common.core.JptResourceModel;
15
import org.eclipse.jpt.common.core.JptResourceModel;
15
import org.eclipse.jpt.common.core.JptResourceType;
16
import org.eclipse.jpt.common.core.JptResourceType;
16
import org.eclipse.jpt.common.utility.internal.Tools;
17
import org.eclipse.jpt.common.utility.internal.Tools;
17
import org.eclipse.jpt.jpa.core.JpaProject;
18
import org.eclipse.jpt.jpa.core.JpaProject;
19
import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings;
18
20
19
/**
21
/**
20
 * Property tester for {@link JptResourceModel}.
22
 * Property tester for {@link JptResourceModel}.
Lines 25-31 Link Here
25
{
27
{
26
	public static final String IS_LATEST_SUPPORTED_VERSION = "isLatestSupportedVersion"; //$NON-NLS-1$
28
	public static final String IS_LATEST_SUPPORTED_VERSION = "isLatestSupportedVersion"; //$NON-NLS-1$
27
	public static final String IS_NOT_LATEST_SUPPORTED_VERSION = "isNotLatestSupportedVersion"; //$NON-NLS-1$
29
	public static final String IS_NOT_LATEST_SUPPORTED_VERSION = "isNotLatestSupportedVersion"; //$NON-NLS-1$
28
30
	public static final String IS_GENERIC_MAPPING_FILE = "isGenericMappingFile"; //$NON-NLS-1$
29
31
30
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
32
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
31
		if (receiver instanceof JptResourceModel) {
33
		if (receiver instanceof JptResourceModel) {
Lines 41-46 Link Here
41
		if (property.equals(IS_LATEST_SUPPORTED_VERSION)) {
43
		if (property.equals(IS_LATEST_SUPPORTED_VERSION)) {
42
			boolean expected = (expectedValue == null) ? true : ((Boolean) expectedValue).booleanValue();
44
			boolean expected = (expectedValue == null) ? true : ((Boolean) expectedValue).booleanValue();
43
			boolean actual = this.isLatestSupportedVersion(resourceModel);
45
			boolean actual = this.isLatestSupportedVersion(resourceModel);
46
			return actual == expected;
47
		}
48
		if (property.equals(IS_GENERIC_MAPPING_FILE)) {
49
			boolean expected = (expectedValue == null) ? true : ((Boolean) expectedValue).booleanValue();
50
			boolean actual = this.isGenericMappingFile(resourceModel);
44
			return actual == expected;
51
			return actual == expected;
45
		}
52
		}
46
		return false;
53
		return false;
Lines 61-66 Link Here
61
		return Tools.valuesAreEqual(resourceType.getVersion(), latestVersion);
68
		return Tools.valuesAreEqual(resourceType.getVersion(), latestVersion);
62
	}
69
	}
63
70
71
	private boolean isGenericMappingFile(JptResourceModel resourceModel) {
72
		JpaProject jpaProject = this.getJpaProject(resourceModel.getFile().getProject());
73
		if (jpaProject == null) {
74
			// if we get to this tester, the JPA project should be there;
75
			// so this will probably never happen
76
			return true;  // effectively disable "upgrade"
77
		}
78
		JptResourceType resourceType = resourceModel.getResourceType();
79
		if (resourceType == null) {
80
			return true; // effectively disable "upgrade"
81
		}
82
		IContentType contentType =  resourceType.getContentType();
83
		return Tools.valuesAreEqual(contentType, XmlEntityMappings.CONTENT_TYPE);
84
	}
85
	
64
	private JpaProject getJpaProject(IProject project) {
86
	private JpaProject getJpaProject(IProject project) {
65
		return (JpaProject) project.getAdapter(JpaProject.class);
87
		return (JpaProject) project.getAdapter(JpaProject.class);
66
	}
88
	}
(-)a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/XmlFileAdapterFactory.java (+46 lines)
Added Link Here
1
package org.eclipse.jpt.jpa.core.internal;
2
3
import org.eclipse.core.resources.IResource;
4
import org.eclipse.core.resources.ResourcesPlugin;
5
import org.eclipse.core.runtime.IAdapterFactory;
6
import org.eclipse.jpt.jpa.core.JpaPreferences;
7
import org.eclipse.jpt.jpa.core.JpaWorkspace;
8
import org.eclipse.jpt.jpa.core.context.XmlFile;
9
import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
10
import org.eclipse.jpt.jpa.core.platform.JpaPlatformManager;
11
12
public class XmlFileAdapterFactory implements IAdapterFactory {
13
	private static final Class<?>[] ADAPTER_LIST = new Class[] {
14
		JpaPlatformDescription.class
15
	};
16
17
	public Class<?>[] getAdapterList() {
18
		return ADAPTER_LIST;
19
	}
20
21
	public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
22
		if (adaptableObject instanceof XmlFile) {
23
			return this.getAdapter(((XmlFile) adaptableObject).getXmlResource().getFile(), adapterType);
24
		}
25
		return null;
26
	}
27
	
28
	private Object getAdapter(IResource resource, Class<?> adapterType) {
29
		if (adapterType == JpaPlatformDescription.class) {
30
			return this.getJpaPlatformDescription(resource);
31
		}
32
		return null;
33
	}
34
	
35
	private JpaPlatformDescription getJpaPlatformDescription(IResource resource) {
36
		return this.getJpaPlatformManager().getJpaPlatformDescription(JpaPreferences.getJpaPlatformID(resource.getProject()));
37
	}
38
39
	private JpaPlatformManager getJpaPlatformManager() {
40
		return this.getJpaWorkspace().getJpaPlatformManager();
41
	}
42
43
	private JpaWorkspace getJpaWorkspace() {
44
		return (JpaWorkspace) ResourcesPlugin.getWorkspace().getAdapter(JpaWorkspace.class);
45
	}
46
}
(-)a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/XmlFilePropertyTester.java (-1 / +6 lines)
Lines 21-27 Link Here
21
{
21
{
22
	public static final String IS_LATEST_SUPPORTED_VERSION = "isLatestSupportedVersion"; //$NON-NLS-1$
22
	public static final String IS_LATEST_SUPPORTED_VERSION = "isLatestSupportedVersion"; //$NON-NLS-1$
23
	public static final String IS_NOT_LATEST_SUPPORTED_VERSION = "isNotLatestSupportedVersion"; //$NON-NLS-1$
23
	public static final String IS_NOT_LATEST_SUPPORTED_VERSION = "isNotLatestSupportedVersion"; //$NON-NLS-1$
24
24
	public static final String IS_GENERIC_MAPPING_FILE = "isGenericMappingFile"; //$NON-NLS-1$
25
25
26
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
26
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
27
		if (receiver instanceof XmlFile) {
27
		if (receiver instanceof XmlFile) {
Lines 39-44 Link Here
39
			boolean actual = xmlFile.isLatestSupportedVersion();
39
			boolean actual = xmlFile.isLatestSupportedVersion();
40
			return actual == expected;
40
			return actual == expected;
41
		}
41
		}
42
		if (property.equals(IS_GENERIC_MAPPING_FILE)) {
43
			boolean expected = (expectedValue == null) ? true : ((Boolean) expectedValue).booleanValue();
44
			boolean actual =xmlFile.isGenericMappingFile();
45
			return actual == expected;
46
		}
42
		return false;
47
		return false;
43
	}
48
	}
44
}
49
}
(-)a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java (+4 lines)
Lines 258-263 Link Here
258
		return Tools.valuesAreEqual(member, file);
258
		return Tools.valuesAreEqual(member, file);
259
	}
259
	}
260
260
261
	public boolean isGenericMappingFile() {
262
		return XmlFile_.isGenericMappingFile(this);
263
	}
261
264
262
	// ********** JpaStructureNode implementation **********
265
	// ********** JpaStructureNode implementation **********
263
266
Lines 366-369 Link Here
366
		// since this is the entire file, point to the top of the file
369
		// since this is the entire file, point to the top of the file
367
		return TextRange.Empty.instance();
370
		return TextRange.Empty.instance();
368
	}
371
	}
372
369
}
373
}
(-)a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java (+3 lines)
Lines 196-201 Link Here
196
		return XmlFile_.isLatestSupportedVersion(this);
196
		return XmlFile_.isLatestSupportedVersion(this);
197
	}
197
	}
198
198
199
	public boolean isGenericMappingFile() {
200
		return XmlFile_.isGenericMappingFile(this);
201
	}
199
202
200
	// ********** metamodel **********
203
	// ********** metamodel **********
201
204
(-)a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.properties (-1 / +3 lines)
Lines 37-40 Link Here
37
jpaNode = JPA
37
jpaNode = JPA
38
eclipseLinkNode = EclipseLink
38
eclipseLinkNode = EclipseLink
39
39
40
addVirtualAttribute = Add Virtual Attribute...
40
addVirtualAttribute = Add Virtual Attribute...
41
42
upgradeToEclipseLinkMappingFile = Upgrade To EclipseLink Mapping File
(-)a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml (+84 lines)
Lines 238-243 Link Here
238
			id="org.eclipse.jpt.jpa.eclipselink.ui.generateDynamicEntities"
238
			id="org.eclipse.jpt.jpa.eclipselink.ui.generateDynamicEntities"
239
			name="%generateDynamicEntities"/>
239
			name="%generateDynamicEntities"/>
240
240
241
		<command
242
        	id="org.eclipse.jpt.jpa.eclipselink.ui.upgradeToEclipseLinkMappingFile"
243
        	name="%upgradeToEclipseLinkMappingFile">
244
  		</command>
245
241
  	</extension>
246
  	</extension>
242
247
243
	<!-- ***** handlers ***** -->
248
	<!-- ***** handlers ***** -->
Lines 273-278 Link Here
273
			commandId="org.eclipse.jpt.jpa.eclipselink.ui.generateDynamicEntities"
278
			commandId="org.eclipse.jpt.jpa.eclipselink.ui.generateDynamicEntities"
274
			class="org.eclipse.jpt.jpa.eclipselink.ui.internal.commands.GenerateDynamicEntitiesHandler">
279
			class="org.eclipse.jpt.jpa.eclipselink.ui.internal.commands.GenerateDynamicEntitiesHandler">
275
		</handler>
280
		</handler>
281
282
  		<handler
283
        	class="org.eclipse.jpt.jpa.eclipselink.ui.internal.commands.UpgradeToEclipseLinkMappingFileHandler"
284
        	commandId="org.eclipse.jpt.jpa.eclipselink.ui.upgradeToEclipseLinkMappingFile">
285
     		<enabledWhen>
286
        		<iterate>
287
           			<or>
288
             			<adapt
289
                    		type="org.eclipse.jpt.jpa.core.context.XmlFile">
290
                 			<test
291
                       			property="org.eclipse.jpt.jpa.core.isGenericMappingFile">
292
                 			</test>
293
              			</adapt>
294
              			<adapt
295
                    		type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource">
296
                 			<test
297
                       			property="org.eclipse.jpt.jpa.core.isGenericMappingFile">
298
                 			</test>
299
              			</adapt>
300
           			</or>
301
        		</iterate>
302
        	</enabledWhen>
303
  		</handler>
276
		
304
		
277
	</extension>
305
	</extension>
278
	
306
	
Lines 311-316 Link Here
311
					</with>
339
					</with>
312
				</visibleWhen>
340
				</visibleWhen>
313
			</command>
341
			</command>
342
343
   			<command
344
         		commandId="org.eclipse.jpt.jpa.eclipselink.ui.upgradeToEclipseLinkMappingFile"
345
         		style="push">
346
      			<visibleWhen>
347
         			<with
348
               		variable="selection">
349
            			<iterate
350
                     ifEmpty="false">
351
               				<adapt
352
                     			type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription">
353
                  				<test
354
                        			property="org.eclipse.jpt.jpa.core.jpaPlatformGroup"
355
                        			value="eclipselink">
356
                  					</test>
357
               				</adapt>
358
               				<adapt
359
                     			type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource">
360
                  				<test
361
                        			property="org.eclipse.jpt.jpa.core.isGenericMappingFile">
362
                  				</test>
363
               				</adapt>
364
            			</iterate>
365
         			</with>
366
      			</visibleWhen>
367
   			</command>
314
			
368
			
315
		</menuContribution>
369
		</menuContribution>
316
		
370
		
Lines 362-367 Link Here
362
			</command>
416
			</command>
363
			
417
			
364
		</menuContribution>
418
		</menuContribution>
419
420
		<!-- contributions for any popup -->
421
        <menuContribution
422
              locationURI="popup:org.eclipse.ui.popup.any">
423
           	  <command
424
                  commandId="org.eclipse.jpt.jpa.eclipselink.ui.upgradeToEclipseLinkMappingFile">
425
              	  <visibleWhen>
426
                 	<with
427
                       variable="selection">
428
                       <iterate
429
                             ifEmpty="false">
430
                       	   <adapt
431
                               type="org.eclipse.jpt.jpa.core.context.XmlFile">
432
                          	   <test
433
                                   property="org.eclipse.jpt.jpa.core.isGenericMappingFile">
434
                          	   </test>
435
                       	   </adapt>
436
                           <adapt
437
                                 type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription">
438
                              <test
439
                                    property="org.eclipse.jpt.jpa.core.jpaPlatformGroup"
440
                                    value="eclipselink">
441
                              </test>
442
                           </adapt>
443
                       </iterate>
444
                    </with>
445
                 </visibleWhen>
446
              </command>
447
              
448
         </menuContribution>
365
	
449
	
366
	
450
	
367
	 </extension>
451
	 </extension>
(-)a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/commands/UpgradeToEclipseLinkMappingFileHandler.java (+139 lines)
Added Link Here
1
package org.eclipse.jpt.jpa.eclipselink.ui.internal.commands;
2
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.HashMap;
6
import javax.xml.parsers.DocumentBuilder;
7
import javax.xml.parsers.DocumentBuilderFactory;
8
import javax.xml.parsers.ParserConfigurationException;
9
import javax.xml.transform.OutputKeys;
10
import javax.xml.transform.Transformer;
11
import javax.xml.transform.TransformerConfigurationException;
12
import javax.xml.transform.TransformerException;
13
import javax.xml.transform.TransformerFactory;
14
import javax.xml.transform.dom.DOMSource;
15
import javax.xml.transform.stream.StreamResult;
16
import org.eclipse.core.commands.AbstractHandler;
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
24
import org.eclipse.jpt.jpa.core.JpaProject;
25
import org.eclipse.jpt.jpa.core.context.XmlFile;
26
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
27
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.EclipseLink;
28
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.XmlEntityMappings;
29
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v1_1.EclipseLink1_1;
30
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v1_2.EclipseLink1_2;
31
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_0.EclipseLink2_0;
32
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_1.EclipseLink2_1;
33
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_2.EclipseLink2_2;
34
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_3.EclipseLink2_3;
35
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.v2_4.EclipseLink2_4;
36
import org.eclipse.ui.handlers.HandlerUtil;
37
import org.w3c.dom.Document;
38
import org.w3c.dom.NamedNodeMap;
39
import org.w3c.dom.Node;
40
import org.w3c.dom.NodeList;
41
import org.xml.sax.SAXException;
42
43
public class UpgradeToEclipseLinkMappingFileHandler extends AbstractHandler {
44
45
	public Object execute(ExecutionEvent event) throws ExecutionException {
46
		IStructuredSelection selection 	= (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
47
48
		for (Object selectedObject : selection.toArray()) {
49
			upgradeToEclipseLinkOrm(selectedObject);
50
		}
51
		return null;
52
	}
53
54
	protected void upgradeToEclipseLinkOrm(Object selectedObject) {
55
		JpaXmlResource xmlResource = PlatformTools.getAdapter(selectedObject, JpaXmlResource.class);
56
		if (xmlResource == null) {
57
			XmlFile xmlFile = PlatformTools.getAdapter(selectedObject, XmlFile.class);
58
			if (xmlFile != null) {
59
				xmlResource = xmlFile.getXmlResource();
60
			}
61
		}
62
		if (xmlResource == null) {
63
			return;
64
		}
65
66
		try {
67
			JpaProject jpaProject = this.getJpaProject(xmlResource.getFile().getProject());
68
			String fileLocation = xmlResource.getFile().getRawLocation().toOSString();
69
			String newVersion = jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(XmlEntityMappings.CONTENT_TYPE).getVersion();
70
71
			
72
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
73
			DocumentBuilder builder = factory.newDocumentBuilder();
74
			Document document = builder.parse(new File(fileLocation));
75
			document.setXmlStandalone(true);
76
			NodeList nodes = document.getElementsByTagName("entity-mappings");
77
			if (nodes.getLength() > 0) {
78
				// we know only one "entity-mappings" element exists in the mapping file
79
				Node node = nodes.item(0);
80
				NamedNodeMap attributes = node.getAttributes();
81
				attributes.getNamedItem("version").setTextContent(newVersion);
82
				attributes.getNamedItem("xmlns").setTextContent(getNamespace());
83
				attributes.getNamedItem("xsi:schemaLocation").setTextContent(buildSchemaLocationString(getNamespace(), getSchemaLocationForVersion(newVersion)));
84
			}
85
86
			TransformerFactory transformerFactory = TransformerFactory.newInstance();
87
			Transformer transformer = transformerFactory.newTransformer();
88
			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
89
			transformer.transform(new DOMSource(document), new StreamResult(new File(fileLocation)));
90
			
91
			// refresh the file to load the changes to the editor
92
			xmlResource.getFile().refreshLocal(IResource.DEPTH_ZERO, null);
93
		} catch (ParserConfigurationException pce) {
94
			pce.printStackTrace();
95
		} catch (SAXException sxe) {
96
			sxe.printStackTrace();
97
		} catch (IOException ioe) {
98
			ioe.printStackTrace();
99
		} catch (TransformerConfigurationException tce) {
100
			tce.printStackTrace();
101
		} catch (TransformerException te) {
102
			te.printStackTrace();
103
		} catch (CoreException ce) {
104
			ce.printStackTrace();
105
		}
106
	}
107
108
	private JpaProject getJpaProject(IProject project) {
109
		return (JpaProject) project.getAdapter(JpaProject.class);
110
	}
111
112
	protected static String buildSchemaLocationString(String namespace, String schemaLocation) {
113
		return namespace + ' ' + schemaLocation;
114
	}
115
116
	protected String getNamespace() {
117
		return EclipseLink.SCHEMA_NAMESPACE;
118
	}
119
120
	protected String getSchemaLocationForVersion(String schemaVersion) {
121
		return SCHEMA_LOCATIONS.get(schemaVersion);
122
	}
123
124
	private static HashMap<String, String> SCHEMA_LOCATIONS = buildSchemaLocations();
125
126
	private static HashMap<String, String> buildSchemaLocations() {
127
		HashMap<String, String> map = new HashMap<String, String>();
128
		map.put(EclipseLink.SCHEMA_VERSION, EclipseLink.SCHEMA_LOCATION);
129
		map.put(EclipseLink1_1.SCHEMA_VERSION, EclipseLink1_1.SCHEMA_LOCATION);
130
		map.put(EclipseLink1_2.SCHEMA_VERSION, EclipseLink1_2.SCHEMA_LOCATION);
131
		map.put(EclipseLink2_0.SCHEMA_VERSION, EclipseLink2_0.SCHEMA_LOCATION);
132
		map.put(EclipseLink2_1.SCHEMA_VERSION, EclipseLink2_1.SCHEMA_LOCATION);
133
		map.put(EclipseLink2_2.SCHEMA_VERSION, EclipseLink2_2.SCHEMA_LOCATION);
134
		map.put(EclipseLink2_3.SCHEMA_VERSION, EclipseLink2_3.SCHEMA_LOCATION);
135
		map.put(EclipseLink2_4.SCHEMA_VERSION, EclipseLink2_4.SCHEMA_LOCATION);
136
		return map;
137
	}
138
139
}

Return to bug 315464