Skip to content

Commit 72caaab

Browse files
committed
[E4 XPath] Deprecate unsuitable XPathContextFactory methods for removal
1 parent 149b29b commit 72caaab

File tree

9 files changed

+37
-24
lines changed

9 files changed

+37
-24
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<component id="org.eclipse.e4.emf.xpath" version="2">
3+
<resource path="src/org/eclipse/e4/emf/xpath/XPathContextFactory.java" type="org.eclipse.e4.emf.xpath.XPathContextFactory">
4+
<filter id="422776937">
5+
<message_arguments>
6+
<message_argument value="org.eclipse.e4.emf.xpath.XPathContextFactory.newInstance()"/>
7+
<message_argument value="T"/>
8+
</message_arguments>
9+
</filter>
10+
</resource>
11+
</component>

bundles/org.eclipse.e4.emf.xpath/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
4-
Bundle-SymbolicName: org.eclipse.e4.emf.xpath
4+
Bundle-SymbolicName: org.eclipse.e4.emf.xpath;deprecated:="This bundle is deprecated since 2025-03 (removal in 2027-03 or later)"
55
Bundle-Version: 0.6.0.qualifier
66
Bundle-RequiredExecutionEnvironment: JavaSE-17
77
Require-Bundle: org.eclipse.emf.ecore;bundle-version="2.35.0",

bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/xpath/EcoreXPathContextFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
******************************************************************************/
1414
package org.eclipse.e4.emf.xpath;
1515

16-
import org.eclipse.e4.emf.xpath.internal.java.JavaXPathContextFactoryImpl;
1716
import org.eclipse.emf.ecore.EObject;
1817

1918
/**
2019
* Factory which creates an XPathContextFactory for {@link EObject}s
2120
*
2221
* @since 1.0
2322
*/
23+
@Deprecated(forRemoval = true, since = "2025-03 (removal in 2027-03 or later)")
2424
public class EcoreXPathContextFactory {
2525

2626
/**
@@ -29,7 +29,7 @@ public class EcoreXPathContextFactory {
2929
* @return the factory
3030
*/
3131
public static XPathContextFactory<EObject> newInstance() {
32-
return new JavaXPathContextFactoryImpl<>();
32+
return XPathContextFactory.newInstance();
3333
}
3434

3535
}

bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/xpath/XPathContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010, 2024 BestSolution.at and others.
2+
* Copyright (c) 2010, 2025 BestSolution.at and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -34,6 +34,7 @@ public interface XPathContext {
3434
* to evaluate
3535
* @return Object found
3636
*/
37+
@Deprecated(forRemoval = true, since = "2025-03 (removal in 2027-03 or later)")
3738
Object getValue(String xpath);
3839

3940
/**
@@ -46,6 +47,7 @@ public interface XPathContext {
4647
* required type
4748
* @return Object found
4849
*/
50+
@Deprecated(forRemoval = true, since = "2025-03 (removal in 2027-03 or later)")
4951
<T> T getValue(String xpath, Class<T> requiredType);
5052

5153
/**

bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/xpath/XPathContextFactory.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010, 2024 BestSolution.at and others.
2+
* Copyright (c) 2010, 2025 BestSolution.at and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,7 @@
1414
package org.eclipse.e4.emf.xpath;
1515

1616
import org.eclipse.e4.emf.xpath.internal.java.JavaXPathContextFactoryImpl;
17+
import org.eclipse.emf.ecore.EObject;
1718

1819
/**
1920
* Factory responsible to create an XPath-Context
@@ -38,14 +39,19 @@ public abstract class XPathContextFactory<T> {
3839
* @param parentContext parent context
3940
* @param contextBean Object
4041
* @return XPathContext
42+
* @deprecated The parent-context does not provide any real value. Just use
43+
* {@link #newContext(Object)}
4144
*/
45+
@Deprecated(forRemoval = true, since = "2025-03 (removal in 2027-03 or later)")
4246
public abstract XPathContext newContext(XPathContext parentContext, T contextBean);
4347

4448
/**
45-
* @param <T> the object type the xpath is created for
46-
* @return Create a new XPath-Factory
49+
* Creates a new {@link XPathContextFactory XPathContextFactory<EObject>} that's
50+
* suitable to query the E4-model.
51+
*
52+
* @return A new {@code XPathContextFactory}.
4753
*/
48-
public static <T> XPathContextFactory<T> newInstance() {
49-
return new JavaXPathContextFactoryImpl<>();
54+
public static XPathContextFactory<EObject> newInstance() {
55+
return new JavaXPathContextFactoryImpl();
5056
}
5157
}

bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/xpath/internal/java/JavaXPathContextFactoryImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,17 @@
5757
import org.w3c.dom.Node;
5858
import org.w3c.dom.NodeList;
5959

60-
public class JavaXPathContextFactoryImpl<T> extends XPathContextFactory<T> {
60+
public class JavaXPathContextFactoryImpl extends XPathContextFactory<EObject> {
6161

6262
private static final XPathFactory XPATH_FACTORY = XPathFactory.newInstance();
6363

6464
@Override
65-
public XPathContext newContext(T contextBean) {
65+
public XPathContext newContext(EObject contextBean) {
6666
return newContext(null, contextBean);
6767
}
6868

6969
@Override
70-
public XPathContext newContext(XPathContext parentContext, T contextBean) {
71-
if (!(contextBean instanceof EObject rootObject)) {
72-
throw new IllegalArgumentException();
73-
}
70+
public XPathContext newContext(XPathContext parentContext, EObject contextBean) {
7471
XPath xpath;
7572
DOMMapping domMapping;
7673
Element rootElement = null;
@@ -95,7 +92,7 @@ public XPathContext newContext(XPathContext parentContext, T contextBean) {
9592
Document document = documentBuilder.newDocument();
9693

9794
domMapping = new DOMMapping();
98-
rootElement = createElement(rootObject, document, domMapping);
95+
rootElement = createElement(contextBean, document, domMapping);
9996
xpath.setNamespaceContext(createNamespaceContext(rootElement));
10097
}
10198
return new EObjectContext(rootElement, domMapping, xpath);

bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/fragment/impl/StringModelFragmentImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.ArrayList;
1919
import java.util.List;
2020
import java.util.regex.Pattern;
21-
import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
2221
import org.eclipse.e4.emf.xpath.XPathContext;
2322
import org.eclipse.e4.emf.xpath.XPathContextFactory;
2423
import org.eclipse.e4.ui.model.application.MApplication;
@@ -355,7 +354,7 @@ private void mergeXPath(MApplication application, List<MApplicationElement> ret,
355354
if ("/".equals(xPath)) {
356355
targetElements = List.of(application);
357356
} else {
358-
XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
357+
XPathContextFactory<EObject> f = XPathContextFactory.newInstance();
359358
XPathContext xpathContext = f.newContext((EObject) application);
360359
try {
361360
targetElements = xpathContext.stream(xPath, MApplicationElement.class).toList();

tests/org.eclipse.e4.emf.xpath.test/src/org/eclipse/e4/emf/xpath/test/ExampleQueriesApplicationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.List;
2121

22-
import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
2322
import org.eclipse.e4.emf.xpath.XPathContext;
2423
import org.eclipse.e4.emf.xpath.XPathContextFactory;
2524
import org.eclipse.e4.ui.internal.workbench.E4XMIResourceFactory;
@@ -69,11 +68,11 @@ public void setUp() {
6968

7069
URI uri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/Application.e4xmi", true);
7170
resource = resourceSet.getResource(uri, true);
72-
XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
71+
XPathContextFactory<EObject> f = XPathContextFactory.newInstance();
7372
xpathContext = f.newContext(resource.getContents().get(0));
7473
URI childUri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/fragment.e4xmi", true);
7574
childResource = resourceSet.getResource(childUri, true);
76-
xpathChildContext = f.newContext(xpathContext, childResource.getContents().get(0));
75+
xpathChildContext = f.newContext(childResource.getContents().get(0));
7776
}
7877

7978
@After

tests/org.eclipse.e4.emf.xpath.test/src/org/eclipse/e4/emf/xpath/test/ExampleQueriesTestCase.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Iterator;
2626
import java.util.List;
2727

28-
import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
2928
import org.eclipse.e4.emf.xpath.XPathContext;
3029
import org.eclipse.e4.emf.xpath.XPathContextFactory;
3130
import org.eclipse.e4.emf.xpath.XPathNotFoundException;
@@ -61,7 +60,7 @@ public void setUp() {
6160
resourceSet.getPackageRegistry().put(XpathtestPackage.eNS_URI, XpathtestPackage.eINSTANCE);
6261
URI uri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/Test.xmi", true);
6362
resource = resourceSet.getResource(uri, true);
64-
xpathContextFactory = EcoreXPathContextFactory.newInstance();
63+
xpathContextFactory = XPathContextFactory.newInstance();
6564
xpathContext = xpathContextFactory.newContext(resource.getContents().get(0));
6665
}
6766

@@ -131,7 +130,7 @@ public void testRelative() {
131130
EObject context = resource.getContents().get(0);
132131
List<EObject> eContents = context.eContents();
133132
EObject firstElement = eContents.get(0);
134-
XPathContext nestedXpathContext = xpathContextFactory.newContext(xpathContext, firstElement);
133+
XPathContext nestedXpathContext = xpathContextFactory.newContext(firstElement);
135134

136135
List<Node> dotList = nestedXpathContext.stream(".", Node.class).toList();
137136
assertEquals(1, dotList.size());

0 commit comments

Comments
 (0)