Author: markt Date: Mon May 26 14:46:22 2014 New Revision: 1597597 URL: http://svn.apache.org/r1597597 Log: Implement first part of pull request from Greg Wilkins to make Jasper more independent from Tomcat.
Added: tomcat/trunk/java/org/apache/tomcat/SimpleInstanceManager.java (with props) Modified: tomcat/trunk/java/org/apache/jasper/servlet/JasperInitializer.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/jasper/servlet/JasperInitializer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JasperInitializer.java?rev=1597597&r1=1597596&r2=1597597&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/servlet/JasperInitializer.java (original) +++ tomcat/trunk/java/org/apache/jasper/servlet/JasperInitializer.java Mon May 26 14:46:22 2014 @@ -31,6 +31,8 @@ import org.apache.jasper.runtime.JspFact import org.apache.jasper.security.SecurityClassLoad; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.InstanceManager; +import org.apache.tomcat.SimpleInstanceManager; import org.xml.sax.SAXException; /** @@ -79,6 +81,11 @@ public class JasperInitializer implement log.debug(Localizer.getMessage(MSG + ".onStartup", context.getServletContextName())); } + // Setup a simple default Instance Manager + if (context.getAttribute(InstanceManager.class.getName())==null) { + context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager()); + } + boolean validate = Boolean.parseBoolean( context.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM)); String blockExternalString = context.getInitParameter( Added: tomcat/trunk/java/org/apache/tomcat/SimpleInstanceManager.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/SimpleInstanceManager.java?rev=1597597&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/SimpleInstanceManager.java (added) +++ tomcat/trunk/java/org/apache/tomcat/SimpleInstanceManager.java Mon May 26 14:46:22 2014 @@ -0,0 +1,68 @@ +/* + * 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.apache.tomcat; + +import java.lang.reflect.InvocationTargetException; + +import javax.naming.NamingException; + +/** + * SimpleInstanceManager + * + * Implement the org.apache.tomcat.InstanceManager interface. + */ +public class SimpleInstanceManager implements InstanceManager { + + public SimpleInstanceManager() { + } + + @Override + public Object newInstance(Class<?> clazz) throws IllegalAccessException, + InvocationTargetException, NamingException, InstantiationException { + return prepareInstance(clazz.newInstance()); + } + + @Override + public Object newInstance(String className) throws IllegalAccessException, + InvocationTargetException, NamingException, InstantiationException, + ClassNotFoundException { + Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); + return prepareInstance(clazz.newInstance()); + } + + @Override + public Object newInstance(String fqcn, ClassLoader classLoader) throws IllegalAccessException, + InvocationTargetException, NamingException, InstantiationException, + ClassNotFoundException { + Class<?> clazz = classLoader.loadClass(fqcn); + return prepareInstance(clazz.newInstance()); + } + + @Override + public void newInstance(Object o) throws IllegalAccessException, InvocationTargetException, + NamingException { + prepareInstance(o); + } + + @Override + public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException { + } + + private Object prepareInstance(Object o) { + return o; + } +} \ No newline at end of file Propchange: tomcat/trunk/java/org/apache/tomcat/SimpleInstanceManager.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1597597&r1=1597596&r2=1597597&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon May 26 14:46:22 2014 @@ -133,6 +133,12 @@ <code>JasperInitializer</code> if one has already been set as might be the case in some embedding scenarios. (markt) </scode> + <add> + Add a simple implementation of <code>InstanceManager</code> and have + Jasper use it if no other <code>InstanceManager</code> is provided. This + makes it easier to use Jasper independently from Tomcat. Patch provided + by Greg Wilkins. (markt) + </add> </changelog> </subsection> <subsection name="WebSocket"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org