Author: doogie
Date: Wed Mar 4 04:21:13 2009 New Revision: 749893 URL: http://svn.apache.org/viewvc?rev=749893&view=rev Log: Move some entity-specific code out of base, by making use of javax.imageio.spi.ServiceRegistry, and META-INF/services. Added: ofbiz/trunk/framework/entity/src/META-INF/ ofbiz/trunk/framework/entity/src/META-INF/services/ ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.util.CachedClassLoader$Init ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/CachedClassLoaderInit.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/CachedClassLoader.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/CachedClassLoader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/CachedClassLoader.java?rev=749893&r1=749892&r2=749893&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/CachedClassLoader.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/CachedClassLoader.java Wed Mar 4 04:21:13 2009 @@ -22,7 +22,9 @@ import java.net.URLClassLoader; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.Map; +import javax.imageio.spi.ServiceRegistry; /** * Caching Class Loader @@ -30,6 +32,10 @@ */ public class CachedClassLoader extends URLClassLoader { + public interface Init { + void loadClasses(ClassLoader loader, Map<String, Class<?>> classNameMap) throws ClassNotFoundException; + } + public static final String module = CachedClassLoader.class.getName(); private String contextName; @@ -107,18 +113,16 @@ globalClassNameClassMap.put("byte", Byte.TYPE); globalClassNameClassMap.put("char", Character.TYPE); - try { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); + ClassLoader loader = Thread.currentThread().getContextClassLoader(); - // note: loadClass is necessary for these since this class doesn't know anything about the Entity Engine at compile time - globalClassNameClassMap.put("GenericValue", loader.loadClass("org.ofbiz.entity.GenericValue")); - globalClassNameClassMap.put("org.ofbiz.entity.GenericValue", loader.loadClass("org.ofbiz.entity.GenericValue")); - globalClassNameClassMap.put("GenericPK", loader.loadClass("org.ofbiz.entity.GenericPK")); - globalClassNameClassMap.put("org.ofbiz.entity.GenericPK", loader.loadClass("org.ofbiz.entity.GenericPK")); - globalClassNameClassMap.put("GenericEntity", loader.loadClass("org.ofbiz.entity.GenericEntity")); - globalClassNameClassMap.put("org.ofbiz.entity.GenericEntity", loader.loadClass("org.ofbiz.entity.GenericEntity")); - } catch (ClassNotFoundException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + Iterator<Init> cachedClassLoaders = ServiceRegistry.lookupProviders(Init.class, loader); + while (cachedClassLoaders.hasNext()) { + Init cachedClassLoader = cachedClassLoaders.next(); + try { + cachedClassLoader.loadClasses(loader, globalClassNameClassMap); + } catch (ClassNotFoundException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } } } Added: ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.util.CachedClassLoader$Init URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.util.CachedClassLoader%24Init?rev=749893&view=auto ============================================================================== --- ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.util.CachedClassLoader$Init (added) +++ ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.util.CachedClassLoader$Init Wed Mar 4 04:21:13 2009 @@ -0,0 +1,18 @@ +# 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. + +org.ofbiz.entity.util.CachedClassLoaderInit Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/CachedClassLoaderInit.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/CachedClassLoaderInit.java?rev=749893&view=auto ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/CachedClassLoaderInit.java (added) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/CachedClassLoaderInit.java Wed Mar 4 04:21:13 2009 @@ -0,0 +1,34 @@ +/* + * 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.ofbiz.entity.util; + +import java.util.Map; + +import org.ofbiz.base.util.CachedClassLoader; + +public class CachedClassLoaderInit implements CachedClassLoader.Init { + public void loadClasses(ClassLoader loader, Map<String, Class<?>> classNameMap) throws ClassNotFoundException { + classNameMap.put("GenericValue", loader.loadClass("org.ofbiz.entity.GenericValue")); + classNameMap.put("org.ofbiz.entity.GenericValue", loader.loadClass("org.ofbiz.entity.GenericValue")); + classNameMap.put("GenericPK", loader.loadClass("org.ofbiz.entity.GenericPK")); + classNameMap.put("org.ofbiz.entity.GenericPK", loader.loadClass("org.ofbiz.entity.GenericPK")); + classNameMap.put("GenericEntity", loader.loadClass("org.ofbiz.entity.GenericEntity")); + classNameMap.put("org.ofbiz.entity.GenericEntity", loader.loadClass("org.ofbiz.entity.GenericEntity")); + } +} |
Free forum by Nabble | Edit this page |