From b3009af8d2f9e007afeace428eb6957ff569188a Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 5 Feb 2010 17:53:29 +0000 Subject: [PATCH] Remainder of Pipeline clean up. The Pipeline interface is now used in place of StandardPipeline throughout the code base. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@907018 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/CatalinaFactory.java | 52 ++++++++++++++++++++++++ java/org/apache/catalina/Pipeline.java | 21 ++++++++++ java/org/apache/catalina/core/ContainerBase.java | 8 ++-- java/org/apache/catalina/core/StandardHost.java | 29 ++++++------- 4 files changed, 88 insertions(+), 22 deletions(-) create mode 100644 java/org/apache/catalina/CatalinaFactory.java diff --git a/java/org/apache/catalina/CatalinaFactory.java b/java/org/apache/catalina/CatalinaFactory.java new file mode 100644 index 000000000..412c1b49e --- /dev/null +++ b/java/org/apache/catalina/CatalinaFactory.java @@ -0,0 +1,52 @@ +/* + * 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.catalina; + +import org.apache.catalina.core.StandardPipeline; + +/** + * Factory class used whenever a default implementation of a component is + * required. It provides both class names (for the digester) and objects for + * other components. The current implementation is as simple as possible. If + * there is demand it can be extended to support alternative factories and/or + * alternative defaults. + * + * TODO: Create the other standard components via this factory + */ +public class CatalinaFactory { + + private static CatalinaFactory factory = new CatalinaFactory(); + + public static CatalinaFactory getFactory() { + return factory; + } + + private CatalinaFactory() { + // Hide the default constructor + } + + public String getDefaultPipelineClassName() { + return StandardPipeline.class.getName(); + } + + public Pipeline createPipeline(Container container) { + Pipeline pipeline = new StandardPipeline(); + pipeline.setContainer(container); + return pipeline; + } +} diff --git a/java/org/apache/catalina/Pipeline.java b/java/org/apache/catalina/Pipeline.java index cfcf303d6..d863b810d 100644 --- a/java/org/apache/catalina/Pipeline.java +++ b/java/org/apache/catalina/Pipeline.java @@ -80,6 +80,10 @@ public interface Pipeline { * be associated with this Container, or IllegalStateException * if it is already associated with a different Container.

* + *

Implementation note: Implementations are expected to trigger the + * {@link Container#ADD_VALVE_EVENT} for the associated container if this + * call is successful.

+ * * @param valve Valve to be added * * @exception IllegalArgumentException if this Container refused to @@ -106,6 +110,10 @@ public interface Pipeline { * found and removed, the Valve's setContainer(null) method * will be called if it implements Contained. * + *

Implementation note: Implementations are expected to trigger the + * {@link Container#REMOVE_VALVE_EVENT} for the associated container if this + * call is successful.

+ * * @param valve Valve to be removed */ public void removeValve(Valve valve); @@ -124,4 +132,17 @@ public interface Pipeline { public boolean isAsyncSupported(); + /** + * Return the Container with which this Pipeline is associated. + */ + public Container getContainer(); + + + /** + * Set the Container with which this Pipeline is associated. + * + * @param container The new associated container + */ + public void setContainer(Container container); + } diff --git a/java/org/apache/catalina/core/ContainerBase.java b/java/org/apache/catalina/core/ContainerBase.java index ccab2ace5..3a5b0b292 100644 --- a/java/org/apache/catalina/core/ContainerBase.java +++ b/java/org/apache/catalina/core/ContainerBase.java @@ -36,6 +36,7 @@ import javax.management.ObjectName; import javax.naming.directory.DirContext; import javax.servlet.ServletException; +import org.apache.catalina.CatalinaFactory; import org.apache.catalina.Cluster; import org.apache.catalina.Container; import org.apache.catalina.ContainerEvent; @@ -229,7 +230,8 @@ public abstract class ContainerBase /** * The Pipeline object with which this Container is associated. */ - protected Pipeline pipeline = new StandardPipeline(this); + protected Pipeline pipeline = + CatalinaFactory.getFactory().createPipeline(this); /** @@ -1216,10 +1218,6 @@ public abstract class ContainerBase pipeline.addValve(valve); } - public ObjectName[] getValveObjectNames() { - return ((StandardPipeline)pipeline).getValveObjectNames(); - } - /** * Execute a periodic task, such as reloading, etc. This method will be diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java index 20e6ecb32..a343e6ed1 100644 --- a/java/org/apache/catalina/core/StandardHost.java +++ b/java/org/apache/catalina/core/StandardHost.java @@ -128,11 +128,6 @@ public class StandardHost "org.apache.catalina.valves.ErrorReportValve"; /** - * The object name for the errorReportValve. - */ - private ObjectName errorReportValveObjectName = null; - - /** * The descriptive information string for this implementation. */ private static final String info = @@ -742,19 +737,19 @@ public class StandardHost && (!errorReportValveClass.equals(""))) { try { boolean found = false; - if(errorReportValveObjectName != null) { - ObjectName[] names = - ((StandardPipeline)pipeline).getValveObjectNames(); - for (int i=0; !found && i