Author: markt Date: Fri Feb 3 20:09:07 2012 New Revision: 1240329 URL: http://svn.apache.org/viewvc?rev=1240329&view=rev Log: Replace specific createXxx() methods with generic createValve. Has several benefits: Automatically supports new Valves as they are added, provides support for all current valves, removes some circular dependencies.
Modified: tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java Modified: tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java?rev=1240329&r1=1240328&r2=1240329&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java (original) +++ tomcat/trunk/java/org/apache/catalina/mbeans/MBeanFactory.java Fri Feb 3 20:09:07 2012 @@ -22,6 +22,7 @@ import java.io.File; import javax.management.MBeanServer; import javax.management.ObjectName; +import org.apache.catalina.Container; import org.apache.catalina.Context; import org.apache.catalina.Engine; import org.apache.catalina.Host; @@ -44,6 +45,7 @@ import org.apache.catalina.realm.UserDat import org.apache.catalina.session.StandardManager; import org.apache.catalina.startup.ContextConfig; import org.apache.catalina.startup.HostConfig; +import org.apache.catalina.util.LifecycleMBeanBase; import org.apache.catalina.valves.AccessLogValve; import org.apache.catalina.valves.RemoteAddrValve; import org.apache.catalina.valves.RemoteHostValve; @@ -235,7 +237,11 @@ public class MBeanFactory { * @param parent MBean Name of the associated parent component * * @exception Exception if an MBean cannot be created or registered + * + * @deprecated Will be removed in Tomcat 8.0.x. Replaced by {@link + * #createValve(String, String)}. */ + @Deprecated public String createAccessLoggerValve(String parent) throws Exception { @@ -467,7 +473,11 @@ public class MBeanFactory { * @param parent MBean Name of the associated parent component * * @exception Exception if an MBean cannot be created or registered + * + * @deprecated Will be removed in Tomcat 8.0.x. Replaced by {@link + * #createValve(String, String)}. */ + @Deprecated public String createRemoteAddrValve(String parent) throws Exception { @@ -490,7 +500,11 @@ public class MBeanFactory { * @param parent MBean Name of the associated parent component * * @exception Exception if an MBean cannot be created or registered + * + * @deprecated Will be removed in Tomcat 8.0.x. Replaced by {@link + * #createValve(String, String)}. */ + @Deprecated public String createRemoteHostValve(String parent) throws Exception { @@ -513,7 +527,12 @@ public class MBeanFactory { * @param parent MBean Name of the associated parent component * * @exception Exception if an MBean cannot be created or registered + * + * @deprecated Will be removed in Tomcat 8.0.x. Replaced by {@link + * #createValve(String, String)}. */ + @Deprecated + public String createSingleSignOn(String parent) throws Exception { @@ -759,6 +778,42 @@ public class MBeanFactory { /** + * Create a new Valve and associate it with a {@link Container}. + * + * @param className The fully qualified class name of the {@link Valve} to + * create + * @param parent The MBean name of the associated parent + * {@link Container}. + * + * @return The MBean name of the {@link Valve} that was created or + * <code>null</code> if the {@link Valve} does not implement + * {@link LifecycleMBeanBase}. + */ + public String createValve(String className, String parent) + throws Exception { + + // Look for the parent + ObjectName parentName = new ObjectName(parent); + Container container = getParentContainerFromParent(parentName); + + if (container == null) { + // TODO + throw new IllegalArgumentException(); + } + + Valve valve = (Valve) Class.forName(className).newInstance(); + + container.getPipeline().addValve(valve); + + if (valve instanceof LifecycleMBeanBase) { + return ((LifecycleMBeanBase) valve).getObjectName().toString(); + } else { + return null; + } + } + + + /** * Create a new Web Application Loader. * * @param parent MBean Name of the associated parent component --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org