From f92becdfdf350f0fdad500d98800424dacf57cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JB=20Onofr=C3=A9?= Date: Sun, 3 May 2026 09:05:18 +0200 Subject: [PATCH] Remove specs bundles --- assemblies/features/base/pom.xml | 40 --- bom/artifacts/pom.xml | 21 -- .../core/internal/InstanceServiceImpl.java | 8 +- .../apache/karaf/itests/KarafTestSupport.java | 10 +- .../KarafMinimalMonitoredTestSupport.java | 11 +- pom.xml | 1 - services/interceptor/impl/pom.xml | 6 - specs/activator/pom.xml | 71 ---- .../karaf/specs/activator/Activator.java | 205 ----------- .../karaf/specs/locator/MockCallable.java | 27 -- .../karaf/specs/locator/MockCallable2.java | 27 -- .../karaf/specs/locator/OsgiLocatorTest.java | 83 ----- specs/javaxml/pom.xml | 143 -------- .../javax/xml/datatype/$FactoryFinder.java | 226 ------------ .../javax/xml/datatype/DatatypeFactory.java | 279 --------------- .../javax/xml/parsers/$FactoryFinder.java | 242 ------------- .../xml/parsers/DocumentBuilderFactory.java | 145 -------- .../javax/xml/parsers/SAXParserFactory.java | 115 ------ .../java/javax/xml/stream/$FactoryFinder.java | 222 ------------ .../javax/xml/stream/XMLEventFactory.java | 102 ------ .../javax/xml/stream/XMLInputFactory.java | 132 ------- .../javax/xml/stream/XMLOutputFactory.java | 74 ---- .../javax/xml/transform/$FactoryFinder.java | 232 ------------ .../xml/transform/TransformerFactory.java | 62 ---- .../xml/validation/$SchemaFactoryFinder.java | 328 ----------------- .../javax/xml/validation/SchemaFactory.java | 138 -------- .../javax/xml/xpath/$XPathFactoryFinder.java | 330 ------------------ .../java/javax/xml/xpath/XPathFactory.java | 120 ------- .../java/org/w3c/dom/ElementTraversal.java | 64 ---- specs/javaxmlws/pom.xml | 84 ----- .../java/javax/xml/soap/$FactoryFinder.java | 256 -------------- .../java/javax/xml/soap/MessageFactory.java | 46 --- .../java/javax/xml/soap/SAAJMetaFactory.java | 38 -- .../javax/xml/soap/SOAPConnectionFactory.java | 33 -- .../main/java/javax/xml/soap/SOAPFactory.java | 68 ---- .../java/javax/xml/ws/spi/$FactoryFinder.java | 165 --------- .../main/java/javax/xml/ws/spi/Provider.java | 89 ----- specs/locator/pom.xml | 37 -- .../karaf/specs/locator/OsgiLocator.java | 161 --------- .../karaf/specs/locator/MockCallable.java | 27 -- .../karaf/specs/locator/MockCallable2.java | 27 -- .../karaf/specs/locator/OsgiLocatorTest.java | 83 ----- specs/pom.xml | 44 --- 43 files changed, 4 insertions(+), 4618 deletions(-) delete mode 100644 specs/activator/pom.xml delete mode 100644 specs/activator/src/main/java/org/apache/karaf/specs/activator/Activator.java delete mode 100644 specs/activator/src/test/java/org/apache/karaf/specs/locator/MockCallable.java delete mode 100644 specs/activator/src/test/java/org/apache/karaf/specs/locator/MockCallable2.java delete mode 100644 specs/activator/src/test/java/org/apache/karaf/specs/locator/OsgiLocatorTest.java delete mode 100644 specs/javaxml/pom.xml delete mode 100644 specs/javaxml/src/main/java/javax/xml/datatype/$FactoryFinder.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/datatype/DatatypeFactory.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/parsers/$FactoryFinder.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/parsers/DocumentBuilderFactory.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/parsers/SAXParserFactory.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/stream/$FactoryFinder.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/stream/XMLEventFactory.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/stream/XMLInputFactory.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/stream/XMLOutputFactory.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/transform/$FactoryFinder.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/transform/TransformerFactory.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/validation/$SchemaFactoryFinder.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/validation/SchemaFactory.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/xpath/$XPathFactoryFinder.java delete mode 100644 specs/javaxml/src/main/java/javax/xml/xpath/XPathFactory.java delete mode 100644 specs/javaxml/src/main/java/org/w3c/dom/ElementTraversal.java delete mode 100644 specs/javaxmlws/pom.xml delete mode 100644 specs/javaxmlws/src/main/java/javax/xml/soap/$FactoryFinder.java delete mode 100644 specs/javaxmlws/src/main/java/javax/xml/soap/MessageFactory.java delete mode 100644 specs/javaxmlws/src/main/java/javax/xml/soap/SAAJMetaFactory.java delete mode 100644 specs/javaxmlws/src/main/java/javax/xml/soap/SOAPConnectionFactory.java delete mode 100644 specs/javaxmlws/src/main/java/javax/xml/soap/SOAPFactory.java delete mode 100644 specs/javaxmlws/src/main/java/javax/xml/ws/spi/$FactoryFinder.java delete mode 100644 specs/javaxmlws/src/main/java/javax/xml/ws/spi/Provider.java delete mode 100644 specs/locator/pom.xml delete mode 100644 specs/locator/src/main/java/org/apache/karaf/specs/locator/OsgiLocator.java delete mode 100644 specs/locator/src/test/java/org/apache/karaf/specs/locator/MockCallable.java delete mode 100644 specs/locator/src/test/java/org/apache/karaf/specs/locator/MockCallable2.java delete mode 100644 specs/locator/src/test/java/org/apache/karaf/specs/locator/OsgiLocatorTest.java delete mode 100644 specs/pom.xml diff --git a/assemblies/features/base/pom.xml b/assemblies/features/base/pom.xml index 1aeaafb8205..edbe045bd5b 100644 --- a/assemblies/features/base/pom.xml +++ b/assemblies/features/base/pom.xml @@ -59,26 +59,6 @@ org.apache.servicemix.specs.activation-api-1.2.1 1.2.1_3 - - org.apache.karaf.specs - org.apache.karaf.specs.locator - runtime - - - org.apache.karaf.specs - org.apache.karaf.specs.java.xml - runtime - - - org.apache.karaf.specs - org.apache.karaf.specs.java.xml.ws - runtime - - - org.apache.karaf.specs - org.apache.karaf.specs.activator - runtime - org.apache.karaf org.apache.karaf.main @@ -155,21 +135,6 @@ - - org.apache.karaf.specs - org.apache.karaf.specs.locator - target/classes/resources/lib/endorsed - - - org.apache.karaf.specs - org.apache.karaf.specs.java.xml - target/classes/resources/lib/endorsed - - - org.apache.karaf.specs - org.apache.karaf.specs.java.xml.ws - target/classes/resources/lib/endorsed - jakarta.annotation jakarta.annotation-api @@ -190,11 +155,6 @@ osgi.core target/classes/resources/lib/boot - - org.apache.karaf.specs - org.apache.karaf.specs.activator - target/classes/resources/lib/boot - org.apache.karaf org.apache.karaf.client diff --git a/bom/artifacts/pom.xml b/bom/artifacts/pom.xml index 471fed0206c..81c383bd9d1 100644 --- a/bom/artifacts/pom.xml +++ b/bom/artifacts/pom.xml @@ -391,27 +391,6 @@ ${project.version} - - org.apache.karaf.specs - org.apache.karaf.specs.locator - ${project.version} - - - org.apache.karaf.specs - org.apache.karaf.specs.activator - ${project.version} - - - org.apache.karaf.specs - org.apache.karaf.specs.java.xml - ${project.version} - - - org.apache.karaf.specs - org.apache.karaf.specs.java.xml.ws - ${project.version} - - org.apache.karaf.subsystem org.apache.karaf.subsystem.core diff --git a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java index 2c56c3c15f7..7671f4c8b90 100644 --- a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java +++ b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java @@ -516,11 +516,7 @@ private void doStart(InstanceState instance, String name, String javaOpts) throw classpath.append(System.getProperty("path.separator")); classpath.append(jdk9Classpath); } - jdkOpts = " --add-reads=java.xml=java.logging" + - " --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED" + - " --patch-module java.base=" + System.getProperty("karaf.home") + "/lib/endorsed/org.apache.karaf.specs.locator-" + System.getProperty("karaf.version") + ".jar" + - " --patch-module java.xml=" + System.getProperty("karaf.home") + "/lib/endorsed/org.apache.karaf.specs.java.xml-" + System.getProperty("karaf.version") + ".jar" + - " --add-opens java.base/java.security=ALL-UNNAMED" + + jdkOpts = " --add-opens java.base/java.security=ALL-UNNAMED" + " --add-opens java.base/java.net=ALL-UNNAMED" + " --add-opens java.base/java.lang=ALL-UNNAMED" + " --add-opens java.base/java.util=ALL-UNNAMED" + @@ -541,7 +537,7 @@ private void doStart(InstanceState instance, String name, String javaOpts) throw jdkOpts += " -Djava.security.manager=allow"; } } else { - jdkOpts = " -Djava.endorsed.dirs=\"" + new File(new File(new File(System.getProperty("java.home"), "jre"), "lib"), "endorsed") + System.getProperty("path.separator") + new File(new File(System.getProperty("java.home"), "lib"), "endorsed") + System.getProperty("path.separator") + new File(libDir, "endorsed").getCanonicalPath() + "\"" + jdkOpts = " -Djava.endorsed.dirs=\"" + new File(new File(new File(System.getProperty("java.home"), "jre"), "lib"), "endorsed") + System.getProperty("path.separator") + new File(new File(System.getProperty("java.home"), "lib"), "endorsed") + "\"" + " -Djava.ext.dirs=\"" + new File(new File(new File(System.getProperty("java.home"), "jre"), "lib"), "ext") + System.getProperty("path.separator") + new File(new File(System.getProperty("java.home"), "lib"), "ext") + System.getProperty("path.separator") + new File(libDir, "ext").getCanonicalPath() + "\""; } String command = "\"" diff --git a/itests/common/src/main/java/org/apache/karaf/itests/KarafTestSupport.java b/itests/common/src/main/java/org/apache/karaf/itests/KarafTestSupport.java index 843a46c5b5c..3a9876d12b0 100644 --- a/itests/common/src/main/java/org/apache/karaf/itests/KarafTestSupport.java +++ b/itests/common/src/main/java/org/apache/karaf/itests/KarafTestSupport.java @@ -260,13 +260,6 @@ public Option[] config() { KarafDistributionOption.editConfigurationFilePut("etc/org.ops4j.pax.url.mvn.cfg", "org.ops4j.pax.url.mvn.localRepository", localRepository), KarafDistributionOption.editConfigurationFilePut("etc/branding.properties", "welcome", ""), // No welcome banner KarafDistributionOption.editConfigurationFilePut("etc/branding-ssh.properties", "welcome", ""), - new VMOption("--add-reads=java.xml=java.logging"), - new VMOption("--add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED"), - new VMOption("--patch-module"), - new VMOption("java.base=lib/endorsed/org.apache.karaf.specs.locator-" - + System.getProperty("karaf.version") + ".jar"), - new VMOption("--patch-module"), new VMOption("java.xml=lib/endorsed/org.apache.karaf.specs.java.xml-" - + System.getProperty("karaf.version") + ".jar"), new VMOption("--add-opens"), new VMOption("java.base/java.security=ALL-UNNAMED"), new VMOption("--add-opens"), @@ -288,8 +281,7 @@ public Option[] config() { new VMOption("--add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED"), new VMOption("--add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED"), new VMOption("-classpath"), - new VMOption("lib/jdk9plus/*" + File.pathSeparator + "lib/boot/*" - + File.pathSeparator + "lib/endorsed/*") + new VMOption("lib/jdk9plus/*" + File.pathSeparator + "lib/boot/*") }; } else { diff --git a/itests/test/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java b/itests/test/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java index 679efd5f489..8269a5c77f9 100644 --- a/itests/test/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java +++ b/itests/test/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java @@ -89,14 +89,6 @@ public Option[] baseConfig() throws Exception { editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort), editConfigurationFilePut("etc/startup.properties", "file:../../" + new File(url.toURI()).getName(), "1"), composite(editConfigurationFilePut("etc/org.apache.karaf.features.cfg", new File("target/test-classes/etc/org.apache.karaf.features.cfg"))), - new VMOption("--add-reads=java.xml=java.logging"), - new VMOption("--add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED"), - new VMOption("--patch-module"), - new VMOption("java.base=lib/endorsed/org.apache.karaf.specs.locator-" - + System.getProperty("karaf.version") + ".jar"), - new VMOption("--patch-module"), - new VMOption("java.xml=lib/endorsed/org.apache.karaf.specs.java.xml-" - + System.getProperty("karaf.version") + ".jar"), new VMOption("--add-opens"), new VMOption("java.base/java.security=ALL-UNNAMED"), new VMOption("--add-opens"), @@ -118,8 +110,7 @@ public Option[] baseConfig() throws Exception { new VMOption("--add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED"), new VMOption("--add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED"), new VMOption("-classpath"), - new VMOption("lib/jdk9plus/*" + File.pathSeparator + "lib/boot/*" - + File.pathSeparator + "lib/endorsed/*" ) + new VMOption("lib/jdk9plus/*" + File.pathSeparator + "lib/boot/*") }; } else { return new Option[] { diff --git a/pom.xml b/pom.xml index 80cafcbdb15..7936005e008 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,6 @@ event tooling manual - specs assemblies examples archetypes diff --git a/services/interceptor/impl/pom.xml b/services/interceptor/impl/pom.xml index 698aff36a41..e0833dafa22 100644 --- a/services/interceptor/impl/pom.xml +++ b/services/interceptor/impl/pom.xml @@ -124,12 +124,6 @@ ${slf4j.version} test - - org.apache.karaf.specs - org.apache.karaf.specs.locator - ${project.version} - test - diff --git a/specs/activator/pom.xml b/specs/activator/pom.xml deleted file mode 100644 index 8ec070e748e..00000000000 --- a/specs/activator/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - 4.0.0 - - - org.apache.karaf.specs - specs - 4.5.0-SNAPSHOT - - - org.apache.karaf.specs.activator - Apache Karaf :: Specs :: Activator - - - - - org.apache.karaf - karaf-bom - ${project.version} - pom - import - - - - - - - org.apache.karaf.specs - org.apache.karaf.specs.locator - - - org.osgi - org.osgi.framework - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - org.apache.karaf.specs.activator.Activator - - - - - - - diff --git a/specs/activator/src/main/java/org/apache/karaf/specs/activator/Activator.java b/specs/activator/src/main/java/org/apache/karaf/specs/activator/Activator.java deleted file mode 100644 index 97a83e31cd3..00000000000 --- a/specs/activator/src/main/java/org/apache/karaf/specs/activator/Activator.java +++ /dev/null @@ -1,205 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.karaf.specs.activator; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.apache.karaf.specs.locator.OsgiLocator; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.framework.SynchronousBundleListener; - -public class Activator implements BundleActivator, SynchronousBundleListener { - - private static boolean debug = false; - - private ConcurrentMap>> factories = new ConcurrentHashMap<>(); - - private BundleContext bundleContext; - - static { - try { - String prop = System.getProperty("org.apache.karaf.specs.debug"); - debug = prop != null && !"false".equals(prop); - } catch (Throwable t) { } - } - - /** - *

Output debugging messages.

- * - * @param msg String to print to stderr. - */ - protected void debugPrintln(String msg) { - if (debug) { - System.err.println("Spec(" + bundleContext.getBundle().getBundleId() + "): " + msg); - } - } - - public synchronized void start(BundleContext bundleContext) throws Exception { - this.bundleContext = bundleContext; - debugPrintln("activating"); - debugPrintln("adding bundle listener"); - bundleContext.addBundleListener(this); - debugPrintln("checking existing bundles"); - for (Bundle bundle : bundleContext.getBundles()) { - if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING || - bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) { - register(bundle); - } - } - debugPrintln("activated"); - } - - public synchronized void stop(BundleContext bundleContext) throws Exception { - debugPrintln("deactivating"); - if (bundleContext != null) { - bundleContext.removeBundleListener(this); - } - while (!factories.isEmpty()) { - unregister(factories.keySet().iterator().next()); - } - debugPrintln("deactivated"); - this.bundleContext = null; - } - - public void bundleChanged(BundleEvent event) { - synchronized (this) { - if (bundleContext == null) { - return; - } - } - if (event.getType() == BundleEvent.RESOLVED) { - register(event.getBundle()); - } else if (event.getType() == BundleEvent.UNRESOLVED || event.getType() == BundleEvent.UNINSTALLED) { - unregister(event.getBundle().getBundleId()); - } - } - - protected void register(final Bundle bundle) { - debugPrintln("checking bundle " + bundle.getBundleId()); - Map> map = factories.get(bundle.getBundleId()); - Enumeration e = bundle.findEntries("META-INF/services/", "*", false); - if (e != null) { - while (e.hasMoreElements()) { - final URL u = (URL) e.nextElement(); - final String url = u.toString(); - if (url.endsWith("/")) { - continue; - } - final String factoryId = url.substring(url.lastIndexOf("/") + 1); - if (map == null) { - map = new HashMap<>(); - factories.put(bundle.getBundleId(), map); - } - map.put(factoryId, new BundleFactoryLoader(factoryId, u, bundle)); - } - } - if (map != null) { - for (Map.Entry> entry : map.entrySet()) { - debugPrintln("registering service for key " + entry.getKey() + " with value " + entry.getValue()); - OsgiLocator.register(entry.getKey(), entry.getValue()); - } - } - } - - protected void unregister(long bundleId) { - Map> map = factories.remove(bundleId); - if (map != null) { - for (Map.Entry> entry : map.entrySet()) { - debugPrintln("unregistering service for key " + entry.getKey() + " with value " + entry.getValue()); - OsgiLocator.unregister(entry.getKey(), entry.getValue()); - } - } - } - - private class BundleFactoryLoader implements Callable { - private final String factoryId; - private final URL u; - private final Bundle bundle; - private volatile Class clazz; - - public BundleFactoryLoader(String factoryId, URL u, Bundle bundle) { - this.factoryId = factoryId; - this.u = u; - this.bundle = bundle; - } - - public Class call() throws Exception { - try { - debugPrintln("loading factory for key: " + factoryId); - - if (clazz == null){ - synchronized (this) { - if (clazz == null){ - debugPrintln("creating factory for key: " + factoryId); - try (BufferedReader br = new BufferedReader( - new InputStreamReader(u.openStream(), StandardCharsets.UTF_8))) { - String factoryClassName = br.readLine(); - while (factoryClassName != null) { - factoryClassName = factoryClassName.trim(); - if (factoryClassName.charAt(0) != '#') { - debugPrintln("factory implementation: " + factoryClassName); - clazz = bundle.loadClass(factoryClassName); - return clazz; - } - factoryClassName = br.readLine(); - } - } - } - } - } - return clazz; - } catch (Exception e) { - debugPrintln("exception caught while creating factory: " + e); - throw e; - } catch (Error e) { - debugPrintln("error caught while creating factory: " + e); - throw e; - } - } - - @Override - public String toString() { - return u.toString(); - } - - @Override - public int hashCode() { - return u.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof BundleFactoryLoader) { - return u.toExternalForm().equals(((BundleFactoryLoader) obj).u.toExternalForm()); - } else { - return false; - } - } - } -} diff --git a/specs/activator/src/test/java/org/apache/karaf/specs/locator/MockCallable.java b/specs/activator/src/test/java/org/apache/karaf/specs/locator/MockCallable.java deleted file mode 100644 index 092d5bdd002..00000000000 --- a/specs/activator/src/test/java/org/apache/karaf/specs/locator/MockCallable.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.karaf.specs.locator; - -import java.util.concurrent.Callable; - -public class MockCallable implements Callable { - - public Class call() throws Exception { - return this.getClass(); - } - -} diff --git a/specs/activator/src/test/java/org/apache/karaf/specs/locator/MockCallable2.java b/specs/activator/src/test/java/org/apache/karaf/specs/locator/MockCallable2.java deleted file mode 100644 index 7fba2f4ad2c..00000000000 --- a/specs/activator/src/test/java/org/apache/karaf/specs/locator/MockCallable2.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.karaf.specs.locator; - -import java.util.concurrent.Callable; - -public class MockCallable2 implements Callable { - - public Class call() throws Exception { - return this.getClass(); - } - -} diff --git a/specs/activator/src/test/java/org/apache/karaf/specs/locator/OsgiLocatorTest.java b/specs/activator/src/test/java/org/apache/karaf/specs/locator/OsgiLocatorTest.java deleted file mode 100644 index 7fc9dbdf77e..00000000000 --- a/specs/activator/src/test/java/org/apache/karaf/specs/locator/OsgiLocatorTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.karaf.specs.locator; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OsgiLocatorTest extends Assert { - - @BeforeClass - public static void setup() { - OsgiLocator.register("Factory", new MockCallable()); - OsgiLocator.register("Factory", new MockCallable2()); - } - - @Test - public void testLocatorWithSystemProperty() { - System.setProperty(OsgiLocator.TIMEOUT, "0"); - System.setProperty("Factory", "org.apache.karaf.specs.locator.MockCallable"); - Class clazz = OsgiLocator.locate(Object.class, "Factory"); - assertNotNull("Expected to find a class", clazz); - assertEquals("Got the wrong class", MockCallable.class.getName(), clazz.getName()); - - System.setProperty("Factory", "org.apache.karaf.specs.locator"); - clazz = OsgiLocator.locate(Object.class, "Factory"); - assertNull("Did not expect to find a class", clazz); - } - - @Test - public void testLocatorWithoutSystemProperty() { - System.setProperty(OsgiLocator.TIMEOUT, "0"); - System.clearProperty("Factory"); - Class clazz = OsgiLocator.locate(Object.class, "Factory"); - assertNotNull("Expected to find a class", clazz); - assertEquals("Got the wrong class", MockCallable2.class.getName(), clazz.getName()); - } - - @Test - public void testLocatorWithSystemPropertyAndTimeout() { - long timeout = 1000; - System.setProperty(OsgiLocator.TIMEOUT, Long.toString(timeout)); - System.setProperty("Factory", "org.apache.karaf.specs.locator.MockCallable"); - Class clazz = OsgiLocator.locate(Object.class, "Factory"); - assertNotNull("Expected to find a class", clazz); - assertEquals("Got the wrong class.", MockCallable.class.getName(), clazz.getName()); - - System.setProperty("Factory", "org.apache.karaf.specs.locator"); - long t0 = System.currentTimeMillis(); - clazz = OsgiLocator.locate(Object.class, "Factory"); - long t1 = System.currentTimeMillis(); - assertNull("Did not expect to find a class", clazz); - assertTrue("Timeout issue", (t1 - t0) > timeout / 2); - } - - @Test - public void testLocatorWithoutSystemPropertyAndTimeout() { - long timeout = 1000; - System.setProperty(OsgiLocator.TIMEOUT, Long.toString(timeout)); - System.clearProperty("Factory"); - long t0 = System.currentTimeMillis(); - Class clazz = OsgiLocator.locate(Object.class, "Factory"); - long t1 = System.currentTimeMillis(); - assertNotNull("Expected to find a class", clazz); - assertEquals("Got the wrong class", MockCallable2.class.getName(), clazz.getName()); - assertTrue("Timeout issue", (t1 - t0) < timeout / 2); - } - -} diff --git a/specs/javaxml/pom.xml b/specs/javaxml/pom.xml deleted file mode 100644 index 8645173fac4..00000000000 --- a/specs/javaxml/pom.xml +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - 4.0.0 - - - org.apache.karaf.specs - specs - 4.5.0-SNAPSHOT - - - org.apache.karaf.specs.java.xml - jar - Apache Karaf :: Specs :: Java Xml - - - 8 - - - - - - org.apache.karaf - karaf-bom - ${project.version} - pom - import - - - - - - - org.apache.geronimo.specs - geronimo-stax-api_1.2_spec - 1.2 - - - xml-apis - xml-apis - 2.0.2 - - - org.apache.karaf.specs - org.apache.karaf.specs.locator - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - true - - - - - - - - diff --git a/specs/javaxml/src/main/java/javax/xml/datatype/$FactoryFinder.java b/specs/javaxml/src/main/java/javax/xml/datatype/$FactoryFinder.java deleted file mode 100644 index 1e550400c77..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/datatype/$FactoryFinder.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.datatype; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Iterator; -import java.util.Properties; -import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; -import java.util.logging.Level; -import java.util.logging.Logger; - -class $FactoryFinder { - - private static final String DEFAULT_PACKAGE = "com.sun.xml.internal."; - - private static final Logger LOGGER = Logger.getLogger("jvaax.xml.datatype"); - - final private static Properties cacheProps = new Properties(); - - private static volatile boolean firstTime = true; - - static private Class getProviderClass(String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException { - try { - if (cl == null) { - if (useBSClsLoader) { - return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); - } else { - cl = getContextClassLoader(); - if (cl == null) { - throw new ClassNotFoundException(); - } - else { - return Class.forName(className, false, cl); - } - } - } - else { - return Class.forName(className, false, cl); - } - } - catch (ClassNotFoundException e1) { - if (doFallback) { - return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); - } - else { - throw e1; - } - } - } - - - static T newInstance(Class type, String className, ClassLoader cl, boolean doFallback) throws DatatypeConfigurationException { - return newInstance(type, className, cl, doFallback, false); - } - - - static T newInstance(Class type, String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws DatatypeConfigurationException { - assert type != null; - if (System.getSecurityManager() != null) { - if (className != null && className.startsWith(DEFAULT_PACKAGE)) { - cl = null; - useBSClsLoader = true; - } - } - try { - Class providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader); - if (!type.isAssignableFrom(providerClass)) { - throw new ClassCastException(className + " cannot be cast to " + type.getName()); - } - Object instance = providerClass.getConstructor().newInstance(); - final ClassLoader clD = cl; - LOGGER.fine(() -> "created new instance of " + providerClass + " using ClassLoader: " + clD); - return type.cast(instance); - } - catch (ClassNotFoundException x) { - throw new DatatypeConfigurationException("Provider " + className + " not found", x); - } - catch (Exception x) { - throw new DatatypeConfigurationException("Provider " + className + " could not be instantiated: " + x, x); - } - } - - - static T find(Class type, String fallbackClassName) throws DatatypeConfigurationException { - return find(type, type.getName(), null, fallbackClassName); - } - - static T find(Class type, String factoryId, ClassLoader cl, String fallbackClassName) throws DatatypeConfigurationException - { - try { - // If we are deployed into an OSGi environment, leverage it - Class spiClass = org.apache.karaf.specs.locator.OsgiLocator.locate(type, factoryId); - if (spiClass != null) { - return spiClass.getConstructor().newInstance(); - } - } catch (Throwable e) { - } - - try { - final String systemProp; - if (type.getName().equals(factoryId)) { - systemProp = getSystemProperty(factoryId); - } else { - systemProp = System.getProperty(factoryId); - } - if (systemProp != null) { - LOGGER.fine(() -> "found system property, value=" + systemProp); - return newInstance(type, systemProp, cl, true); - } - } - catch (SecurityException se) { - throw new DatatypeConfigurationException("Failed to read factoryId '" + factoryId + "'", se); - } - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - firstTime = false; - String javaHome = getSystemProperty("java.home"); - String configFile; - configFile = javaHome + File.separator + "conf" + File.separator + "jaxp.properties"; - File jaxp = new File(configFile); - if (doesFileExist(jaxp)) { - cacheProps.load(getFileInputStream(jaxp)); - } - configFile = javaHome + File.separator + "conf" + File.separator + "stax.properties"; - File stax = new File(configFile); - if (doesFileExist(stax)) { - cacheProps.load(getFileInputStream(stax)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(factoryId); - if (factoryClassName != null) { - return newInstance(type, factoryClassName, cl, true); - } - } - catch (Exception ex) { - LOGGER.log(Level.FINE, "Error loading JDK properties", ex); - } - if (type.getName().equals(factoryId)) { - final T provider = findServiceProvider(type, cl); - if (provider != null) { - return provider; - } - } else { - assert fallbackClassName == null; - } - if (fallbackClassName == null) { - throw new DatatypeConfigurationException("Provider for " + factoryId + " cannot be found", null); - } - LOGGER.fine(() -> "loaded from fallback value: " + fallbackClassName); - return newInstance(type, fallbackClassName, cl, true); - } - - - private static T findServiceProvider(final Class type, final ClassLoader cl) throws DatatypeConfigurationException { - try { - return AccessController.doPrivileged((PrivilegedAction) () -> { - final ServiceLoader serviceLoader; - if (cl == null) { - serviceLoader = ServiceLoader.load(type); - } else { - serviceLoader = ServiceLoader.load(type, cl); - } - final Iterator iterator = serviceLoader.iterator(); - if (iterator.hasNext()) { - return iterator.next(); - } else { - return null; - } - }); - } catch(ServiceConfigurationError e) { - final RuntimeException x = new RuntimeException("Provider for " + type + " cannot be created", e); - throw new DatatypeConfigurationException(x.getMessage(), x); - } - } - - private static ClassLoader getContextClassLoader() throws SecurityException{ - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - return cl; - }); - } - - private static String getSystemProperty(final String propName) { - return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(propName)); - } - - private static FileInputStream getFileInputStream(final File file) throws FileNotFoundException { - try { - return AccessController.doPrivileged((PrivilegedExceptionAction) () -> new FileInputStream(file)); - } catch (PrivilegedActionException e) { - throw (FileNotFoundException)e.getException(); - } - } - - private static boolean doesFileExist(final File f) { - return AccessController.doPrivileged((PrivilegedAction) f::exists); - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/datatype/DatatypeFactory.java b/specs/javaxml/src/main/java/javax/xml/datatype/DatatypeFactory.java deleted file mode 100644 index 5ff92db72ab..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/datatype/DatatypeFactory.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.datatype; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.GregorianCalendar; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public abstract class DatatypeFactory { - - public static final String DATATYPEFACTORY_PROPERTY = "javax.xml.datatype.DatatypeFactory"; - - private static final String DATATYPEFACTORY_IMPLEMENTATION_CLASS = "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl"; - - private static final Pattern XDTSCHEMA_YMD = Pattern.compile("[^DT]*"); - - private static final Pattern XDTSCHEMA_DTD = Pattern.compile("[^YM]*[DT].*"); - - - protected DatatypeFactory() { - } - - - public static DatatypeFactory newDefaultInstance() { - try { - return $FactoryFinder.newInstance(DatatypeFactory.class, DATATYPEFACTORY_IMPLEMENTATION_CLASS, null, false, true); - } catch (DatatypeConfigurationException e) { - throw new RuntimeException("Unable to create default instance", e); - } - } - - public static DatatypeFactory newInstance() throws DatatypeConfigurationException { - return $FactoryFinder.find(DatatypeFactory.class, DATATYPEFACTORY_IMPLEMENTATION_CLASS); - } - - - public static DatatypeFactory newInstance(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException { - return $FactoryFinder.newInstance(DatatypeFactory.class, factoryClassName, classLoader, false); - } - - public abstract Duration newDuration(final String lexicalRepresentation); - - public abstract Duration newDuration(final long durationInMilliSeconds); - - public abstract Duration newDuration(final boolean isPositive, final BigInteger years, final BigInteger months, - final BigInteger days, final BigInteger hours, final BigInteger minutes, final BigDecimal seconds); - - public Duration newDuration(final boolean isPositive, final int years, final int months, - final int days, final int hours, final int minutes, final int seconds) { - BigInteger realYears = (years != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) years) : null; - BigInteger realMonths = (months != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) months) : null; - BigInteger realDays = (days != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) days) : null; - BigInteger realHours = (hours != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) hours) : null; - BigInteger realMinutes = (minutes != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) minutes) : null; - BigDecimal realSeconds = (seconds != DatatypeConstants.FIELD_UNDEFINED) ? BigDecimal.valueOf((long) seconds) : null; - return newDuration(isPositive, realYears, realMonths, realDays, realHours, realMinutes, realSeconds); - } - - - public Duration newDurationDayTime(final String lexicalRepresentation) { - if (lexicalRepresentation == null) { - throw new NullPointerException("Trying to create an xdt:dayTimeDuration with an invalid lexical representation of \"null\""); - } - Matcher matcher = XDTSCHEMA_DTD.matcher(lexicalRepresentation); - if (!matcher.matches()) { - throw new IllegalArgumentException("Trying to create an xdt:dayTimeDuration with an invalid" - + " lexical representation of \"" + lexicalRepresentation - + "\", data model requires years and months only."); - } - return newDuration(lexicalRepresentation); - } - - public Duration newDurationDayTime(final long durationInMilliseconds) { - return newDuration(durationInMilliseconds); - } - - public Duration newDurationDayTime(final boolean isPositive, final BigInteger day, - final BigInteger hour, final BigInteger minute, final BigInteger second) { - return newDuration(isPositive, null, null, - day, hour, minute, (second != null) ? new BigDecimal(second) : null); - } - - public Duration newDurationDayTime(final boolean isPositive, final int day, - final int hour, final int minute, final int second) { - return newDurationDayTime(isPositive, BigInteger.valueOf((long) day), BigInteger.valueOf((long) hour), - BigInteger.valueOf((long) minute), BigInteger.valueOf((long) second)); - } - - public Duration newDurationYearMonth(final String lexicalRepresentation) { - if (lexicalRepresentation == null) { - throw new NullPointerException( - "Trying to create an xdt:yearMonthDuration with an invalid" - + " lexical representation of \"null\""); - } - Matcher matcher = XDTSCHEMA_YMD.matcher(lexicalRepresentation); - if (!matcher.matches()) { - throw new IllegalArgumentException( - "Trying to create an xdt:yearMonthDuration with an invalid" - + " lexical representation of \"" + lexicalRepresentation - + "\", data model requires days and times only."); - } - return newDuration(lexicalRepresentation); - } - - - public Duration newDurationYearMonth(final long durationInMilliseconds) { - Duration fullDuration = newDuration(durationInMilliseconds); - boolean isPositive = fullDuration.getSign() != -1; - BigInteger years = (BigInteger) fullDuration.getField(DatatypeConstants.YEARS); - if (years == null) { - years = BigInteger.ZERO; - } - BigInteger months = (BigInteger) fullDuration.getField(DatatypeConstants.MONTHS); - if (months == null) { - months = BigInteger.ZERO; - } - return newDurationYearMonth(isPositive, years, months); - } - - - public Duration newDurationYearMonth(final boolean isPositive, final BigInteger year, final BigInteger month) { - return newDuration(isPositive, year, month, - null, null, null, null); - } - - - public Duration newDurationYearMonth(final boolean isPositive, final int year, final int month) { - return newDurationYearMonth(isPositive, BigInteger.valueOf((long) year), BigInteger.valueOf((long) month)); - } - - public abstract XMLGregorianCalendar newXMLGregorianCalendar(); - - public abstract XMLGregorianCalendar newXMLGregorianCalendar(final String lexicalRepresentation); - - public abstract XMLGregorianCalendar newXMLGregorianCalendar(final GregorianCalendar cal); - - public abstract XMLGregorianCalendar newXMLGregorianCalendar( - final BigInteger year, - final int month, - final int day, - final int hour, - final int minute, - final int second, - final BigDecimal fractionalSecond, - final int timezone); - - public XMLGregorianCalendar newXMLGregorianCalendar( - final int year, - final int month, - final int day, - final int hour, - final int minute, - final int second, - final int millisecond, - final int timezone) { - BigInteger realYear = (year != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) year) : null; - BigDecimal realMillisecond = null; - if (millisecond != DatatypeConstants.FIELD_UNDEFINED) { - if (millisecond < 0 || millisecond > 1000) { - throw new IllegalArgumentException( - "javax.xml.datatype.DatatypeFactory#newXMLGregorianCalendar(" - + "int year, int month, int day, int hour, int minute, int second, int millisecond, int timezone)" - + "with invalid millisecond: " + millisecond - ); - } - realMillisecond = BigDecimal.valueOf((long) millisecond).movePointLeft(3); - } - return newXMLGregorianCalendar(realYear, month, - day, - hour, - minute, - second, - realMillisecond, - timezone - ); - } - - - public XMLGregorianCalendar newXMLGregorianCalendarDate( - final int year, - final int month, - final int day, - final int timezone) { - - return newXMLGregorianCalendar( - year, - month, - day, - DatatypeConstants.FIELD_UNDEFINED, - DatatypeConstants.FIELD_UNDEFINED, - DatatypeConstants.FIELD_UNDEFINED, - DatatypeConstants.FIELD_UNDEFINED, - timezone); - } - - - public XMLGregorianCalendar newXMLGregorianCalendarTime( - final int hours, - final int minutes, - final int seconds, - final int timezone) { - - return newXMLGregorianCalendar( - DatatypeConstants.FIELD_UNDEFINED, - DatatypeConstants.FIELD_UNDEFINED, - DatatypeConstants.FIELD_UNDEFINED, - hours, - minutes, - seconds, - DatatypeConstants.FIELD_UNDEFINED, - timezone); - } - - - public XMLGregorianCalendar newXMLGregorianCalendarTime( - final int hours, - final int minutes, - final int seconds, - final BigDecimal fractionalSecond, - final int timezone) { - - return newXMLGregorianCalendar( - null, - DatatypeConstants.FIELD_UNDEFINED, - DatatypeConstants.FIELD_UNDEFINED, - hours, - minutes, - seconds, - fractionalSecond, - timezone); - } - - - public XMLGregorianCalendar newXMLGregorianCalendarTime( - final int hours, - final int minutes, - final int seconds, - final int milliseconds, - final int timezone) { - - - BigDecimal realMilliseconds = null; - if (milliseconds != DatatypeConstants.FIELD_UNDEFINED) { - if (milliseconds < 0 || milliseconds > 1000) { - throw new IllegalArgumentException( - "javax.xml.datatype.DatatypeFactory#newXMLGregorianCalendarTime(" - + "int hours, int minutes, int seconds, int milliseconds, int timezone)" - + "with invalid milliseconds: " + milliseconds - ); - } - - realMilliseconds = BigDecimal.valueOf((long) milliseconds).movePointLeft(3); - } - - return newXMLGregorianCalendarTime( - hours, - minutes, - seconds, - realMilliseconds, - timezone - ); - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/parsers/$FactoryFinder.java b/specs/javaxml/src/main/java/javax/xml/parsers/$FactoryFinder.java deleted file mode 100644 index f209bf40601..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/parsers/$FactoryFinder.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.parsers; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Iterator; -import java.util.Properties; -import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; -import java.util.function.Supplier; - -class $FactoryFinder { - - private static final String DEFAULT_PACKAGE = "com.sun.xml.internal."; - - private static boolean debug; - - final private static Properties cacheProps = new Properties(); - - private static volatile boolean firstTime = true; - - static { - try { - String val = getSystemProperty("jaxp.debug"); - debug = val != null && !"false".equals(val); - } - catch (SecurityException se) { - debug = false; - } - } - - private static void dPrint(Supplier msgGen) { - if (debug) { - System.err.println("JAXP: " + msgGen.get()); - } - } - - - static private Class getProviderClass(String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException { - try { - if (cl == null) { - if (useBSClsLoader) { - return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); - } else { - cl = getContextClassLoader(); - if (cl == null) { - throw new ClassNotFoundException(); - } - else { - return Class.forName(className, false, cl); - } - } - } - else { - return Class.forName(className, false, cl); - } - } - catch (ClassNotFoundException e1) { - if (doFallback) { - return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); - } - else { - throw e1; - } - } - } - - - static T newInstance(Class type, String className, ClassLoader cl, boolean doFallback) throws FactoryConfigurationError { - return newInstance(type, className, cl, doFallback, false); - } - - - static T newInstance(Class type, String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws FactoryConfigurationError { - assert type != null; - if (System.getSecurityManager() != null) { - if (className != null && className.startsWith(DEFAULT_PACKAGE)) { - cl = null; - useBSClsLoader = true; - } - } - try { - Class providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader); - if (!type.isAssignableFrom(providerClass)) { - throw new ClassCastException(className + " cannot be cast to " + type.getName()); - } - Object instance = providerClass.getConstructor().newInstance(); - final ClassLoader clD = cl; - dPrint(()->"created new instance of " + providerClass + " using ClassLoader: " + clD); - return type.cast(instance); - } - catch (ClassNotFoundException x) { - throw new FactoryConfigurationError(x, "Provider " + className + " not found"); - } - catch (Exception x) { - throw new FactoryConfigurationError(x, "Provider " + className + " could not be instantiated: " + x); - } - } - - - static T find(Class type, String fallbackClassName) throws FactoryConfigurationError { - return find(type, type.getName(), null, fallbackClassName); - } - - static T find(Class type, String factoryId, ClassLoader cl, String fallbackClassName) throws FactoryConfigurationError - { - try { - // If we are deployed into an OSGi environment, leverage it - Class spiClass = org.apache.karaf.specs.locator.OsgiLocator.locate(type, factoryId); - if (spiClass != null) { - return spiClass.getConstructor().newInstance(); - } - } catch (Throwable e) { - } - - try { - final String systemProp; - if (type.getName().equals(factoryId)) { - systemProp = getSystemProperty(factoryId); - } else { - systemProp = System.getProperty(factoryId); - } - if (systemProp != null) { - dPrint(()->"found system property, value=" + systemProp); - return newInstance(type, systemProp, cl, true); - } - } - catch (SecurityException se) { - throw new FactoryConfigurationError(se, "Failed to read factoryId '" + factoryId + "'"); - } - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - firstTime = false; - String javaHome = getSystemProperty("java.home"); - String configFile; - configFile = javaHome + File.separator + "conf" + File.separator + "jaxp.properties"; - File jaxp = new File(configFile); - if (doesFileExist(jaxp)) { - cacheProps.load(getFileInputStream(jaxp)); - } - configFile = javaHome + File.separator + "conf" + File.separator + "stax.properties"; - File stax = new File(configFile); - if (doesFileExist(stax)) { - cacheProps.load(getFileInputStream(stax)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(factoryId); - if (factoryClassName != null) { - return newInstance(type, factoryClassName, cl, true); - } - } - catch (Exception ex) { - if (debug) ex.printStackTrace(); - } - if (type.getName().equals(factoryId)) { - final T provider = findServiceProvider(type, cl); - if (provider != null) { - return provider; - } - } else { - assert fallbackClassName == null; - } - if (fallbackClassName == null) { - throw new FactoryConfigurationError("Provider for " + factoryId + " cannot be found"); - } - dPrint(()->"loaded from fallback value: " + fallbackClassName); - return newInstance(type, fallbackClassName, cl, true); - } - - - private static T findServiceProvider(final Class type, final ClassLoader cl) { - try { - return AccessController.doPrivileged((PrivilegedAction) () -> { - final ServiceLoader serviceLoader; - if (cl == null) { - serviceLoader = ServiceLoader.load(type); - } else { - serviceLoader = ServiceLoader.load(type, cl); - } - final Iterator iterator = serviceLoader.iterator(); - if (iterator.hasNext()) { - return iterator.next(); - } else { - return null; - } - }); - } catch(ServiceConfigurationError e) { - final RuntimeException x = new RuntimeException("Provider for " + type + " cannot be created", e); - throw new FactoryConfigurationError(x, x.getMessage()); - } - } - - private static ClassLoader getContextClassLoader() throws SecurityException{ - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - return cl; - }); - } - - private static String getSystemProperty(final String propName) { - return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(propName)); - } - - private static FileInputStream getFileInputStream(final File file) throws FileNotFoundException { - try { - return AccessController.doPrivileged((PrivilegedExceptionAction) () -> new FileInputStream(file)); - } catch (PrivilegedActionException e) { - throw (FileNotFoundException)e.getException(); - } - } - - private static boolean doesFileExist(final File f) { - return AccessController.doPrivileged((PrivilegedAction) f::exists); - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/parsers/DocumentBuilderFactory.java b/specs/javaxml/src/main/java/javax/xml/parsers/DocumentBuilderFactory.java deleted file mode 100644 index 1a6865e46ef..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/parsers/DocumentBuilderFactory.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.parsers; - -import javax.xml.validation.Schema; - - -public abstract class DocumentBuilderFactory { - - private static final String DEFAULT_IMPL = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"; - - private boolean validating = false; - private boolean namespaceAware = false; - private boolean whitespace = false; - private boolean expandEntityRef = true; - private boolean ignoreComments = false; - private boolean coalescing = false; - - protected DocumentBuilderFactory() { - } - - public static DocumentBuilderFactory newDefaultInstance() { - return $FactoryFinder.newInstance(DocumentBuilderFactory.class, DEFAULT_IMPL, null, false, true); - } - - public static DocumentBuilderFactory newInstance() { - return $FactoryFinder.find(DocumentBuilderFactory.class, DEFAULT_IMPL); - } - - public static DocumentBuilderFactory newInstance(String factoryClassName, ClassLoader classLoader) { - return $FactoryFinder.newInstance(DocumentBuilderFactory.class, factoryClassName, classLoader, false); - } - - public abstract DocumentBuilder newDocumentBuilder() throws ParserConfigurationException; - - public boolean isNamespaceAware() { - return namespaceAware; - } - - public void setNamespaceAware(boolean awareness) { - this.namespaceAware = awareness; - } - - public boolean isValidating() { - return validating; - } - - public void setValidating(boolean validating) { - this.validating = validating; - } - - public boolean isIgnoringElementContentWhitespace() { - return whitespace; - } - - public void setIgnoringElementContentWhitespace(boolean whitespace) { - this.whitespace = whitespace; - } - - public boolean isExpandEntityReferences() { - return expandEntityRef; - } - - public void setExpandEntityReferences(boolean expandEntityRef) { - this.expandEntityRef = expandEntityRef; - } - - public boolean isIgnoringComments() { - return ignoreComments; - } - - public void setIgnoringComments(boolean ignoreComments) { - this.ignoreComments = ignoreComments; - } - - public boolean isCoalescing() { - return coalescing; - } - - public void setCoalescing(boolean coalescing) { - this.coalescing = coalescing; - } - - public abstract void setAttribute(String name, Object value) throws IllegalArgumentException; - - public abstract Object getAttribute(String name) throws IllegalArgumentException; - - public abstract void setFeature(String name, boolean value) throws ParserConfigurationException; - - public abstract boolean getFeature(String name) throws ParserConfigurationException; - - - public Schema getSchema() { - throw new UnsupportedOperationException( - "This parser does not support specification \"" - + this.getClass().getPackage().getSpecificationTitle() - + "\" version \"" - + this.getClass().getPackage().getSpecificationVersion() - + "\"" - ); - - } - - public void setSchema(Schema schema) { - throw new UnsupportedOperationException( - "This parser does not support specification \"" - + this.getClass().getPackage().getSpecificationTitle() - + "\" version \"" - + this.getClass().getPackage().getSpecificationVersion() - + "\"" - ); - } - - public boolean isXIncludeAware() { - throw new UnsupportedOperationException( - "This parser does not support specification \"" - + this.getClass().getPackage().getSpecificationTitle() - + "\" version \"" - + this.getClass().getPackage().getSpecificationVersion() - + "\"" - ); - } - - public void setXIncludeAware(final boolean state) { - if (state) { - throw new UnsupportedOperationException(" setXIncludeAware " + - "is not supported on this JAXP" + - " implementation or earlier: " + this.getClass()); - } - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/parsers/SAXParserFactory.java b/specs/javaxml/src/main/java/javax/xml/parsers/SAXParserFactory.java deleted file mode 100644 index 4ff834387cc..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/parsers/SAXParserFactory.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.parsers; - -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; - -import javax.xml.validation.Schema; - -public abstract class SAXParserFactory { - - private static final String DEFAULT_IMPL = "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"; - - private boolean validating = false; - - private boolean namespaceAware = false; - - protected SAXParserFactory() { - - } - - public static SAXParserFactory newDefaultInstance() { - return $FactoryFinder.newInstance(SAXParserFactory.class, DEFAULT_IMPL, null, false, true); - } - - - public static SAXParserFactory newInstance() { - return $FactoryFinder.find(SAXParserFactory.class, DEFAULT_IMPL); - } - - public static SAXParserFactory newInstance(String factoryClassName, ClassLoader classLoader) { - return $FactoryFinder.newInstance(SAXParserFactory.class, factoryClassName, classLoader, false); - } - - - public abstract SAXParser newSAXParser() throws ParserConfigurationException, SAXException; - - public boolean isNamespaceAware() { - return namespaceAware; - } - - public void setNamespaceAware(boolean awareness) { - this.namespaceAware = awareness; - } - - public boolean isValidating() { - return validating; - } - - public void setValidating(boolean validating) { - this.validating = validating; - } - - public abstract void setFeature(String name, boolean value) - throws ParserConfigurationException, SAXNotRecognizedException, - SAXNotSupportedException; - - public abstract boolean getFeature(String name) - throws ParserConfigurationException, SAXNotRecognizedException, - SAXNotSupportedException; - - - public Schema getSchema() { - throw new UnsupportedOperationException( - "This parser does not support specification \"" - + this.getClass().getPackage().getSpecificationTitle() - + "\" version \"" - + this.getClass().getPackage().getSpecificationVersion() - + "\"" - ); - } - - public void setSchema(Schema schema) { - throw new UnsupportedOperationException( - "This parser does not support specification \"" - + this.getClass().getPackage().getSpecificationTitle() - + "\" version \"" - + this.getClass().getPackage().getSpecificationVersion() - + "\"" - ); - } - - public boolean isXIncludeAware() { - throw new UnsupportedOperationException( - "This parser does not support specification \"" - + this.getClass().getPackage().getSpecificationTitle() - + "\" version \"" - + this.getClass().getPackage().getSpecificationVersion() - + "\"" - ); - } - - public void setXIncludeAware(final boolean state) { - if (state) { - throw new UnsupportedOperationException(" setXIncludeAware " + - "is not supported on this JAXP" + - " implementation or earlier: " + this.getClass()); - } - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/stream/$FactoryFinder.java b/specs/javaxml/src/main/java/javax/xml/stream/$FactoryFinder.java deleted file mode 100644 index 919cba8d995..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/stream/$FactoryFinder.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.stream; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Iterator; -import java.util.Properties; -import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; -import java.util.logging.Level; -import java.util.logging.Logger; - -class $FactoryFinder { - - private static final String DEFAULT_PACKAGE = "com.sun.xml.internal."; - - private static final Logger LOGGER = Logger.getLogger("javax.xml.stream"); - - final private static Properties cacheProps = new Properties(); - - private static volatile boolean firstTime = true; - - static private Class getProviderClass(String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException { - try { - if (cl == null) { - if (useBSClsLoader) { - return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); - } else { - cl = getContextClassLoader(); - if (cl == null) { - throw new ClassNotFoundException(); - } - else { - return Class.forName(className, false, cl); - } - } - } - else { - return Class.forName(className, false, cl); - } - } - catch (ClassNotFoundException e1) { - if (doFallback) { - return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); - } - else { - throw e1; - } - } - } - - - static T newInstance(Class type, String className, ClassLoader cl, boolean doFallback) throws FactoryConfigurationError { - return newInstance(type, className, cl, doFallback, false); - } - - - static T newInstance(Class type, String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws FactoryConfigurationError { - assert type != null; - if (System.getSecurityManager() != null) { - if (className != null && className.startsWith(DEFAULT_PACKAGE)) { - cl = null; - useBSClsLoader = true; - } - } - try { - Class providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader); - if (!type.isAssignableFrom(providerClass)) { - throw new ClassCastException(className + " cannot be cast to " + type.getName()); - } - Object instance = providerClass.getConstructor().newInstance(); - final ClassLoader clD = cl; - LOGGER.fine(() -> "created new instance of " + providerClass + " using ClassLoader: " + clD); - return type.cast(instance); - } - catch (ClassNotFoundException x) { - throw new FactoryConfigurationError("Provider " + className + " not found", x); - } - catch (Exception x) { - throw new FactoryConfigurationError("Provider " + className + " could not be instantiated: " + x, x); - } - } - - - static T find(Class type, String fallbackClassName) throws FactoryConfigurationError { - return find(type, type.getName(), null, fallbackClassName); - } - - static T find(Class type, String factoryId, ClassLoader cl, String fallbackClassName) throws FactoryConfigurationError - { - try { - // If we are deployed into an OSGi environment, leverage it - Class spiClass = org.apache.karaf.specs.locator.OsgiLocator.locate(type, factoryId); - if (spiClass != null) { - return spiClass.getConstructor().newInstance(); - } - } catch (Throwable e) { - } - - try { - final String systemProp; - if (type.getName().equals(factoryId)) { - systemProp = getSystemProperty(factoryId); - } else { - systemProp = System.getProperty(factoryId); - } - if (systemProp != null) { - LOGGER.fine(() -> "found system property, value=" + systemProp); - return newInstance(type, systemProp, cl, true); - } - } - catch (SecurityException se) { - throw new FactoryConfigurationError("Failed to read factoryId '" + factoryId + "'", se); - } - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - firstTime = false; - String javaHome = getSystemProperty("java.home"); - String configFile; - configFile = javaHome + File.separator + "conf" + File.separator + "jaxp.properties"; - File jaxp = new File(configFile); - if (doesFileExist(jaxp)) { - cacheProps.load(getFileInputStream(jaxp)); - } - configFile = javaHome + File.separator + "conf" + File.separator + "stax.properties"; - File stax = new File(configFile); - if (doesFileExist(stax)) { - cacheProps.load(getFileInputStream(stax)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(factoryId); - if (factoryClassName != null) { - return newInstance(type, factoryClassName, cl, true); - } - } - catch (Exception ex) { - LOGGER.log(Level.FINE, "Error loading JDK properties file", ex); - } - if (type.getName().equals(factoryId)) { - final T provider = findServiceProvider(type, cl); - if (provider != null) { - return provider; - } - } else { - assert fallbackClassName == null; - } - if (fallbackClassName == null) { - throw new FactoryConfigurationError("Provider for " + factoryId + " cannot be found", null); - } - LOGGER.fine(() -> "loaded from fallback value: " + fallbackClassName); - return newInstance(type, fallbackClassName, cl, true); - } - - - private static T findServiceProvider(final Class type, final ClassLoader cl) { - try { - return AccessController.doPrivileged((PrivilegedAction) () -> { - final ServiceLoader serviceLoader; - serviceLoader = ServiceLoader.load(type, cl != null ? cl : Thread.currentThread().getContextClassLoader()); - final Iterator iterator = serviceLoader.iterator(); - if (iterator.hasNext()) { - return iterator.next(); - } else { - return null; - } - }); - } catch(ServiceConfigurationError e) { - final RuntimeException x = new RuntimeException("Provider for " + type + " cannot be created", e); - throw new FactoryConfigurationError(x, x.getMessage()); - } - } - - private static ClassLoader getContextClassLoader() throws SecurityException{ - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - return cl; - }); - } - - private static String getSystemProperty(final String propName) { - return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(propName)); - } - - private static FileInputStream getFileInputStream(final File file) throws FileNotFoundException { - try { - return AccessController.doPrivileged((PrivilegedExceptionAction) () -> new FileInputStream(file)); - } catch (PrivilegedActionException e) { - throw (FileNotFoundException)e.getException(); - } - } - - private static boolean doesFileExist(final File f) { - return AccessController.doPrivileged((PrivilegedAction) f::exists); - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/stream/XMLEventFactory.java b/specs/javaxml/src/main/java/javax/xml/stream/XMLEventFactory.java deleted file mode 100644 index f08eadd29eb..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/stream/XMLEventFactory.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.stream; - -import java.util.Iterator; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.stream.events.*; - -public abstract class XMLEventFactory { - - private static final String DEFAULT_IMPL = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl"; - - protected XMLEventFactory(){} - - public static XMLEventFactory newDefaultFactory() { - return $FactoryFinder.newInstance(XMLEventFactory.class, DEFAULT_IMPL, null, false, true); - } - - public static XMLEventFactory newInstance() throws FactoryConfigurationError { - return $FactoryFinder.find(XMLEventFactory.class, DEFAULT_IMPL); - } - - public static XMLEventFactory newFactory() throws FactoryConfigurationError { - return $FactoryFinder.find(XMLEventFactory.class, DEFAULT_IMPL); - } - - @Deprecated - public static XMLEventFactory newInstance(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError { - return $FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null); - } - - public static XMLEventFactory newFactory(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError { - return $FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null); - } - - public abstract void setLocation(Location location); - - public abstract Attribute createAttribute(String prefix, String namespaceURI, String localName, String value); - - public abstract Attribute createAttribute(String localName, String value); - - public abstract Attribute createAttribute(QName name, String value); - - public abstract Namespace createNamespace(String namespaceURI); - - public abstract Namespace createNamespace(String prefix, String namespaceUri); - - public abstract StartElement createStartElement(QName name, Iterator attributes, Iterator namespaces); - - public abstract StartElement createStartElement(String prefix, String namespaceUri, String localName); - - public abstract StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces); - - public abstract StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces, NamespaceContext context); - - public abstract EndElement createEndElement(QName name, Iterator namespaces); - - public abstract EndElement createEndElement(String prefix, String namespaceUri, String localName); - - public abstract EndElement createEndElement(String prefix, String namespaceUri, String localName, Iterator namespaces); - - public abstract Characters createCharacters(String content); - - public abstract Characters createCData(String content); - - public abstract Characters createSpace(String content); - - public abstract Characters createIgnorableSpace(String content); - - public abstract StartDocument createStartDocument(); - - public abstract StartDocument createStartDocument(String encoding, String version, boolean standalone); - - public abstract StartDocument createStartDocument(String encoding, String version); - - public abstract StartDocument createStartDocument(String encoding); - - public abstract EndDocument createEndDocument(); - - public abstract EntityReference createEntityReference(String name, EntityDeclaration declaration); - - public abstract Comment createComment(String text); - - public abstract ProcessingInstruction createProcessingInstruction(String target, String data); - - public abstract DTD createDTD(String dtd); -} diff --git a/specs/javaxml/src/main/java/javax/xml/stream/XMLInputFactory.java b/specs/javaxml/src/main/java/javax/xml/stream/XMLInputFactory.java deleted file mode 100644 index 1b87e3c3b3a..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/stream/XMLInputFactory.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.stream; - -import javax.xml.stream.util.XMLEventAllocator; -import javax.xml.transform.Source; - -public abstract class XMLInputFactory { - - public static final String IS_NAMESPACE_AWARE= "javax.xml.stream.isNamespaceAware"; - - public static final String IS_VALIDATING= "javax.xml.stream.isValidating"; - - public static final String IS_COALESCING= "javax.xml.stream.isCoalescing"; - - public static final String IS_REPLACING_ENTITY_REFERENCES= "javax.xml.stream.isReplacingEntityReferences"; - - public static final String IS_SUPPORTING_EXTERNAL_ENTITIES= "javax.xml.stream.isSupportingExternalEntities"; - - public static final String SUPPORT_DTD= "javax.xml.stream.supportDTD"; - - public static final String REPORTER= "javax.xml.stream.reporter"; - - public static final String RESOLVER= "javax.xml.stream.resolver"; - - public static final String ALLOCATOR= "javax.xml.stream.allocator"; - - private static final String DEFAULT_IMPL = "com.sun.xml.internal.stream.XMLInputFactoryImpl"; - - protected XMLInputFactory(){} - - private static void setProperties(XMLInputFactory factory) { - factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); - factory.setProperty(XMLInputFactory.SUPPORT_DTD, false); - factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); - factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); - factory.setXMLResolver((publicID, systemID, baseURI, namespace) -> { - throw new XMLStreamException("Reading external entities is disabled"); - }); - } - - public static XMLInputFactory newDefaultFactory() { - XMLInputFactory factory = $FactoryFinder.newInstance(XMLInputFactory.class, DEFAULT_IMPL, null, false, true); - setProperties(factory); - return factory; - } - - public static XMLInputFactory newInstance() throws FactoryConfigurationError { - XMLInputFactory factory = $FactoryFinder.find(XMLInputFactory.class, DEFAULT_IMPL); - setProperties(factory); - return factory; - } - - @Deprecated - public static XMLInputFactory newFactory() throws FactoryConfigurationError { - return newInstance(); - } - - public static XMLInputFactory newFactory(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError { - XMLInputFactory factory = $FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null); - setProperties(factory); - return factory; - } - - @Deprecated - public static XMLInputFactory newInstance(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError { - return newFactory(factoryId, classLoader); - } - - public abstract XMLStreamReader createXMLStreamReader(java.io.Reader reader) throws XMLStreamException; - - public abstract XMLStreamReader createXMLStreamReader(Source source) throws XMLStreamException; - - public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream) throws XMLStreamException; - - public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream, String encoding) throws XMLStreamException; - - public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.InputStream stream) throws XMLStreamException; - - public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.Reader reader) throws XMLStreamException; - - public abstract XMLEventReader createXMLEventReader(java.io.Reader reader) throws XMLStreamException; - - public abstract XMLEventReader createXMLEventReader(String systemId, java.io.Reader reader) throws XMLStreamException; - - public abstract XMLEventReader createXMLEventReader(XMLStreamReader reader) throws XMLStreamException; - - public abstract XMLEventReader createXMLEventReader(Source source) throws XMLStreamException; - - public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream) throws XMLStreamException; - - public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding) throws XMLStreamException; - - public abstract XMLEventReader createXMLEventReader(String systemId, java.io.InputStream stream) throws XMLStreamException; - - public abstract XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException; - - public abstract XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter) throws XMLStreamException; - - public abstract XMLResolver getXMLResolver(); - - public abstract void setXMLResolver(XMLResolver resolver); - - public abstract XMLReporter getXMLReporter(); - - public abstract void setXMLReporter(XMLReporter reporter); - - public abstract void setProperty(java.lang.String name, Object value) throws IllegalArgumentException; - - public abstract Object getProperty(java.lang.String name) throws IllegalArgumentException; - - public abstract boolean isPropertySupported(String name); - - public abstract void setEventAllocator(XMLEventAllocator allocator); - - public abstract XMLEventAllocator getEventAllocator(); - -} diff --git a/specs/javaxml/src/main/java/javax/xml/stream/XMLOutputFactory.java b/specs/javaxml/src/main/java/javax/xml/stream/XMLOutputFactory.java deleted file mode 100644 index 69ccca38f21..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/stream/XMLOutputFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.stream; - -import javax.xml.transform.Result; -import java.io.OutputStream; -import java.io.Writer; - -public abstract class XMLOutputFactory { - - public static final String IS_REPAIRING_NAMESPACES = "javax.xml.stream.isRepairingNamespaces"; - - private static final String DEFAULT_IMPL = "com.sun.xml.internal.stream.XMLOutputFactoryImpl"; - - protected XMLOutputFactory() { - } - - public static XMLOutputFactory newDefaultFactory() { - return $FactoryFinder.newInstance(XMLOutputFactory.class, DEFAULT_IMPL, null, false, true); - } - - public static XMLOutputFactory newInstance() throws FactoryConfigurationError { - return $FactoryFinder.find(XMLOutputFactory.class, DEFAULT_IMPL); - } - - public static XMLOutputFactory newFactory() throws FactoryConfigurationError { - return $FactoryFinder.find(XMLOutputFactory.class, DEFAULT_IMPL); - } - - @Deprecated - public static XMLInputFactory newInstance(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError { - return $FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null); - } - - public static XMLOutputFactory newFactory(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError { - return $FactoryFinder.find(XMLOutputFactory.class, factoryId, classLoader, null); - } - - public abstract XMLStreamWriter createXMLStreamWriter(Writer stream) throws XMLStreamException; - - public abstract XMLStreamWriter createXMLStreamWriter(OutputStream stream) throws XMLStreamException; - - public abstract XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding) throws XMLStreamException; - - public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException; - - public abstract XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException; - - public abstract XMLEventWriter createXMLEventWriter(OutputStream stream) throws XMLStreamException; - - public abstract XMLEventWriter createXMLEventWriter(OutputStream stream, String encoding) throws XMLStreamException; - - public abstract XMLEventWriter createXMLEventWriter(Writer stream) throws XMLStreamException; - - public abstract void setProperty(String name, Object value) throws IllegalArgumentException; - - public abstract Object getProperty(String name) throws IllegalArgumentException; - - public abstract boolean isPropertySupported(String name); -} diff --git a/specs/javaxml/src/main/java/javax/xml/transform/$FactoryFinder.java b/specs/javaxml/src/main/java/javax/xml/transform/$FactoryFinder.java deleted file mode 100644 index 20f3b87720c..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/transform/$FactoryFinder.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.transform; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Iterator; -import java.util.Properties; -import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; -import java.util.function.Supplier; - -class $FactoryFinder { - - private static final String DEFAULT_PACKAGE = "com.sun.xml.internal."; - - private static boolean debug; - - final private static Properties cacheProps = new Properties(); - - private static volatile boolean firstTime = true; - - static { - try { - String val = getSystemProperty("jaxp.debug"); - debug = val != null && !"false".equals(val); - } catch (SecurityException se) { - debug = false; - } - } - - private static void dPrint(Supplier msgGen) { - if (debug) { - System.err.println("JAXP: " + msgGen.get()); - } - } - - - static private Class getProviderClass(String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException { - try { - if (cl == null) { - if (useBSClsLoader) { - return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); - } else { - cl = getContextClassLoader(); - if (cl == null) { - throw new ClassNotFoundException(); - } else { - return Class.forName(className, false, cl); - } - } - } else { - return Class.forName(className, false, cl); - } - } catch (ClassNotFoundException e1) { - if (doFallback) { - return Class.forName(className, false, $FactoryFinder.class.getClassLoader()); - } else { - throw e1; - } - } - } - - - static T newInstance(Class type, String className, ClassLoader cl, boolean doFallback) { - return newInstance(type, className, cl, doFallback, false); - } - - - static T newInstance(Class type, String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader) { - assert type != null; - if (System.getSecurityManager() != null) { - if (className != null && className.startsWith(DEFAULT_PACKAGE)) { - cl = null; - useBSClsLoader = true; - } - } - try { - Class providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader); - if (!type.isAssignableFrom(providerClass)) { - throw new ClassCastException(className + " cannot be cast to " + type.getName()); - } - Object instance = providerClass.getConstructor().newInstance(); - final ClassLoader clD = cl; - dPrint(() -> "created new instance of " + providerClass + " using ClassLoader: " + clD); - return type.cast(instance); - } catch (ClassNotFoundException x) { - throw new TransformerFactoryConfigurationError(x, "Provider " + className + " not found"); - } catch (Exception x) { - throw new TransformerFactoryConfigurationError(x, "Provider " + className + " could not be instantiated: " + x); - } - } - - - static T find(Class type, String fallbackClassName) { - return find(type, type.getName(), null, fallbackClassName); - } - - static T find(Class type, String factoryId, ClassLoader cl, String fallbackClassName) { - try { - // If we are deployed into an OSGi environment, leverage it - Class spiClass = org.apache.karaf.specs.locator.OsgiLocator.locate(type, factoryId); - if (spiClass != null) { - return spiClass.getConstructor().newInstance(); - } - } catch (Throwable e) { - } - - try { - final String systemProp; - if (type.getName().equals(factoryId)) { - systemProp = getSystemProperty(factoryId); - } else { - systemProp = System.getProperty(factoryId); - } - if (systemProp != null) { - dPrint(() -> "found system property, value=" + systemProp); - return newInstance(type, systemProp, cl, true); - } - } catch (SecurityException se) { - throw new TransformerFactoryConfigurationError(se, "Failed to read factoryId '" + factoryId + "'"); - } - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - firstTime = false; - String javaHome = getSystemProperty("java.home"); - String configFile; - configFile = javaHome + File.separator + "conf" + File.separator + "jaxp.properties"; - File jaxp = new File(configFile); - if (doesFileExist(jaxp)) { - cacheProps.load(getFileInputStream(jaxp)); - } - configFile = javaHome + File.separator + "conf" + File.separator + "stax.properties"; - File stax = new File(configFile); - if (doesFileExist(stax)) { - cacheProps.load(getFileInputStream(stax)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(factoryId); - if (factoryClassName != null) { - return newInstance(type, factoryClassName, cl, true); - } - } catch (Exception ex) { - if (debug) ex.printStackTrace(); - } - if (type.getName().equals(factoryId)) { - final T provider = findServiceProvider(type, cl); - if (provider != null) { - return provider; - } - } else { - assert fallbackClassName == null; - } - if (fallbackClassName == null) { - throw new TransformerFactoryConfigurationError("Provider for " + factoryId + " cannot be found"); - } - dPrint(() -> "loaded from fallback value: " + fallbackClassName); - return newInstance(type, fallbackClassName, cl, true); - } - - - private static T findServiceProvider(final Class type, final ClassLoader cl) { - try { - return AccessController.doPrivileged((PrivilegedAction) () -> { - final ServiceLoader serviceLoader; - if (cl == null) { - serviceLoader = ServiceLoader.load(type); - } else { - serviceLoader = ServiceLoader.load(type, cl); - } - final Iterator iterator = serviceLoader.iterator(); - if (iterator.hasNext()) { - return iterator.next(); - } else { - return null; - } - }); - } catch (ServiceConfigurationError e) { - final RuntimeException x = new RuntimeException("Provider for " + type + " cannot be created", e); - throw new TransformerFactoryConfigurationError(x, x.getMessage()); - } - } - - private static ClassLoader getContextClassLoader() throws SecurityException { - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - return cl; - }); - } - - private static String getSystemProperty(final String propName) { - return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(propName)); - } - - private static FileInputStream getFileInputStream(final File file) throws FileNotFoundException { - try { - return AccessController.doPrivileged((PrivilegedExceptionAction) () -> new FileInputStream(file)); - } catch (PrivilegedActionException e) { - throw (FileNotFoundException) e.getException(); - } - } - - private static boolean doesFileExist(final File f) { - return AccessController.doPrivileged((PrivilegedAction) f::exists); - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/transform/TransformerFactory.java b/specs/javaxml/src/main/java/javax/xml/transform/TransformerFactory.java deleted file mode 100644 index 886b07b0dbd..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/transform/TransformerFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.transform; - -public abstract class TransformerFactory { - - private static final String DEFAULT_IMPL = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"; - - protected TransformerFactory() { - } - - public static TransformerFactory newDefaultInstance() { - return $FactoryFinder.newInstance(TransformerFactory.class, DEFAULT_IMPL, null, false, true); - } - - public static TransformerFactory newInstance() throws TransformerFactoryConfigurationError { - return $FactoryFinder.find(TransformerFactory.class, DEFAULT_IMPL); - } - - public static TransformerFactory newInstance(String factoryClassName, ClassLoader classLoader) throws TransformerFactoryConfigurationError { - return $FactoryFinder.newInstance(TransformerFactory.class, factoryClassName, classLoader, false, false); - } - - public abstract Transformer newTransformer(Source source) throws TransformerConfigurationException; - - public abstract Transformer newTransformer() throws TransformerConfigurationException; - - public abstract Templates newTemplates(Source source) throws TransformerConfigurationException; - - public abstract Source getAssociatedStylesheet(Source source, String media, String title, String charset) throws TransformerConfigurationException; - - public abstract void setURIResolver(URIResolver resolver); - - public abstract URIResolver getURIResolver(); - - public abstract void setFeature(String name, boolean value) throws TransformerConfigurationException; - - public abstract boolean getFeature(String name); - - public abstract void setAttribute(String name, Object value); - - public abstract Object getAttribute(String name); - - public abstract void setErrorListener(ErrorListener listener); - - public abstract ErrorListener getErrorListener(); - -} diff --git a/specs/javaxml/src/main/java/javax/xml/validation/$SchemaFactoryFinder.java b/specs/javaxml/src/main/java/javax/xml/validation/$SchemaFactoryFinder.java deleted file mode 100644 index d96ccfd0a81..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/validation/$SchemaFactoryFinder.java +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.validation; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.URL; -import java.security.*; -import java.util.Properties; -import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; -import java.util.function.Supplier; - -class $SchemaFactoryFinder { - - private static boolean debug = false; - private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xerces.internal"; - private static final Properties cacheProps = new Properties(); - - private static volatile boolean firstTime = true; - - static { - try { - debug = getSystemProperty("jaxp.debug") != null; - } catch (Exception unused) { - debug = false; - } - } - - private static void debugPrintln(Supplier msgGen) { - if (debug) { - System.err.println("JAXP: " + msgGen.get()); - } - } - - private final ClassLoader classLoader; - - public $SchemaFactoryFinder(ClassLoader loader) { - this.classLoader = loader; - if (debug) { - debugDisplayClassLoader(); - } - } - - private void debugDisplayClassLoader() { - try { - if (classLoader == getContextClassLoader()) { - debugPrintln(() -> "using thread context class loader (" + classLoader + ") for search"); - return; - } - } catch (Throwable unused) { - } - - if (classLoader == ClassLoader.getSystemClassLoader()) { - debugPrintln(() -> "using system class loader (" + classLoader + ") for search"); - return; - } - - debugPrintln(() -> "using class loader (" + classLoader + ") for search"); - } - - public SchemaFactory newFactory(String schemaLanguage) { - if (schemaLanguage == null) { - throw new NullPointerException(); - } - SchemaFactory f = _newFactory(schemaLanguage); - if (f != null) { - debugPrintln(() -> "factory '" + f.getClass().getName() + "' was found for " + schemaLanguage); - } else { - debugPrintln(() -> "unable to find a factory for " + schemaLanguage); - } - return f; - } - - private SchemaFactory _newFactory(String schemaLanguage) { - SchemaFactory sf; - - String propertyName = SERVICE_CLASS.getName() + ":" + schemaLanguage; - - try { - debugPrintln(() -> "Looking up system property '" + propertyName + "'"); - String r = getSystemProperty(propertyName); - if (r != null) { - debugPrintln(() -> "The value is '" + r + "'"); - sf = createInstance(r, true); - if (sf != null) return sf; - } else - debugPrintln(() -> "The property is undefined."); - } catch (Throwable t) { - if (debug) { - debugPrintln(() -> "failed to look up system property '" + propertyName + "'"); - t.printStackTrace(); - } - } - - String javah = getSystemProperty("java.home"); - String configFile = javah + File.separator + - "conf" + File.separator + "jaxp.properties"; - - - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - File f = new File(configFile); - firstTime = false; - if (doesFileExist(f)) { - debugPrintln(() -> "Read properties file " + f); - cacheProps.load(getFileInputStream(f)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(propertyName); - debugPrintln(() -> "found " + factoryClassName + " in $java.home/conf/jaxp.properties"); - - if (factoryClassName != null) { - sf = createInstance(factoryClassName, true); - if (sf != null) { - return sf; - } - } - } catch (Exception ex) { - if (debug) { - ex.printStackTrace(); - } - } - - final SchemaFactory factoryImpl = findServiceProvider(schemaLanguage); - - - if (factoryImpl != null) { - return factoryImpl; - } - - if (schemaLanguage.equals("http://www.w3.org/2001/XMLSchema")) { - debugPrintln(() -> "attempting to use the platform default XML Schema validator"); - return createInstance("com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory", true); - } - - debugPrintln(() -> "all things were tried, but none was found. bailing out."); - return null; - } - - private Class createClass(String className) { - Class clazz; - boolean internal = false; - if (System.getSecurityManager() != null) { - if (className != null && className.startsWith(DEFAULT_PACKAGE)) { - internal = true; - } - } - - try { - if (classLoader != null && !internal) { - clazz = Class.forName(className, false, classLoader); - } else { - clazz = Class.forName(className); - } - } catch (Throwable t) { - if (debug) { - t.printStackTrace(); - } - return null; - } - - return clazz; - } - - SchemaFactory createInstance(String className) { - return createInstance(className, false); - } - - SchemaFactory createInstance(String className, boolean useServicesMechanism) { - SchemaFactory schemaFactory = null; - - debugPrintln(() -> "createInstance(" + className + ")"); - - Class clazz = createClass(className); - if (clazz == null) { - debugPrintln(() -> "failed to getClass(" + className + ")"); - return null; - } - debugPrintln(() -> "loaded " + className + " from " + which(clazz)); - - try { - if (!SchemaFactory.class.isAssignableFrom(clazz)) { - throw new ClassCastException(clazz.getName() - + " cannot be cast to " + SchemaFactory.class); - } - if (!useServicesMechanism) { - schemaFactory = newInstanceNoServiceLoader(clazz); - } - if (schemaFactory == null) { - schemaFactory = (SchemaFactory) clazz.newInstance(); - } - } catch (ClassCastException | IllegalAccessException | InstantiationException classCastException) { - debugPrintln(() -> "could not instantiate " + clazz.getName()); - if (debug) { - classCastException.printStackTrace(); - } - return null; - } - - return schemaFactory; - } - - private static SchemaFactory newInstanceNoServiceLoader( - Class providerClass - ) { - if (System.getSecurityManager() == null) { - return null; - } - try { - final Method creationMethod = - providerClass.getDeclaredMethod( - "newXMLSchemaFactoryNoServiceLoader" - ); - final int modifiers = creationMethod.getModifiers(); - - if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) { - return null; - } - - // Only calls "newXMLSchemaFactoryNoServiceLoader" if it's - final Class returnType = creationMethod.getReturnType(); - if (SERVICE_CLASS.isAssignableFrom(returnType)) { - return SERVICE_CLASS.cast(creationMethod.invoke(null, (Object[]) null)); - } else { - throw new ClassCastException(returnType - + " cannot be cast to " + SERVICE_CLASS); - } - } catch (ClassCastException e) { - throw new SchemaFactoryConfigurationError(e.getMessage(), e); - } catch (Exception exc) { - return null; - } - } - - private boolean isSchemaLanguageSupportedBy(final SchemaFactory factory, - final String schemaLanguage, - AccessControlContext acc) { - return AccessController.doPrivileged( - (PrivilegedAction) () -> factory.isSchemaLanguageSupported(schemaLanguage), acc); - } - - private SchemaFactory findServiceProvider(final String schemaLanguage) { - assert schemaLanguage != null; - final AccessControlContext acc = AccessController.getContext(); - try { - return AccessController.doPrivileged((PrivilegedAction) () -> { - final ServiceLoader loader = - ServiceLoader.load(SERVICE_CLASS); - for (SchemaFactory factory : loader) { - if (isSchemaLanguageSupportedBy(factory, schemaLanguage, acc)) { - return factory; - } - } - return null; - }); - } catch (ServiceConfigurationError error) { - throw new SchemaFactoryConfigurationError( - "Provider for " + SERVICE_CLASS + " cannot be created", error); - } - } - - private static final Class SERVICE_CLASS = SchemaFactory.class; - - - private static String which(Class clazz) { - return getClassSource(clazz); - } - - static ClassLoader getContextClassLoader() throws SecurityException { - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - return cl; - }); - } - - private static String getSystemProperty(final String propName) { - return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(propName)); - } - - private static FileInputStream getFileInputStream(final File file) throws FileNotFoundException { - try { - return AccessController.doPrivileged((PrivilegedExceptionAction) () -> new FileInputStream(file)); - } catch (PrivilegedActionException e) { - throw (FileNotFoundException)e.getException(); - } - } - - private static String getClassSource(Class cls) { - return AccessController.doPrivileged((PrivilegedAction) () -> { - CodeSource cs = cls.getProtectionDomain().getCodeSource(); - if (cs != null) { - URL loc = cs.getLocation(); - return loc != null ? loc.toString() : "(no location)"; - } else { - return "(no code source)"; - } - }); - } - - private static boolean doesFileExist(final File f) { - return AccessController.doPrivileged((PrivilegedAction) f::exists); - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/validation/SchemaFactory.java b/specs/javaxml/src/main/java/javax/xml/validation/SchemaFactory.java deleted file mode 100644 index da93cc62e48..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/validation/SchemaFactory.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.validation; - -import org.w3c.dom.ls.LSResourceResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; - -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import java.io.File; -import java.net.URL; - -public abstract class SchemaFactory { - - private static final String DEFAULT_IMPL = "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory"; - - protected SchemaFactory() { - } - - public static SchemaFactory newDefaultInstance() { - return new $SchemaFactoryFinder(null).createInstance(DEFAULT_IMPL, true); - } - - public static SchemaFactory newInstance(String schemaLanguage) { - ClassLoader cl = $SchemaFactoryFinder.getContextClassLoader(); - if (cl == null) { - cl = SchemaFactory.class.getClassLoader(); - } - SchemaFactory f = new $SchemaFactoryFinder(cl).newFactory(schemaLanguage); - if (f == null) { - throw new IllegalArgumentException( - "No SchemaFactory" - + " that implements the schema language specified by: " + schemaLanguage - + " could be loaded"); - } - return f; - } - - public static SchemaFactory newInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader) { - ClassLoader cl = classLoader; - if (cl == null) { - cl = $SchemaFactoryFinder.getContextClassLoader(); - } - SchemaFactory f = new $SchemaFactoryFinder(cl).createInstance(factoryClassName); - if (f == null) { - throw new IllegalArgumentException( - "Factory " + factoryClassName - + " could not be loaded to implement the schema language specified by: " + schemaLanguage); - } - if (f.isSchemaLanguageSupported(schemaLanguage)) { - return f; - } else { - throw new IllegalArgumentException( - "Factory " + f.getClass().getName() - + " does not implement the schema language specified by: " + schemaLanguage); - } - - } - - public abstract boolean isSchemaLanguageSupported(String schemaLanguage); - - public boolean getFeature(String name) - throws SAXNotRecognizedException, SAXNotSupportedException { - - if (name == null) { - throw new NullPointerException("the name parameter is null"); - } - throw new SAXNotRecognizedException(name); - } - - public void setFeature(String name, boolean value) - throws SAXNotRecognizedException, SAXNotSupportedException { - - if (name == null) { - throw new NullPointerException("the name parameter is null"); - } - throw new SAXNotRecognizedException(name); - } - - public void setProperty(String name, Object object) - throws SAXNotRecognizedException, SAXNotSupportedException { - - if (name == null) { - throw new NullPointerException("the name parameter is null"); - } - throw new SAXNotRecognizedException(name); - } - - public Object getProperty(String name) - throws SAXNotRecognizedException, SAXNotSupportedException { - - if (name == null) { - throw new NullPointerException("the name parameter is null"); - } - throw new SAXNotRecognizedException(name); - } - - public abstract void setErrorHandler(ErrorHandler errorHandler); - - public abstract ErrorHandler getErrorHandler(); - - public abstract void setResourceResolver(LSResourceResolver resourceResolver); - - public abstract LSResourceResolver getResourceResolver(); - - public Schema newSchema(Source schema) throws SAXException { - return newSchema(new Source[]{schema}); - } - - public Schema newSchema(File schema) throws SAXException { - return newSchema(new StreamSource(schema)); - } - - public Schema newSchema(URL schema) throws SAXException { - return newSchema(new StreamSource(schema.toExternalForm())); - } - - public abstract Schema newSchema(Source[] schemas) throws SAXException; - - public abstract Schema newSchema() throws SAXException; -} diff --git a/specs/javaxml/src/main/java/javax/xml/xpath/$XPathFactoryFinder.java b/specs/javaxml/src/main/java/javax/xml/xpath/$XPathFactoryFinder.java deleted file mode 100644 index f6cc156bf3b..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/xpath/$XPathFactoryFinder.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.xpath; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.URL; -import java.security.*; -import java.util.Properties; -import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; -import java.util.function.Supplier; - -class $XPathFactoryFinder { - private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xpath.internal"; - - private static boolean debug = false; - - static { - try { - debug = getSystemProperty("jaxp.debug") != null; - } catch (Exception unused) { - debug = false; - } - } - - private static final Properties cacheProps = new Properties(); - - private volatile static boolean firstTime = true; - - private static void debugPrintln(Supplier msgGen) { - if (debug) { - System.err.println("JAXP: " + msgGen.get()); - } - } - - private final ClassLoader classLoader; - - public $XPathFactoryFinder(ClassLoader loader) { - this.classLoader = loader; - if (debug) { - debugDisplayClassLoader(); - } - } - - private void debugDisplayClassLoader() { - try { - if (classLoader == getContextClassLoader()) { - debugPrintln(() -> "using thread context class loader (" + classLoader + ") for search"); - return; - } - } catch (Throwable unused) { - } - - if (classLoader == ClassLoader.getSystemClassLoader()) { - debugPrintln(() -> "using system class loader (" + classLoader + ") for search"); - return; - } - - debugPrintln(() -> "using class loader (" + classLoader + ") for search"); - } - - public XPathFactory newFactory(String uri) throws XPathFactoryConfigurationException { - if (uri == null) { - throw new NullPointerException(); - } - XPathFactory f = _newFactory(uri); - if (f != null) { - debugPrintln(() -> "factory '" + f.getClass().getName() + "' was found for " + uri); - } else { - debugPrintln(() -> "unable to find a factory for " + uri); - } - return f; - } - - private XPathFactory _newFactory(String uri) throws XPathFactoryConfigurationException { - XPathFactory xpathFactory = null; - - String propertyName = SERVICE_CLASS.getName() + ":" + uri; - - try { - debugPrintln(() -> "Looking up system property '" + propertyName + "'"); - String r = getSystemProperty(propertyName); - if (r != null) { - debugPrintln(() -> "The value is '" + r + "'"); - xpathFactory = createInstance(r, true); - if (xpathFactory != null) { - return xpathFactory; - } - } else - debugPrintln(() -> "The property is undefined."); - } catch (Throwable t) { - if (debug) { - debugPrintln(() -> "failed to look up system property '" + propertyName + "'"); - t.printStackTrace(); - } - } - - String javah = getSystemProperty("java.home"); - String configFile = javah + File.separator + - "conf" + File.separator + "jaxp.properties"; - - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - File f = new File(configFile); - firstTime = false; - if (doesFileExist(f)) { - debugPrintln(() -> "Read properties file " + f); - cacheProps.load(getFileInputStream(f)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(propertyName); - debugPrintln(() -> "found " + factoryClassName + " in $java.home/conf/jaxp.properties"); - - if (factoryClassName != null) { - xpathFactory = createInstance(factoryClassName, true); - if (xpathFactory != null) { - return xpathFactory; - } - } - } catch (Exception ex) { - if (debug) { - ex.printStackTrace(); - } - } - - assert xpathFactory == null; - xpathFactory = findServiceProvider(uri); - - - if (xpathFactory != null) { - return xpathFactory; - } - - if (uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) { - debugPrintln(() -> "attempting to use the platform default W3C DOM XPath lib"); - return createInstance("com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", true); - } - - debugPrintln(() -> "all things were tried, but none was found. bailing out."); - return null; - } - - private Class createClass(String className) { - Class clazz; - boolean internal = false; - if (System.getSecurityManager() != null) { - if (className != null && className.startsWith(DEFAULT_PACKAGE)) { - internal = true; - } - } - - try { - if (classLoader != null && !internal) { - clazz = Class.forName(className, false, classLoader); - } else { - clazz = Class.forName(className); - } - } catch (Throwable t) { - if (debug) { - t.printStackTrace(); - } - return null; - } - - return clazz; - } - - XPathFactory createInstance(String className) - throws XPathFactoryConfigurationException { - return createInstance(className, false); - } - - XPathFactory createInstance(String className, boolean useServicesMechanism) - throws XPathFactoryConfigurationException { - XPathFactory xPathFactory = null; - - debugPrintln(() -> "createInstance(" + className + ")"); - - Class clazz = createClass(className); - if (clazz == null) { - debugPrintln(() -> "failed to getClass(" + className + ")"); - return null; - } - debugPrintln(() -> "loaded " + className + " from " + which(clazz)); - - try { - if (!useServicesMechanism) { - xPathFactory = newInstanceNoServiceLoader(clazz); - } - if (xPathFactory == null) { - xPathFactory = (XPathFactory) clazz.newInstance(); - } - } catch (ClassCastException | IllegalAccessException | InstantiationException classCastException) { - debugPrintln(() -> "could not instantiate " + clazz.getName()); - if (debug) { - classCastException.printStackTrace(); - } - return null; - } - - return xPathFactory; - } - - private static XPathFactory newInstanceNoServiceLoader( - Class providerClass - ) throws XPathFactoryConfigurationException { - if (System.getSecurityManager() == null) { - return null; - } - try { - Method creationMethod = - providerClass.getDeclaredMethod( - "newXPathFactoryNoServiceLoader" - ); - final int modifiers = creationMethod.getModifiers(); - - // Do not call "newXPathFactoryNoServiceLoader" if it's - if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) { - return null; - } - - // Only calls "newXPathFactoryNoServiceLoader" if it's - final Class returnType = creationMethod.getReturnType(); - if (SERVICE_CLASS.isAssignableFrom(returnType)) { - return SERVICE_CLASS.cast(creationMethod.invoke(null, (Object[]) null)); - } else { - throw new ClassCastException(returnType - + " cannot be cast to " + SERVICE_CLASS); - } - } catch (ClassCastException e) { - throw new XPathFactoryConfigurationException(e); - } catch (Exception exc) { - return null; - } - } - - private boolean isObjectModelSupportedBy(final XPathFactory factory, - final String objectModel, - AccessControlContext acc) { - return AccessController.doPrivileged( - (PrivilegedAction) () -> factory.isObjectModelSupported(objectModel), acc); - } - - private XPathFactory findServiceProvider(final String objectModel) - throws XPathFactoryConfigurationException { - - assert objectModel != null; - final AccessControlContext acc = AccessController.getContext(); - try { - return AccessController.doPrivileged((PrivilegedAction) () -> { - final ServiceLoader loader = - ServiceLoader.load(SERVICE_CLASS); - for (XPathFactory factory : loader) { - if (isObjectModelSupportedBy(factory, objectModel, acc)) { - return factory; - } - } - return null; - }); - } catch (ServiceConfigurationError error) { - throw new XPathFactoryConfigurationException(error); - } - } - - private static final Class SERVICE_CLASS = XPathFactory.class; - - private static String which(Class clazz) { - return getClassSource(clazz); - } - - static ClassLoader getContextClassLoader() throws SecurityException{ - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - return cl; - }); - } - - private static String getSystemProperty(final String propName) { - return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(propName)); - } - - private static FileInputStream getFileInputStream(final File file) throws FileNotFoundException { - try { - return AccessController.doPrivileged((PrivilegedExceptionAction) () -> new FileInputStream(file)); - } catch (PrivilegedActionException e) { - throw (FileNotFoundException)e.getException(); - } - } - - private static String getClassSource(Class cls) { - return AccessController.doPrivileged((PrivilegedAction) () -> { - CodeSource cs = cls.getProtectionDomain().getCodeSource(); - if (cs != null) { - URL loc = cs.getLocation(); - return loc != null ? loc.toString() : "(no location)"; - } else { - return "(no code source)"; - } - }); - } - - private static boolean doesFileExist(final File f) { - return AccessController.doPrivileged((PrivilegedAction) f::exists); - } -} diff --git a/specs/javaxml/src/main/java/javax/xml/xpath/XPathFactory.java b/specs/javaxml/src/main/java/javax/xml/xpath/XPathFactory.java deleted file mode 100644 index c236a7c0ad1..00000000000 --- a/specs/javaxml/src/main/java/javax/xml/xpath/XPathFactory.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.xpath; - -public abstract class XPathFactory { - - public static final String DEFAULT_PROPERTY_NAME = "javax.xml.xpath.XPathFactory"; - - public static final String DEFAULT_OBJECT_MODEL_URI = "http://java.sun.com/jaxp/xpath/dom"; - - private static final String DEFAULT_IMPL = "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl"; - - protected XPathFactory() { - } - - public static XPathFactory newDefaultInstance() { - try { - return new $XPathFactoryFinder(null).createInstance(DEFAULT_IMPL, true); - } catch (XPathFactoryConfigurationException e) { - throw new RuntimeException( - "XPathFactory#newInstance() failed to create an XPathFactory for the default object model: " - + DEFAULT_OBJECT_MODEL_URI - + " with the XPathFactoryConfigurationException: " - + e.getMessage(), e - ); - } - } - - public static XPathFactory newInstance() { - try { - return newInstance(DEFAULT_OBJECT_MODEL_URI); - } catch (XPathFactoryConfigurationException e) { - throw new RuntimeException( - "XPathFactory#newInstance() failed to create an XPathFactory for the default object model: " - + DEFAULT_OBJECT_MODEL_URI - + " with the XPathFactoryConfigurationException: " - + e.getMessage(), e - ); - } - } - - public static XPathFactory newInstance(final String uri) throws XPathFactoryConfigurationException { - if (uri == null) { - throw new NullPointerException( - "XPathFactory#newInstance(String uri) cannot be called with uri == null"); - } - if (uri.length() == 0) { - throw new IllegalArgumentException( - "XPathFactory#newInstance(String uri) cannot be called with uri == \"\""); - } - ClassLoader classLoader = $XPathFactoryFinder.getContextClassLoader(); - if (classLoader == null) { - classLoader = XPathFactory.class.getClassLoader(); - } - XPathFactory xpathFactory = new $XPathFactoryFinder(classLoader).newFactory(uri); - if (xpathFactory == null) { - throw new XPathFactoryConfigurationException( - "No XPathFactory implementation found for the object model: " - + uri); - } - return xpathFactory; - } - - public static XPathFactory newInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException { - ClassLoader cl = classLoader; - if (uri == null) { - throw new NullPointerException("XPathFactory#newInstance(String uri) cannot be called with uri == null"); - } - if (uri.length() == 0) { - throw new IllegalArgumentException("XPathFactory#newInstance(String uri) cannot be called with uri == \"\""); - } - if (cl == null) { - cl = $XPathFactoryFinder.getContextClassLoader(); - } - XPathFactory f = new $XPathFactoryFinder(cl).createInstance(factoryClassName); - - if (f == null) { - throw new XPathFactoryConfigurationException( - "No XPathFactory implementation found for the object model: " - + uri); - } - if (f.isObjectModelSupported(uri)) { - return f; - } else { - throw new XPathFactoryConfigurationException("Factory " - + factoryClassName + " doesn't support given " + uri - + " object model"); - } - - } - - public abstract boolean isObjectModelSupported(String objectModel); - - public abstract void setFeature(String name, boolean value) - throws XPathFactoryConfigurationException; - - public abstract boolean getFeature(String name) - throws XPathFactoryConfigurationException; - - public abstract void setXPathVariableResolver(XPathVariableResolver resolver); - - public abstract void setXPathFunctionResolver(XPathFunctionResolver resolver); - - public abstract XPath newXPath(); - -} diff --git a/specs/javaxml/src/main/java/org/w3c/dom/ElementTraversal.java b/specs/javaxml/src/main/java/org/w3c/dom/ElementTraversal.java deleted file mode 100644 index 16406b532d5..00000000000 --- a/specs/javaxml/src/main/java/org/w3c/dom/ElementTraversal.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2009 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] in the hope that - * it will be useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.w3c.dom; - -/** - * The ElementTraversal interface is a set of read-only attributes - * which allow an author to easily navigate between elements in a document. - *

In conforming implementations of Element Traversal, all objects that - * implement {@link Element} must also implement the - * ElementTraversal interface. Four of the methods, - * {@link #getFirstElementChild}, {@link #getLastElementChild}, - * {@link #getPreviousElementSibling}, and {@link #getNextElementSibling}, - * each return a live reference to another element with the defined - * relationship to the current element, if the related element exists. The - * fifth method, {@link #getChildElementCount}, exposes the number of child - * elements of an element, for preprocessing before navigation. - *

See also the - * Element Traversal Specification. - */ -public interface ElementTraversal { - - /** - * Returns the first child element node of this element. null - * if this element has no child elements. - */ - Element getFirstElementChild(); - - /** - * Returns the last child element node of this element. null - * if this element has no child elements. - */ - Element getLastElementChild(); - - /** - * Returns the previous sibling element node of this element. - * null if this element has no element sibling nodes that - * come before this one in the document tree. - */ - Element getPreviousElementSibling(); - - /** - * Returns the next sibling element node of this element. - * null if this element has no element sibling nodes that - * come after this one in the document tree. - */ - Element getNextElementSibling(); - - /** - * Returns the current number of element nodes that are children of this - * element. 0 if this element has no child nodes that are of - * nodeType 1. - */ - int getChildElementCount(); -} diff --git a/specs/javaxmlws/pom.xml b/specs/javaxmlws/pom.xml deleted file mode 100644 index 47f5b455cba..00000000000 --- a/specs/javaxmlws/pom.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - 4.0.0 - - - org.apache.karaf.specs - specs - 4.5.0-SNAPSHOT - - - org.apache.karaf.specs.java.xml.ws - Apache Karaf :: Specs :: Java Xml WS - - - 8 - - - - - - org.apache.karaf - karaf-bom - ${project.version} - pom - import - - - - - - - org.apache.geronimo.specs - geronimo-saaj_1.3_spec - 1.1 - - - org.apache.geronimo.specs - geronimo-jaxws_2.2_spec - 1.2 - - - org.apache.geronimo.specs - geronimo-saaj_1.3_spec - - - org.apache.geronimo.specs - geronimo-stax_1.0_spec - - - org.apache.geronimo.specs - geronimo-activation_1.1_spec - - - javax.xml.bind - jaxb-api - - - - - org.apache.karaf.specs - org.apache.karaf.specs.locator - - - - diff --git a/specs/javaxmlws/src/main/java/javax/xml/soap/$FactoryFinder.java b/specs/javaxmlws/src/main/java/javax/xml/soap/$FactoryFinder.java deleted file mode 100644 index 65938dd9f79..00000000000 --- a/specs/javaxmlws/src/main/java/javax/xml/soap/$FactoryFinder.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.soap; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Properties; -import java.util.ServiceLoader; -import java.util.logging.Level; -import java.util.logging.Logger; - - -class $FactoryFinder { - - private static final Logger LOGGER = Logger.getLogger("javax.xml.soap"); - - @SuppressWarnings("unchecked") - static T find(Class factoryClass, String defaultClassName, boolean tryFallback, String deprecatedFactoryId) throws SOAPException { - ClassLoader tccl = contextClassLoader(); - - String factoryId = factoryClass.getName(); - String className = fromSystemProperty(factoryId, deprecatedFactoryId); - if (className != null) { - Object result = newInstance(className, defaultClassName, tccl); - return (T) result; - } - - className = fromJDKProperties(factoryId, deprecatedFactoryId); - if (className != null) { - Object result = newInstance(className, defaultClassName, tccl); - return (T) result; - } - - try { - Class spiClass = org.apache.karaf.specs.locator.OsgiLocator.locate(factoryClass); - if (spiClass != null) { - return spiClass.getConstructor().newInstance(); - } - } catch (Throwable t) { - } - - T factory = firstByServiceLoader(factoryClass); - if (factory != null) { - return factory; - } - - className = fromMetaInfServices(deprecatedFactoryId, tccl); - if (className != null) { - LOGGER.log(Level.WARNING, - "Using deprecated META-INF/services mechanism with non-standard property: {0}. " + - "Property {1} should be used instead.", - new Object[]{deprecatedFactoryId, factoryId}); - Object result = newInstance(className, defaultClassName, tccl); - return (T) result; - } - - if (!tryFallback) - return null; - - if (defaultClassName == null) { - throw new SOAPException("Provider for " + factoryId + " cannot be found", null); - } - return (T) newInstance(defaultClassName, defaultClassName, tccl); - } - - static T find(Class factoryClass, String defaultClassName, boolean tryFallback) throws SOAPException { - return find(factoryClass, defaultClassName, tryFallback, null); - } - - private static String fromMetaInfServices(String deprecatedFactoryId, ClassLoader tccl) { - String serviceId = "META-INF/services/" + deprecatedFactoryId; - LOGGER.log(Level.FINE, "Checking deprecated {0} resource", serviceId); - - try (InputStream is = - tccl == null - ? ClassLoader.getSystemResourceAsStream(serviceId) - : tccl.getResourceAsStream(serviceId)) { - - if (is != null) { - String factoryClassName; - try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); - BufferedReader rd = new BufferedReader(isr)) { - factoryClassName = rd.readLine(); - } - - logFound(factoryClassName); - if (factoryClassName != null && !"".equals(factoryClassName)) { - return factoryClassName; - } - } - } catch (IOException e) { - } - return null; - } - - private static String fromJDKProperties(String factoryId, String deprecatedFactoryId) { - Path path = null; - try { - String JAVA_HOME = getSystemProperty("java.home"); - path = Paths.get(JAVA_HOME, "conf", "jaxm.properties"); - LOGGER.log(Level.FINE, "Checking configuration in {0}", path); - - if (!Files.exists(path)) { - path = Paths.get(JAVA_HOME, "lib", "jaxm.properties"); - } - - LOGGER.log(Level.FINE, "Checking configuration in {0}", path); - if (Files.exists(path)) { - Properties props = new Properties(); - try (InputStream inputStream = Files.newInputStream(path)) { - props.load(inputStream); - } - - LOGGER.log(Level.FINE, "Checking property {0}", factoryId); - String factoryClassName = props.getProperty(factoryId); - logFound(factoryClassName); - if (factoryClassName != null) { - return factoryClassName; - } - - if (deprecatedFactoryId != null) { - LOGGER.log(Level.FINE, "Checking deprecated property {0}", deprecatedFactoryId); - factoryClassName = props.getProperty(deprecatedFactoryId); - logFound(factoryClassName); - if (factoryClassName != null) { - LOGGER.log(Level.WARNING, - "Using non-standard property: {0}. Property {1} should be used instead.", - new Object[]{deprecatedFactoryId, factoryId}); - return factoryClassName; - } - } - } - } catch (Exception ignored) { - LOGGER.log(Level.SEVERE, "Error reading SAAJ configuration from [" + path + - "] file. Check it is accessible and has correct format.", ignored); - } - return null; - } - - private static String fromSystemProperty(String factoryId, String deprecatedFactoryId) { - String systemProp = getSystemProperty(factoryId); - if (systemProp != null) { - return systemProp; - } - if (deprecatedFactoryId != null) { - systemProp = getSystemProperty(deprecatedFactoryId); - if (systemProp != null) { - LOGGER.log(Level.WARNING, - "Using non-standard property: {0}. Property {1} should be used instead.", - new Object[] {deprecatedFactoryId, factoryId}); - return systemProp; - } - } - return null; - } - - private static String getSystemProperty(final String property) { - LOGGER.log(Level.FINE, "Checking system property {0}", property); - String value = AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property)); - logFound(value); - return value; - } - - private static void logFound(String value) { - if (value != null) { - LOGGER.log(Level.FINE, " found {0}", value); - } else { - LOGGER.log(Level.FINE, " not found"); - } - } - - private static T firstByServiceLoader(Class spiClass) throws SOAPException { - LOGGER.log(Level.FINE, "Using java.util.ServiceLoader to find {0}", spiClass.getName()); - try { - ServiceLoader serviceLoader = ServiceLoader.load(spiClass); - for (T impl : serviceLoader) { - LOGGER.fine("ServiceProvider loading Facility used; returning object [" + impl.getClass().getName() + "]"); - return impl; - } - } catch (Throwable t) { - throw new SOAPException("Error while searching for service [" + spiClass.getName() + "]", t); - } - return null; - } - - private static void checkPackageAccess(String className) { - SecurityManager s = System.getSecurityManager(); - if (s != null) { - int i = className.lastIndexOf('.'); - if (i != -1) { - s.checkPackageAccess(className.substring(0, i)); - } - } - } - - private static Class nullSafeLoadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { - if (classLoader == null) { - return Class.forName(className); - } else { - return classLoader.loadClass(className); - } - } - - static Object newInstance(String className, String defaultImplClassName, ClassLoader classLoader) throws SOAPException { - try { - return safeLoadClass(className, defaultImplClassName, classLoader).getConstructor().newInstance(); - } catch (ClassNotFoundException x) { - throw new SOAPException("Provider " + className + " not found", x); - } catch (Exception x) { - throw new SOAPException("Provider " + className + " could not be instantiated: " + x, x); - } - } - - private static Class safeLoadClass(String className, String defaultImplClassName, ClassLoader classLoader) throws ClassNotFoundException { - try { - checkPackageAccess(className); - } catch (SecurityException se) { - if (defaultImplClassName != null && defaultImplClassName.equals(className)) { - return Class.forName(className); - } - throw se; - } - return nullSafeLoadClass(className, classLoader); - } - - private static ClassLoader contextClassLoader() throws SOAPException { - try { - return Thread.currentThread().getContextClassLoader(); - } catch (Exception x) { - throw new SOAPException(x.toString(), x); - } - } - -} diff --git a/specs/javaxmlws/src/main/java/javax/xml/soap/MessageFactory.java b/specs/javaxmlws/src/main/java/javax/xml/soap/MessageFactory.java deleted file mode 100644 index 6f0686a68b4..00000000000 --- a/specs/javaxmlws/src/main/java/javax/xml/soap/MessageFactory.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.soap; - -import java.io.IOException; -import java.io.InputStream; - -public abstract class MessageFactory { - - private static final String DEFAULT_MESSAGE_FACTORY = "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"; - - public static MessageFactory newInstance() throws SOAPException { - try { - MessageFactory factory = $FactoryFinder.find(MessageFactory.class, DEFAULT_MESSAGE_FACTORY, false); - if (factory != null) { - return factory; - } - return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); - } catch (Exception ex) { - throw new SOAPException("Unable to create message factory for SOAP: " + ex.getMessage(), ex); - } - - } - - public static MessageFactory newInstance(String protocol) throws SOAPException { - return SAAJMetaFactory.getInstance().newMessageFactory(protocol); - } - - public abstract SOAPMessage createMessage() throws SOAPException; - - public abstract SOAPMessage createMessage(MimeHeaders headers, InputStream in) throws IOException, SOAPException; -} diff --git a/specs/javaxmlws/src/main/java/javax/xml/soap/SAAJMetaFactory.java b/specs/javaxmlws/src/main/java/javax/xml/soap/SAAJMetaFactory.java deleted file mode 100644 index cf83c554a16..00000000000 --- a/specs/javaxmlws/src/main/java/javax/xml/soap/SAAJMetaFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.soap; - -public abstract class SAAJMetaFactory { - - private static final String META_FACTORY_DEPRECATED_CLASS_PROPERTY = "javax.xml.soap.MetaFactory"; - - private static final String DEFAULT_META_FACTORY_CLASS = "com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl"; - - static SAAJMetaFactory getInstance() throws SOAPException { - try { - return $FactoryFinder.find(SAAJMetaFactory.class, DEFAULT_META_FACTORY_CLASS, true, META_FACTORY_DEPRECATED_CLASS_PROPERTY); - } catch (Exception e) { - throw new SOAPException("Unable to create SAAJ meta-factory: " + e.getMessage(), e); - } - } - - protected SAAJMetaFactory() { } - - protected abstract MessageFactory newMessageFactory(String protocol) throws SOAPException; - - protected abstract SOAPFactory newSOAPFactory(String protocol) throws SOAPException; -} diff --git a/specs/javaxmlws/src/main/java/javax/xml/soap/SOAPConnectionFactory.java b/specs/javaxmlws/src/main/java/javax/xml/soap/SOAPConnectionFactory.java deleted file mode 100644 index 9466f2d99ce..00000000000 --- a/specs/javaxmlws/src/main/java/javax/xml/soap/SOAPConnectionFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.soap; - -public abstract class SOAPConnectionFactory { - - private static final String DEFAULT_SOAP_CONNECTION_FACTORY = "com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnectionFactory"; - - public static SOAPConnectionFactory newInstance() throws SOAPException, UnsupportedOperationException { - try { - return $FactoryFinder.find(SOAPConnectionFactory.class, DEFAULT_SOAP_CONNECTION_FACTORY, true); - } catch (Exception ex) { - throw new SOAPException("Unable to create SOAP connection factory: " + ex.getMessage(), ex); - } - } - - public abstract SOAPConnection createConnection() throws SOAPException; - -} diff --git a/specs/javaxmlws/src/main/java/javax/xml/soap/SOAPFactory.java b/specs/javaxmlws/src/main/java/javax/xml/soap/SOAPFactory.java deleted file mode 100644 index eebdcc5f8ce..00000000000 --- a/specs/javaxmlws/src/main/java/javax/xml/soap/SOAPFactory.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.soap; - -import org.w3c.dom.Element; - -import javax.xml.namespace.QName; - -public abstract class SOAPFactory { - - private static final String DEFAULT_SOAP_FACTORY = "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl"; - - public SOAPElement createElement(Element domElement) throws SOAPException { - throw new UnsupportedOperationException("createElement(org.w3c.dom.Element) must be overridden by all subclasses of SOAPFactory."); - } - - public abstract SOAPElement createElement(Name name) throws SOAPException; - - public SOAPElement createElement(QName qname) throws SOAPException { - throw new UnsupportedOperationException("createElement(QName) must be overridden by all subclasses of SOAPFactory."); - } - - public abstract SOAPElement createElement(String localName) throws SOAPException; - - - public abstract SOAPElement createElement(String localName, String prefix, String uri) throws SOAPException; - - public abstract Detail createDetail() throws SOAPException; - - public abstract SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException; - - public abstract SOAPFault createFault() throws SOAPException; - - public abstract Name createName(String localName, String prefix, String uri) throws SOAPException; - - public abstract Name createName(String localName) throws SOAPException; - - public static SOAPFactory newInstance() throws SOAPException { - try { - SOAPFactory factory = $FactoryFinder.find(SOAPFactory.class, DEFAULT_SOAP_FACTORY, false); - if (factory != null) { - return factory; - } - return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); - } catch (Exception ex) { - throw new SOAPException("Unable to create SOAP Factory: " + ex.getMessage(), ex); - } - - } - - public static SOAPFactory newInstance(String protocol) throws SOAPException { - return SAAJMetaFactory.getInstance().newSOAPFactory(protocol); - } -} diff --git a/specs/javaxmlws/src/main/java/javax/xml/ws/spi/$FactoryFinder.java b/specs/javaxmlws/src/main/java/javax/xml/ws/spi/$FactoryFinder.java deleted file mode 100644 index 12bce644faf..00000000000 --- a/specs/javaxmlws/src/main/java/javax/xml/ws/spi/$FactoryFinder.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.ws.spi; - -import javax.xml.ws.WebServiceException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Properties; -import java.util.ServiceLoader; -import java.util.logging.Level; -import java.util.logging.Logger; - -class $FactoryFinder { - - private static final Logger LOGGER = Logger.getLogger("javax.xml.ws"); - - @SuppressWarnings("unchecked") - static T find(Class factoryClass, String fallbackClassName) { - ClassLoader classLoader = contextClassLoader(); - - T provider = firstByServiceLoader(factoryClass); - if (provider != null) { - return provider; - } - - String factoryId = factoryClass.getName(); - - provider = (T) fromJDKProperties(factoryId, fallbackClassName, classLoader); - if (provider != null) { - return provider; - } - - provider = (T) fromSystemProperty(factoryId, fallbackClassName, classLoader); - if (provider != null) { - return provider; - } - - try { - Class spiClass = org.apache.karaf.specs.locator.OsgiLocator.locate(factoryClass); - if (spiClass != null) { - return spiClass.getConstructor().newInstance(); - } - } catch (Throwable t) { - } - - if (fallbackClassName == null) { - throw new WebServiceException("Provider for " + factoryId + " cannot be found", null); - } - - return (T) newInstance(fallbackClassName, fallbackClassName, classLoader); - } - - private static Object fromSystemProperty(String factoryId, String fallbackClassName, ClassLoader classLoader) { - try { - String systemProp = System.getProperty(factoryId); - if (systemProp != null) { - return newInstance(systemProp, fallbackClassName, classLoader); - } - } catch (SecurityException ignored) { - } - return null; - } - - private static Object fromJDKProperties(String factoryId, String fallbackClassName, ClassLoader classLoader) { - Path path = null; - try { - String JAVA_HOME = System.getProperty("java.home"); - path = Paths.get(JAVA_HOME, "conf", "jaxws.properties"); - if (!Files.exists(path)) { - path = Paths.get(JAVA_HOME, "lib", "jaxws.properties"); - } - if (Files.exists(path)) { - Properties props = new Properties(); - try (InputStream inStream = Files.newInputStream(path)) { - props.load(inStream); - } - String factoryClassName = props.getProperty(factoryId); - return newInstance(factoryClassName, fallbackClassName, classLoader); - } - } catch (Exception ignored) { - LOGGER.log(Level.SEVERE, "Error reading JAX-WS configuration from [" + path + - "] file. Check it is accessible and has correct format.", ignored); - } - return null; - } - - private static T firstByServiceLoader(Class spiClass) throws WebServiceException { - LOGGER.log(Level.FINE, "Using java.util.ServiceLoader to find {0}", spiClass.getName()); - try { - ServiceLoader serviceLoader = ServiceLoader.load(spiClass); - for (T impl : serviceLoader) { - LOGGER.fine("ServiceProvider loading Facility used; returning object [" + impl.getClass().getName() + "]"); - return impl; - } - } catch (Throwable t) { - throw new WebServiceException("Error while searching for service [" + spiClass.getName() + "]", t); - } - return null; - } - - private static void checkPackageAccess(String className) { - SecurityManager s = System.getSecurityManager(); - if (s != null) { - int i = className.lastIndexOf('.'); - if (i != -1) { - s.checkPackageAccess(className.substring(0, i)); - } - } - } - - private static Class nullSafeLoadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { - if (classLoader == null) { - return Class.forName(className); - } else { - return classLoader.loadClass(className); - } - } - - private static Object newInstance(String className, String defaultImplClassName, ClassLoader classLoader) throws WebServiceException { - try { - return safeLoadClass(className, defaultImplClassName, classLoader).getConstructor().newInstance(); - } catch (ClassNotFoundException x) { - throw new WebServiceException("Provider " + className + " not found", x); - } catch (Exception x) { - throw new WebServiceException("Provider " + className + " could not be instantiated: " + x, x); - } - } - - private static Class safeLoadClass(String className, String defaultImplClassName, ClassLoader classLoader) throws ClassNotFoundException { - try { - checkPackageAccess(className); - } catch (SecurityException se) { - if (defaultImplClassName != null && defaultImplClassName.equals(className)) { - return Class.forName(className); - } - throw se; - } - return nullSafeLoadClass(className, classLoader); - } - - private static ClassLoader contextClassLoader() throws WebServiceException { - try { - return Thread.currentThread().getContextClassLoader(); - } catch (Exception x) { - throw new WebServiceException(x.toString(), x); - } - } - -} diff --git a/specs/javaxmlws/src/main/java/javax/xml/ws/spi/Provider.java b/specs/javaxmlws/src/main/java/javax/xml/ws/spi/Provider.java deleted file mode 100644 index 9eca1402a94..00000000000 --- a/specs/javaxmlws/src/main/java/javax/xml/ws/spi/Provider.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javax.xml.ws.spi; - -import org.w3c.dom.Element; - -import javax.xml.namespace.QName; -import javax.xml.transform.Source; -import javax.xml.ws.*; -import javax.xml.ws.wsaddressing.W3CEndpointReference; -import java.net.URL; -import java.util.List; -import java.util.Map; - -public abstract class Provider { - - private static final String DEFAULT_JAXWSPROVIDER = "com.sun.xml.internal.ws.spi.ProviderImpl"; - - protected Provider() { - } - - public static Provider provider() { - try { - return $FactoryFinder.find(Provider.class, DEFAULT_JAXWSPROVIDER); - } catch (WebServiceException ex) { - throw ex; - } catch (Exception ex) { - throw new WebServiceException("Unable to createEndpointReference Provider", ex); - } - } - - public abstract ServiceDelegate createServiceDelegate(URL wsdlDocumentLocation, QName serviceName, - Class serviceClass); - - public ServiceDelegate createServiceDelegate(URL wsdlDocumentLocation, QName serviceName, - Class serviceClass, WebServiceFeature... features) { - throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); - } - - public abstract Endpoint createEndpoint(String bindingId, Object implementor); - - public abstract Endpoint createAndPublishEndpoint(String address, Object implementor); - - public abstract EndpointReference readEndpointReference(Source eprInfoset); - - public abstract T getPort(EndpointReference endpointReference, Class serviceEndpointInterface, - WebServiceFeature... features); - - public abstract W3CEndpointReference createW3CEndpointReference(String address, QName serviceName, - QName portName, List metadata, - String wsdlDocumentLocation, - List referenceParameters); - - public W3CEndpointReference createW3CEndpointReference(String address, - QName interfaceName, QName serviceName, QName portName, - List metadata, String wsdlDocumentLocation, - List referenceParameters, - List elements, Map attributes) { - throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); - } - - public Endpoint createAndPublishEndpoint(String address, Object implementor, WebServiceFeature... features) { - throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); - } - - public Endpoint createEndpoint(String bindingId, Object implementor, WebServiceFeature... features) { - throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); - } - - public Endpoint createEndpoint(String bindingId, Class implementorClass, - Invoker invoker, WebServiceFeature... features) { - throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); - } - -} diff --git a/specs/locator/pom.xml b/specs/locator/pom.xml deleted file mode 100644 index 6722210a186..00000000000 --- a/specs/locator/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - 4.0.0 - - - org.apache.karaf.specs - specs - 4.5.0-SNAPSHOT - - - org.apache.karaf.specs.locator - Apache Karaf :: Specs :: Locator - - - 8 - - - diff --git a/specs/locator/src/main/java/org/apache/karaf/specs/locator/OsgiLocator.java b/specs/locator/src/main/java/org/apache/karaf/specs/locator/OsgiLocator.java deleted file mode 100644 index cbc2b7c02de..00000000000 --- a/specs/locator/src/main/java/org/apache/karaf/specs/locator/OsgiLocator.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.karaf.specs.locator; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -public class OsgiLocator { - - public static final long DEFAULT_TIMEOUT = 0L; - public static final String TIMEOUT = "org.apache.karaf.specs.timeout"; - - private static final Map>> FACTORIES = new HashMap<>(); - - private static final ReadWriteLock LOCK = new ReentrantReadWriteLock(); - - private OsgiLocator() { - } - - public static void unregister(String id, Callable factory) { - LOCK.writeLock().lock(); - try { - List> l = FACTORIES.get(id); - if (l != null) { - l.remove(factory); - } - } finally { - LOCK.writeLock().unlock(); - } - } - - public static void register(String id, Callable factory) { - LOCK.writeLock().lock(); - try { - FACTORIES.computeIfAbsent(id, k -> new ArrayList<>()) - .add(0, factory); - synchronized (LOCK) { - LOCK.notifyAll(); - } - } finally { - LOCK.writeLock().unlock(); - } - } - - - public static Class locate(Class factoryId) { - return locate(factoryId, factoryId.getName()); - } - - private static long getTimeout() { - long timeout = DEFAULT_TIMEOUT; - try { - String prop = System.getProperty(TIMEOUT); - if (prop != null) { - timeout = Long.parseLong(prop); - } - } catch (Throwable t) { } - return timeout; - } - - public static Class locate(Class factoryClass, String factoryId) { - long timeout = getTimeout(); - if (timeout <= 0) { - return doLocate(factoryClass, factoryId); - } - long t0 = System.currentTimeMillis(); - long t1 = t0; - while (t1 - t0 < timeout) { - Class impl = doLocate(factoryClass, factoryId); - if (impl != null) { - return impl; - } - synchronized (LOCK) { - try { - LOCK.wait(timeout - (t1 - t0)); - } catch (InterruptedException e) { - return null; - } - } - t1 = System.currentTimeMillis(); - } - return null; - } - - private static Class doLocate(Class factoryClass, String factoryId) { - LOCK.readLock().lock(); - try { - List> l = FACTORIES.get(factoryId); - if (l != null && !l.isEmpty()) { - // look up the System property first - String factoryClassName = System.getProperty(factoryId); - try { - for (Callable i : l) { - Class c = null; - try { - c = i.call(); - } catch (Exception ex) { - // do nothing here - } - if (c != null && factoryClass == c.getClassLoader().loadClass(factoryClass.getName()) - && (factoryClassName == null || c.getName().equals(factoryClassName))) - { - return c; - } - } - } catch (Exception ex) { - // do nothing here - } - } - return null; - } finally { - LOCK.readLock().unlock(); - } - } - - public static List> locateAll(Class factoryId) { - return locateAll(factoryId, factoryId.getName()); - } - - public static List> locateAll(Class factoryClass, String factoryId) { - LOCK.readLock().lock(); - try { - List> classes = new ArrayList<>(); - List> l = FACTORIES.get(factoryId); - if (l != null) { - for (Callable i : l) { - try { - Class c = i.call(); - if (c != null && factoryClass.isAssignableFrom(c)) { - classes.add(c); - } - } catch (Exception e) { - } - } - } - return classes; - } finally { - LOCK.readLock().unlock(); - } - } - -} diff --git a/specs/locator/src/test/java/org/apache/karaf/specs/locator/MockCallable.java b/specs/locator/src/test/java/org/apache/karaf/specs/locator/MockCallable.java deleted file mode 100644 index 092d5bdd002..00000000000 --- a/specs/locator/src/test/java/org/apache/karaf/specs/locator/MockCallable.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.karaf.specs.locator; - -import java.util.concurrent.Callable; - -public class MockCallable implements Callable { - - public Class call() throws Exception { - return this.getClass(); - } - -} diff --git a/specs/locator/src/test/java/org/apache/karaf/specs/locator/MockCallable2.java b/specs/locator/src/test/java/org/apache/karaf/specs/locator/MockCallable2.java deleted file mode 100644 index 7fba2f4ad2c..00000000000 --- a/specs/locator/src/test/java/org/apache/karaf/specs/locator/MockCallable2.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.karaf.specs.locator; - -import java.util.concurrent.Callable; - -public class MockCallable2 implements Callable { - - public Class call() throws Exception { - return this.getClass(); - } - -} diff --git a/specs/locator/src/test/java/org/apache/karaf/specs/locator/OsgiLocatorTest.java b/specs/locator/src/test/java/org/apache/karaf/specs/locator/OsgiLocatorTest.java deleted file mode 100644 index 7fc9dbdf77e..00000000000 --- a/specs/locator/src/test/java/org/apache/karaf/specs/locator/OsgiLocatorTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.karaf.specs.locator; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OsgiLocatorTest extends Assert { - - @BeforeClass - public static void setup() { - OsgiLocator.register("Factory", new MockCallable()); - OsgiLocator.register("Factory", new MockCallable2()); - } - - @Test - public void testLocatorWithSystemProperty() { - System.setProperty(OsgiLocator.TIMEOUT, "0"); - System.setProperty("Factory", "org.apache.karaf.specs.locator.MockCallable"); - Class clazz = OsgiLocator.locate(Object.class, "Factory"); - assertNotNull("Expected to find a class", clazz); - assertEquals("Got the wrong class", MockCallable.class.getName(), clazz.getName()); - - System.setProperty("Factory", "org.apache.karaf.specs.locator"); - clazz = OsgiLocator.locate(Object.class, "Factory"); - assertNull("Did not expect to find a class", clazz); - } - - @Test - public void testLocatorWithoutSystemProperty() { - System.setProperty(OsgiLocator.TIMEOUT, "0"); - System.clearProperty("Factory"); - Class clazz = OsgiLocator.locate(Object.class, "Factory"); - assertNotNull("Expected to find a class", clazz); - assertEquals("Got the wrong class", MockCallable2.class.getName(), clazz.getName()); - } - - @Test - public void testLocatorWithSystemPropertyAndTimeout() { - long timeout = 1000; - System.setProperty(OsgiLocator.TIMEOUT, Long.toString(timeout)); - System.setProperty("Factory", "org.apache.karaf.specs.locator.MockCallable"); - Class clazz = OsgiLocator.locate(Object.class, "Factory"); - assertNotNull("Expected to find a class", clazz); - assertEquals("Got the wrong class.", MockCallable.class.getName(), clazz.getName()); - - System.setProperty("Factory", "org.apache.karaf.specs.locator"); - long t0 = System.currentTimeMillis(); - clazz = OsgiLocator.locate(Object.class, "Factory"); - long t1 = System.currentTimeMillis(); - assertNull("Did not expect to find a class", clazz); - assertTrue("Timeout issue", (t1 - t0) > timeout / 2); - } - - @Test - public void testLocatorWithoutSystemPropertyAndTimeout() { - long timeout = 1000; - System.setProperty(OsgiLocator.TIMEOUT, Long.toString(timeout)); - System.clearProperty("Factory"); - long t0 = System.currentTimeMillis(); - Class clazz = OsgiLocator.locate(Object.class, "Factory"); - long t1 = System.currentTimeMillis(); - assertNotNull("Expected to find a class", clazz); - assertEquals("Got the wrong class", MockCallable2.class.getName(), clazz.getName()); - assertTrue("Timeout issue", (t1 - t0) < timeout / 2); - } - -} diff --git a/specs/pom.xml b/specs/pom.xml deleted file mode 100644 index 45ed552ba51..00000000000 --- a/specs/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - 4.0.0 - - - org.apache.karaf - karaf - 4.5.0-SNAPSHOT - ../pom.xml - - - org.apache.karaf.specs - specs - pom - Apache Karaf :: Specs - - - locator - activator - javaxml - javaxmlws - - - -