You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/10/19 13:36:10 UTC
svn commit: r1400049 - in
/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb:
ClassLoaderUtil.java classloader/CompositeClassLoaderConfigurer.java
Author: rmannibucau
Date: Fri Oct 19 11:36:10 2012
New Revision: 1400049
URL: http://svn.apache.org/viewvc?rev=1400049&view=rev
Log:
TOMEE-473 composite classloader enricher
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/classloader/CompositeClassLoaderConfigurer.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java?rev=1400049&r1=1400048&r2=1400049&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java Fri Oct 19 11:36:10 2012
@@ -17,6 +17,7 @@
package org.apache.openejb;
import org.apache.openejb.classloader.ClassLoaderConfigurer;
+import org.apache.openejb.classloader.CompositeClassLoaderConfigurer;
import org.apache.openejb.core.TempClassLoader;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.util.LogCategory;
@@ -542,24 +543,48 @@ public class ClassLoaderUtil {
if (impl != null) {
key = key.substring(0, key.length() - "clazz".length());
+ boolean list = false;
try {
- final ObjectRecipe recipe = new ObjectRecipe(impl);
- for (Map.Entry<Object, Object> entry : SystemInstance.get().getProperties().entrySet()) {
- String entryKey = entry.getKey().toString();
- if (entryKey.startsWith(key)) {String newKey = entryKey.substring(key.length());if (!"clazz".equals(newKey))
+ ClassLoaderUtil.class.getClassLoader().loadClass(impl);
+ } catch (ClassNotFoundException e) {
+ list = true;
+ }
+
+ if (!list) {
+ return createConfigurer(key, impl);
+ } else {
+ final String[] names = impl.split(",");
+ final ClassLoaderConfigurer[] configurers = new ClassLoaderConfigurer[names.length];
+ for (int i = 0; i < names.length; i++) {
+ configurers[i] = createConfigurer(names[i], SystemInstance.get().getProperty(names[i] + ".clazz"));
+ }
+ return new CompositeClassLoaderConfigurer(configurers);
+ }
+ }
+ return null;
+ }
+
+ private static ClassLoaderConfigurer createConfigurer(final String key, final String impl) {
+ try {
+ final ObjectRecipe recipe = new ObjectRecipe(impl);
+ for (Map.Entry<Object, Object> entry : SystemInstance.get().getProperties().entrySet()) {
+ String entryKey = entry.getKey().toString();
+ if (entryKey.startsWith(key)) {
+ String newKey = entryKey.substring(key.length());
+ if (!"clazz".equals(newKey)) {
recipe.setProperty(newKey, entry.getValue());
}
}
+ }
- final Object instance = recipe.create();
- if (instance instanceof ClassLoaderConfigurer) {
- return (ClassLoaderConfigurer) instance;
- } else {
- logger.error(impl + " is not a classlaoder configurer, using default behavior");
- }
- } catch (Exception e) {
- logger.error("Can't create classloader configurer " + impl + ", using default behavior");
+ final Object instance = recipe.create();
+ if (instance instanceof ClassLoaderConfigurer) {
+ return (ClassLoaderConfigurer) instance;
+ } else {
+ logger.error(impl + " is not a classlaoder configurer, using default behavior");
}
+ } catch (Exception e) {
+ logger.error("Can't create classloader configurer " + impl + ", using default behavior");
}
return null;
}
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/classloader/CompositeClassLoaderConfigurer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/classloader/CompositeClassLoaderConfigurer.java?rev=1400049&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/classloader/CompositeClassLoaderConfigurer.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/classloader/CompositeClassLoaderConfigurer.java Fri Oct 19 11:36:10 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.classloader;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class CompositeClassLoaderConfigurer implements ClassLoaderConfigurer {
+ private final ClassLoaderConfigurer[] composites;
+ private final URL[] urls;
+
+ public CompositeClassLoaderConfigurer(final ClassLoaderConfigurer[] configurers) {
+ composites = configurers;
+
+ final Set<URL> urlSet = new HashSet<URL>();
+ for (ClassLoaderConfigurer configurer : configurers) {
+ urlSet.addAll(Arrays.asList(configurer.additionalURLs()));
+ }
+ urls = urlSet.toArray(new URL[urlSet.size()]);
+ }
+
+ @Override
+ public URL[] additionalURLs() {
+ return urls;
+ }
+
+ @Override
+ public boolean accept(final URL url) {
+ for (ClassLoaderConfigurer configurer : composites) {
+ if (!configurer.accept(url)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}