diff options
author | gjoranv <gv@oath.com> | 2018-10-19 17:45:32 +0200 |
---|---|---|
committer | gjoranv <gv@oath.com> | 2019-01-21 15:09:24 +0100 |
commit | 2b330565d1243ae7da0a9cbe9c5203b52a44c515 (patch) | |
tree | 898b5ca54f55ccfd78116bcbdd044ed3947c1d95 /container-core | |
parent | f01b513c56a3bd52f9270db1cb7c4dd83e6df54f (diff) |
Remove built-in support for JAXBContextFactory.
Diffstat (limited to 'container-core')
3 files changed, 0 insertions, 126 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/xml/bind/JAXBContextFactory.java b/container-core/src/main/java/com/yahoo/container/xml/bind/JAXBContextFactory.java deleted file mode 100644 index c2355ce74be..00000000000 --- a/container-core/src/main/java/com/yahoo/container/xml/bind/JAXBContextFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.xml.bind; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; - -/** - * Container components can take an instance of this class as a constructor argument, - * to get a new instance injected by the container framework. There is usually no - * need to create an instance with this class' constructor. - * <p> - * This factory is needed because the JAXBContext needs a user defined context path, - * which means that it cannot be created at the time the container creates its - * component graph. - * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> - * @author gjoranv - * @since 5.3 - * @deprecated Do not use! - */ -@Deprecated -public class JAXBContextFactory { - public static final String FACTORY_CLASS = "com.sun.xml.internal.bind.v2.ContextFactory"; - - /** - * Returns a new JAXBContext for the context path defined by the given list of classes. - * @return A new JAXBContext. - * @param classes One class per package that contains schema derived classes and/or - * java to schema (JAXB-annotated) mapped classes - */ - public JAXBContext newInstance(Class<?>... classes) { - return newInstance(getContextPath(classes), classes[0].getClassLoader()); - } - - // TODO: guard against adding the same package more than once - static String getContextPath(Class<?>... classes) { - if (classes == null || classes.length == 0) { - throw new IllegalArgumentException("Empty package list."); - } - StringBuilder contextPath = new StringBuilder(); - for (Class<?> clazz : classes) { - contextPath - .append(clazz.getPackage().getName()) - .append(':'); - } - contextPath.deleteCharAt(contextPath.length() - 1); - return contextPath.toString(); - } - - private static JAXBContext newInstance(String contextPath, ClassLoader classLoader) { - System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY, FACTORY_CLASS); - try { - return JAXBContext.newInstance(contextPath, classLoader); - } catch (JAXBException e) { - throw new IllegalStateException(e); - } - } -} diff --git a/container-core/src/main/java/com/yahoo/container/xml/providers/JAXBContextFactoryProvider.java b/container-core/src/main/java/com/yahoo/container/xml/providers/JAXBContextFactoryProvider.java deleted file mode 100644 index 6d82fa7af82..00000000000 --- a/container-core/src/main/java/com/yahoo/container/xml/providers/JAXBContextFactoryProvider.java +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.xml.providers; - -import com.yahoo.container.di.componentgraph.Provider; - -/** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> - * @since 5.1.29 - * @deprecated Do not use! - */ -@Deprecated -@SuppressWarnings("deprecation") -public class JAXBContextFactoryProvider implements Provider<com.yahoo.container.xml.bind.JAXBContextFactory> { - public static final String FACTORY_CLASS = com.yahoo.container.xml.bind.JAXBContextFactory.class.getName(); - - @Override - public com.yahoo.container.xml.bind.JAXBContextFactory get() { - return new com.yahoo.container.xml.bind.JAXBContextFactory(); - } - - @Override - public void deconstruct() { } -} diff --git a/container-core/src/test/java/com/yahoo/container/xml/bind/JAXBContextFactoryTest.java b/container-core/src/test/java/com/yahoo/container/xml/bind/JAXBContextFactoryTest.java deleted file mode 100644 index 670b69516bf..00000000000 --- a/container-core/src/test/java/com/yahoo/container/xml/bind/JAXBContextFactoryTest.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.xml.bind; - -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -/** - * @author einarmr - * @author gjoranv - * @since 5.3 - */ -@SuppressWarnings("deprecation") -public class JAXBContextFactoryTest { - @Test - public void testInstantiationAndDestruction() { - - com.yahoo.container.xml.providers.JAXBContextFactoryProvider provider = new com.yahoo.container.xml.providers.JAXBContextFactoryProvider(); - JAXBContextFactory factory = provider.get(); - assertThat(factory.getClass().getName(), equalTo(com.yahoo.container.xml.providers.JAXBContextFactoryProvider.FACTORY_CLASS)); - - try { - JAXBContextFactory.getContextPath((Class) null); - fail("Should have failed with null classes."); - } catch (Exception e) { } - - try { - JAXBContextFactory.getContextPath(); - fail("Should have failed with empty list."); - } catch (Exception e) { } - - assertThat(JAXBContextFactory.getContextPath(this.getClass()), - equalTo(this.getClass().getPackage().getName())); - - assertThat(JAXBContextFactory.getContextPath(this.getClass(), - String.class), - equalTo(this.getClass().getPackage().getName() + ":" + - String.class.getPackage().getName())); - - provider.deconstruct(); - - } -} |