This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 003e071 Add default instance manager factory method 003e071 is described below commit 003e071140520ffc2d02b4b1cee75e647352b2b6 Author: remm <r...@apache.org> AuthorDate: Mon May 27 18:55:02 2019 +0200 Add default instance manager factory method This can be used for nicer looking framework integration, instead of hacking and replacing the instance manager after the fact (if extending the default instance manager was desired). --- java/org/apache/catalina/Context.java | 8 ++++++++ java/org/apache/catalina/core/StandardContext.java | 21 +++++++++++++-------- java/org/apache/catalina/startup/FailedContext.java | 3 +++ test/org/apache/tomcat/unittest/TesterContext.java | 5 +++++ webapps/docs/changelog.xml | 4 ++++ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index 5e3d285..49453f2 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -931,6 +931,14 @@ public interface Context extends Container, ContextBind { /** + * Factory method to create and return a new InstanceManager + * instance. This can be used for framework integration or easier + * configuration with custom Context implementations. + * @return the instance manager + */ + public InstanceManager createInstanceManager(); + + /** * Factory method to create and return a new Wrapper instance, of * the Java implementation class appropriate for this Context * implementation. The constructor of the instantiated Wrapper diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 2753ff8..975b81e 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -5109,14 +5109,7 @@ public class StandardContext extends ContainerBase if (ok ) { if (getInstanceManager() == null) { - javax.naming.Context context = null; - if (isUseNaming() && getNamingContextListener() != null) { - context = getNamingContextListener().getEnvContext(); - } - Map<String, Map<String, String>> injectionMap = buildInjectionMap( - getIgnoreAnnotations() ? new NamingResourcesImpl(): getNamingResources()); - setInstanceManager(new DefaultInstanceManager(context, - injectionMap, this, this.getClass().getClassLoader())); + setInstanceManager(createInstanceManager()); } getServletContext().setAttribute( InstanceManager.class.getName(), getInstanceManager()); @@ -5248,6 +5241,18 @@ public class StandardContext extends ContainerBase } } + @Override + public InstanceManager createInstanceManager() { + javax.naming.Context context = null; + if (isUseNaming() && getNamingContextListener() != null) { + context = getNamingContextListener().getEnvContext(); + } + Map<String, Map<String, String>> injectionMap = buildInjectionMap( + getIgnoreAnnotations() ? new NamingResourcesImpl(): getNamingResources()); + return new DefaultInstanceManager(context, injectionMap, + this, this.getClass().getClassLoader()); + } + private Map<String, Map<String, String>> buildInjectionMap(NamingResourcesImpl namingResources) { Map<String, Map<String, String>> injectionMap = new HashMap<>(); for (Injectable resource: namingResources.findLocalEjbs()) { diff --git a/java/org/apache/catalina/startup/FailedContext.java b/java/org/apache/catalina/startup/FailedContext.java index 02f5847..39d7b8a 100644 --- a/java/org/apache/catalina/startup/FailedContext.java +++ b/java/org/apache/catalina/startup/FailedContext.java @@ -605,6 +605,9 @@ public class FailedContext extends LifecycleMBeanBase implements Context { public void removeWrapperListener(String listener) { /* NO-OP */ } @Override + public InstanceManager createInstanceManager() { return null; } + + @Override public Wrapper createWrapper() { return null; } @Override diff --git a/test/org/apache/tomcat/unittest/TesterContext.java b/test/org/apache/tomcat/unittest/TesterContext.java index 9725e76..c3e54ad 100644 --- a/test/org/apache/tomcat/unittest/TesterContext.java +++ b/test/org/apache/tomcat/unittest/TesterContext.java @@ -786,6 +786,11 @@ public class TesterContext implements Context { } @Override + public InstanceManager createInstanceManager() { + return null; + } + + @Override public Wrapper createWrapper() { return null; } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index a6979de..debf1bc 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -76,6 +76,10 @@ Avoid potential <code>NullPointerException</code> when generating an HTTP <code>Allow</code> header. Identified by Coverity Scan. (markt) </fix> + <scode> + Add <code>Context.createInstanceManager()</code> for easier framework + integration. (remm) + </scode> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org