[Proxool-cvs] proxool/src/java/org/logicalcobwebs/proxool ProxyFactory.java,1.32,1.33
UNMAINTAINED!
Brought to you by:
billhorsman
From: <bil...@us...> - 2006-04-09 21:08:51
|
Update of /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24115/src/java/org/logicalcobwebs/proxool Modified Files: ProxyFactory.java Log Message: Use our own naming policy for Cglib to avoid duplicate class definition exceptions. Index: ProxyFactory.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ProxyFactory.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** ProxyFactory.java 18 Jan 2006 14:40:02 -0000 1.32 --- ProxyFactory.java 9 Apr 2006 21:08:43 -0000 1.33 *************** *** 9,12 **** --- 9,14 ---- import org.logicalcobwebs.cglib.proxy.Factory; import org.logicalcobwebs.cglib.proxy.Callback; + import org.logicalcobwebs.cglib.core.NamingPolicy; + import org.logicalcobwebs.cglib.core.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; *************** *** 38,41 **** --- 40,78 ---- /** + * This naming policy stops conflicts with other Cglib instances that are running + * (Even ones in different packages). Without using our own naming policy we end + * up with exceptions like: + * <pre> + * java.lang.LinkageError: duplicate class definition: + * $java/lang/Object$$FastClassByCGLIB$$3f697993 + * </pre> + */ + private static NamingPolicy NAMING_POLICY = new NamingPolicy() { + public String getClassName(String prefix, String source, Object key, Predicate names) { + StringBuffer sb = new StringBuffer(); + sb.append( + (prefix != null) ? + ( + prefix.startsWith("java") ? + "$" + prefix : prefix + ) + : "net.sf.cglib.empty.Object" + ); + sb.append("$$"); + sb.append(source.substring(source.lastIndexOf('.') + 1)); + sb.append("ByProxool$$"); + sb.append(Integer.toHexString(key.hashCode())); + String base = sb.toString(); + String attempt = base; + int index = 2; + while (names.evaluate(attempt)) { + attempt = base + "_" + index++; + } + + return attempt; + } + }; + + /** * Wraps up a proxyConnection inside a {@link WrappedConnection} and then proxies it as a * simple {@link Connection}. You should call this immediately before the connection is served *************** *** 73,76 **** --- 110,114 ---- private static Object getProxy(Object delegate, Callback callback, ConnectionPoolDefinitionIF def) { Enhancer e = new Enhancer(); + e.setNamingPolicy(NAMING_POLICY); e.setInterfaces(getInterfaces(delegate.getClass(), def)); e.setCallback(callback); *************** *** 245,248 **** --- 283,289 ---- Revision history: $Log$ + Revision 1.33 2006/04/09 21:08:43 billhorsman + Use our own naming policy for Cglib to avoid duplicate class definition exceptions. + Revision 1.32 2006/01/18 14:40:02 billhorsman Unbundled Jakarta's Commons Logging. |