Violetta, On 12/8/14 4:04 AM, [email protected] wrote: > Author: violetagg > Date: Mon Dec 8 09:04:56 2014 > New Revision: 1643766 > > URL: http://svn.apache.org/r1643766 > Log: > Extract several "protected" methods in order to make StandardRoot easier for > extending. > > Modified: > tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java > > Modified: tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java > URL: > http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java?rev=1643766&r1=1643765&r2=1643766&view=diff > ============================================================================== > --- tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java > (original) > +++ tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java Mon > Dec 8 09:04:56 2014 > @@ -457,6 +457,10 @@ public class StandardRoot extends Lifecy > return postResources.toArray(new WebResourceSet[0]); > } > > + protected WebResourceSet[] getClassResources() { > + return classResources.toArray(new WebResourceSet[0]);
Any reason not to properly-size the argument to toArray? If you pass-in
WebResourceSet[0], you create an array that can't be used for anything,
then toArray needs to create another one for you, so you get two array
allocations when only one is necessary.
-chris
> + }
> +
> @Override
> public void setAllowLinking(boolean allowLinking) {
> this.allowLinking = allowLinking;
> @@ -633,9 +637,7 @@ public class StandardRoot extends Lifecy
>
> cacheJmxName = register(cache, getObjectNameKeyProperties() +
> ",name=Cache");
>
> - // Ensure support for jar:war:file:/ URLs will be available (required
> - // for resource JARs in packed WAR files).
> - TomcatURLStreamHandlerFactory.register();
> + registerURLStreamHandlerFactory();
>
> if (context == null) {
> throw new IllegalStateException(
> @@ -649,29 +651,17 @@ public class StandardRoot extends Lifecy
> }
> }
>
> + protected void registerURLStreamHandlerFactory() {
> + // Ensure support for jar:war:file:/ URLs will be available (required
> + // for resource JARs in packed WAR files).
> + TomcatURLStreamHandlerFactory.register();
> + }
> +
> @Override
> protected void startInternal() throws LifecycleException {
> - String docBase = context.getDocBase();
> -
> mainResources.clear();
>
> - if (docBase == null) {
> - main = new EmptyResourceSet(this);
> - } else {
> - File f = new File(docBase);
> - if (!f.isAbsolute()) {
> - f = new File(((Host)context.getParent()).getAppBaseFile(),
> f.getPath());
> - }
> - if (f.isDirectory()) {
> - main = new DirResourceSet(this, "/", f.getAbsolutePath(),
> "/");
> - } else if(f.isFile() && docBase.endsWith(".war")) {
> - main = new JarResourceSet(this, "/", f.getAbsolutePath(),
> "/");
> - } else {
> - throw new IllegalArgumentException(
> - sm.getString("standardRoot.startInvalidMain",
> - f.getAbsolutePath()));
> - }
> - }
> + main = createMainResourceSet();
>
> mainResources.add(main);
>
> @@ -694,6 +684,31 @@ public class StandardRoot extends Lifecy
> setState(LifecycleState.STARTING);
> }
>
> + protected WebResourceSet createMainResourceSet() {
> + String docBase = context.getDocBase();
> +
> + WebResourceSet mainResourceSet;
> + if (docBase == null) {
> + mainResourceSet = new EmptyResourceSet(this);
> + } else {
> + File f = new File(docBase);
> + if (!f.isAbsolute()) {
> + f = new File(((Host)context.getParent()).getAppBaseFile(),
> f.getPath());
> + }
> + if (f.isDirectory()) {
> + mainResourceSet = new DirResourceSet(this, "/",
> f.getAbsolutePath(), "/");
> + } else if(f.isFile() && docBase.endsWith(".war")) {
> + mainResourceSet = new JarResourceSet(this, "/",
> f.getAbsolutePath(), "/");
> + } else {
> + throw new IllegalArgumentException(
> + sm.getString("standardRoot.startInvalidMain",
> + f.getAbsolutePath()));
> + }
> + }
> +
> + return mainResourceSet;
> + }
> +
> @Override
> protected void stopInternal() throws LifecycleException {
> for (ArrayList<WebResourceSet> list : allResources) {
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
signature.asc
Description: OpenPGP digital signature
