You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2019/07/24 09:03:52 UTC
[tomee] branch master updated: Simplifying this code
This is an automated email from the ASF dual-hosted git repository.
jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/master by this push:
new 76463ff Simplifying this code
76463ff is described below
commit 76463ffb883ef7648b5efab8d28ff42cee03f00b
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Tue Jul 23 23:03:57 2019 +0100
Simplifying this code
---
.../tests/cmp/sample/CustomOrmXmlTest.java | 2 +-
.../apache/openejb/config/CmpJpaConversion.java | 3 +-
.../openejb/config/EntityMappingURLFinder.java | 112 ---------------------
3 files changed, 3 insertions(+), 114 deletions(-)
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java
index 97bb17d..d48d27e 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java
@@ -46,7 +46,7 @@ public class CustomOrmXmlTest {
LocalMovie.class, LocalMovieHome.class, MovieBean.class, MovieDetails.class,
MoviesBusiness.class, MoviesBusinessBean.class, MoviesBusinessHome.class,
MoviesServlet.class)
- .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"), "META-INF/openejb-cmp-generated-orm.xml")
+ .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"), "META-INF/custom-orm.xml")
.addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml"), "META-INF/persistence.xml")
.addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/openejb-jar.xml"), "openejb-jar.xml")
.addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/ejb-jar.xml"), "ejb-jar.xml")
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java b/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
index 1acac8a..96d1bc2 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
@@ -64,6 +64,7 @@ import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
import org.apache.openejb.util.Strings;
+import org.apache.xbean.finder.ResourceFinder;
import javax.ejb.EJBLocalObject;
import java.lang.reflect.Field;
@@ -108,7 +109,7 @@ class CmpJpaConversion implements DynamicDeployer {
private static EntityMappings readEntityMappings(final String location, final AppModule appModule) {
try {
- URL url = EntityMappingURLFinder.INSTANCE.apply(location, appModule);
+ final URL url = new ResourceFinder("", appModule.getClassLoader()).getResource(location);
if (Objects.isNull(url)) {
return null;
}
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/EntityMappingURLFinder.java b/container/openejb-core/src/main/java/org/apache/openejb/config/EntityMappingURLFinder.java
deleted file mode 100644
index 46a2e98..0000000
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/EntityMappingURLFinder.java
+++ /dev/null
@@ -1,112 +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.openejb.config;
-
-import org.apache.openejb.util.LogCategory;
-import org.apache.openejb.util.Logger;
-import org.apache.xbean.finder.ResourceFinder;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.BiFunction;
-
-import static java.util.Arrays.asList;
-
-enum EntityMappingURLFinder implements BiFunction<String, AppModule, URL> {
-
-
-
- INSTANCE;
- private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, EntityMappingURLFinder.class);
-
- private final DefaultFinder defaultFinder = new DefaultFinder();
-
- private final URLFinder urlFinder = new URLFinder();
-
- private final AppModuleMetaInfFinder appModuleMetaInfFinder = new AppModuleMetaInfFinder();
-
- private final List<BiFunction<String, AppModule, URL>> finders = asList(defaultFinder, urlFinder, appModuleMetaInfFinder);
-
-
- @Override
- public URL apply(String location, AppModule appModule) {
- for (BiFunction<String, AppModule, URL> finder : finders) {
- URL url = finder.apply(location, appModule);
- if (Objects.nonNull(url)) {
- return url;
- }
- }
- return null;
- }
-
-
- private class DefaultFinder implements BiFunction<String, AppModule, URL> {
-
- @Override
- public URL apply(String location, AppModule appModule) {
- return Thread.currentThread().getContextClassLoader().getResource(location);
- }
- }
-
- private class URLFinder implements BiFunction<String, AppModule, URL> {
-
- @Override
- public URL apply(String location, AppModule appModule) {
- try {
- return new URL(location);
- } catch (MalformedURLException e) {
- LOGGER.info("Unable to using URL: " + location);
- return null;
- }
- }
- }
-
- private class AppModuleMetaInfFinder implements BiFunction<String, AppModule, URL> {
-
- @Override
- public URL apply(String location, AppModule appModule) {
-
- if (!location.contains(DeploymentLoader.META_INF)) {
- return null;
- }
-
- for (EjbModule ejbModule : appModule.getEjbModules()) {
-
- URL url = getUrl(location, ejbModule);
- if (Objects.nonNull(url)) {
- return url;
- }
- }
- return null;
- }
-
- private URL getUrl(String location, EjbModule ejbModule) {
- try {
- final ResourceFinder finder = new ResourceFinder("", ejbModule.getClassLoader());
- Map<String, URL> map = DeploymentLoader.mapDescriptors(finder);
- String fileName = location.replace(DeploymentLoader.META_INF, "");
- return map.get(fileName);
- } catch (Exception ex) {
- LOGGER.error("Unable to read entity mappings from " + location, ex);
- return null;
- }
- }
- }
-}