ASF Bugzilla – Attachment 25103 Details for
Bug 48870
avoid parallel arrays of base types
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
patch_parallelArrays.txt
patch_parallelArrays.txt (text/plain), 11.30 KB, created by
Ralf Hauser
on 2010-03-08 06:55:57 UTC
(
hide
)
Description:
patch_parallelArrays.txt
Filename:
MIME Type:
Creator:
Ralf Hauser
Created:
2010-03-08 06:55:57 UTC
Size:
11.30 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P tomcat >Index: container/catalina/src/share/org/apache/catalina/startup/Bootstrap.java >=================================================================== >--- container/catalina/src/share/org/apache/catalina/startup/Bootstrap.java (revision 791795) >+++ container/catalina/src/share/org/apache/catalina/startup/Bootstrap.java (working copy) >@@ -31,6 +31,7 @@ > import javax.management.ObjectName; > > import org.apache.catalina.security.SecurityClassLoad; >+import org.apache.catalina.startup.ClassLoaderFactory.BootLocation; > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > >@@ -116,35 +117,34 @@ > if ((value == null) || (value.equals(""))) > return parent; > >- ArrayList repositoryLocations = new ArrayList(); >- ArrayList repositoryTypes = new ArrayList(); >+ ArrayList<BootLocation> repositoryLocations = new ArrayList<BootLocation>(); > int i; > > StringTokenizer tokenizer = new StringTokenizer(value, ","); > while (tokenizer.hasMoreElements()) { >- String repository = tokenizer.nextToken(); >+ BootLocation repository = new BootLocation(tokenizer.nextToken()); > > // Local repository > boolean replace = false; >- String before = repository; >+ BootLocation before = repository; > while ((i=repository.indexOf(CATALINA_HOME_TOKEN))>=0) { > replace=true; > if (i>0) { >- repository = repository.substring(0,i) + getCatalinaHome() >- + repository.substring(i+CATALINA_HOME_TOKEN.length()); >+ repository.set(repository.substring(0,i) + getCatalinaHome() >+ + repository.substring(i+CATALINA_HOME_TOKEN.length())); > } else { >- repository = getCatalinaHome() >- + repository.substring(CATALINA_HOME_TOKEN.length()); >+ repository.set(getCatalinaHome() >+ + repository.substring(CATALINA_HOME_TOKEN.length())); > } > } > while ((i=repository.indexOf(CATALINA_BASE_TOKEN))>=0) { > replace=true; > if (i>0) { >- repository = repository.substring(0,i) + getCatalinaBase() >- + repository.substring(i+CATALINA_BASE_TOKEN.length()); >+ repository.set( repository.substring(0,i) + getCatalinaBase() >+ + repository.substring(i+CATALINA_BASE_TOKEN.length())); > } else { >- repository = getCatalinaBase() >- + repository.substring(CATALINA_BASE_TOKEN.length()); >+ repository.set(getCatalinaBase() >+ + repository.substring(CATALINA_BASE_TOKEN.length())); > } > } > if (replace && log.isDebugEnabled()) >@@ -152,33 +152,33 @@ > > // Check for a JAR URL repository > try { >- URL url=new URL(repository); >+ URL url=new URL(repository.toString()); >+ > repositoryLocations.add(repository); >- repositoryTypes.add(ClassLoaderFactory.IS_URL); >+ repository.setType(ClassLoaderFactory.IS_URL); > continue; > } catch (MalformedURLException e) { > // Ignore > } > > if (repository.endsWith("*.jar")) { >- repository = repository.substring >- (0, repository.length() - "*.jar".length()); >+ repository.set(repository.substring >+ (0, repository.length() - "*.jar".length())); > repositoryLocations.add(repository); >- repositoryTypes.add(ClassLoaderFactory.IS_GLOB); >+ repository.setType(ClassLoaderFactory.IS_GLOB); > } else if (repository.endsWith(".jar")) { > repositoryLocations.add(repository); >- repositoryTypes.add(ClassLoaderFactory.IS_JAR); >+ repository.setType(ClassLoaderFactory.IS_JAR); > } else { > repositoryLocations.add(repository); >- repositoryTypes.add(ClassLoaderFactory.IS_DIR); >+ repository.setType(ClassLoaderFactory.IS_DIR); > } > } > >- String[] locations = (String[]) repositoryLocations.toArray(new String[0]); >- Integer[] types = (Integer[]) repositoryTypes.toArray(new Integer[0]); >+ BootLocation[] locations = (BootLocation[]) repositoryLocations.toArray(new BootLocation[0]); > > ClassLoader classLoader = ClassLoaderFactory.createClassLoader >- (locations, types, parent); >+ (locations, parent); > > // Retrieving MBean server > MBeanServer mBeanServer = null; >Index: container/catalina/src/share/org/apache/catalina/startup/ClassLoaderFactory.java >=================================================================== >--- container/catalina/src/share/org/apache/catalina/startup/ClassLoaderFactory.java (revision 791795) >+++ container/catalina/src/share/org/apache/catalina/startup/ClassLoaderFactory.java (working copy) >@@ -27,6 +27,8 @@ > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > >+import org.apache.commons.lang.StringUtils; >+ > > /** > * <p>Utility class for building class loaders for Catalina. The factory >@@ -52,9 +54,21 @@ > > private static Log log = LogFactory.getLog(ClassLoaderFactory.class); > >+ /** >+ * @deprecated FIXME make this an enum type >+ */ > protected static final Integer IS_DIR = new Integer(0); >+ /** >+ * @deprecated FIXME make this an enum type >+ */ > protected static final Integer IS_JAR = new Integer(1); >+ /** >+ * @deprecated FIXME make this an enum type >+ */ > protected static final Integer IS_GLOB = new Integer(2); >+ /** >+ * @deprecated FIXME make this an enum type >+ */ > protected static final Integer IS_URL = new Integer(3); > > // --------------------------------------------------------- Public Methods >@@ -159,7 +173,89 @@ > return (classLoader); > > } >+ >+ public static class BootLocation implements CharSequence { >+ >+ static Log log = LogFactory.getLog(BootLocation.class); >+ >+ private String str = null; >+ >+ Integer type = -1; >+ >+ public Integer getType() { >+ return this.type; >+ } >+ public void setType(Integer type) { >+ this.type = type; >+ } >+ public BootLocation(String strHere) { >+ this.str = strHere; >+ } >+ public void set(String strHere) { >+ this.str = strHere; >+ } >+ public void append(CharSequence strHere) { >+ this.str += strHere; >+ } > >+ public char charAt(int index) { >+ if (StringUtils.isBlank(this.str)) { >+ return 0; >+ } >+ return this.str.charAt(index); >+ } >+ >+ public int length() { >+ if (StringUtils.isBlank(this.str)) { >+ return 0; >+ } >+ return this.str.length(); >+ } >+ >+ public CharSequence subSequence(int start, int end) { >+ if (StringUtils.isBlank(this.str)) { >+ return null; >+ } >+ return this.subSequence(start, end); >+ } >+ >+ public String toString() { >+ return this.str; >+ } >+ >+ public int indexOf(String str) { >+ if (StringUtils.isBlank(this.str)) { >+ return -1; >+ } >+ return this.str.toString().indexOf(str, 0); >+ } >+ >+ public String substring(int beginIndex, int endIndex) { >+ if (null == this.str) { >+ return null; >+ } >+ return this.str.toString().substring(beginIndex, endIndex); >+ } >+ >+ public String substring(int beginIndex) { >+ if (null == this.str) { >+ return null; >+ } >+ return substring(beginIndex, this.str.toString().length()); >+ } >+ >+ public boolean endsWith(String suffix) { >+ if (null == this.str) { >+ if (null == suffix) { >+ return true; >+ } >+ return false; >+ } >+ return this.str.toString().endsWith(suffix); >+ } >+ >+ } >+ > > /** > * Create and return a new class loader, based on the configuration >@@ -176,8 +272,7 @@ > * > * @exception Exception if an error occurs constructing the class loader > */ >- public static ClassLoader createClassLoader(String locations[], >- Integer types[], >+ public static ClassLoader createClassLoader(BootLocation locations[], > ClassLoader parent) > throws Exception { > >@@ -187,16 +282,16 @@ > // Construct the "class path" for this class loader > ArrayList list = new ArrayList(); > >- if (locations != null && types != null && locations.length == types.length) { >+ if (locations != null ) { > for (int i = 0; i < locations.length; i++) { >- String location = locations[i]; >- if ( types[i] == IS_URL ) { >- URL url = new URL(location); >+ BootLocation location = locations[i]; >+ if ( location.getType() == IS_URL ) { >+ URL url = new URL(location.toString()); > if (log.isDebugEnabled()) > log.debug(" Including URL " + url); > list.add(url); >- } else if ( types[i] == IS_DIR ) { >- File directory = new File(location); >+ } else if ( location.getType() == IS_DIR ) { >+ File directory = new File(location.toString()); > directory = new File(directory.getCanonicalPath()); > if (!directory.exists() || !directory.isDirectory() || > !directory.canRead()) >@@ -205,8 +300,8 @@ > if (log.isDebugEnabled()) > log.debug(" Including directory " + url); > list.add(url); >- } else if ( types[i] == IS_JAR ) { >- File file=new File(location); >+ } else if ( location.getType() == IS_JAR ) { >+ File file=new File(location.toString()); > file = new File(file.getCanonicalPath()); > if (!file.exists() || !file.canRead()) > continue; >@@ -214,8 +309,8 @@ > if (log.isDebugEnabled()) > log.debug(" Including jar file " + url); > list.add(url); >- } else if ( types[i] == IS_GLOB ) { >- File directory=new File(location); >+ } else if ( location.getType() == IS_GLOB ) { >+ File directory=new File(location.toString()); > if (!directory.exists() || !directory.isDirectory() || > !directory.canRead()) > continue;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 48870
: 25103